35#include <sptk5/DataSource.h>
37#include <sptk5/FieldList.h>
38#include <sptk5/db/AutoDatabaseConnection.h>
39#include <sptk5/db/QueryParameterList.h>
40#include <sptk5/threads/Locks.h>
58 : m_autoPrepare(autoPrepare)
152 m_statement = statement;
155 void setPrepared(
bool prepared)
157 m_prepared = prepared;
160 void setActive(
bool active)
165 void setEof(
bool eof)
203 const String& getSQL()
const
208 void setSQL(
const String& sql)
219 bool m_autoPrepare {
true};
220 StmtHandle m_statement {
nullptr};
221 bool m_prepared {
false};
222 bool m_active {
false};
224 bool m_bulkMode {
false};
227 PoolDatabaseConnection* m_db {
nullptr};
261 explicit
Query(const DatabaseConnection& db, const
String& sql = "",
bool autoPrepare = true);
294 Field& operator[](
size_t fieldIndex)
override
296 return m_fields[(int) fieldIndex];
304 return m_fields[fieldName];
313 return m_fields.size();
323 notImplemented(
"recordCount");
427 return m_params.size();
440 return m_params[paramName];
452 return m_params[paramName.c_str()];
462 return m_params[paramIndex];
520 void sqlParseParameter(
const char* paramStart,
const char* paramEnd,
int& paramNumber, String& sql);
522 String parseParameters(
const String& _sql);
524 const char* readParamater(String& sql,
int& paramNumber,
const char* paramStart,
const char* paramEnd);
527using SQuery = std::shared_ptr<Query>;
533#define THROW_QUERY_ERROR(query, error) \
535 std::stringstream err; \
537 throw sptk::DatabaseException(err.str(), __FILE__, __LINE__, query->sql()); \
540constexpr int FETCH_BUFFER_SIZE = 1024;
Definition: DataSource.h:49
Definition: FieldList.h:50
Definition: PoolDatabaseConnection.h:98
Definition: PoolDatabaseConnection.h:231
Definition: QueryParameterList.h:57
Definition: QueryParameter.h:44
void connect(PoolDatabaseConnection *db)
void closeStmt(bool freeStatement=false)
void closeQuery(bool releaseStatement=false)
StmtHandle statement() const
Definition: Query.h:67
bool eof() const override
Definition: Query.h:101
void setDatabase(PoolDatabaseConnection *db)
void database(PoolDatabaseConnection *db)
Definition: Query.h:136
void notImplemented(const String &functionName) const
Strings & messages()
Definition: Query.h:193
bool prepared() const
Definition: Query.h:93
void setStatement(StmtHandle statement)
Definition: Query.h:150
PoolDatabaseConnection * database() const
Definition: Query.h:128
bool autoPrepare() const
Definition: Query.h:77
bool active() const
Definition: Query.h:85
QueryStatementManagement(bool autoPrepare)
Definition: Query.h:57
void setBulkMode(bool _bulkMode)
bool close() override
Definition: Query.h:380
bool next() override
Definition: Query.h:389
bool readField(const char *fname, Variant &value) override
FieldList & fields()
Definition: Query.h:344
Field & operator[](const String &fieldName) override
Definition: Query.h:302
size_t recordCount() const override
Definition: Query.h:321
virtual String sql() const
Definition: Query.h:329
QueryParameter & param(const String ¶mName) const
Definition: Query.h:450
QueryParameterList & params()
Definition: Query.h:352
QueryParameter & param(const char *paramName) const
Definition: Query.h:438
size_t paramCount() const
Definition: Query.h:425
virtual void exec(const String &newSQL)
Definition: Query.h:409
bool saveData() override
Definition: Query.h:497
virtual void sql(const String &_sql)
virtual void exec()
Definition: Query.h:398
QueryParameter & param(size_t paramIndex) const
Definition: Query.h:460
bool loadData() override
Definition: Query.h:486
bool writeField(const char *fname, const Variant &fvalue) override
static void throwError(const String &method, const String &error)
size_t fieldCount() const override
Definition: Query.h:311
Definition: Variant.h:372