Index: src/libchcore/TSQLiteStatement.cpp =================================================================== diff -u -N -rb1ecc12ba4c1f2a7b4acd6e82fc4193535e55ff0 -r1875711000138ff9d4185c2e3e74d455533de8a8 --- src/libchcore/TSQLiteStatement.cpp (.../TSQLiteStatement.cpp) (revision b1ecc12ba4c1f2a7b4acd6e82fc4193535e55ff0) +++ src/libchcore/TSQLiteStatement.cpp (.../TSQLiteStatement.cpp) (revision 1875711000138ff9d4185c2e3e74d455533de8a8) @@ -21,6 +21,7 @@ #include "sqlite3/sqlite3.h" #include "ErrorCodes.h" #include "TSQLiteException.h" +#include BEGIN_CHCORE_NAMESPACE @@ -85,16 +86,21 @@ } } - void TSQLiteStatement::BindValue(int iColumn, double dValue) + void TSQLiteStatement::BindValue(int iColumn, bool bValue) { - if(!m_pStatement) - THROW_SQLITE_EXCEPTION(eErr_SQLiteStatementNotPrepared, 0, _T("Tried to step on unprepared statement")); + BindValue(iColumn, bValue ? 1 : 0); + } - int iResult = sqlite3_bind_double(m_pStatement, iColumn, dValue); - if(iResult != SQLITE_OK) - THROW_SQLITE_EXCEPTION(eErr_SQLiteBindError, iResult, _T("Cannot bind a parameter")); + void TSQLiteStatement::BindValue(int iColumn, short siValue) + { + BindValue(iColumn, (int)siValue); } + void TSQLiteStatement::BindValue(int iColumn, unsigned short usiValue) + { + BindValue(iColumn, (unsigned int)usiValue); + } + void TSQLiteStatement::BindValue(int iColumn, int iValue) { if(!m_pStatement) @@ -105,6 +111,21 @@ THROW_SQLITE_EXCEPTION(eErr_SQLiteBindError, iResult, _T("Cannot bind a parameter")); } + void TSQLiteStatement::BindValue(int iColumn, unsigned int uiValue) + { + BindValue(iColumn, *(int*)&uiValue); + } + + void TSQLiteStatement::BindValue(int iColumn, long lValue) + { + BindValue(iColumn, boost::numeric_cast(lValue)); + } + + void TSQLiteStatement::BindValue(int iColumn, unsigned long ulValue) + { + BindValue(iColumn, boost::numeric_cast(ulValue)); + } + void TSQLiteStatement::BindValue(int iColumn, long long llValue) { if(!m_pStatement) @@ -115,14 +136,19 @@ THROW_SQLITE_EXCEPTION(eErr_SQLiteBindError, iResult, _T("Cannot bind a parameter")); } - void TSQLiteStatement::BindValue(int iColumn, unsigned int uiValue) + void TSQLiteStatement::BindValue(int iColumn, unsigned long long ullValue) { - BindValue(iColumn, *(int*)&uiValue); + BindValue(iColumn, *(long long*)&ullValue); } - void TSQLiteStatement::BindValue(int iColumn, unsigned long long ullValue) + void TSQLiteStatement::BindValue(int iColumn, double dValue) { - BindValue(iColumn, *(long long*)&ullValue); + if(!m_pStatement) + THROW_SQLITE_EXCEPTION(eErr_SQLiteStatementNotPrepared, 0, _T("Tried to step on unprepared statement")); + + int iResult = sqlite3_bind_double(m_pStatement, iColumn, dValue); + if(iResult != SQLITE_OK) + THROW_SQLITE_EXCEPTION(eErr_SQLiteBindError, iResult, _T("Cannot bind a parameter")); } void TSQLiteStatement::BindValue(int iColumn, PCTSTR pszText) @@ -135,16 +161,32 @@ THROW_SQLITE_EXCEPTION(eErr_SQLiteBindError, iResult, _T("Cannot bind a parameter")); } - double TSQLiteStatement::GetDouble(int iCol) + void TSQLiteStatement::BindValue(int iColumn, const TString& strText) { - if(!m_pStatement) - THROW_SQLITE_EXCEPTION(eErr_SQLiteStatementNotPrepared, 0, _T("Tried to step on unprepared statement")); - if(!m_bHasRow) - THROW_SQLITE_EXCEPTION(eErr_SQLiteNoRowAvailable, 0, _T("No row available")); + BindValue(iColumn, (PCTSTR)strText); + } - return sqlite3_column_double(m_pStatement, iCol); + void TSQLiteStatement::BindValue(int iColumn, const TSmartPath& path) + { + BindValue(iColumn, path.ToString()); } + + bool TSQLiteStatement::GetBool(int iCol) + { + return GetInt(iCol) != 0; + } + + short TSQLiteStatement::GetShort(int iCol) + { + return boost::numeric_cast(GetInt(iCol)); + } + + unsigned short TSQLiteStatement::GetUShort(int iCol) + { + return boost::numeric_cast(GetUInt(iCol)); + } + int TSQLiteStatement::GetInt(int iCol) { if(!m_pStatement) @@ -155,6 +197,22 @@ return sqlite3_column_int(m_pStatement, iCol); } + unsigned int TSQLiteStatement::GetUInt(int iCol) + { + int iVal = GetInt(iCol); + return *(unsigned int*)&iVal; + } + + long TSQLiteStatement::GetLong(int iCol) + { + return boost::numeric_cast(GetInt(iCol)); + } + + unsigned long TSQLiteStatement::GetULong(int iCol) + { + return boost::numeric_cast(GetUInt(iCol)); + } + long long TSQLiteStatement::GetInt64(int iCol) { if(!m_pStatement) @@ -165,6 +223,22 @@ return sqlite3_column_int64(m_pStatement, iCol); } + unsigned long long TSQLiteStatement::GetUInt64(int iCol) + { + long long llVal = GetInt64(iCol); + return *(unsigned long long*)&llVal; + } + + double TSQLiteStatement::GetDouble(int iCol) + { + if(!m_pStatement) + THROW_SQLITE_EXCEPTION(eErr_SQLiteStatementNotPrepared, 0, _T("Tried to step on unprepared statement")); + if(!m_bHasRow) + THROW_SQLITE_EXCEPTION(eErr_SQLiteNoRowAvailable, 0, _T("No row available")); + + return sqlite3_column_double(m_pStatement, iCol); + } + TString TSQLiteStatement::GetText(int iCol) { if(!m_pStatement) @@ -175,6 +249,11 @@ return TString((const wchar_t*)sqlite3_column_text16(m_pStatement, iCol)); } + TSmartPath TSQLiteStatement::GetPath(int iCol) + { + return PathFromWString(GetText(iCol)); + } + void TSQLiteStatement::ClearBindings() { if(!m_pStatement) @@ -195,17 +274,55 @@ THROW_SQLITE_EXCEPTION(eErr_SQLiteBindError, iResult, _T("Cannot reset statement")); } - unsigned int TSQLiteStatement::GetUInt(int iCol) + void TSQLiteStatement::GetValue(int iCol, bool& bValue) { - int iVal = GetInt(iCol); - return *(unsigned int*)&iVal; + bValue = GetBool(iCol); } - unsigned long long TSQLiteStatement::GetUInt64(int iCol) + void TSQLiteStatement::GetValue(int iCol, short& iValue) { - long long llVal = GetInt64(iCol); - return *(unsigned long long*)&llVal; + iValue = GetShort(iCol); } + + void TSQLiteStatement::GetValue(int iCol, unsigned short& uiValue) + { + uiValue = GetUShort(iCol); + } + + void TSQLiteStatement::GetValue(int iCol, int& iValue) + { + iValue = GetInt(iCol); + } + + void TSQLiteStatement::GetValue(int iCol, unsigned int& uiValue) + { + uiValue = GetUInt(iCol); + } + + void TSQLiteStatement::GetValue(int iCol, long long& llValue) + { + llValue = GetInt64(iCol); + } + + void TSQLiteStatement::GetValue(int iCol, unsigned long long& ullValue) + { + ullValue = GetUInt64(iCol); + } + + void TSQLiteStatement::GetValue(int iCol, double& dValue) + { + dValue = GetDouble(iCol); + } + + void TSQLiteStatement::GetValue(int iCol, TString& strValue) + { + strValue = GetText(iCol); + } + + void TSQLiteStatement::GetValue(int iCol, TSmartPath& pathValue) + { + pathValue = GetPath(iCol); + } } END_CHCORE_NAMESPACE