Re: [sqlite] Basic Text Bind Question
Thanks Dan! Works like a charm now. On 6/7/05, Kiel W. <[EMAIL PROTECTED]> wrote: > > Ok, thanks for the responses. > > --Ulrik > >I think it stops right here, because you've got fname twice. That > >induces an error. > > You are correct, I'm not sure when I introduced that error, but thanks for > pointing it out. Its not in my running code so it was either C/P error or > something else dumb. > > -- Dr. H & Ted > Ok, I see what you guys are saying. I split my code up so I create and > populate the database with another set of sqlite3_exec() statements. I > confirmed the database is populated with the following results: > > $ ./sqlite3 test.db > SQLite version 3.2.1 > Enter ".help" for instructions > sqlite> select * from People; > fname|lname > John|Fullman > Mike|Fullman > Mike|Smith > > My select code is as follows: > > sqlite3_open( "test.db", ); > > size = sprintf( buf, "SELECT * FROM People WHERE lname = '?'" ); > > iPrep = sqlite3_prepare( database, buf, size, , 0 ); > > sqlite3_bind_text(statement, 1, "Fullman", 7, SQLITE_STATIC ); > > rc = sqlite3_step(statement); > std::cout << rc << " " << SQLITE_DONE; > > I would expect rc to be SQLITE_ROW, but it is SQLITE_DONE. I undertand > with getting multiple row back I will need to loop the sqlite3_step function > later. > > > -- > Kiel W. > [EMAIL PROTECTED] > -- > >> time is swift << > -- Kiel W. [EMAIL PROTECTED] -- >> time is swift <<
Re: [sqlite] Basic Text Bind Question
Ok, thanks for the responses. --Ulrik >I think it stops right here, because you've got fname twice. That >induces an error. You are correct, I'm not sure when I introduced that error, but thanks for pointing it out. Its not in my running code so it was either C/P error or something else dumb. -- Dr. H & Ted Ok, I see what you guys are saying. I split my code up so I create and populate the database with another set of sqlite3_exec() statements. I confirmed the database is populated with the following results: $ ./sqlite3 test.db SQLite version 3.2.1 Enter ".help" for instructions sqlite> select * from People; fname|lname John|Fullman Mike|Fullman Mike|Smith My select code is as follows: sqlite3_open( "test.db", ); size = sprintf( buf, "SELECT * FROM People WHERE lname = '?'" ); iPrep = sqlite3_prepare( database, buf, size, , 0 ); sqlite3_bind_text(statement, 1, "Fullman", 7, SQLITE_STATIC ); rc = sqlite3_step(statement); std::cout << rc << " " << SQLITE_DONE; I would expect rc to be SQLITE_ROW, but it is SQLITE_DONE. I undertand with getting multiple row back I will need to loop the sqlite3_step function later. -- Kiel W. [EMAIL PROTECTED] -- >> time is swift <<
Re: [sqlite] Basic Text Bind Question
> size = sprintf( buf, "SELECT * FROM People WHERE lname = '?'" ); ^^^ > rc = sqlite3_prepare( database, buf, -1, , 0 ); > sqlite3_bind_text(statement, 1, "Fullman", 7, SQLITE_STATIC ); > rc = sqlite3_step(statement); As others have pointed out, unless you omitted some code for clarity, the SELECT is never being executed. But after you get that fixed up, you also need to leave out the quotes around the question mark. With the quotes in, this is a literal question mark, not an SQL variable. Replace the SQL you have with: "SELECT * FROM People WHERE lname = ?" __ Discover Yahoo! Use Yahoo! to plan a weekend, have fun online and more. Check it out! http://discover.yahoo.com/
Re: [sqlite] Basic Text Bind Question
Kiel W. wrote: size = sprintf( buf, "CREATE TABLE People( fname varchar(25), fname varchar(25) );" ); size = sprintf( buf, "INSERT INTO People VALUES( 'John', 'Fullman' );" ); size = sprintf( buf, "INSERT INTO People VALUES( 'Sally', 'Fullman' );" ); size = sprintf( buf, "INSERT INTO People VALUES( 'Mike', 'Smith' );" ); size = sprintf( buf, "SELECT * FROM People WHERE lname = '?'" ); unless you deleted the code between the sprintf lines, this isn't doing what you think it is. -- Ted Unangst www.coverity.com Coverity, Inc.
Re: [sqlite] Basic Text Bind Question
On Tue, 2005-06-07 at 16:53 -0700, Kiel W. wrote: > size = sprintf( buf, "CREATE TABLE People( fname varchar(25), fname > varchar(25) );" ); > rc = sqlite3_prepare( database, buf, -1, , 0 ); > sqlite3_prepare only processes the first statement in your list of SQL statements. It then returns a pointer to the beginning of the second statement so that you can process them all in a loop. But your code appears to omit this loop and thus is processing only the first one. It never reaches the SELECT. -- D. Richard Hipp <[EMAIL PROTECTED]>
Re: [sqlite] Basic Text Bind Question
Hi, Kiel W. wrote: Could someone point out what I missing or not understanding on this? I'm trying to do a simple text bind to search for people with the last name "Fullman". However my return code (rc) from sqlite3_step() is the same as SQLITE_DONE. I'm assuming this means it doesn't find anything. Also, how do I pull the character string of the sqlite statement to be executed from 'sqlite3_stmt' ? Thanks for the hand. -- code snipet -- sqlite3_open( "test.db", ); size = sprintf( buf, "CREATE TABLE People( fname varchar(25), fname varchar(25) );" ); I think it stops right here, because you've got fname twice. That induces an error. Also, I'd execute each statement by itself. HTH Ulrik Petersen -- Ulrik Petersen, PhD student, MA, B.Sc. University of Aalborg, Denmark
[sqlite] Basic Text Bind Question
Could someone point out what I missing or not understanding on this? I'm trying to do a simple text bind to search for people with the last name "Fullman". However my return code (rc) from sqlite3_step() is the same as SQLITE_DONE. I'm assuming this means it doesn't find anything. Also, how do I pull the character string of the sqlite statement to be executed from 'sqlite3_stmt' ? Thanks for the hand. -- code snipet -- sqlite3_open( "test.db", ); size = sprintf( buf, "CREATE TABLE People( fname varchar(25), fname varchar(25) );" ); size = sprintf( buf, "INSERT INTO People VALUES( 'John', 'Fullman' );" ); size = sprintf( buf, "INSERT INTO People VALUES( 'Sally', 'Fullman' );" ); size = sprintf( buf, "INSERT INTO People VALUES( 'Mike', 'Smith' );" ); size = sprintf( buf, "SELECT * FROM People WHERE lname = '?'" ); rc = sqlite3_prepare( database, buf, -1, , 0 ); sqlite3_bind_text(statement, 1, "Fullman", 7, SQLITE_STATIC ); rc = sqlite3_step(statement); std::cout << rc << " " << SQLITE_DONE; // rc == SQLITE_DONE at this point --- end code --- -- Kiel W. [EMAIL PROTECTED] -- >> time is swift <<