C/C++ API

classic Classic list List threaded Threaded
13 messages Options
Reply | Threaded
Open this post in threaded view
|

C/C++ API

"Severin Müller"
Hi

I'm new to sqlite3, and i' have some Problems with my code. I'm trying to select data from a table and to save the result in a string. but i have no clue how to accomplish this.

Here is a part of my code:

std::string get_user_info(const char* nick,int mode)
{
#ifdef _WIN32
        const char *filename = "db\\users.db";
#else
        const char *filename = "db/users.db";
#endif
        services serv;
        Config conf;
        sqlite3 *db;
        char *zErrMsg = 0;
        int rc;
        char *sql = (char*) malloc(sizeof(char)*64);
        rc = sqlite3_open(filename,&db);
        if(rc)
        {
                std::cout << "S_ERR_USERDATABASE" << std::endl;
                globops(conf.get_s_name(),S_MSG_SRVGOINGDOWN);
                sqlite3_close(db);
                return NULL;
        }
        sprintf(sql,"SELECT * FROM '%s';",nick);
        if(rc!=SQLITE_OK)
        {
                fprintf(stderr,"SQL error: %s\n",zErrMsg);
                sqlite3_free(zErrMsg);
        }
        user = ...// i'd like to store the db data in a string here...
        return user;
}

Can anybody help me here? Thanks


Regards

Sevi


--
GMX FreeMail: 1 GB Postfach, 5 E-Mail-Adressen, 10 Free SMS.
Alle Infos und kostenlose Anmeldung: http://www.gmx.net/de/go/freemail

-----------------------------------------------------------------------------
To unsubscribe, send email to [hidden email]
-----------------------------------------------------------------------------

Reply | Threaded
Open this post in threaded view
|

Re: C/C++ API

ashu_ynr
hi,
in sqlite3 u r having a function named callback whose third argument is used
to save the
value of a column. u can store that value in an array or in char vairiable
also.
try this

regards
Nishit


On 9/5/07, "Severin Müller" <[hidden email]> wrote:

>
> Hi
>
> I'm new to sqlite3, and i' have some Problems with my code. I'm trying to
> select data from a table and to save the result in a string. but i have no
> clue how to accomplish this.
>
> Here is a part of my code:
>
> std::string get_user_info(const char* nick,int mode)
> {
> #ifdef _WIN32
>        const char *filename = "db\\users.db";
> #else
>        const char *filename = "db/users.db";
> #endif
>        services serv;
>        Config conf;
>        sqlite3 *db;
>        char *zErrMsg = 0;
>        int rc;
>        char *sql = (char*) malloc(sizeof(char)*64);
>        rc = sqlite3_open(filename,&db);
>        if(rc)
>        {
>                std::cout << "S_ERR_USERDATABASE" << std::endl;
>                globops(conf.get_s_name(),S_MSG_SRVGOINGDOWN);
>                sqlite3_close(db);
>                return NULL;
>        }
>        sprintf(sql,"SELECT * FROM '%s';",nick);
>        if(rc!=SQLITE_OK)
>        {
>                fprintf(stderr,"SQL error: %s\n",zErrMsg);
>                sqlite3_free(zErrMsg);
>        }
>        user = ...// i'd like to store the db data in a string here...
>        return user;
> }
>
> Can anybody help me here? Thanks
>
>
> Regards
>
> Sevi
>
>
> --
> GMX FreeMail: 1 GB Postfach, 5 E-Mail-Adressen, 10 Free SMS.
> Alle Infos und kostenlose Anmeldung: http://www.gmx.net/de/go/freemail
>
>
> -----------------------------------------------------------------------------
> To unsubscribe, send email to [hidden email]
>
> -----------------------------------------------------------------------------
>
>
Reply | Threaded
Open this post in threaded view
|

Re: C/C++ API

