Re: [sqlite] Newbie trying to list resultSet with C

2009-05-10 Thread Nuno Magalhães
Thanks for the replies guys! :)

-- 
()  ascii ribbon campaign - against html e-mail
/\  ascii-rubanda kampajno - kontraŭ html-a retpoŝto
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] Newbie trying to list resultSet with C

2009-05-08 Thread Kees Nuyt
On Fri, 8 May 2009 16:26:20 +0100, Nuno Magalhães
 wrote:

>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...
>
>Can someone please give me some nice RTFM links will good basic
>tutorials for the C API? Ones that include the aforementioned task
>preferably ;)

http://www.sqlite.org/cvstrac/wiki , more specifically:

http://www.sqlite.org/cvstrac/wiki?p=SimpleCode
Quickstart C code for executing any SQL against an SQLite
database. Very basic but fully functional nevertheless. 

http://www.sqlite.org/cvstrac/wiki?p=SampleCode
Example C code for creating / writing to / reading from a
database. 

>TIA,
>Nuno Magalhães
-- 
  (  Kees Nuyt
  )
c[_]
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] Newbie trying to list resultSet with C

2009-05-08 Thread Simon Davies
2009/5/8 Simon Davies :
> 2009/5/8 Nuno Magalhães :
>> 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 );
>               }
>           }
>       }
Sorry - don't forget to finalize!
 rc = sqlite3_finalize( stmt );
>   }
>   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


Re: [sqlite] Newbie trying to list resultSet with C

2009-05-08 Thread Simon Davies
2009/5/8 Nuno Magalhães :
> 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


[sqlite] Newbie trying to list resultSet with C

2009-05-08 Thread Nuno Magalhães
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...

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

TIA,
Nuno Magalhães

-- 
()  ascii ribbon campaign - against html e-mail
/\  ascii-rubanda kampajno - kontraŭ html-a retpoŝto
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users