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);
Exception type used by the sqlite3x classes.
Encapsulates a command to send to an sqlite3_connection.
bool reset()
Resets this statement using sqlite3_reset().
int colcount()
Returns the column count of this object's query, or throws on error.
std::string errormsg() const
Returns the equivalent of sqlite3_errmsg(), or an empty string if that function returns null.
A type for reading results from an sqlite3_command.
int getint(int index)
Gets the integer value at the given field number.
int64_t getint64(int index)
Gets the (int64_t) value at the given field number.
std::string getstring(int index)
Gets the string value at the given field number.
sqlite3_cursor()
Creates an empty cursor object, suitable only for use as the target of a copy/assignment.
void close()
Closes this cursor.
bool isnull(int index)
Check if the given field number is NULL.
~sqlite3_cursor()
Closes this cursor, freeing up db resources if this is the last cursor of a copied set.
int colcount()
Returns the column count of the result set or throws on error.
std::string getcolname(int index)
Gets the column name for the given column index.
bool step()
Steps one step through the sql result set and returns true on SQLITE_ROW, false on SQLITE3_DONE,...
sqlite3_cursor & operator=(const sqlite3_cursor ©)
Copies the given cursor object.
void reset()
Resets the underlying prepared statement of this cursor.
std::string getblob(int index)
Gets the blob value at the given field number.
double getdouble(int index)
Gets the double value at the given field number.
This namespace encapsulates a C++ API wrapper for sqlite3 databases.
sqlite_int64 int64_t
64-bit integer type used by this code.