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: <sqlite-users@sqlite.org>
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", &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 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]
-----------------------------------------------------------------------------

Reply via email to