Download the free trial version
Basic4android Video
Features
Tutorials and manuals
Showcase
Screenshots

Go Back   Android Development Forum - Basic4android > Basic4ppc (Windows Mobile) > Questions (Windows Mobile)
Documentation Wiki Register Members List B4P Search Today's Posts Mark Forums Read

Questions (Windows Mobile) Post any question regarding Basic4ppc.

Convert data csv to sl3(SQLite)

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-24-2008, 04:12 PM
JJM JJM is offline
Senior Member
 
Join Date: Apr 2007
Location: France
Posts: 150
Default Convert data csv to sl3(SQLite)

Hello,
Could you help me?
I don't remember how to convert a CSV file to a sl3 file.

Best regards
JJM
Reply With Quote
  #2 (permalink)  
Old 12-24-2008, 04:43 PM
Erel's Avatar
Administrator
 
Join Date: Apr 2007
Posts: 15,726
Awards Showcase
Basic4ppc Founder 
Total Awards: 1
Default

You can load the data to a table with Table.LoadCSV and then create a new SQL table with Connection.CreateSQLTable.
You will need to first open the connection (with the new file name).
Reply With Quote
  #3 (permalink)  
Old 12-28-2008, 03:43 AM
Senior Member
 
Join Date: Mar 2008
Location: Dhaka, Bangladesh
Posts: 164
Default

I'm using the attached application for the same purpose.


regards,
Attached Files
File Type: sbp convert csv to sqlite.sbp (2.2 KB, 96 views)
Reply With Quote
  #4 (permalink)  
Old 12-29-2008, 08:57 PM
JJM JJM is offline
Senior Member
 
Join Date: Apr 2007
Location: France
Posts: 150
Default

Thank you for your help.

JJ M
Reply With Quote
  #5 (permalink)  
Old 03-19-2010, 10:09 AM
Junior Member
 
Join Date: Mar 2010
Posts: 13
Default

Is there a way to Update a whole table in the Database, with the actual loaded table? in your example, you create a new database, but what is, when i have an old database and want to update his data with a newly imported csv file? can i use only a "for->To construct" and Update? whats with new entry, in this updated file?

Update: I have found the way to Drop the table. but now i have another problem. i have imported a csv an converted this to sqlite successfully. but whats with the datatypes? the firts field MUST be unique /primary key/ autoincrement. how can i resolve this?

Last edited by bilbob : 03-19-2010 at 10:48 AM.
Reply With Quote
  #6 (permalink)  
Old 03-19-2010, 03:54 PM
Erel's Avatar
Administrator
 
Join Date: Apr 2007
Posts: 15,726
Awards Showcase
Basic4ppc Founder 
Total Awards: 1
Default

You can first create a temporary table with Connection.CreateSQLTable and then use an Insert with select to copy the data to the real table which you previously defined with the required constraints.
Reply With Quote
  #7 (permalink)  
Old 03-19-2010, 05:07 PM
Junior Member
 
Join Date: Mar 2010
Posts: 13
Default

When i try this, it work in parts. I get a new (temp)table, with the data from the table control. But all fieldtypes are in TEXT. After this i create a new (target) table with the needed field types. That works also. But when i copy the data from the (temp)table to the (target)table, i will get an error : „type missmatch“. I think this belongs to the different field types in both tables. but how can i convert the field types, espacialy from TEXT to INTEGER (PRIMARY KEY)?
Reply With Quote
  #8 (permalink)  
Old 03-19-2010, 08:55 PM
Erel's Avatar
Administrator
 
Join Date: Apr 2007
Posts: 15,726
Awards Showcase
Basic4ppc Founder 
Total Awards: 1
Default

Do you load your data from a CSV file? If yes, then first create the columns with the correct type (cNumbers) and only then load the data.
That way when you convert it to SQL it will create columns of type REAL in the db. You will still need to convert it to INTEGER which can be done with the CAST keyword (in your select query).
Reply With Quote
  #9 (permalink)  
Old 03-19-2010, 09:24 PM
Junior Member
 
