#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); } } } }