Sha256: 6df30ef27ad8cb03f9ef82395057e6a13171dad81fcc37d118027a2d2dc92327

Contents?: true

Size: 1.81 KB

Versions: 5

Compression:

Stored size: 1.81 KB

Contents

#pragma once

#include "common/RhoStd.h"
#include "common/AutoPointer.h"
#include "common/RhoMutexLock.h"
#include "sqlite/sqlite3.h"

namespace rho{
namespace db{

class CDBResult
{
    common::CMutexLock m_lockDB;
    sqlite3_stmt* m_dbStatement;
    boolean m_bReportNonUnique;
    int     m_nErrorCode;
public:
    CDBResult(sqlite3_stmt* st,common::CMutex& mx) : m_lockDB(mx), m_dbStatement(st){m_bReportNonUnique=false;m_nErrorCode=0;}
    CDBResult(common::CMutex& mx) : m_lockDB(mx), m_dbStatement(null){m_bReportNonUnique=false;m_nErrorCode=0;}

    ~CDBResult(void);

    void setStatement(sqlite3_stmt* st);
    sqlite3_stmt* getStatement(){ return m_dbStatement; }
    boolean getReportNonUnique(){ return m_bReportNonUnique; }
    void setReportNonUnique(boolean bSet){ m_bReportNonUnique = bSet; }
    boolean isNonUnique(){ return m_nErrorCode==SQLITE_CONSTRAINT; }
    boolean isError(){ return m_nErrorCode!=SQLITE_OK; }
    int     getErrorCode(){ return m_nErrorCode; }
    void    setErrorCode(int nError){ m_nErrorCode=nError; }

    virtual bool isEnd(){ return m_dbStatement == null; }
    void next()
    {
        if ( sqlite3_step(m_dbStatement) != SQLITE_ROW )
            setStatement(null);
    }

    virtual String getStringByIdx(int nCol)
    {
        char* res = (char *)sqlite3_column_text(m_dbStatement, nCol);
        return res ? res : String();
    }

    int getIntByIdx(int nCol)
    {
        return sqlite3_column_int(m_dbStatement, nCol);
    }

    uint64 getUInt64ByIdx(int nCol)
    {
        return sqlite3_column_int64(m_dbStatement, nCol);
    }
//private:
    CDBResult() : m_lockDB(*new common::CMutex() ){} //TEST ONLY

};

typedef rho::common::CAutoPtr<rho::db::CDBResult> DBResultPtr;
#define DBResult(name, call)\
    rho::db::DBResultPtr p##name = call;\
    rho::db::CDBResult& name = *p##name;

}
}

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
rhodes-1.5.4 platform/shared/db/DBResult.h
rhodes-1.5.3 platform/shared/db/DBResult.h
rhodes-1.5.2 platform/shared/db/DBResult.h
rhodes-1.5.1 platform/shared/db/DBResult.h
rhodes-1.5.0 platform/shared/db/DBResult.h