fastdo  0.5.12
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 
17 {
18 public:
19  MemoryResult( winux::StringArray const & fields );
20 
21  #if defined(__GNUC__) || _MSC_VER > 1200
22  template < winux::uint n >
23  MemoryResult( winux::String (&fields)[n] ) : _curRowIndex(0), _fieldNames( fields, fields + n )
24  {
25  }
26  #endif
27 
28  virtual ~MemoryResult();
29 
31  template < typename _Ty >
32  int addRow( std::vector<_Ty> const & values )
33  {
34  winux::MixedArray newRow;
35  typename std::vector<_Ty>::const_iterator it;
36  for ( it = values.begin(); it != values.end(); ++it )
37  {
38  newRow.push_back(*it);
39  }
40  int index = _dataRows.size();
41  _dataRows.push_back(newRow);
42  return index;
43  }
44 
45  #if defined(__GNUC__) || _MSC_VER > 1200
46  template < typename _Ty, winux::uint n >
47  int addRow( _Ty (&values)[n] )
48  {
49  winux::MixedArray newRow;
50  int i;
51  for ( i = 0; i < (int)n; ++i )
52  {
53  newRow.push_back(values[i]);
54  }
55  int index = _dataRows.size();
56  _dataRows.push_back(newRow);
57  return index;
58  }
59  #endif
60 
61  virtual bool dataSeek( int index );
62  virtual bool fetchRow( winux::Mixed * fields, int type = 0 );
63  virtual bool fetchRow( winux::MixedArray * fields );
64  virtual bool fetchRow( winux::StringMixedMap * fields );
65  virtual winux::String fieldName( int fieldIndex ) { return _fieldNames[fieldIndex]; }
66  virtual bool free() { return true; }
67  virtual winux::ulong fieldsCount() { return (int)_fieldNames.size(); }
68  virtual winux::ulong rowsCount() { return (int)_dataRows.size(); }
69  virtual winux::String fieldType( int fieldIndex );
70 
71 private:
72  MemoryResult( MemoryResult const & );
73  MemoryResult & operator = ( MemoryResult const & );
74 
75  int _curRowIndex; // 当前行索引
76  winux::StringArray _fieldNames; // 字段名称信息
77  std::vector<winux::MixedArray> _dataRows;// 作为内部数据
78 };
79 
82 {
83 private:
84  winux::StringArray _sqlArr;
85  winux::StringArray _errArr;
86  //std::vector< winux::SharedPointer<IDBResult> > _resArr;
87  IDBConnection * _cnn;
88 
89 public:
90  SQLScript( IDBConnection * cnn );
91 
93  winux::ulong loadSql( winux::String const & sqlText );
94 
96  winux::ulong load( winux::IFile * sqlFile );
97 
98  typedef bool (* ProgressCallback)( SQLScript * script, winux::ulong iCurSql, winux::String const & errStr, void * param );
99 
103  winux::ulong exec(
104  bool onErrorNext = false,
105  bool storeError = true,
106  ProgressCallback progress = NULL,
107  void * param = NULL
108  );
109 
110  winux::StringArray const & sqls() { return this->_sqlArr; }
111  winux::StringArray const & errors() { return this->_errArr; }
112 };
113 
116 {
117 private:
119  IDBConnection * _cnn;
121  IDBConnection * _compatible;
123  winux::IFile * _file;
124 
125  winux::StringArray _tableNames;
126 public:
134  SQLBackup( IDBConnection * cnn, winux::IFile * file, IDBConnection * compatible = NULL );
135 
138  {
139  bptNone, bptBackupData, bptBackupStruct
140  };
143  {
146  int tblIndex;
148  int rowIndex;
149  int rowsCount;
150  BackupProgressData() : type(bptNone), tblIndex(0), tblsCount(0), rowIndex(0), rowsCount(0) { }
151  };
152  typedef bool (* ProgressCallback)( SQLBackup * backup, BackupProgressData * data, void * param );
153 
155  void backupTableStructure( winux::String const & tableName );
156 
160  void backupTableData( winux::String const & tableName, bool noDeleteFrom = false, ProgressCallback progress = NULL, void * param = NULL );
161 
163  void backupDb( bool backupStructure = true, bool noDeleteFrom = false, ProgressCallback progress = NULL, void * param = NULL );
165  bool resumeDb( bool onErrorNext = false, SQLScript::ProgressCallback progress = NULL, void * param = NULL );
166 };
167 
170 {
171 public:
192  Database( winux::Mixed const & configParams );
193  virtual ~Database();
195  operator bool() const { return (bool)_cnn && (bool)*_cnn.get(); }
197  IDBConnection * cnn() { return this->_cnn.get(); }
199  IDBConnection * operator -> () { return this->_cnn.get(); }
201  winux::SharedPointer<IDBModifier> mdf( winux::String const & tableName );
203  winux::Mixed const & config() const { return _configParams; }
204  //winux::Mixed & config() { return _configParams; }
205 private:
206  void _doCreateConnection();
207  winux::Mixed _configParams;
209 };
210 
211 }
212 
213 #endif // __EIENDB_COMMON_HPP__
BackupProgressType
备份进度种类
数据结果操作接口
数据库连接接口
Definition: eiendb_base.hpp:61
std::map< String, Mixed > StringMixedMap
Definition: utilities.hpp:176
virtual bool free()
释放Result资源
int rowIndex
vaild if type=bptBackupData
IDBConnection * cnn()
获取Connection指针
winux::Mixed const & config() const
获取配置参数的引用
int addRow(_Ty(&values)[n])
std::vector< String > StringArray
Definition: utilities.hpp:171
int addRow(std::vector< _Ty > const &values)
添加一数据行
bool(* ProgressCallback)(SQLScript *script, winux::ulong iCurSql, winux::String const &errStr, void *param)
std::vector< Mixed > MixedArray
Definition: utilities.hpp:175
#define EIENDB_DLL
Definition: eiendb_base.hpp:25
数据库备份器,把数据备份成SQL脚本,方便跨数据库转移
MemoryResult(winux::String(&fields)[n])
int rowsCount
vaild if type=bptBackupData
virtual winux::String fieldName(int fieldIndex)
获取结果集中指定字段的名称
SQL脚本执行器,执行多条语句,保存结果和错误信息
混合体,能表示多种类型的值
Definition: utilities.hpp:586
简单指针
Definition: smartptr.hpp:232
virtual winux::ulong fieldsCount()
获取结果里的字段数
数据库通用接口
Definition: eiendb_base.hpp:7
virtual winux::ulong rowsCount()
获取结果里的记录数
文件接口
Definition: filesys.hpp:194
数据库操作
unsigned long ulong
Definition: utilities.hpp:129
内存结果集
std::basic_string< tchar > String
Definition: utilities.hpp:162
winux::StringArray const & errors()
winux::StringArray const & sqls()