23 #include "sqlite3x.hpp"
30 if(this->cmd) ++this->cmd->refs;
45 if(this->cmd) ++this->cmd->refs;
54 throw database_error(
"sqlite3_cursor::colcount(): reader is closed");
60 if(!this->cmd)
throw database_error(
"sqlite3_cursor::step(): reader is closed");
62 switch(sqlite3_step(this->cmd->stmt)) {
73 if(!this->cmd)
throw database_error(
"sqlite3_cursor::reset(): reader is closed");
75 if(! this->cmd->
reset() )
83 if(--this->cmd->refs==0) { sqlite3_reset(this->cmd->stmt); }
88 #define READER_CHECK(FUNC) \
89 if( ! this->cmd ) throw database_error( "sqlite3_cursor::%s(%d): reader is closed", # FUNC, index ); \
90 if( (index)>(this->cmd->argc-1)) throw database_error("sqlite3_cursor::%s(%d): index out of range", # FUNC, index );
94 return sqlite3_column_type(this->cmd->stmt, index) == SQLITE_NULL;
99 return sqlite3_column_int(this->cmd->stmt, index);
104 return sqlite3_column_int64(this->cmd->stmt, index);
109 return sqlite3_column_double(this->cmd->stmt, index);
113 READER_CHECK(
string);
114 return std::string((
const char*)sqlite3_column_text(this->cmd->stmt, index), sqlite3_column_bytes(this->cmd->stmt, index));
118 READER_CHECK(
string);
119 size = sqlite3_column_bytes(this->cmd->stmt, index);
120 return (
char const *)sqlite3_column_text(this->cmd->stmt, index);
123 #if SQLITE3X_USE_WCHAR
124 std::wstring sqlite3_cursor::getstring16(
int index) {
125 READER_CHECK(wstring);
126 return std::wstring((
const wchar_t*)sqlite3_column_text16(this->cmd->stmt, index), sqlite3_column_bytes16(this->cmd->stmt, index)/2);
131 READER_CHECK(
string);
132 return std::string((
const char*)sqlite3_column_blob(this->cmd->stmt, index), sqlite3_column_bytes(this->cmd->stmt, index));
136 READER_CHECK(
string);
137 size = sqlite3_column_bytes(this->cmd->stmt, index);
138 return sqlite3_column_blob(this->cmd->stmt, index);
142 READER_CHECK(
string);
143 char const * cn = sqlite3_column_name(this->cmd->stmt, index);
153 #if SQLITE3X_USE_WCHAR
154 std::wstring sqlite3_cursor::getcolname16(
int index) {
155 READER_CHECK(wstring);
156 return (
const wchar_t*)sqlite3_column_name16(this->cmd->stmt, index);