Public Member Functions | Private Member Functions | Private Attributes

CppSQLite3Statement Class Reference

#include <CppSQLite3.h>

List of all members.

Public Member Functions

 CppSQLite3Statement ()
 CppSQLite3Statement (const CppSQLite3Statement &rStatement)
 CppSQLite3Statement (sqlite3 *pDB, sqlite3_stmt *pVM)
virtual ~CppSQLite3Statement ()
CppSQLite3Statementoperator= (const CppSQLite3Statement &rStatement)
int execDML ()
CppSQLite3Query execQuery ()
void bind (int nParam, const char *szValue)
void bind (int nParam, const int nValue)
void bind (int nParam, const double dwValue)
void bind (int nParam, const unsigned char *blobValue, int nLen)
void bindNull (int nParam)
void reset ()
void finalize ()

Private Member Functions

void checkDB ()
void checkVM ()

Private Attributes

sqlite3 * mpDB
sqlite3_stmt * mpVM

Detailed Description

Definition at line 451 of file CppSQLite3.h.


Constructor & Destructor Documentation

CppSQLite3Statement::CppSQLite3Statement (  ) 

Definition at line 1757 of file CppSQLite3.cpp.

References mpDB, and mpVM.

{

        mpDB = 0;

        mpVM = 0;

}

CppSQLite3Statement::CppSQLite3Statement ( const CppSQLite3Statement rStatement  ) 

Definition at line 1771 of file CppSQLite3.cpp.

References mpDB, and mpVM.

{

        mpDB = rStatement.mpDB;

        mpVM = rStatement.mpVM;

        // Only one object can own VM

        const_cast<CppSQLite3Statement&>(rStatement).mpVM = 0;

}

CppSQLite3Statement::CppSQLite3Statement ( sqlite3 *  pDB,
sqlite3_stmt *  pVM 
)

Definition at line 1789 of file CppSQLite3.cpp.

References mpDB, and mpVM.

{

        mpDB = pDB;

        mpVM = pVM;

}

CppSQLite3Statement::~CppSQLite3Statement (  )  [virtual]

Definition at line 1803 of file CppSQLite3.cpp.

References finalize().

{

        try

        {

                finalize();

        }

        catch (...)

        {

        }

}

Here is the call graph for this function:


Member Function Documentation

void CppSQLite3Statement::bind ( int  nParam,
const char *  szValue 
)

Definition at line 1963 of file CppSQLite3.cpp.

References checkVM(), DONT_DELETE_MSG, and mpVM.

{

        checkVM();

        int nRes = sqlite3_bind_text(mpVM, nParam, szValue, -1, SQLITE_TRANSIENT);



        if (nRes != SQLITE_OK)

        {

                throw CppSQLite3Exception(nRes,

                                                                "Error binding string param",

                                                                DONT_DELETE_MSG);

        }

}

Here is the call graph for this function:

void CppSQLite3Statement::bind ( int  nParam,
const int  nValue 
)

Definition at line 1991 of file CppSQLite3.cpp.

References checkVM(), DONT_DELETE_MSG, and mpVM.

{

        checkVM();

        int nRes = sqlite3_bind_int(mpVM, nParam, nValue);



        if (nRes != SQLITE_OK)

        {

                throw CppSQLite3Exception(nRes,

                                                                "Error binding int param",

                                                                DONT_DELETE_MSG);

        }

}

Here is the call graph for this function:

void CppSQLite3Statement::bind ( int  nParam,
const double  dwValue 
)

Definition at line 2019 of file CppSQLite3.cpp.

References checkVM(), DONT_DELETE_MSG, and mpVM.

{

        checkVM();

        int nRes = sqlite3_bind_double(mpVM, nParam, dValue);



        if (nRes != SQLITE_OK)

        {

                throw CppSQLite3Exception(nRes,

                                                                "Error binding double param",

                                                                DONT_DELETE_MSG);

        }

}

Here is the call graph for this function:

void CppSQLite3Statement::bind ( int  nParam,
const unsigned char *  blobValue,
int  nLen 
)

Definition at line 2047 of file CppSQLite3.cpp.

References checkVM(), DONT_DELETE_MSG, and mpVM.

{

        checkVM();

        int nRes = sqlite3_bind_blob(mpVM, nParam,

                                                                (const void*)blobValue, nLen, SQLITE_TRANSIENT);



        if (nRes != SQLITE_OK)

        {

                throw CppSQLite3Exception(nRes,

                                                                "Error binding blob param",

                                                                DONT_DELETE_MSG);

        }

}

Here is the call graph for this function:

void CppSQLite3Statement::bindNull ( int  nParam  ) 

Definition at line 2077 of file CppSQLite3.cpp.

References checkVM(), DONT_DELETE_MSG, and mpVM.

{

        checkVM();

        int nRes = sqlite3_bind_null(mpVM, nParam);



        if (nRes != SQLITE_OK)

        {

                throw CppSQLite3Exception(nRes,

                                                                "Error binding NULL param",

                                                                DONT_DELETE_MSG);

        }

}