Daniel Önnerby
In reply to this post by "Severin Müller"
This code is totaly untested. But something like this:

    std::string sUsername;
    sqlite3 *db;
    if( sqlite3_open("db/users.db",&db) ){
     
       // prepare the statement
        sqlite3_stmt *oStmt;
        if( sqlite3_prepare_v2(db,"SELECT username FROM users WHERE
nick=?",-1,&oStmt,NULL)==SQLITE_OK ){
       
            // Bind your nickname to the ?-parameter in SQL.
            sqlite3_bind_text(oStmt,1,nick,-1,SQLITE_STATIC);
           
            // Execute the statement
            if( sqlite3_step(oStmt)==SQLITE_ROW){
                sUsername.assign( sqlite3_column_text(oStmt,1) );
            }
           
        }
        sqlite3_reset(oStmt);
        sqlite3_finalize(oStmt);
       
        sqlite3_close(db);
       
        return sUsername;
    }


Severin Müller wrote:

> Hi
>
> I'm new to sqlite3, and i' have some Problems with my code. I'm trying to select data from a table and to save the result in a string. but i have no clue how to accomplish this.
>
> Here is a part of my code:
>
> std::string get_user_info(const char* nick,int mode)
> {
> #ifdef _WIN32
> const char *filename = "db\\users.db";
> #else
> const char *filename = "db/users.db";
> #endif
> services serv;
> Config conf;
> sqlite3 *db;
> char *zErrMsg = 0;
> int rc;
> char *sql = (char*) malloc(sizeof(char)*64);
> rc = sqlite3_open(filename,&db);
> if(rc)
> {
> std::cout << "S_ERR_USERDATABASE" << std::endl;
> globops(conf.get_s_name(),S_MSG_SRVGOINGDOWN);
> sqlite3_close(db);
> return NULL;
> }
> sprintf(sql,"SELECT * FROM '%s';",nick);
> if(rc!=SQLITE_OK)
> {
> fprintf(stderr,"SQL error: %s\n",zErrMsg);
> sqlite3_free(zErrMsg);
> }
>         user = ...// i'd like to store the db data in a string here...
> return user;
> }
>
> Can anybody help me here? Thanks
>
>
> Regards
>
> Sevi
>
>
>  


-----------------------------------------------------------------------------
To unsubscribe, send email to [hidden email]
-----------------------------------------------------------------------------

Reply | Threaded
Open this post in threaded view
|

Re: C/C++ API

"Severin Müller"
Hi

This won't work, because sUsername.assign... will not be accepted with sqlite3_column_text, because sqlite_column_text if of type const unsigned char...

Anyway, the other version with the callback function still gives me headache... how shall i access the data in my statement, when i have to call another function? Does somebody have another good example for this?


-------- Original-Nachricht --------
> Datum: Wed, 05 Sep 2007 12:13:25 +0200
> Von: "Daniel Önnerby" <[hidden email]>
> An: [hidden email]
> Betreff: Re: [sqlite] C/C++ API

> This code is totaly untested. But something like this:
>
>     std::string sUsername;
>     sqlite3 *db;
>     if( sqlite3_open("db/users.db",&db) ){
>      
>        // prepare the statement
>         sqlite3_stmt *oStmt;
>         if( sqlite3_prepare_v2(db,"SELECT username FROM users WHERE
> nick=?",-1,&oStmt,NULL)==SQLITE_OK ){
>        
>             // Bind your nickname to the ?-parameter in SQL.
>             sqlite3_bind_text(oStmt,1,nick,-1,SQLITE_STATIC);
>            
>             // Execute the statement
>             if( sqlite3_step(oStmt)==SQLITE_ROW){
>                 sUsername.assign( sqlite3_column_text(oStmt,1) );
>             }
>            
>         }
>         sqlite3_reset(oStmt);
>         sqlite3_finalize(oStmt);
>        
>         sqlite3_close(db);
>        
>         return sUsername;
>     }
>
>
> Severin Müller wrote:
> > Hi
> >
> > I'm new to sqlite3, and i' have some Problems with my code. I'm trying
> to select data from a table and to save the result in a string. but i have
> no clue how to accomplish this.
> >
> > Here is a part of my code:
> >
> > std::string get_user_info(const char* nick,int mode)
> > {
> > #ifdef _WIN32
> > const char *filename = "db\\users.db";
> > #else
> > const char *filename = "db/users.db";
> > #endif
> > services serv;
> > Config conf;
> > sqlite3 *db;
> > char *zErrMsg = 0;
> > int rc;
> > char *sql = (char*) malloc(sizeof(char)*64);
> > rc = sqlite3_open(filename,&db);
> > if(rc)
> > {
> > std::cout << "S_ERR_USERDATABASE" << std::endl;
> > globops(conf.get_s_name(),S_MSG_SRVGOINGDOWN);
> > sqlite3_close(db);
> > return NULL;
> > }
> > sprintf(sql,"SELECT * FROM '%s';",nick);
> > if(rc!=SQLITE_OK)
> > {
> > fprintf(stderr,"SQL error: %s\n",zErrMsg);
> > sqlite3_free(zErrMsg);
> > }
> >         user = ...// i'd like to store the db data in a string here...
> > return user;
> > }
> >
> > Can anybody help me here? Thanks
> >
> >
> > Regards
> >
> > Sevi
> >
> >
> >  
>
>
> -----------------------------------------------------------------------------
> To unsubscribe, send email to [hidden email]
> -----------------------------------------------------------------------------

--
Psssst! Schon vom neuen GMX MultiMessenger gehört?
Der kanns mit allen: http://www.gmx.net/de/go/multimessenger

-----------------------------------------------------------------------------
To unsubscribe, send email to [hidden email]
-----------------------------------------------------------------------------

Reply | Threaded
Open this post in threaded view
|

Re: C/C++ API

Igor Tandetnik
"Severin Müller" <[hidden email]> wrote:
> This won't work, because sUsername.assign... will not be accepted
> with sqlite3_column_text, because sqlite_column_text if of type const
> unsigned char...

Just cast it to const char*

Igor Tandetnik


-----------------------------------------------------------------------------
To unsubscribe, send email to [hidden email]
-----------------------------------------------------------------------------

Reply | Threaded
Open this post in threaded view
|

Re: Re: C/C++ API

"Severin Müller"
Hey

Naw, the entire code doesn't work properly.

I just need something where i can save my query results in a string and return the string...


-------- Original-Nachricht --------
> Datum: Wed, 5 Sep 2007 08:30:12 -0400
> Von: "Igor Tandetnik" <[hidden email]>
> An: "SQLite" <[hidden email]>
> Betreff: [sqlite] Re: C/C++ API

> "Severin Müller" <[hidden email]> wrote:
> > This won't work, because sUsername.assign... will not be accepted
> > with sqlite3_column_text, because sqlite_column_text if of type const
> > unsigned char...
>
> Just cast it to const char*
>
> Igor Tandetnik
>
>
> -----------------------------------------------------------------------------
> To unsubscribe, send email to [hidden email]
> -----------------------------------------------------------------------------

--
Psssst! Schon vom neuen GMX MultiMessenger gehört?
Der kanns mit allen: http://www.gmx.net/de/go/multimessenger

-----------------------------------------------------------------------------
To unsubscribe, send email to [hidden email]
-----------------------------------------------------------------------------

Reply | Threaded
Open this post in threaded view
|

Re: Re: C/C++ API

Igor Tandetnik
"Severin Müller" <[hidden email]> wrote:
> Naw, the entire code doesn't work properly.

What's improper about the way it works? What specifically seems to be
the problem?

> I just need something where i can save my query results in a string
> and return the string...

I seem to have misplaced my crystal ball today, so my mind-reading
abilities are somewhat impaired. The results of what query? In a string
of what format?

Igor Tandetnik


-----------------------------------------------------------------------------
To unsubscribe, send email to [hidden email]
-----------------------------------------------------------------------------

Reply | Threaded
Open this post in threaded view
|

Re: Re: Re: C/C++ API

"Severin Müller"
Hey

Sorry for my unclearness. I want to access information in a sqlite database and store it in a std::string or const char*, so i can return it to the callin function. I have the following code:

std::string get_user_info(const char* nick,int mode)
{
#ifdef _WIN32
        const char *filename = "db\\users.db";
#else
        const char *filename = "db/users.db";
#endif
        services serv;
        Config conf;
        sqlite3 *db;
        char *zErrMsg = 0;
        int rc;
        char *sql = (char*) malloc(sizeof(char)*64);
        rc = sqlite3_open(filename,&db);
        if(rc!=SQLITE_OK)
        {
                std::cout << "S_ERR_USERDATABASE" << std::endl;
                globops(conf.get_s_name(),S_MSG_SRVGOINGDOWN);
                sqlite3_close(db);
                return NULL;
        }
        const unsigned char *userinfo = (unsigned char*) malloc(sizeof(unsigned char)*1024);
        std::string sUsername;
        sqlite3_stmt *oStmt;
        switch(mode)
        {
        case 1:
                sprintf(sql,"SELECT username FROM '%s';",nick);
        case 2:
                sprintf(sql,"SELECT hostname FROM '%s';",nick);
        case 3:
                sprintf(sql,"SELECT realname FROM '%s';",nick);
        case 4:
                sprintf(sql,"SELECT operline FROM '%s';",nick);
        }
        if(sqlite3_prepare(db,sql,-1,&oStmt,NULL)==SQLITE_OK )
        {
                sqlite3_bind_text(oStmt,1,nick,-1,SQLITE_STATIC);
                if(sqlite3_step(oStmt)==SQLITE_ROW)
                {
                        sUsername.assign((const char*) sqlite3_column_text(oStmt,0));
           
                }
        }
        std::cout << sUsername << std::endl;
        sqlite3_reset(oStmt);
        sqlite3_finalize(oStmt);
        return sUsername;
}


So The std::cout << sUsername << sts::endl; is supposed to put the data out there from case 1 (i'm calling case 1 only)

But it just puts out a blank line... Do you have a suggestion? Thanks a lot...
--
Psssst! Schon vom neuen GMX MultiMessenger gehört?
Der kanns mit allen: http://www.gmx.net/de/go/multimessenger

-----------------------------------------------------------------------------
To unsubscribe, send email to [hidden email]
-----------------------------------------------------------------------------

Reply | Threaded
Open this post in threaded view
|

Re: Re: C/C++ API

John Stanton-3
In reply to this post by "Severin Müller"
Look up the Sqlite API.  The sqlite3_column_text call does what you want.

    sqlite3_open
    sqlite3_prepare
    loop
       sqlite3_step
       if SQLITE_ROW sqlite_column_text;
       if SQLITE_DONE sqlite3_finalize; exit
    repeat
    sqlite3_close

Add your own error tests.

Severin Müller wrote:

> Hey
>
> Naw, the entire code doesn't work properly.
>
> I just need something where i can save my query results in a string and return the string...
>
>
> -------- Original-Nachricht --------
>
>>Datum: Wed, 5 Sep 2007 08:30:12 -0400
>>Von: "Igor Tandetnik" <[hidden email]>
>>An: "SQLite" <[hidden email]>
>>Betreff: [sqlite] Re: C/C++ API
>
>
>>"Severin Müller" <[hidden email]> wrote:
>>
>>>This won't work, because sUsername.assign... will not be accepted
>>>with sqlite3_column_text, because sqlite_column_text if of type const
>>>unsigned char...
>>
>>Just cast it to const char*
>>
>>Igor Tandetnik
>>
>>
>>-----------------------------------------------------------------------------
>>To unsubscribe, send email to [hidden email]
>>-----------------------------------------------------------------------------
>
>


-----------------------------------------------------------------------------
To unsubscribe, send email to [hidden email]
-----------------------------------------------------------------------------

Reply | Threaded
Open this post in threaded view
|

Re: Re: Re: C/C++ API

Daniel Önnerby
In reply to this post by "Severin Müller"
Your SQL-strings seem a little strange. You are trying to select from a
table named as the content of nick, this would assume that you have a
table for each "nick" witch seems unlikely. How is your database modeled?

Severin Müller wrote:

> Hey
>
> Sorry for my unclearness. I want to access information in a sqlite database and store it in a std::string or const char*, so i can return it to the callin function. I have the following code:
>
> std::string get_user_info(const char* nick,int mode)
> {
> #ifdef _WIN32
> const char *filename = "db\\users.db";
> #else
> const char *filename = "db/users.db";
> #endif
> services serv;
> Config conf;
> sqlite3 *db;
> char *zErrMsg = 0;
> int rc;
> char *sql = (char*) malloc(sizeof(char)*64);
> rc = sqlite3_open(filename,&db);
> if(rc!=SQLITE_OK)
> {
> std::cout << "S_ERR_USERDATABASE" << std::endl;
> globops(conf.get_s_name(),S_MSG_SRVGOINGDOWN);
> sqlite3_close(db);
> return NULL;
> }
> const unsigned char *userinfo = (unsigned char*) malloc(sizeof(unsigned char)*1024);
> std::string sUsername;
> sqlite3_stmt *oStmt;
> switch(mode)
> {
> case 1:
> sprintf(sql,"SELECT username FROM '%s';",nick);
> case 2:
> sprintf(sql,"SELECT hostname FROM '%s';",nick);
> case 3:
> sprintf(sql,"SELECT realname FROM '%s';",nick);
> case 4:
> sprintf(sql,"SELECT operline FROM '%s';",nick);
> }
> if(sqlite3_prepare(db,sql,-1,&oStmt,NULL)==SQLITE_OK )
> {
> sqlite3_bind_text(oStmt,1,nick,-1,SQLITE_STATIC);
> if(sqlite3_step(oStmt)==SQLITE_ROW)
> {
> sUsername.assign((const char*) sqlite3_column_text(oStmt,0));
>            
> }
> }
> std::cout << sUsername << std::endl;
> sqlite3_reset(oStmt);
> sqlite3_finalize(oStmt);
> return sUsername;
> }
>
>
> So The std::cout << sUsername << sts::endl; is supposed to put the data out there from case 1 (i'm calling case 1 only)
>
> But it just puts out a blank line... Do you have a suggestion? Thanks a lot...
>  


-----------------------------------------------------------------------------
To unsubscribe, send email to [hidden email]
-----------------------------------------------------------------------------

Reply | Threaded
Open this post in threaded view
|

Re: Re: Re: C/C++ API

"Severin Müller"
Hey


This is correct. This database is just for the users, who send commands to nickserv. every nickname online is a entry in the database. i plan to change that later, in case, sqlite encouters problems with 1000 tables in a database, but for now it really like this.


-------- Original-Nachricht --------
> Datum: Wed, 05 Sep 2007 16:28:19 +0200
> Von: "Daniel Önnerby" <[hidden email]>
> An: [hidden email]
> Betreff: Re: [sqlite] Re: Re: C/C++ API

> Your SQL-strings seem a little strange. You are trying to select from a
> table named as the content of nick, this would assume that you have a
> table for each "nick" witch seems unlikely. How is your database modeled?
>
> Severin Müller wrote:
> > Hey
> >
> > Sorry for my unclearness. I want to access information in a sqlite
> database and store it in a std::string or const char*, so i can return it to the
> callin function. I have the following code:
> >
> > std::string get_user_info(const char* nick,int mode)
> > {
> > #ifdef _WIN32
> > const char *filename = "db\\users.db";
> > #else
> > const char *filename = "db/users.db";
> > #endif
> > services serv;
> > Config conf;
> > sqlite3 *db;
> > char *zErrMsg = 0;
> > int rc;
> > char *sql = (char*) malloc(sizeof(char)*64);
> > rc = sqlite3_open(filename,&db);
> > if(rc!=SQLITE_OK)
> > {
> > std::cout << "S_ERR_USERDATABASE" << std::endl;
> > globops(conf.get_s_name(),S_MSG_SRVGOINGDOWN);
> > sqlite3_close(db);
> > return NULL;
> > }
> > const unsigned char *userinfo = (unsigned char*) malloc(sizeof(unsigned
> char)*1024);
> > std::string sUsername;
> > sqlite3_stmt *oStmt;
> > switch(mode)
> > {
> > case 1:
> > sprintf(sql,"SELECT username FROM '%s';",nick);
> > case 2:
> > sprintf(sql,"SELECT hostname FROM '%s';",nick);
> > case 3:
> > sprintf(sql,"SELECT realname FROM '%s';",nick);
> > case 4:
> > sprintf(sql,"SELECT operline FROM '%s';",nick);
> > }
> > if(sqlite3_prepare(db,sql,-1,&oStmt,NULL)==SQLITE_OK )
> > {
> > sqlite3_bind_text(oStmt,1,nick,-1,SQLITE_STATIC);
> > if(sqlite3_step(oStmt)==SQLITE_ROW)
> > {
> > sUsername.assign((const char*) sqlite3_column_text(oStmt,0));
> >            
> > }
> > }
> > std::cout << sUsername << std::endl;
> > sqlite3_reset(oStmt);
> > sqlite3_finalize(oStmt);
> > return sUsername;
> > }
> >
> >
> > So The std::cout << sUsername << sts::endl; is supposed to put the data
> out there from case 1 (i'm calling case 1 only)
> >
> > But it just puts out a blank line... Do you have a suggestion? Thanks a
> lot...
> >  
>
>
> -----------------------------------------------------------------------------
> To unsubscribe, send email to [hidden email]
> -----------------------------------------------------------------------------

--
Ist Ihr Browser Vista-kompatibel? Jetzt die neuesten
Browser-Versionen downloaden: http://www.gmx.net/de/go/browser

-----------------------------------------------------------------------------
To unsubscribe, send email to [hidden email]
-----------------------------------------------------------------------------

Reply | Threaded
Open this post in threaded view
|

Re: Re: Re: C/C++ API

David Bicking-2
One thing I note is that you have no parameters in your queries, so you
don't need to use sqlite3_bind_text.

Further, you might want to add "else" statements so you can print out
the errmsg if the prepare or step calls are failing.

David


On Wed, 2007-09-05 at 16:35 +0200, "Severin Müller" wrote:

> Hey
>
>
> This is correct. This database is just for the users, who send commands to nickserv. every nickname online is a entry in the database. i plan to change that later, in case, sqlite encouters problems with 1000 tables in a database, but for now it really like this.
>
>
> -------- Original-Nachricht --------
> > Datum: Wed, 05 Sep 2007 16:28:19 +0200
> > Von: "Daniel Önnerby" <[hidden email]>
> > An: [hidden email]
> > Betreff: Re: [sqlite] Re: Re: C/C++ API
>
> > Your SQL-strings seem a little strange. You are trying to select from a
> > table named as the content of nick, this would assume that you have a
> > table for each "nick" witch seems unlikely. How is your database modeled?
> >
> > Severin Müller wrote:
> > > Hey
> > >
> > > Sorry for my unclearness. I want to access information in a sqlite
> > database and store it in a std::string or const char*, so i can return it to the
> > callin function. I have the following code:
> > >
> > > std::string get_user_info(const char* nick,int mode)
> > > {
> > > #ifdef _WIN32
> > > const char *filename = "db\\users.db";
> > > #else
> > > const char *filename = "db/users.db";
> > > #endif
> > > services serv;
> > > Config conf;
> > > sqlite3 *db;
> > > char *zErrMsg = 0;
> > > int rc;
> > > char *sql = (char*) malloc(sizeof(char)*64);
> > > rc = sqlite3_open(filename,&db);
> > > if(rc!=SQLITE_OK)
> > > {
> > > std::cout << "S_ERR_USERDATABASE" << std::endl;
> > > globops(conf.get_s_name(),S_MSG_SRVGOINGDOWN);
> > > sqlite3_close(db);
> > > return NULL;
> > > }
> > > const unsigned char *userinfo = (unsigned char*) malloc(sizeof(unsigned
> > char)*1024);
> > > std::string sUsername;
> > > sqlite3_stmt *oStmt;
> > > switch(mode)
> > > {
> > > case 1:
> > > sprintf(sql,"SELECT username FROM '%s';",nick);
> > > case 2:
> > > sprintf(sql,"SELECT hostname FROM '%s';",nick);
> > > case 3:
> > > sprintf(sql,"SELECT realname FROM '%s';",nick);
> > > case 4:
> > > sprintf(sql,"SELECT operline FROM '%s';",nick);
> > > }
> > > if(sqlite3_prepare(db,sql,-1,&oStmt,NULL)==SQLITE_OK )
> > > {
> > > sqlite3_bind_text(oStmt,1,nick,-1,SQLITE_STATIC);
> > > if(sqlite3_step(oStmt)==SQLITE_ROW)
> > > {
> > > sUsername.assign((const char*) sqlite3_column_text(oStmt,0));
> > >            
> > > }
> > > }
> > > std::cout << sUsername << std::endl;
> > > sqlite3_reset(oStmt);
> > > sqlite3_finalize(oStmt);
> > > return sUsername;
> > > }
> > >
> > >
> > > So The std::cout << sUsername << sts::endl; is supposed to put the data
> > out there from case 1 (i'm calling case 1 only)
> > >
> > > But it just puts out a blank line... Do you have a suggestion? Thanks a
> > lot...
> > >  



-----------------------------------------------------------------------------
To unsubscribe, send email to [hidden email]
-----------------------------------------------------------------------------

Reply | Threaded
Open this post in threaded view
|

Re: C/C++ API

Clay Dowling
In reply to this post by "Severin Müller"
Check out http://www.lazarusid.com/sqlite3 for a working example.

Clay Dowling

"Severin Müller" wrote:

> Hi
>
> I'm new to sqlite3, and i' have some Problems with my code. I'm trying to
> select data from a table and to save the result in a string. but i have no
> clue how to accomplish this.
>
> Here is a part of my code:
>
> std::string get_user_info(const char* nick,int mode)
> {
> #ifdef _WIN32
> const char *filename = "db\\users.db";
> #else
> const char *filename = "db/users.db";
> #endif
> services serv;
> Config conf;
> sqlite3 *db;
> char *zErrMsg = 0;
> int rc;
> char *sql = (char*) malloc(sizeof(char)*64);
> rc = sqlite3_open(filename,&db);
> if(rc)
> {
> std::cout << "S_ERR_USERDATABASE" << std::endl;
> globops(conf.get_s_name(),S_MSG_SRVGOINGDOWN);
> sqlite3_close(db);
> return NULL;
> }
> sprintf(sql,"SELECT * FROM '%s';",nick);
> if(rc!=SQLITE_OK)
> {
> fprintf(stderr,"SQL error: %s\n",zErrMsg);
> sqlite3_free(zErrMsg);
> }
>         user = ...// i'd like to store the db data in a string here...
> return user;
> }
>
> Can anybody help me here? Thanks
>
>
> Regards
>
> Sevi
>
>
> --
> GMX FreeMail: 1 GB Postfach, 5 E-Mail-Adressen, 10 Free SMS.
> Alle Infos und kostenlose Anmeldung: http://www.gmx.net/de/go/freemail
>
> -----------------------------------------------------------------------------
> To unsubscribe, send email to [hidden email]
> -----------------------------------------------------------------------------
>
>


--
Lazarus Registration
http://www.lazarusid.com/registration.shtml


-----------------------------------------------------------------------------
To unsubscribe, send email to [hidden email]
-----------------------------------------------------------------------------