22 #include <unordered_map> 28 #define S_NO_CONNECTION "No active connection"; 30 #define DB_BUFF_MAX 8 * 1024 // Maximum buffer's capacity 32 #define DB_CONNECTION_NONE 0 33 #define DB_CONNECTION_OK 1 34 #define DB_CONNECTION_BAD 2 36 #define DB_COMMAND_OK 0 // OK - command executed 37 #define DB_EMPTY_QUERY 1 // Query didn't return tuples 38 #define DB_TUPLES_OK 2 // Query returned tuples 40 #define DB_BAD_RESPONSE 6 41 #define DB_UNEXPECTED 7 // This shouldn't ever happen 42 #define DB_UNEXPECTED_RESULT -1 //For integer functions 55 host, port, db, login, passwd,
58 key, cert, ca, capath, ciphers;
65 virtual Dataset* CreateDataset()
const = 0;
67 virtual void setHostName(
const char* newHost) { host = newHost; }
69 const char* getHostName(
void)
const {
return host.c_str(); }
71 void setPort(
const char* newPort) { port = newPort; }
73 const char* getPort(
void)
const {
return port.c_str(); }
75 virtual void setDatabase(
const char* newDb) { db = newDb; }
77 const char* getDatabase(
void)
const {
return db.c_str(); }
79 void setLogin(
const char* newLogin) { login = newLogin; }
81 const char* getLogin(
void)
const {
return login.c_str(); }
83 void setPasswd(
const char* newPasswd) { passwd = newPasswd; }
85 const char* getPasswd(
void)
const {
return passwd.c_str(); }
87 virtual bool isActive(
void)
const {
return active; }
89 void setSequenceTable(
const char* new_seq_table) { sequence_table = new_seq_table; }
91 const char* getSequenceTable(
void) {
return sequence_table.c_str(); }
93 const char* getDefaultCharset(
void) {
return default_charset.c_str(); }
95 virtual void setConfig(
const char* newKey,
98 const char* newCApath,
99 const char* newCiphers,
106 ciphers = newCiphers;
107 compression = newCompression;
112 virtual int init(
void) {
return DB_COMMAND_OK; }
113 virtual int status(
void) {
return DB_CONNECTION_NONE; }
114 virtual int setErr(
int err_code,
const char* qry) = 0;
115 virtual const char* getErrorMsg(
void) {
return error.c_str(); }
117 virtual int connect(
bool create) {
return DB_COMMAND_OK; }
118 virtual int connectFull(
const char* newDb,
119 const char* newHost = NULL,
120 const char* newLogin = NULL,
121 const char* newPasswd = NULL,
122 const char* newPort = NULL,
123 const char* newKey = NULL,
124 const char* newCert = NULL,
125 const char* newCA = NULL,
126 const char* newCApath = NULL,
127 const char* newCiphers = NULL,
128 bool newCompression =
false);
129 virtual void disconnect(
void) { active =
false; }
130 virtual int reset(
void) {
return DB_COMMAND_OK; }
131 virtual int create(
void) {
return DB_COMMAND_OK; }
132 virtual int drop(
void) {
return DB_COMMAND_OK; }
133 virtual long nextid(
const char* seq_name) = 0;
136 virtual int copy(
const char* new_name) {
return -1; }
139 virtual int drop_analytics(
void) {
return -1; }
141 virtual bool exists(
void) {
return false; }
145 virtual void start_transaction() {}
146 virtual void commit_transaction() {}
147 virtual void rollback_transaction() {}
156 virtual std::string
prepare(
const char* format, ...);
163 virtual std::string
vprepare(
const char* format, va_list args) = 0;
165 virtual bool in_transaction() {
return false; }
193 typedef std::list<std::string> StringList;
194 typedef std::map<std::string, field_value> ParamList;
207 Fields *fields_object, *edit_object;
208 std::unordered_map<std::string, unsigned int>
226 std::string empty_sql;
227 std::string select_sql;
229 StringList update_sql;
237 StringList insert_sql;
244 StringList delete_sql;
255 virtual void make_insert() = 0;
257 virtual void make_edit() = 0;
259 virtual void make_deletion() = 0;
263 virtual void fill_fields(
void) = 0;
266 void parse_sql(std::string& sql);
272 char* str_toLower(
char* s);
283 void setDatabase(
Database* newDb) { db = newDb; }
285 Database* getDatabase(
void) {
return db; }
288 void setExecSql(
const char* newSql) { sql = newSql; }
290 const char* getExecSql(
void) {
return sql.c_str(); }
293 virtual bool isActive(
void) {
return active; }
295 virtual void setSqlParams(sqlType t,
const char* sqlFrmt, ...);
301 virtual int64_t lastinsertid() = 0;
303 virtual long nextid(
const char* seq_name) = 0;
305 virtual int num_rows() = 0;
308 virtual void open(
const std::string& sql) = 0;
309 virtual void open() = 0;
311 virtual int exec(
const std::string& sql) = 0;
312 virtual int exec() = 0;
313 virtual const void* getExecRes() = 0;
315 virtual bool query(
const std::string& sql) = 0;
317 virtual void close();
323 virtual void refresh();
330 virtual bool dropIndex(
const char* table,
const char* index) {
return false; }
333 virtual bool seek(
int pos = 0);
335 virtual bool goto_rec(
int pos = 1);
337 virtual void first();
346 virtual bool eof(
void) {
return feof; }
348 virtual bool bof(
void) {
return fbof; }
351 virtual void insert();
353 virtual void append() { insert(); }
362 virtual void deletion();
364 virtual void cancel() {}
366 virtual void interrupt() {}
368 virtual void setParamList(
const ParamList& params);
369 virtual bool locate();
370 virtual bool locate(
const ParamList& params);
371 virtual bool findNext();
375 virtual int field_count();
376 virtual int fieldCount();
378 virtual const char* fieldName(
int n);
380 virtual int fieldIndex(
const char* fn);
383 virtual bool set_field_value(
const char* f_name,
const field_value& value);
385 virtual bool sf(
const char* f,
const field_value& v) {
return set_field_value(f, v); }
391 virtual const field_value& get_field_value(
const char* f_name);
392 virtual const field_value& get_field_value(
int index);
394 const field_value& fv(
const char* f) {
return get_field_value(f); }
395 const field_value& fv(
int index) {
return get_field_value(index); }
398 void set_autocommit(
bool v) { autocommit = v; }
399 bool get_autocommit() {
return autocommit; }
402 Fields* get_fields_object() {
return fields_object; }
403 Fields* get_edit_object() {
return edit_object; }
406 const result_set& get_result_set() {
return result; }
407 const sql_record* get_sql_record();
414 bool get_index_map_entry(
const char* f_name);
416 void set_ds_state(dsStates new_state) { ds_state = new_state; }
420 dsStates get_state() {
return ds_state; }
423 void set_select_sql(
const char* sel_sql);
424 void set_select_sql(
const std::string& select_sql);
426 void add_update_sql(
const char* upd_sql);
427 void add_update_sql(
const std::string& upd_sql);
429 void add_insert_sql(
const char* ins_sql);
430 void add_insert_sql(
const std::string& ins_sql);
432 void add_delete_sql(
const char* del_sql);
433 void add_delete_sql(
const std::string& del_sql);
436 void clear_update_sql();
438 void clear_insert_sql();
440 void clear_delete_sql();
443 size_t insert_sql_count();
445 size_t delete_sql_count();
448 const char* get_select_sql();
464 const char* getMsg();
virtual bool dropIndex(const char *table, const char *index)
Drop an index from the database table, provided it exists.
Definition: dataset.h:330
Definition: Database.h:11
virtual std::string prepare(const char *format,...)
Prepare a SQL statement for execution or querying using C printf nomenclature.
Definition: dataset.cpp:73
Definition: LibInputPointer.h:13
Definition: dataset.h:456
virtual std::string vprepare(const char *format, va_list args)=0
Prepare a SQL statement for execution or querying using C printf nomenclature.
Definition: qry_dat.h:255
Definition: dataset.h:196