WysG wrote:
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.
Yeah, this was an easy one...
sqlite3_step keep returning SQLITE_MISUSE so I must be forgetting something, but I can't find it.
It's a C++ realted error, you made.
I query like this
Here is the error:
//=====================================================
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; }
Look: After the 'if(this->db) {' you create an CRecordset object 'oRs' on the stack. Calling sqlite3_prepare() you store the statement in '&oRs.vm'. After the closing '}' your CRecordset object 'oRs' on the stack gets destroyed. I assume your CRecordset::~CRecordset() destructor calls sqlite3_finalize() on his member 'vm'. The destructor will be always called on 'oRs' because this object lives on the stack. Additionally it's copy-operator is called in the 'return oRs;' statement to construct the object which will returned to the caller.
Looks like a serious design problem.
signature.asc
Description: OpenPGP digital signature