/* CVSNT Generic API Copyright (C) 2004 Tony Hoyle and March-Hare Software Ltd This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifdef _WIN32 #define WIN32_LEAN_AND_MEAN #include #include #define vsnprintf _vsnprintf #define snprintf _snprintf #endif #include #include "../lib/api_system.h" #ifdef HAVE_SQLITE3_H #include #else // else what? #endif #include #include "../cvs_string.h" #include "../ServerIO.h" #include "SQLiteRecordset.h" CSQLiteField::CSQLiteField() { } CSQLiteField::~CSQLiteField() { } CSQLiteField::operator int() { return sqlite3_column_int(pStmt,field); } CSQLiteField::operator long() { return (long)sqlite3_column_int64(pStmt,field); } CSQLiteField::operator unsigned() { return (unsigned)sqlite3_column_int64(pStmt,field); } CSQLiteField::operator unsigned long() { return (unsigned long)sqlite3_column_int64(pStmt,field); } #if defined(_WIN32) || defined(_WIN64) CSQLiteField::operator __int64() { return (__int64)sqlite3_column_int64(pStmt,field); } #else CSQLiteField::operator long long() { return (long long)sqlite3_column_int64(pStmt,field); } #endif CSQLiteField::operator const char *() { return (const char *)sqlite3_column_text(pStmt,field); } CSQLiteField::operator const wchar_t *() { return (const wchar_t *)sqlite3_column_text16(pStmt,field); } /**********************************************************************/ CSQLiteRecordset::CSQLiteRecordset() { m_pStmt = NULL; } CSQLiteRecordset::~CSQLiteRecordset() { Close(); } bool CSQLiteRecordset::Init(sqlite3 *pDb, sqlite3_stmt *pStmt) { m_pStmt = pStmt; m_bEof = false; m_num_fields = sqlite3_column_count(m_pStmt); m_sqlfields.resize(m_num_fields); for(int n=0; n=(size_t)m_num_fields) return NULL; return (CSqlField*)&m_sqlfields[item]; } CSqlField* CSQLiteRecordset::operator[](int item) const { if(item<0 || item>=m_num_fields) return NULL; return (CSqlField*)&m_sqlfields[item]; } CSqlField* CSQLiteRecordset::operator[](const char *item) const { for(size_t n=0; n<(size_t)m_num_fields; n++) if(!strcasecmp(m_sqlfields[n].name.c_str(),item)) return (CSqlField*)&m_sqlfields[n]; CServerIo::error("Database error - field '%s' not found in recordset.",item); return NULL; }