I suck at writing C, so I can't help you there, but what you basically need to 
do is read the lines of text that consist of one record in to variables for 
each field. You then bind these to placeholders for the insert statements. 


<pseudo code>
open file
sql1 = prepare( "INSERT INTO myTABLE1 (field1, field2, field3) VALUES(?,?,?);")
sql2 = prepare( "INSERT INTO myTABLE2 (field4, field5, filed6) VALUES(?,?,?);")
sql3 = prepare("INSERT INTO myTABLE3 (field7, field8, filed9) VALUES(?,?,?);")

while text left in file
  read line into field1 variable
  read line into field2 variable
  read line into field3 variable
  read line into field4 variable
  read line into field5 variable
  read line into field6 variable
  read line into field7 variable
  read line into field8 variable
  read line into field9 variable

  sqlite3_bind(sql1,1,field1)
  sqlite3_bind(sql1,2,field2)
  sqlite3_bind(sql1,3,field3)
  sqlite3_bind(sql2,1,field4)
  sqlite3_bind(sql2,2,field5)
  sqlite3_bind(sql2,3,field6)
  sqlite3_bind(sql3,1,field7)
  sqlite3_bind(sql3,2,field8)
  sqlite3_bind(sql3,3,field9)

  sqlite3_step(sql1)
  sqlite3_step(sql2)
  sqlite3_step(sql3)
  sqlite3_reset(sql1)
  sqlite3_reset(sql2)
  sqlite3_reset(sql3)
loop
close file
sqlite3_finalize(sql1)
sqlite3_finalize(sql2)
sqlite3_finalize(sql3)


I suspect in reality, the fifth line probably needs to be broken in to 4 
values, each of which goes in to an author table or the like. 

Without knowing how the text maps to the fields you want to store, this is the 
best pseudo code I can give you.

Hopefully it helps,
David

--- On Thu, 12/9/10, yazdan asgari <yazda...@yahoo.com> wrote:

> From: yazdan asgari <yazda...@yahoo.com>
> Subject: Re: [sqlite] Reading a text file and insert to sqlite tables
> To: "General Discussion of SQLite Database" <sqlite-users@sqlite.org>
> Date: Thursday, December 9, 2010, 12:13 PM
> Hi
> I use C Programming Language and I also know that I could
> use INSERT command. But my problem is whether any one could
> show me a simple code which demonstrate how an INSERT
> command should be written during reading a text file. I have
> searched Google but I could not find any useful link.  
> Yazdan
> 
> --- On Thu, 12/9/10, Simon Slavin <slav...@bigfraud.org>
> wrote:
> 
> From: Simon Slavin <slav...@bigfraud.org>
> Subject: Re: [sqlite] Reading a text file and insert to
> sqlite tables
> To: "General Discussion of SQLite Database" <sqlite-users@sqlite.org>
> Date: Thursday, December 9, 2010, 2:57 AM
> 
> 
> On 9 Dec 2010, at 9:58am, yazdan asgari wrote:
> 
> > I want to write a program in order to insert data to a
> sqlite database from a text file. The text file contains
> data in each line as below which repeats about 200 lines:
> > 
> > P05075
> > 01-JAN-1988
> > 16
> > TOBACCO RATTLE VIRUS (STRAIN PSG).
> > CORNELISSEN B.J.C., LINTHORST H.J.M., BREDERODE F.T.,
> BOL J.F.;
> > NUCL. ACIDS RES. 14:2157-2169(1986).
> > 141
> > 16297
> > 93420
> >
> MTCVLKGCVNEVTVLGHETCSIGHANKLRKQVADMVGVTRRCAENNCGWFVCIIINDFTFDVYNCCGRSHLEKCRKRVEARNREIWKQIRRIQAESSSATRKKSHNSKNSKKKFKEDREFGAPKRFLRDDVPLGIDQLFVF
> > ...
> > 
> > 
> > I want to read this file and insert each line into a
> value of a database (database contains 3 tables). I can
> write a code to read text file but I do not know how to
> insert these data to sqlite tables during reading process.
> Could any one suggest me a simple program to do this?
> 
> Just use the INSERT command, which is part of the SQL
> standard.
> 
> http://www.sqlite.org/lang_insert.html
> 
> How to access SQLite from your programming language depends
> on what programming language you're using.  If Google
> doesn't find anything helpful for you, tell us what language
> you're using and we might be able to help.
> 
> However, if you are doing this once only, to get your
> database started, it will be simpler to convert your text
> file to .csv format, and use the SQLite command-line tool to
> make a table out of it.
> 
> http://www.sqlite.org/sqlite.html
> 
> Simon.
> _______________________________________________
> sqlite-users mailing list
> sqlite-users@sqlite.org
> http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
> 
> 
> 
>       
> _______________________________________________
> sqlite-users mailing list
> sqlite-users@sqlite.org
> http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
> 
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to