fastdo  0.6.8
eiendb_common.hpp
浏览该文件的文档.
1 
3 #ifndef __EIENDB_COMMON_HPP__
4 #define __EIENDB_COMMON_HPP__
5 
6 #include "eiendb_base.hpp"
7 
8 namespace eiendb
9 {
10 
16 {
17 public:
18  MemoryResult( winux::StringArray const & fields );
19 
20  #if defined(__GNUC__) || _MSC_VER > 1200
21  template < size_t _N >
22  MemoryResult( winux::String (&fields)[_N] ) : _curRowIndex(0), _fieldNames( fields, fields + _N )
23  {
24  }
25  #endif
26 
27  virtual ~MemoryResult();
28 
30  template < typename _Ty >
31  size_t addRow( std::vector<_Ty> const & values )
32  {
33  winux::MixedArray newRow;
34  typename std::vector<_Ty>::const_iterator it;
35  for ( it = values.begin(); it != values.end(); ++it )
36  {
37  newRow.push_back(*it);
38  }
39  size_t index = _dataRows.size();
40  _dataRows.push_back(newRow);
41  return index;
42  }
43 
44  #if defined(__GNUC__) || _MSC_VER > 1200
45  template < typename _Ty, size_t _N >
46  size_t addRow( _Ty (&values)[_N] )
47  {
48  winux::MixedArray newRow;
49  size_t i;
50  for ( i = 0; i < _N; ++i )
51  {
52  newRow.push_back(values[i]);
53  }
54  size_t index = _dataRows.size();
55  _dataRows.push_back(newRow);
56  return index;
57  }
58  #endif
59 
60  virtual bool dataSeek( size_t index ) override;
61  virtual bool fetchRow( winux::Mixed * fields, int type = 0 ) override;
62  virtual bool fetchRow( winux::MixedArray * fields ) override;
63  virtual bool fetchRow( winux::StringMixedMap * fields ) override;
64  virtual winux::String fieldName( size_t fieldIndex ) override { return _fieldNames[fieldIndex]; }
65  virtual bool free() override { return true; }
66  virtual size_t fieldsCount() override { return _fieldNames.size(); }
67  virtual size_t rowsCount() override { return _dataRows.size(); }
68  virtual winux::String fieldType( size_t fieldIndex ) override;
69 
70 private:
71  size_t _curRowIndex; // 当前行索引
72  winux::StringArray _fieldNames; // 字段名称信息
73  std::vector<winux::MixedArray> _dataRows;// 作为内部数据
74 
76 };
77 
80 {
81 public:
85  SqlScript( IDbConnection * cnn );
86 
88  size_t loadSql( winux::String const & sqlText );
89 
91  size_t load( winux::IFile * sqlFile );
92 
94  typedef bool (* ProgressCallback)( SqlScript * script, size_t iCurSql, winux::String const & errStr, void * param );
95 
103  size_t exec(
104  bool onErrorNext = false,
105  bool storeError = true,
106  ProgressCallback progress = NULL,
107  void * param = NULL
108  );
109 
111  winux::StringArray const & sqls() { return this->_sqlArr; }
112 
114  winux::StringArray const & errors() { return this->_errArr; }
115 
116 private:
117  winux::StringArray _sqlArr;
118  winux::StringArray _errArr;
119  //std::vector< winux::SharedPointer<IDbResult> > _resArr;
120  IDbConnection * _cnn;
121 };
122 
125 {
126 public:
134  SqlBackup( IDbConnection * cnn, winux::IFile * file, IDbConnection * compatible = NULL );
135 
138  {
141  bptBackupStruct
142  };
143 
146  {
147  enum BackupProgressType type;
149  size_t tblIndex;
150  size_t tblsCount;
151  size_t rowIndex;
152  size_t rowsCount;
153  BackupProgressData() : type(bptNone), tblIndex(0), tblsCount(0), rowIndex(0), rowsCount(0) { }
154  };
155 
157  typedef bool (* ProgressCallback)( SqlBackup * backup, BackupProgressData * data, void * param );
158 
160  void backupTableStructure( winux::String const & tableName );
161 
165  void backupTableData( winux::String const & tableName, bool noDeleteFrom = false, ProgressCallback progress = NULL, void * param = NULL );
166 
168  void backupDb( bool backupStructure = true, bool noDeleteFrom = false, ProgressCallback progress = NULL, void * param = NULL );
170  bool resumeDb( bool onErrorNext = false, SqlScript::ProgressCallback progress = NULL, void * param = NULL );
171 
172 private:
174  IDbConnection * _cnn;
176  IDbConnection * _compatible;
178  winux::IFile * _file;
180  winux::StringArray _tableNames;
181 };
182 
185 {
186 public:
208  Database( winux::Mixed const & configParams );
209  virtual ~Database();
211  operator bool() const { return (bool)_cnn && (bool)*_cnn.get(); }
213  IDbConnection * cnn() { return this->_cnn.get(); }
215  IDbConnection * operator -> () { return this->_cnn.get(); }
217  winux::SharedPointer<IDbModifier> mdf( winux::String const & tableName );
219  winux::Mixed const & config() const { return _configParams; }
220  //winux::Mixed & config() { return _configParams; }
221 private:
222  void _doCreateConnection();
223  winux::Mixed _configParams;
225 };
226 
227 }
228 
229 #endif // __EIENDB_COMMON_HPP__
数据库连接接口
Definition: eiendb_base.hpp:63
SQL脚本执行器。执行多条语句,保存结果和错误信息。
bool(* ProgressCallback)(SqlScript *script, size_t iCurSql, winux::String const &errStr, void *param)
SqlScript的进度回调函数指针类型
std::map< String, Mixed > StringMixedMap
Definition: utilities.hpp:233
IDbConnection * cnn()
获取Connection指针
XString< tchar > String
Definition: utilities.hpp:216
MemoryResult(winux::String(&fields)[_N])
winux::StringArray const & sqls()
SQL语句数组
#define DISABLE_OBJECT_COPY(clsname)
Definition: utilities.hpp:81
winux::Mixed const & config() const
获取配置参数的引用
size_t addRow(_Ty(&values)[_N])
BackupProgressType
备份进度种类
std::vector< Mixed > MixedArray
Definition: utilities.hpp:232
数据结果操作接口
#define EIENDB_DLL
Definition: eiendb_base.hpp:25
virtual size_t fieldsCount() override
获取结果里的字段数
size_t rowIndex
行索引 vaild if type=bptBackupData
virtual size_t rowsCount() override
获取结果里的记录数
数据库备份器。把数据备份成SQL脚本,方便跨数据库转移。
混合体,能表示多种类型的值
Definition: utilities.hpp:750
virtual bool free() override
释放Result资源
简单指针
Definition: smartptr.hpp:235
数据库通用接口
Definition: eiendb_base.hpp:7
virtual winux::String fieldName(size_t fieldIndex) override
获取结果集中指定字段的名称
winux::StringArray const & errors()
错误信息数组
文件接口
Definition: filesys.hpp:206
数据库操作
内存结果集
XStringArray< tchar > StringArray
Definition: utilities.hpp:227
size_t addRow(std::vector< _Ty > const &values)
添加一数据行,返回索引值
size_t rowsCount
行数 vaild if type=bptBackupData