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 [EMAIL PROTECTED]
-----------------------------------------------------------------------------