OpenM++ runtime library (libopenm)
dbExec.h
Go to the documentation of this file.
1 
5 // Copyright (c) 2013-2015 OpenM++
6 // This code is licensed under the MIT license (see LICENSE.txt for details)
7 
8 #ifndef DB_EXEC_H
9 #define DB_EXEC_H
10 
11 #include <mutex>
12 using namespace std;
13 
14 #include "libopenm/omLog.h"
15 #include "libopenm/db/dbCommon.h"
16 
17 namespace openm
18 {
20  class IDbExec
21  {
22  public:
24  virtual ~IDbExec(void) noexcept = 0;
25 
31  static IDbExec * create(const string & i_sqlProvider, const string & i_connectionStr);
32 
41  virtual int selectToInt(const string & i_sql, int i_default) = 0;
42 
51  virtual long long selectToLong(const string & i_sql, long long i_default) = 0;
52 
60  virtual string selectToStr(const string & i_sql) = 0;
61 
69  virtual bool selectToBool(const string & i_sql) = 0;
70 
79  virtual double selectToDouble(const string & i_sql, double i_default) = 0;
80 
88  virtual vector<string> selectRowStr(const string & i_sql) = 0;
89 
98  virtual IRowBaseVec selectRowVector(const string & i_sql, const IRowAdapter & i_adapter) = 0;
99 
108  virtual IRowBaseList selectRowList(const string & i_sql, const IRowAdapter & i_adapter) = 0;
109 
117  virtual void selectToRowProcessor(const string & i_sql, const IRowAdapter & i_adapter, IRowProcessor & i_processor) = 0;
118 
135  virtual size_t selectColumn(
136  const string & i_sql, int i_column, const type_info & i_type, size_t i_size, void * io_valueArr
137  ) = 0;
138 
146  virtual size_t update(const string & i_sql) = 0;
147 
149  virtual void beginTransaction(void) = 0;
150 
152  virtual unique_lock<recursive_mutex> beginTransactionThreaded(void) = 0;
153 
155  virtual void commit(void) = 0;
156 
158  virtual void rollback(void) = 0;
159 
161  virtual bool isTransaction(void) = 0;
162 
182  virtual void createStatement(const string & i_sql, int i_paramCount, const type_info ** i_typeArr) = 0;
183 
199  virtual void releaseStatement(void) noexcept = 0;
200 
220  virtual void executeStatement(int i_paramCount, const DbValue * i_valueArr) = 0;
221 
223  static list<string> parseListOfProviderNames(const string & i_sqlProviderNames);
224 
226  static bool isValidProviderName(const char * i_sqlProvider);
227 
229  static bool isSqlKeyword(const char * i_keyword, size_t i_length = 0);
230 
232  static const int maxDbTableNameSize;
233 
235  static string bigIntTypeName(const string & i_sqlProvider);
236 
238  static string floatTypeName(const string & i_sqlProvider);
239 
241  static string textTypeName(const string & i_sqlProvider, int i_size);
242 
244  static string makeSqlBeginTransaction(const string & i_sqlProvider);
245 
247  static string makeSqlCommitTransaction(const string & i_sqlProvider);
248 
263  static string makeSqlCreateTableIfNotExist(
264  const string & i_sqlProvider, const string & i_tableName, const string & i_tableBodySql
265  );
266 
283  static string makeSqlCreateViewReplace(
284  const string & i_sqlProvider, const string & i_viewName, const string & i_viewBodySql
285  );
286 
312  virtual void runSqlScript(const string & i_sqlScript) = 0;
313  };
314 }
315 
316 #endif // DB_EXEC_H
database connection wrapper to execute sql commands.
Definition: dbExec.h:21
virtual void releaseStatement(void) noexcept=0
release statement resources.
virtual vector< string > selectRowStr(const string &i_sql)=0
select string vector of first row or empty vector if no rows, empty "" string used for NULLs.
virtual bool selectToBool(const string &i_sql)=0
select boolean value of first (row,column) or false if no rows or value IS NULL.
virtual void createStatement(const string &i_sql, int i_paramCount, const type_info **i_typeArr)=0
create new statement with specified parameters.
virtual void commit(void)=0
commit transaction, does nothing if no active transaction.
virtual double selectToDouble(const string &i_sql, double i_default)=0
select double value of first (row,column) or default if no rows or value IS NULL.
virtual bool isTransaction(void)=0
return true in transaction scope.
virtual string selectToStr(const string &i_sql)=0
select string value of first (row,column) or empty "" string if no rows or value IS NULL.
virtual size_t selectColumn(const string &i_sql, int i_column, const type_info &i_type, size_t i_size, void *io_valueArr)=0
select column into io_valueArray[i_size] buffer and return row count.
virtual long long selectToLong(const string &i_sql, long long i_default)=0
select long value of first (row,column) or default if no rows or value IS NULL.
virtual void selectToRowProcessor(const string &i_sql, const IRowAdapter &i_adapter, IRowProcessor &i_processor)=0
select and process rows: each row created by row adapter and passed to processor.
virtual int selectToInt(const string &i_sql, int i_default)=0
select integer value of first (row,column) or default if no rows or value IS NULL.
static const int maxDbTableNameSize
return max length of db table or view name.
Definition: dbExec.h:232
virtual IRowBaseList selectRowList(const string &i_sql, const IRowAdapter &i_adapter)=0
select list of rows, each row created and field values set by row adapter.
virtual void executeStatement(int i_paramCount, const DbValue *i_valueArr)=0
execute statement with parameters.
virtual IRowBaseVec selectRowVector(const string &i_sql, const IRowAdapter &i_adapter)=0
select vector of rows, each row created and field values set by row adapter.
virtual void rollback(void)=0
rollback transaction.
virtual size_t update(const string &i_sql)=0
execute sql statement (update, insert, delete, create, etc).
virtual unique_lock< recursive_mutex > beginTransactionThreaded(void)=0
begin transaction in multi-threaded environment.
virtual void runSqlScript(const string &i_sqlScript)=0
parse and execute list of sql statements.
virtual void beginTransaction(void)=0
begin transaction.
row factory and setter interface to select row from database
Definition: dbCommon.h:45
public interafce for row processing during select, ie: select and append to row list
Definition: dbCommon.h:181
OpenM++ data library: public interface for db common structures.
openM++ namespace
Definition: log.h:32
std::list< IRowBaseUptr > IRowBaseList
db rows: list of unique pointers to db row
Definition: omHelper.h:206
std::vector< IRowBaseUptr > IRowBaseVec
db rows: vector of unique pointers to db row
Definition: omHelper.h:203
OpenM++: public interface for log and trace support.
union to pass value to database methods
Definition: dbCommon.h:73