Hi all,

First I wanted to say that SQLite is pretty impressive ! Cheer to all the dev team, you've made a wonderfull SQL DB Engin ^_^ Keep up the good work.

Second, I'm currently working on wrapper that I will use in some of my C++ project but I got a little problem that I've been stubbling on for two days, I'm sure it's pretty dumb, but I can't find why I keep getting this error.

sqlite3_step keep returning SQLITE_MISUSE so I must be forgetting something, but I can't find it.
So here it goes, I'll strip my code to the bare minimum


My main look like this
//=====================================================
int main()
{       
        try
        {
                CConnection oConn;
                oConn.open("test.db");

                oConn.execute("DROP TABLE test");
                oConn.execute("CREATE TABLE test(number);");
                oConn.execute("BEGIN;");
                oConn.execute("INSERT INTO test VALUES(1);");
                oConn.execute("COMMIT;");

                CRecordset rs = oConn.query("SELECT * FROM test;");
                while(rs.read()) // This is the line I get the error
                        cout << "Reading" << endl;

                rs.close();
                oConn.close();
        }
        catch(CDBException ex)
        {
                cout << ex.message << endl;
        }
        return 0;
}
//=====================================================

Ok I open the connection like this

//=====================================================
void CConnection::open( const char *db )
{
        if(!this->db)
        {
                if(sqlite3_open(db, (sqlite3**)&this->db) != SQLITE_OK)
                        throw CDBException("Unable to open the database");
        }       
        else
                throw CDBException("Connection is already open");
}
//=====================================================

I query like this

//=====================================================
CRecordset CConnection::query(const char *sqlQuery)
{
if(this->db)
{
CRecordset oRs;
oRs.oConn = this;

int result = sqlite3_prepare((sqlite3*)this->db, sqlQuery, -1, (sqlite3_stmt**)&oRs.vm, NULL); //Not sure if I'm forgetting something to do before the prepare.


                if(result != SQLITE_OK)
                        throw CDBException("Error on query");
                
                oRs.columnCount = sqlite3_column_count((sqlite3_stmt*)oRs.vm);

                return oRs;
        }
        else
                throw CDBException("Connection is closed");
}
//=====================================================

Then I read with this function

//=====================================================
bool CRecordset::read()
{
if(this->vm)
{
switch( sqlite3_step((sqlite3_stmt*)this->vm) )
{
case SQLITE_ROW: return true;
break;
case SQLITE_DONE: return false;
break;
case SQLITE_MISUSE: throw CDBException("This routine was called inappropriately"); // This is where the error gets throwed
break;
default: throw CDBException("Error reading");
break;
}
}
else throw CDBException("Recordset is already closed");
}
//=====================================================
You'll say that it looks like the minimalist wrapper of int64.org which is exactly what it is. I'm inspiring myself from this wrapper to understand the API of SQLite 3, so that I can later add some functionnalities to the wrapper.
--
WysG
"Codito Ergo Sum" - 'I code, therefore I am' - 'Je code, donc je suis'
GPG Public Key : http://wysg.hextudio.com/WysG.gpg




Reply via email to