Re: [sqlite] C/C++ API

2007-09-05 Thread 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" <[EMAIL PROTECTED]>
> An: sqlite-users@sqlite.org
> 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",) ){
>  
>// prepare the statement
> sqlite3_stmt *oStmt;
> if( sqlite3_prepare_v2(db,"SELECT username FROM users WHERE 
> nick=?",-1,,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,);
> > 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 [EMAIL PROTECTED]
> -

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

-
To unsubscribe, send email to [EMAIL PROTECTED]
-



Re: [sqlite] C/C++ API

2007-09-05 Thread Daniel Önnerby

This code is totaly untested. But something like this:

   std::string sUsername;
   sqlite3 *db;
   if( sqlite3_open("db/users.db",) ){

  // prepare the statement

   sqlite3_stmt *oStmt;
   if( sqlite3_prepare_v2(db,"SELECT username FROM users WHERE 
nick=?",-1,,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,);
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 [EMAIL PROTECTED]
-



Re: [sqlite] C/C++ API

2007-09-05 Thread nishit sharma
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" <[EMAIL PROTECTED]> 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,);
>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 [EMAIL PROTECTED]
>
> -
>
>


[sqlite] C/C++ API

2007-09-05 Thread 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,);
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 [EMAIL PROTECTED]
-