Join Date: Mar 2010
Posts: 13
Default

i try it with:

Code:
Sub Test_Click
    Connection.Close
    Connection.Open(
"Data Source = " & AppPath & "\test.sqlite")
    
    Connection.BeginTransaction
    Command.CommandText=
"DROP table movies"
    Command.ExecuteNonQuery
    Connection.CreateSQLTable(
"ImportMovies","tmp_movies")
    Command.CommandText=
"INSERT INTO tmp_movies SELECT * FROM tmp_movies"
    Command.ExecuteNonQuery
    Command.CommandText = 
"CREATE TABLE movies (movie_id INTEGER PRIMARY KEY, movie_title TEXT, genre_id NUMERIC, format_id NUMERIC, movie_date NUMERIC, movie_modified NUMERIC, movie_copy TEXT, movie_place TEXT, movie_comment TEXT, movie_fsk TEXT, movie_length NUMERIC, movie_celebs TEXT, movie_regie TEXT, movie_description TEXT)"
    Command.ExecuteNonQuery
    Command.CommandText = 
"INSERT INTO movies SELECT * FROM tmp_movies"
    Command.ExecuteNonQuery
    Command.CommandText = 
"DROP TABLE tmp_movies"
    Command.ExecuteNonQuery
    Connection.EndTransaction
    
    
Msgbox("Database successfully created !")
End Sub
but this doesnt work :-( i dont know why, i will test your comments tomorrow... maybe you can correct my code, when you have the time...


PS: when i use the SQL statement in the SQL Browser (mozilla AddoN). it works like a charm, but not with Basic4PPC. In the mozillAddon, i put the SQL statement with ";" at the end... line for line

PPS: I get the error "constraint failed". hope this helps...

Last edited by bilbob : 03-20-2010 at 08:18 PM.
Reply With Quote
  #10 (permalink)  
Old 03-22-2010, 03:07 PM
Junior Member
 
Join Date: Mar 2010
Posts: 13
Default

Oh my god, im so stupid. i have the solution!!! I have added the records twice, so i get the arror with the constraints. i use now this code:

Code:
 Connection.Close
    Connection.Open(
"Data Source = " & AppPath & "\test.sqlite")
    Command.CommandText=
"DROP table If Exists test_movies"
    Command.ExecuteNonQuery
    Connection.CreateSQLTable(
"ImportTable","tmp_movies")
    Command.CommandText = 
"CREATE TABLE movies (movie_id INTEGER PRIMARY KEY, movie_title TEXT, genre_id NUMERIC, format_id NUMERIC, movie_date NUMERIC, movie_modified NUMERIC, movie_copy TEXT, movie_place TEXT, movie_comment TEXT, movie_fsk TEXT, movie_length NUMERIC, movie_celebs TEXT, movie_regie TEXT, movie_description TEXT)"
    Command.ExecuteNonQuery
    Command.CommandText = 
"INSERT INTO movies SELECT * FROM tmp_movies"
    Command.ExecuteNonQuery
    Command.CommandText = 
"DROP TABLE tmp_movies"
    Command.ExecuteNonQuery
    Command.CommandText = 
"VACUUM"
    Command.ExecuteNonQuery
    Connection.Close
this works. after the insert and convert, it cleans up the database...
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Fastest way to display SQLite data? RB Smissaert Questions (Windows Mobile) 11 12-06-2008 03:29 PM
help to convert a csv file to a sqlite table. mozaharul Questions (Windows Mobile) 3 11-23-2008 08:56 AM
Sqlite Data Sequence ceaser Questions (Windows Mobile) 2 07-29-2008 11:03 AM
Data collection from devices to Desktop using SQLite mozaharul Questions (Windows Mobile) 3 04-03-2008 10:00 AM
Convert Any Database to SQLite (source & exe) dzt Code Samples & Tips 6 02-28-2008 07:39 AM


All times are GMT. The time now is 03:33 AM.


Powered by vBulletin® Version 3.6.12
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0