2009/3/16  <[email protected]>:
> Hello,
>
> I am new on SQLite so bear with me :-)
>
> Can someone give me a simple c solution on following:
>
> I execute select telnr from contacts where name="David"
>
> I just want to get from the found record the content of field telnr back to 
> my c
> program in variable c_telnr.
>
> Thanks in advance,
>
> Danny
> Belgium
>

Hi Danny,

See http://www.sqlite.org/c3ref/prepare.html
       http://www.sqlite.org/c3ref/bind_blob.html,
       http://www.sqlite.org/c3ref/step.html
       http://www.sqlite.org/c3ref/column_blob.html

Experiment with

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 );
}

Rgds,
Simon
_______________________________________________
sqlite-users mailing list
[email protected]
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to