Re: Re[2]: [sqlite] A lillte help adding sqlite to a c program
I am still having some problems compiling my code. I suspect it maybe something to do with my app not linking (ld) with sqlite libraries, but I do not know how to do this or it could be something else. Can you advise? - /usr/src/logger-1.2-beta3/src/logger.cpp:731: undefined reference to `sqlite3_open' logger.o(.text+0xc99):/usr/src/logger-1.2-beta3/src/logger.cpp:732: undefined reference to `sqlite3_exec' logger.o(.text+0xcae):/usr/src/logger-1.2-beta3/src/logger.cpp:735: undefined reference to `sqlite3_free' logger.o(.text+0xcbf):/usr/src/logger-1.2-beta3/src/logger.cpp:737: undefined reference to `sqlite3_close' collect2: ld returned 1 exit status make: *** [logger] Error 1 - Original Message - From: <[EMAIL PROTECTED]> To: Sent: Sunday, September 10, 2006 1:32 PM Subject: Re: Re[2]: [sqlite] A lillte help adding sqlite to a c program On Sun, 10 Sep 2006 13:02:58 +0100, you wrote: Thanks Teg, I have been trying to do using a basic example but still running into problems. Can you expand a little more on your example below. This is where I am so far. I am getting a bit closer bit still getting some errors. clearly I am still getting something wrong with the format of snprintf. any ideas? Hello Lloydie If you use a MS Compiler like VC++ 6 or VC++ 7 Net you can look at my HP. There is a little Example and a Wrapperclass simple to understand, desgined to handle small Databases. http://www.thlu.de Best Regards Thomas - To unsubscribe, send email to [EMAIL PROTECTED] - - To unsubscribe, send email to [EMAIL PROTECTED] -
Re: Re[2]: [sqlite] A lillte help adding sqlite to a c program
Nearly there just a couple of outstanding issues any help apreciated Error:-- make: Warning: File `logger.cpp' has modification time 45 s in the future g++ -c -Wall -O -g logger.cpp -o logger.o logger.cpp: In function `void* start_one_channel(void*)': logger.cpp:607: warning: format argument is not a pointer (arg 6) logger.cpp:629: error: jump to case label logger.cpp:603: error: crosses initialization of `char*zErrMsg' make: *** [logger.o] Error 1 code sample:--- char *zErrMsg = 0; char sql[200]; int rc; sqlite3 *db; sprintf(sql, "insert into call_data (direction, call_time, dest, trunk_no, file_name)values('%s','%s','%s','%s','%s')", details.inout, details.statime,details.cidn,channel,details.filename); rc = sqlite3_open("/var/tmp/logger/database/logger.db", &db); rc = sqlite3_exec(db, sql, NULL, 0, &zErrMsg); if( rc!=SQLITE_OK ){ //fprintf(stderr, "SQL error: %s\n", zErrMsg); sqlite3_free(zErrMsg); } sqlite3_close(db); LOGIT("[%02d] sql string = %s\n",channel,sql); // Clear out details ready for next call details.inout[0] = 0; details.filename[0] = 0; details.statime[0] = 0; details.endtime[0] = 0; details.cidn[0] = 0; details.cidt[0] = 0; strcpy(details.term, ""); break; default: // Any thing else ?? break; } break; ----- - Original Message - From: <[EMAIL PROTECTED]> To: Sent: Sunday, September 10, 2006 1:32 PM Subject: Re: Re[2]: [sqlite] A lillte help adding sqlite to a c program On Sun, 10 Sep 2006 13:02:58 +0100, you wrote: Thanks Teg, I have been trying to do using a basic example but still running into problems. Can you expand a little more on your example below. This is where I am so far. I am getting a bit closer bit still getting some errors. clearly I am still getting something wrong with the format of snprintf. any ideas? Hello Lloydie If you use a MS Compiler like VC++ 6 or VC++ 7 Net you can look at my HP. There is a little Example and a Wrapperclass simple to understand, desgined to handle small Databases. http://www.thlu.de Best Regards Thomas - To unsubscribe, send email to [EMAIL PROTECTED] - - To unsubscribe, send email to [EMAIL PROTECTED] -
Re: Re[2]: [sqlite] A lillte help adding sqlite to a c program
On Sun, 10 Sep 2006 13:02:58 +0100, you wrote: >Thanks Teg, > I have been trying to do using a basic example but still >running into problems. Can you expand a little more on your example below. >This is where I am so far. >I am getting a bit closer bit still getting some errors. clearly I am still >getting something wrong with the format of snprintf. any ideas? Hello Lloydie If you use a MS Compiler like VC++ 6 or VC++ 7 Net you can look at my HP. There is a little Example and a Wrapperclass simple to understand, desgined to handle small Databases. http://www.thlu.de Best Regards Thomas - To unsubscribe, send email to [EMAIL PROTECTED] -
Re: Re[2]: [sqlite] A lillte help adding sqlite to a c program
Thanks Teg, I have been trying to do using a basic example but still running into problems. Can you expand a little more on your example below. This is where I am so far. I am getting a bit closer bit still getting some errors. clearly I am still getting something wrong with the format of snprintf. any ideas? errors: logger.cpp: In function `void* start_one_channel(void*)': logger.cpp:607: error: invalid conversion from `const char*' to `size_t' logger.cpp:607: error: initializing argument 2 of `int snprintf(char*, size_t, const char*, ...)' logger.cpp:629: error: jump to case label logger.cpp:603: error: crosses initialization of `char*zErrMsg' make: *** [logger.o] Error 1 --- code:- char *zErrMsg = 0; char *sql; int rc; sqlite3 *db; snprintf(sql, "insert into call_data (direction, call_time, dest, trunk_no, file_name)values(\'%s\',\'%s\',\'%s\',\'%s\',\'%s\')", details.inout, details.statime,details.cidn, details.channel,details.filename);//line 607 rc = sqlite3_open("/var/tmp/logger/database/logger.db", &db); //line 608 rc = sqlite3_exec(db, sql, NULL, 0, &zErrMsg); if( rc!=SQLITE_OK ){ //fprintf(stderr, "SQL error: %s\n", zErrMsg); sqlite3_free(zErrMsg); } sqlite3_close(db); --- 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> - Origina
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.
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", &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), &pStmt, 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 Buc