Here is the call graph for this function:

void CppSQLite3Statement::checkDB (  )  [private]

Definition at line 2167 of file CppSQLite3.cpp.

References CPPSQLITE_ERROR, DONT_DELETE_MSG, and mpDB.

Referenced by execDML(), and execQuery().

{

        if (mpDB == 0)

        {

                throw CppSQLite3Exception(CPPSQLITE_ERROR,

                                                                "Database not open",

                                                                DONT_DELETE_MSG);

        }

}

Here is the caller graph for this function:

void CppSQLite3Statement::checkVM (  )  [private]

Definition at line 2189 of file CppSQLite3.cpp.

References CPPSQLITE_ERROR, DONT_DELETE_MSG, and mpVM.

Referenced by bind(), bindNull(), execDML(), and execQuery().

{

        if (mpVM == 0)

        {

                throw CppSQLite3Exception(CPPSQLITE_ERROR,

                                                                "Null Virtual Machine pointer",

                                                                DONT_DELETE_MSG);

        }

}

Here is the caller graph for this function:

int CppSQLite3Statement::execDML (  ) 

Definition at line 1847 of file CppSQLite3.cpp.

References checkDB(), checkVM(), DONT_DELETE_MSG, mpDB, and mpVM.

{

        checkDB();

        checkVM();



        const char* szError=0;



        int nRet = sqlite3_step(mpVM);



        if (nRet == SQLITE_DONE)

        {

                int nRowsChanged = sqlite3_changes(mpDB);



                nRet = sqlite3_reset(mpVM);



                if (nRet != SQLITE_OK)

                {

                        szError = sqlite3_errmsg(mpDB);

                        throw CppSQLite3Exception(nRet, (char*)szError, DONT_DELETE_MSG);

                }



                return nRowsChanged;

        }

        else

        {

                nRet = sqlite3_reset(mpVM);

                szError = sqlite3_errmsg(mpDB);

                throw CppSQLite3Exception(nRet, (char*)szError, DONT_DELETE_MSG);

        }

}

Here is the call graph for this function:

CppSQLite3Query CppSQLite3Statement::execQuery (  ) 

Definition at line 1911 of file CppSQLite3.cpp.

References checkDB(), checkVM(), DONT_DELETE_MSG, mpDB, and mpVM.

{

        checkDB();

        checkVM();



        int nRet = sqlite3_step(mpVM);



        if (nRet == SQLITE_DONE)

        {

                // no rows

                return CppSQLite3Query(mpDB, mpVM, true/*eof*/, false);

        }

        else if (nRet == SQLITE_ROW)

        {

                // at least 1 row

                return CppSQLite3Query(mpDB, mpVM, false/*eof*/, false);

        }

        else

        {

                nRet = sqlite3_reset(mpVM);

                const char* szError = sqlite3_errmsg(mpDB);

                throw CppSQLite3Exception(nRet, (char*)szError, DONT_DELETE_MSG);

        }

}

Here is the call graph for this function:

void CppSQLite3Statement::finalize (  ) 

Definition at line 2135 of file CppSQLite3.cpp.

References DONT_DELETE_MSG, mpDB, and mpVM.

Referenced by ~CppSQLite3Statement().

{

        if (mpVM)

        {

                int nRet = sqlite3_finalize(mpVM);

                mpVM = 0;



                if (nRet != SQLITE_OK)

                {

                        const char* szError = sqlite3_errmsg(mpDB);

                        throw CppSQLite3Exception(nRet, (char*)szError, DONT_DELETE_MSG);

                }

        }

}

Here is the caller graph for this function:

CppSQLite3Statement & CppSQLite3Statement::operator= ( const CppSQLite3Statement rStatement  ) 

Definition at line 1827 of file CppSQLite3.cpp.

References mpDB, and mpVM.

{

        mpDB = rStatement.mpDB;

        mpVM = rStatement.mpVM;

        // Only one object can own VM

        const_cast<CppSQLite3Statement&>(rStatement).mpVM = 0;

        return *this;

}

void CppSQLite3Statement::reset (  ) 

Definition at line 2105 of file CppSQLite3.cpp.

References DONT_DELETE_MSG, mpDB, and mpVM.

{

        if (mpVM)

        {

                int nRet = sqlite3_reset(mpVM);



                if (nRet != SQLITE_OK)

                {

                        const char* szError = sqlite3_errmsg(mpDB);

                        throw CppSQLite3Exception(nRet, (char*)szError, DONT_DELETE_MSG);

                }

        }

}


Member Data Documentation

sqlite3* CppSQLite3Statement::mpDB [private]

Definition at line 517 of file CppSQLite3.h.

Referenced by checkDB(), CppSQLite3Statement(), execDML(), execQuery(), finalize(), operator=(), and reset().

sqlite3_stmt* CppSQLite3Statement::mpVM [private]

The documentation for this class was generated from the following files: