123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238 |
- #include "stdafx.h"
- #include "SQLiteQuery.h"
- #include "SQLiteStore.h"
- namespace OTSSQLITE
- {
- CSQLiteQuery::CSQLiteQuery(CppSQLite3QueryPtr a_query)
- : m_query(a_query)
- {
- }
- CSQLiteQuery::~CSQLiteQuery(void)
- {
- }
- int CSQLiteQuery::GetColCount()
- {
- if (m_query)
- {
- try
- {
- return m_query->numFields();
- }
- catch (CppSQLite3Exception& ex)
- {
- LogErrorTrace(__FILE__,__LINE__, CSQLiteStore::GetExceptionErrorString(ex));
- ASSERT(FALSE);
- }
- }
- return -1;
- }
- int CSQLiteQuery::GetColType(const int a_nColIndex)
- {
- if (m_query)
- {
- try
- {
- return m_query->fieldDataType(a_nColIndex);
- }
- catch (CppSQLite3Exception& ex)
- {
- LogErrorTrace(__FILE__, __LINE__, CSQLiteStore::GetExceptionErrorString(ex));
- ASSERT(FALSE);
- }
- }
- return -1;
- }
- CString CSQLiteQuery::GetColName(const int a_nColIndex)
- {
- if (m_query)
- {
- try
- {
- return m_query->fieldName(a_nColIndex);
- }
- catch (CppSQLite3Exception& ex)
- {
- LogErrorTrace(__FILE__, __LINE__, CSQLiteStore::GetExceptionErrorString(ex));
- ASSERT(FALSE);
- }
- }
- return _T("");
- }
- CString CSQLiteQuery::GetColValue(const int a_nColIndex)
- {
- if (m_query)
- {
- try
- {
- return m_query->fieldValue(a_nColIndex);
- }
- catch (CppSQLite3Exception& ex)
- {
- LogErrorTrace(__FILE__, __LINE__, CSQLiteStore::GetExceptionErrorString(ex));
- ASSERT(FALSE);
- }
- }
- return _T("");
- }
- int CSQLiteQuery::GetColIntValue(const int a_nColIndex, const int a_nNullValue /*= 0*/)
- {
- if (m_query)
- {
- try
- {
- return m_query->getIntField(a_nColIndex, a_nNullValue);
- }
- catch (CppSQLite3Exception& ex)
- {
- LogErrorTrace(__FILE__, __LINE__, CSQLiteStore::GetExceptionErrorString(ex));
- ASSERT(FALSE);
- }
- }
- return a_nNullValue;
- }
- double CSQLiteQuery::GetColFloatValue(const int a_nColIndex, const double a_dNullValue /*= 0.0*/)
- {
- if (m_query)
- {
- try
- {
- return m_query->getFloatField(a_nColIndex, a_dNullValue);
- }
- catch (CppSQLite3Exception& ex)
- {
- LogErrorTrace(__FILE__, __LINE__, CSQLiteStore::GetExceptionErrorString(ex));
- ASSERT(FALSE);
- }
- }
- return a_dNullValue;
- }
- CString CSQLiteQuery::GetColStringValue(const int a_nColIndex, LPCTSTR a_sNullValue /*= _T("")*/)
- {
- if (m_query)
- {
- try
- {
- return m_query->getStringField(a_nColIndex, a_sNullValue);
- }
- catch (CppSQLite3Exception& ex)
- {
- LogErrorTrace(__FILE__, __LINE__, CSQLiteStore::GetExceptionErrorString(ex));
- ASSERT(FALSE);
- }
- }
- return a_sNullValue;
- }
- const unsigned char* CSQLiteQuery::GetColBlobValue(const int a_nColIndex, int& a_nLen)
- {
- if (m_query)
- {
- try
- {
- return m_query->getBlobField(a_nColIndex, a_nLen);
- }
- catch (CppSQLite3Exception& ex)
- {
- LogErrorTrace(__FILE__, __LINE__, CSQLiteStore::GetExceptionErrorString(ex));
- ASSERT(FALSE);
- }
- }
- return nullptr;
- }
- BOOL CSQLiteQuery::IsColNull(const int a_nColIndex)
- {
- if (m_query)
- {
- try
- {
- return m_query->fieldIsNull(a_nColIndex) ? TRUE : FALSE;
- }
- catch (CppSQLite3Exception& ex)
- {
- LogErrorTrace(__FILE__, __LINE__, CSQLiteStore::GetExceptionErrorString(ex));
- ASSERT(FALSE);
- }
- }
- return TRUE;
- }
- BOOL CSQLiteQuery::IsValid()
- {
- return (m_query) ? TRUE : FALSE;
- }
- BOOL CSQLiteQuery::IsEOF()
- {
- if (m_query)
- {
- try
- {
- return m_query->eof() ? TRUE : FALSE;
- }
- catch (CppSQLite3Exception& ex)
- {
- LogErrorTrace(__FILE__, __LINE__, CSQLiteStore::GetExceptionErrorString(ex));
- _ASSERT(FALSE);
- }
- }
- ASSERT(FALSE);
- return TRUE;
- }
- BOOL CSQLiteQuery::NextRow()
- {
- if (m_query)
- {
- try
- {
- m_query->nextRow();
- return TRUE;
- }
- catch (CppSQLite3Exception& ex)
- {
- LogErrorTrace(__FILE__, __LINE__, CSQLiteStore::GetExceptionErrorString(ex));
- ASSERT(FALSE);
- }
- }
- ASSERT(FALSE);
- return FALSE;
- }
- void CSQLiteQuery::Close()
- {
- if (m_query)
- {
- try
- {
- m_query->finalize();
- }
- catch (CppSQLite3Exception& ex)
- {
- LogErrorTrace(__FILE__, __LINE__, CSQLiteStore::GetExceptionErrorString(ex));
- ASSERT(FALSE);
- }
- }
- }
- }
|