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

Reply via email to