2009/5/8 Nuno Magalhães <nunomagalh...@eu.ipp.pt>:
> Greetings.
>
> I've managed to compile the example, after installing the amalgamation
> and using -lsqlite3 in gcc, otherwise it'll complain about undefined
> references.
>
> I can't figure out how to read a simple result set. I know i shoud use
> sqlite3_exec and/or sqlite3_step and i'm required to have a
> sqlite3_stmt* somewhere, but i can't find good examples and lots of
> the ones i find use sqlite3_prepare_v2, which i think is deprecated
> for SQLite3...

No - see http://www.sqlite.org/c3ref/prepare.html

>
> Can someone please give me some nice RTFM links will good basic
> tutorials for the C API? Ones that include the aforementioned task
> preferably ;)

See http://www.sqlite.org/cintro.html

The following gives an idea of how to use the prepare/step api:


int get_telnr( char** c_telnr, sqlite3* db, char* name )
{
   char* sql = "SELECT telnr FROM contacts WHERE name=?;";
   char* tail;
   const char* data;
   sqlite3_stmt* stmt;
   int rc = sqlite3_prepare_v2( db,
                                           sql,
                                           strlen( sql ),
                                           &stmt,
                                           &tail );
   if( SQLITE_OK == rc )
   {
       rc = sqlite3_bind_text( stmt, 1, name, strlen( name ), SQLITE_STATIC );
       if( SQLITE_OK == rc )
       {
           rc = sqlite3_step( stmt );
           if( SQLITE_ROW == rc )
           {
               data = sqlite3_column_text( stmt, 0 );
               if( data )
               {
                   *c_telnr = (char*)malloc( strlen( data ) + 1 );
                   strcpy( *c_telnr, data );
               }
           }
       }
   }
   return( rc );
}

>
> TIA,
> Nuno Magalhães
>

Rgtds,
Simon
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to