Re[4]: [sqlite] A lillte help adding sqlite to a c program
Hello Lloyd, I gave you the answer, you just don't want to use it. Generating SQL this way is painful, messy and error prone. SQLite already has a far better mechanism for doing it using late binding of the parameters. How about learning the right way to do this? I'll give you a hint though sql += "','"; sql += "details.statime"; sql += "','"; ... should work You could do it with sprintf too and/or some IO stream thing but, I never use them. Conrad Saturday, September 9, 2006, 9:41:01 PM, you wrote: LT> if I could somehow create the following string as a char i cpuld probably LT> get the code to work. LT> sql = "insert into call_data (direction, call_time, dest, LT> trunk_no, file_name)values('"; LT> sql += details.inout; LT> sql += "','"; LT> sql += details.statime; LT> sql += "','"; LT> sql += details.cidn; LT> sql += "'"; LT> sql +=details.channel; LT> sql += "','"; LT> sql += details.filename; LT> sql += "')"; LT> I am getting stuck adding exist chars to the sql char LT>defined chars LT> ^^ LT> sql = "insert into call_data(direction, LT> call_time)values('details.inout','details.statime)" LT> Do you have any ideas? LT> Lloydie T LT> - Original Message - LT> From: "Teg" <[EMAIL PROTECTED]> LT> To: "Lloyd Thomas"LT> Sent: Sunday, September 10, 2006 12:47 AM LT> Subject: Re[2]: [sqlite] A lillte help adding sqlite to a c program >> Hello Lloyd, >> >> You need to escape the quotes. Remember in C and C++ " means the >> beginning or end of a literal string so, when you want to embed quotes >> in a string you have to escape them. Probaby \". >> >> You'd be better off using the paramaterized version of the SQL >> >> std::string sql = "insert into call_data (direction, call_time, dest, >> trunk_no, >> file_name)values(?,?,?,?,?);"; >> >> Then bind the actual parameters after the fact. >> >> C >> >> >> Saturday, September 9, 2006, 7:02:43 PM, you wrote: >> >> LT> Jay, Thanks for your reply. >> LT> I gave it a try with and got a few errors. as follows >> LT> --- >> LT> logger.cpp:609: error: invalid operands of types `const char[80]' and >> LT> `char[4]' to binary `operator+' >> LT> logger.cpp:615: error: `t' was not declared in this scope >> LT> logger.cpp:615: warning: unused variable 't' >> LT> logger.cpp:634: error: jump to case label >> LT> logger.cpp:631: error: crosses initialization of `std::string test2' >> LT> logger.cpp:628: error: crosses initialization of `std::string test1' >> LT> logger.cpp:637: error: jump to case label >> LT> logger.cpp:631: error: crosses initialization of `std::string test2' >> LT> logger.cpp:628: error: crosses initialization of `std::string test1' >> LT> logger.cpp:638: error: jump to case label >> LT> logger.cpp:631: error: crosses initialization of `std::string test2' >> LT> logger.cpp:628: error: crosses initialization of `std::string test1' >> LT> logger.cpp:639: error: jump to case label >> LT> logger.cpp:631: error: crosses initialization of `std::string test2' >> LT> logger.cpp:628: error: crosses initialization of `std::string test1' >> LT> logger.cpp:641: error: `t' was not declared in this scope >> LT> logger.cpp:641: warning: unused variable 't' >> LT> logger.cpp:664: error: jump to case label >> LT> logger.cpp:621: error: crosses initialization of `bool Loop' >> LT> logger.cpp:634: warning: destructor needed for `test2' >> LT> logger.cpp:634: warning: where case label appears here >> LT> logger.cpp:634: warning: (enclose actions of previous case statements >> LT> requiring destructors in their own scope.) >> LT> logger.cpp:637: warning: destructor needed for `test2' >> LT> logger.cpp:637: warning: where case label appears here >> LT> logger.cpp:638: warning: destructor needed for `test2' >> LT> logger.cpp:638: warning: where case label appears here >> LT> logger.cpp:639: warning: destructor needed for `test2' >> LT> logger.cpp:639: warning: where case label appears here >> LT> make: *** [logger.o] Error 1 >> LT> -- >> LT> line 609 = >> LT> sql = "insert into call_data (direction, call_time, dest, trunk_no, >> LT> >> file_name)values('"+details.inout+"','"+details.statime+"','"+details.cidn+"'"+details.channel+"','"+details.filename+"')"; >> >> >> >> >> >> >> LT> - Original Message - >> LT> From: "Jay Sprenkle" <[EMAIL PROTECTED]> >> LT> To: >> LT> Sent: Saturday, September 09, 2006 11:16 PM >> LT> Subject: Re: [sqlite] A lillte help adding sqlite to a c program >> >> On 9/9/06, Lloyd Thomas <[EMAIL
Re: Re[2]: [sqlite] A lillte help adding sqlite to a c program
if I could somehow create the following string as a char i cpuld probably get the code to work. sql = "insert into call_data (direction, call_time, dest, trunk_no, file_name)values('"; sql += details.inout; sql += "','"; sql += details.statime; sql += "','"; sql += details.cidn; sql += "'"; sql +=details.channel; sql += "','"; sql += details.filename; sql += "')"; I am getting stuck adding exist chars to the sql char defined chars ^^ sql = "insert into call_data(direction, call_time)values('details.inout','details.statime)" Do you have any ideas? Lloydie T - Original Message - From: "Teg" <[EMAIL PROTECTED]> To: "Lloyd Thomas"Sent: Sunday, September 10, 2006 12:47 AM Subject: Re[2]: [sqlite] A lillte help adding sqlite to a c program Hello Lloyd, You need to escape the quotes. Remember in C and C++ " means the beginning or end of a literal string so, when you want to embed quotes in a string you have to escape them. Probaby \". You'd be better off using the paramaterized version of the SQL std::string sql = "insert into call_data (direction, call_time, dest, trunk_no, file_name)values(?,?,?,?,?);"; Then bind the actual parameters after the fact. C Saturday, September 9, 2006, 7:02:43 PM, you wrote: LT> Jay, Thanks for your reply. LT> I gave it a try with and got a few errors. as follows LT> --- LT> logger.cpp:609: error: invalid operands of types `const char[80]' and LT> `char[4]' to binary `operator+' LT> logger.cpp:615: error: `t' was not declared in this scope LT> logger.cpp:615: warning: unused variable 't' LT> logger.cpp:634: error: jump to case label LT> logger.cpp:631: error: crosses initialization of `std::string test2' LT> logger.cpp:628: error: crosses initialization of `std::string test1' LT> logger.cpp:637: error: jump to case label LT> logger.cpp:631: error: crosses initialization of `std::string test2' LT> logger.cpp:628: error: crosses initialization of `std::string test1' LT> logger.cpp:638: error: jump to case label LT> logger.cpp:631: error: crosses initialization of `std::string test2' LT> logger.cpp:628: error: crosses initialization of `std::string test1' LT> logger.cpp:639: error: jump to case label LT> logger.cpp:631: error: crosses initialization of `std::string test2' LT> logger.cpp:628: error: crosses initialization of `std::string test1' LT> logger.cpp:641: error: `t' was not declared in this scope LT> logger.cpp:641: warning: unused variable 't' LT> logger.cpp:664: error: jump to case label LT> logger.cpp:621: error: crosses initialization of `bool Loop' LT> logger.cpp:634: warning: destructor needed for `test2' LT> logger.cpp:634: warning: where case label appears here LT> logger.cpp:634: warning: (enclose actions of previous case statements LT> requiring destructors in their own scope.) LT> logger.cpp:637: warning: destructor needed for `test2' LT> logger.cpp:637: warning: where case label appears here LT> logger.cpp:638: warning: destructor needed for `test2' LT> logger.cpp:638: warning: where case label appears here LT> logger.cpp:639: warning: destructor needed for `test2' LT> logger.cpp:639: warning: where case label appears here LT> make: *** [logger.o] Error 1 LT> -- LT> line 609 = LT> sql = "insert into call_data (direction, call_time, dest, trunk_no, LT> file_name)values('"+details.inout+"','"+details.statime+"','"+details.cidn+"'"+details.channel+"','"+details.filename+"')"; LT> - Original Message - LT> From: "Jay Sprenkle" <[EMAIL PROTECTED]> LT> To: LT> Sent: Saturday, September 09, 2006 11:16 PM LT> Subject: Re: [sqlite] A lillte help adding sqlite to a c program On 9/9/06, Lloyd Thomas <[EMAIL PROTECTED]> wrote: I know nothing of C++ and therefore need a lilte help editing a C++ app to insert some records into a database. here's an example to read from a database. If you build the sql like you're doing and you use it on the web you leave yourself open to sql injection attacks. Using the bind() method eliminates that vulnerability. Something to consider. Jay Here's some example code: sqlite3*db; // connect to database if ( sqlite3_open( "test.db", ) ) throw "Can't open database"; char* sql; sql = "SELECT one.test1, two.test2" " FROM one" " INNER JOIN two ON one.id = two.id" ; sqlite3_stmt* pStmt; if ( sqlite3_prepare( db, sql, strlen(sql), , NULL ) != SQLITE_OK ) { string str = "Cannot prepare sql: "; str += sql[t]; str += ", Error: "; str += sqlite3_errmsg(db); throw str.c_str();
Re[2]: [sqlite] A lillte help adding sqlite to a c program
Hello Lloyd, You need to escape the quotes. Remember in C and C++ " means the beginning or end of a literal string so, when you want to embed quotes in a string you have to escape them. Probaby \". You'd be better off using the paramaterized version of the SQL std::string sql = "insert into call_data (direction, call_time, dest, trunk_no, file_name)values(?,?,?,?,?);"; Then bind the actual parameters after the fact. C Saturday, September 9, 2006, 7:02:43 PM, you wrote: LT> Jay, Thanks for your reply. LT> I gave it a try with and got a few errors. as follows LT> --- LT> logger.cpp:609: error: invalid operands of types `const char[80]' and LT> `char[4]' to binary `operator+' LT> logger.cpp:615: error: `t' was not declared in this scope LT> logger.cpp:615: warning: unused variable 't' LT> logger.cpp:634: error: jump to case label LT> logger.cpp:631: error: crosses initialization of `std::string test2' LT> logger.cpp:628: error: crosses initialization of `std::string test1' LT> logger.cpp:637: error: jump to case label LT> logger.cpp:631: error: crosses initialization of `std::string test2' LT> logger.cpp:628: error: crosses initialization of `std::string test1' LT> logger.cpp:638: error: jump to case label LT> logger.cpp:631: error: crosses initialization of `std::string test2' LT> logger.cpp:628: error: crosses initialization of `std::string test1' LT> logger.cpp:639: error: jump to case label LT> logger.cpp:631: error: crosses initialization of `std::string test2' LT> logger.cpp:628: error: crosses initialization of `std::string test1' LT> logger.cpp:641: error: `t' was not declared in this scope LT> logger.cpp:641: warning: unused variable 't' LT> logger.cpp:664: error: jump to case label LT> logger.cpp:621: error: crosses initialization of `bool Loop' LT> logger.cpp:634: warning: destructor needed for `test2' LT> logger.cpp:634: warning: where case label appears here LT> logger.cpp:634: warning: (enclose actions of previous case statements LT> requiring destructors in their own scope.) LT> logger.cpp:637: warning: destructor needed for `test2' LT> logger.cpp:637: warning: where case label appears here LT> logger.cpp:638: warning: destructor needed for `test2' LT> logger.cpp:638: warning: where case label appears here LT> logger.cpp:639: warning: destructor needed for `test2' LT> logger.cpp:639: warning: where case label appears here LT> make: *** [logger.o] Error 1 LT> -- LT> line 609 = LT> sql = "insert into call_data (direction, call_time, dest, trunk_no, LT> file_name)values('"+details.inout+"','"+details.statime+"','"+details.cidn+"'"+details.channel+"','"+details.filename+"')"; LT> - Original Message - LT> From: "Jay Sprenkle" <[EMAIL PROTECTED]> LT> To:LT> Sent: Saturday, September 09, 2006 11:16 PM LT> Subject: Re: [sqlite] A lillte help adding sqlite to a c program >> On 9/9/06, Lloyd Thomas <[EMAIL PROTECTED]> wrote: >>> I know nothing of C++ and therefore need a lilte help editing a C++ app >>> to >>> insert some records into a database. >> >> here's an example to read from a database. >> If you build the sql like you're doing and you use it on the web you >> leave yourself >> open to sql injection attacks. Using the bind() method eliminates that >> vulnerability. >> Something to consider. >> >> Jay >> >> >> Here's some example code: >> >> sqlite3*db; >> >> // connect to database >> if ( sqlite3_open( "test.db", ) ) >> throw "Can't open database"; >> >> char* sql; >> >> sql = "SELECT one.test1, two.test2" >> " FROM one" >> " INNER JOIN two ON one.id = two.id" >> ; >> sqlite3_stmt* pStmt; >> >> if ( sqlite3_prepare( db, sql, strlen(sql), , NULL ) != SQLITE_OK ) >> { >> string str = "Cannot prepare sql: "; >> str += sql[t]; >> str += ", Error: "; >> str += sqlite3_errmsg(db); >> throw str.c_str(); >> } >> >> bool Loop = true; >> while ( Loop ) >> switch ( sqlite3_step( pStmt ) ) >> { >>case SQLITE_ROW: >> // retrieve the results >> char* p = (char *) sqlite3_column_text( pStmt, 0 ); >> string test1 = string( p ? p : "" ); >> >> p = (char *) sqlite3_column_text( pStmt, 1 ); >> string test2 = string( p ? p : "" ); >> >> break; >>case SQLITE_DONE: >> Loop = false; >> break; >>case SQLITE_BUSY: >>case SQLITE_LOCKED: >>default: >> string str = "Cannot execute sql: "; >> str += sql[t]; >> str += ", Error: "; >> str += sqlite3_errmsg(db); >> throw str.c_str(); >> break; >> } >> >> // clean up when finished >> sqlite3_finalize( pStmt ); >> >> sqlite3_close( db ); >> >> >> >> -- >> SqliteImporter and SqliteReplicator: Command line utilities for Sqlite >> http://www.reddawn.net/~jsprenkl/Sqlite
Re: [sqlite] A lillte help adding sqlite to a c program
I don't know how to work string types in c++, but it looks like you need to initialize an integer t=0, or replace sql[t] with sql[0] perhaps? /m Lloyd Thomas wrote: Jay, Thanks for your reply. I gave it a try with and got a few errors. as follows --- logger.cpp:609: error: invalid operands of types `const char[80]' and `char[4]' to binary `operator+' logger.cpp:615: error: `t' was not declared in this scope logger.cpp:615: warning: unused variable 't' logger.cpp:634: error: jump to case label logger.cpp:631: error: crosses initialization of `std::string test2' logger.cpp:628: error: crosses initialization of `std::string test1' logger.cpp:637: error: jump to case label logger.cpp:631: error: crosses initialization of `std::string test2' logger.cpp:628: error: crosses initialization of `std::string test1' logger.cpp:638: error: jump to case label logger.cpp:631: error: crosses initialization of `std::string test2' logger.cpp:628: error: crosses initialization of `std::string test1' logger.cpp:639: error: jump to case label logger.cpp:631: error: crosses initialization of `std::string test2' logger.cpp:628: error: crosses initialization of `std::string test1' logger.cpp:641: error: `t' was not declared in this scope logger.cpp:641: warning: unused variable 't' logger.cpp:664: error: jump to case label logger.cpp:621: error: crosses initialization of `bool Loop' logger.cpp:634: warning: destructor needed for `test2' logger.cpp:634: warning: where case label appears here logger.cpp:634: warning: (enclose actions of previous case statements requiring destructors in their own scope.) logger.cpp:637: warning: destructor needed for `test2' logger.cpp:637: warning: where case label appears here logger.cpp:638: warning: destructor needed for `test2' logger.cpp:638: warning: where case label appears here logger.cpp:639: warning: destructor needed for `test2' logger.cpp:639: warning: where case label appears here make: *** [logger.o] Error 1 -- line 609 = sql = "insert into call_data (direction, call_time, dest, trunk_no, file_name)values('"+details.inout+"','"+details.statime+"','"+details.cidn+"'"+details.channel+"','"+details.filename+"')"; - Original Message - From: "Jay Sprenkle" <[EMAIL PROTECTED]> To:Sent: Saturday, September 09, 2006 11:16 PM Subject: Re: [sqlite] A lillte help adding sqlite to a c program On 9/9/06, Lloyd Thomas <[EMAIL PROTECTED]> wrote: I know nothing of C++ and therefore need a lilte help editing a C++ app to insert some records into a database. here's an example to read from a database. If you build the sql like you're doing and you use it on the web you leave yourself open to sql injection attacks. Using the bind() method eliminates that vulnerability. Something to consider. Jay Here's some example code: sqlite3*db; // connect to database if ( sqlite3_open( "test.db", ) ) throw "Can't open database"; char* sql; sql = "SELECT one.test1, two.test2" " FROM one" " INNER JOIN two ON one.id = two.id" ; sqlite3_stmt* pStmt; if ( sqlite3_prepare( db, sql, strlen(sql), , NULL ) != SQLITE_OK ) { string str = "Cannot prepare sql: "; str += sql[t]; str += ", Error: "; str += sqlite3_errmsg(db); throw str.c_str(); } bool Loop = true; while ( Loop ) switch ( sqlite3_step( pStmt ) ) { case SQLITE_ROW: // retrieve the results char* p = (char *) sqlite3_column_text( pStmt, 0 ); string test1 = string( p ? p : "" ); p = (char *) sqlite3_column_text( pStmt, 1 ); string test2 = string( p ? p : "" ); break; case SQLITE_DONE: Loop = false; break; case SQLITE_BUSY: case SQLITE_LOCKED: default: string str = "Cannot execute sql: "; str += sql[t]; str += ", Error: "; str += sqlite3_errmsg(db); throw str.c_str(); break; } // clean up when finished sqlite3_finalize( pStmt ); sqlite3_close( db ); -- SqliteImporter and SqliteReplicator: Command line utilities for Sqlite http://www.reddawn.net/~jsprenkl/Sqlite Cthulhu Bucks! http://www.cthulhubucks.com - To unsubscribe, send email to [EMAIL PROTECTED] - - To unsubscribe, send email to [EMAIL PROTECTED] - - To unsubscribe, send email to [EMAIL PROTECTED] -
Re: [sqlite] A lillte help adding sqlite to a c program
Jay, Thanks for your reply. I gave it a try with and got a few errors. as follows --- logger.cpp:609: error: invalid operands of types `const char[80]' and `char[4]' to binary `operator+' logger.cpp:615: error: `t' was not declared in this scope logger.cpp:615: warning: unused variable 't' logger.cpp:634: error: jump to case label logger.cpp:631: error: crosses initialization of `std::string test2' logger.cpp:628: error: crosses initialization of `std::string test1' logger.cpp:637: error: jump to case label logger.cpp:631: error: crosses initialization of `std::string test2' logger.cpp:628: error: crosses initialization of `std::string test1' logger.cpp:638: error: jump to case label logger.cpp:631: error: crosses initialization of `std::string test2' logger.cpp:628: error: crosses initialization of `std::string test1' logger.cpp:639: error: jump to case label logger.cpp:631: error: crosses initialization of `std::string test2' logger.cpp:628: error: crosses initialization of `std::string test1' logger.cpp:641: error: `t' was not declared in this scope logger.cpp:641: warning: unused variable 't' logger.cpp:664: error: jump to case label logger.cpp:621: error: crosses initialization of `bool Loop' logger.cpp:634: warning: destructor needed for `test2' logger.cpp:634: warning: where case label appears here logger.cpp:634: warning: (enclose actions of previous case statements requiring destructors in their own scope.) logger.cpp:637: warning: destructor needed for `test2' logger.cpp:637: warning: where case label appears here logger.cpp:638: warning: destructor needed for `test2' logger.cpp:638: warning: where case label appears here logger.cpp:639: warning: destructor needed for `test2' logger.cpp:639: warning: where case label appears here make: *** [logger.o] Error 1 -- line 609 = sql = "insert into call_data (direction, call_time, dest, trunk_no, file_name)values('"+details.inout+"','"+details.statime+"','"+details.cidn+"'"+details.channel+"','"+details.filename+"')"; - Original Message - From: "Jay Sprenkle" <[EMAIL PROTECTED]> To:Sent: Saturday, September 09, 2006 11:16 PM Subject: Re: [sqlite] A lillte help adding sqlite to a c program On 9/9/06, Lloyd Thomas <[EMAIL PROTECTED]> wrote: I know nothing of C++ and therefore need a lilte help editing a C++ app to insert some records into a database. here's an example to read from a database. If you build the sql like you're doing and you use it on the web you leave yourself open to sql injection attacks. Using the bind() method eliminates that vulnerability. Something to consider. Jay Here's some example code: sqlite3*db; // connect to database if ( sqlite3_open( "test.db", ) ) throw "Can't open database"; char* sql; sql = "SELECT one.test1, two.test2" " FROM one" " INNER JOIN two ON one.id = two.id" ; sqlite3_stmt* pStmt; if ( sqlite3_prepare( db, sql, strlen(sql), , NULL ) != SQLITE_OK ) { string str = "Cannot prepare sql: "; str += sql[t]; str += ", Error: "; str += sqlite3_errmsg(db); throw str.c_str(); } bool Loop = true; while ( Loop ) switch ( sqlite3_step( pStmt ) ) { case SQLITE_ROW: // retrieve the results char* p = (char *) sqlite3_column_text( pStmt, 0 ); string test1 = string( p ? p : "" ); p = (char *) sqlite3_column_text( pStmt, 1 ); string test2 = string( p ? p : "" ); break; case SQLITE_DONE: Loop = false; break; case SQLITE_BUSY: case SQLITE_LOCKED: default: string str = "Cannot execute sql: "; str += sql[t]; str += ", Error: "; str += sqlite3_errmsg(db); throw str.c_str(); break; } // clean up when finished sqlite3_finalize( pStmt ); sqlite3_close( db ); -- SqliteImporter and SqliteReplicator: Command line utilities for Sqlite http://www.reddawn.net/~jsprenkl/Sqlite Cthulhu Bucks! http://www.cthulhubucks.com - To unsubscribe, send email to [EMAIL PROTECTED] - - To unsubscribe, send email to [EMAIL PROTECTED] -
Re: [sqlite] Reg number of tables.
On 9/8/06, chetana bhargav <[EMAIL PROTECTED]> wrote: Hi, I wanted to know will there be any performance impact if the number of tables in a DB grow. I am planning to have around 8-9 tables in a single DB, so want to make sure does it have any affect. Is there any number for optimal usage. Apart from tables we may have indexes (of course not on all tables) and some triggers. That should be no problem. - To unsubscribe, send email to [EMAIL PROTECTED] -
Re: [sqlite] A lillte help adding sqlite to a c program
On 9/9/06, Lloyd Thomas <[EMAIL PROTECTED]> wrote: I know nothing of C++ and therefore need a lilte help editing a C++ app to insert some records into a database. here's an example to read from a database. If you build the sql like you're doing and you use it on the web you leave yourself open to sql injection attacks. Using the bind() method eliminates that vulnerability. Something to consider. Jay Here's some example code: sqlite3*db; // connect to database if ( sqlite3_open( "test.db", ) ) throw "Can't open database"; char* sql; sql = "SELECT one.test1, two.test2" " FROM one" " INNER JOIN two ON one.id = two.id" ; sqlite3_stmt* pStmt; if ( sqlite3_prepare( db, sql, strlen(sql), , NULL ) != SQLITE_OK ) { string str = "Cannot prepare sql: "; str += sql[t]; str += ", Error: "; str += sqlite3_errmsg(db); throw str.c_str(); } bool Loop = true; while ( Loop ) switch ( sqlite3_step( pStmt ) ) { case SQLITE_ROW: // retrieve the results char* p = (char *) sqlite3_column_text( pStmt, 0 ); string test1 = string( p ? p : "" ); p = (char *) sqlite3_column_text( pStmt, 1 ); string test2 = string( p ? p : "" ); break; case SQLITE_DONE: Loop = false; break; case SQLITE_BUSY: case SQLITE_LOCKED: default: string str = "Cannot execute sql: "; str += sql[t]; str += ", Error: "; str += sqlite3_errmsg(db); throw str.c_str(); break; } // clean up when finished sqlite3_finalize( pStmt ); sqlite3_close( db ); -- SqliteImporter and SqliteReplicator: Command line utilities for Sqlite http://www.reddawn.net/~jsprenkl/Sqlite Cthulhu Bucks! http://www.cthulhubucks.com - To unsubscribe, send email to [EMAIL PROTECTED] -
Re: [sqlite] A lillte help adding sqlite to a c program
Maybe. Here's what I do (in c). DoSql() is a wrapper function. I've included a callback function (and associated structure) below it. The call is made thusly: static char cData[1024]; char query[255]; snprintf(query, QUERY_SIZE, "SELECT * FROM inikeys WHERE inisection = \"%s\" AND inikey = \"%s\" ",section,key); if (!DoSql(query, _inirecord_callback, nDoSqlTimeout)) { FORMAT_TRACE(ERR_DEBUG,"aem.db temporarily locked by another process. Cannot continue"); return(""); } int DoSql(char *query, int (*callback) (), int nRetrySeconds) { int nResult=0; nSQLRetry=0; char *cError; db=sqlite_open("/var/tmp/solarwave/aem.db", 0, NULL); sqlite_busy_timeout(db,1000); printf("DoSql gets query=->%s<-\n",query); while (nSQLRetry<=nRetrySeconds) { nResult=sqlite_exec(db, query, callback, NULL, ); if (nResult==SQLITE_BUSY || nResult==SQLITE_LOCKED) { if (nSQLRetry==0) printf("Sleeping "); else printf("."); sleep(1); ++nSQLRetry; continue; } if (nSQLRetry>0) printf("\n"); break; } if (nResult==SQLITE_BUSY || nResult==SQLITE_LOCKED) { FORMAT_TRACE(ERR_CRIT,"DoSql: aem.db temporarily locked by another process. Cannot continue"); free(cError); sqlite_close(db); return(false); } if (!(nResult==0)) { FORMAT_TRACE(ERR_CRIT,"DoSql: query %s returned error %s. Cannot continue",query, cError); free(cError); sqlite_close(db); return(false); } free(cError); sqlite_close(db); return(true); } struct _inirecord { int record_key; char inisection[30]; char inikey[30]; char iniline[255]; } inirecord[1]; int sql_inirecord_callback(void *args, int numCols, char **results, char **columnNames) { int i; for (i=0; i
[sqlite] A lillte help adding sqlite to a c program
I know nothing of C++ and therefore need a lilte help editing a C++ app to insert some records into a database. This is where I am so far #include sqlite *db; //insert record into database db=sqlite_open("/var/tmp/logger/database/logger.db", 0, NULL); query = "insert into call_data"; query += "(direction, call_time, dest, trunk_no, file_name)values("; query += "'"details.inout"','"details.statime"','"details.cidn"','"details.channel"','"details.filename; sqlite_exec(db, query, NULL, NULL, NULL); sqlite_close(db); -- Can someone tell me if I am going in the right direction. Sorry for being so lazy,but I need to get something working quick. Lloydie T - To unsubscribe, send email to [EMAIL PROTECTED] -