fastdo  0.6.16
eiendb_common.hpp
浏览该文件的文档.
1 #ifndef __EIENDB_COMMON_HPP__
2 #define __EIENDB_COMMON_HPP__
3 
4 #include "eiendb_base.hpp"
5 
6 namespace eiendb
7 {
8 
14 {
15 public:
16  MemoryResult( winux::StringArray const & fields );
17 
18  #if defined(__GNUC__) || _MSC_VER > 1200
19  template < size_t _N >
20  MemoryResult( winux::String (&fields)[_N] ) : _curRowIndex(0), _fieldNames( fields, fields + _N )
21  {
22  }
23  #endif
24 
25  virtual ~MemoryResult();
26 
27  virtual bool free() override { return true; }
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 fetchArray( winux::MixedArray * fields ) override;
63  virtual bool fetchMap( winux::StringMixedMap * fields ) override;
64  virtual winux::String fieldName( size_t fieldIndex ) override { return _fieldNames[fieldIndex]; }
65  virtual size_t fieldsCount() override { return _fieldNames.size(); }
66  virtual size_t rowsCount() override { return _dataRows.size(); }
67  virtual winux::String fieldType( size_t fieldIndex ) override;
68 
69 private:
70  size_t _curRowIndex; // 当前行索引
71  winux::StringArray _fieldNames; // 字段名称信息
72  std::vector<winux::MixedArray> _dataRows; // 作为内部数据
73 
75 };
76 
79 {
80 public:
84  SqlScript( IDbConnection * cnn );
85 
87  size_t load( winux::IFile * sqlFile );
88 
90  typedef bool (* ProgressCallback)( SqlScript * script, size_t iCurSql, winux::String const & errStr, void * param );
91 
99  size_t exec(
100  bool onErrorNext = false,
101  bool storeError = true,
102  ProgressCallback progress = NULL,
103  void * param = NULL
104  );
105 
107  winux::StringArray const & sqls() { return this->_sqlArr; }
108 
110  winux::StringArray const & errors() { return this->_errArr; }
111 
112 private:
113  winux::StringArray _sqlArr;
114  winux::StringArray _errArr;
115  //std::vector< winux::SharedPointer<IDbResult> > _resArr;
116  IDbConnection * _cnn;
117 };
118 
121 {
122 public:
130  SqlBackup( IDbConnection * cnn, winux::IFile * file, IDbConnection * compatible = NULL );
131 
134  {
137  bptBackupStruct
138  };
139 
142  {
143  enum BackupProgressType type;
145  size_t tblIndex;
146  size_t tblsCount;
147  size_t rowIndex;
148  size_t rowsCount;
149  BackupProgressData() : type(bptNone), tblIndex(0), tblsCount(0), rowIndex(0), rowsCount(0) { }
150  };
151 
153  typedef bool (* ProgressCallback)( SqlBackup * backup, BackupProgressData * data, void * param );
154 
156  void backupTableStructure( winux::String const & tableName );
157 
161  void backupTableData( winux::String const & tableName, bool noDeleteFrom = false, ProgressCallback progress = NULL, void * param = NULL );
162 
164  void backupDb( bool backupStructure = true, bool noDeleteFrom = false, ProgressCallback progress = NULL, void * param = NULL );
166  bool resumeDb( bool onErrorNext = false, SqlScript::ProgressCallback progress = NULL, void * param = NULL );
167 
168 private:
170  IDbConnection * _cnn;
172  IDbConnection * _compatible;
174  winux::IFile * _file;
176  winux::StringArray _tableNames;
177 };
178 
181 {
182 public:
217  Database( winux::Mixed const & configParams );
218  virtual ~Database();
220  operator bool() const { return (bool)_cnn && (bool)*_cnn.get(); }
222  IDbConnection * cnn() { return this->_cnn.get(); }
224  IDbConnection * operator -> () { return this->_cnn.get(); }
226  winux::SharedPointer<IDbModifier> mdf( winux::String const & tableName );
228  winux::Mixed const & config() const { return _configParams; }
230  winux::Mixed & config() { return _configParams; }
231 
232 private:
233  void _doCreateConnection();
234  winux::Mixed _configParams;
236 };
237 
238 
239 } // namespace eiendb
240 
241 #endif // __EIENDB_COMMON_HPP__
数据库连接接口
Definition: eiendb_base.hpp:65
SQL脚本执行器。执行多条语句,保存结果和错误信息。
bool(* ProgressCallback)(SqlScript *script, size_t iCurSql, winux::String const &errStr, void *param)
SqlScript的进度回调函数指针类型
std::map< String, Mixed > StringMixedMap
Definition: utilities.hpp:278
winux::Mixed & config()
获取配置参数的引用
IDbConnection * cnn()
获取Connection指针
XString< tchar > String
Definition: utilities.hpp:261
MemoryResult(winux::String(&fields)[_N])
winux::StringArray const & sqls()
SQL语句数组
#define DISABLE_OBJECT_COPY(clsname)
Definition: utilities.hpp:85
winux::Mixed const & config() const
获取配置参数的引用
size_t addRow(_Ty(&values)[_N])
BackupProgressType
备份进度种类
引用计数共享指针
Definition: smartptr.hpp:456
std::vector< Mixed > MixedArray
Definition: utilities.hpp:277
数据结果操作接口
#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:1440
virtual bool free() override
释放Result资源
简单指针
Definition: smartptr.hpp:302
数据库通用接口
Definition: eiendb_base.hpp:7
virtual winux::String fieldName(size_t fieldIndex) override
获取结果集中指定字段的名称
winux::StringArray const & errors()
错误信息数组
文件接口
Definition: filesys.hpp:313
数据库操作
内存结果集
XStringArray< tchar > StringArray
Definition: utilities.hpp:272
size_t addRow(std::vector< _Ty > const &values)
添加一数据行,返回索引值
size_t rowsCount
行数 vaild if type=bptBackupData