fastdo  0.6.16
eiendb_mysql.hpp
浏览该文件的文档.
1 #ifndef __EIENDB_MYSQL_HPP__
2 #define __EIENDB_MYSQL_HPP__
3 
4 #include "eiendb_base.hpp"
5 
6 namespace eiendb
7 {
8 #ifdef HAVE_DB_MYSQL
9 
12 {
13 public:
14  MysqlDbError( int mysqlErrNo, winux::AnsiString const & s ) throw() : DbError( DbError::dbeMysqlError, s ), _mysqlErrNo(mysqlErrNo) { }
15  int getMysqlErrCode() const throw() { return _mysqlErrNo; }
16 
17 private:
18  int _mysqlErrNo;
19 };
20 
22 {
23 public:
24  MysqlConnection( winux::String const & host, winux::String const & user, winux::String const & pwd, winux::String const & dbName, winux::String const & linkCharset, bool doConnect = true );
25  virtual ~MysqlConnection();
26 
27  virtual bool connect() override;
28  virtual bool close() override;
29  virtual void alive() override;
30  virtual bool setLinkCharset( winux::String const & charset ) override;
31  virtual bool selectDb( winux::String const & database ) override;
32  virtual bool createDb( winux::String const & database ) override;
33  virtual bool dropDb( winux::String const & database ) override;
34  virtual size_t affectedRows() override;
35  virtual size_t insertId() override;
36  virtual int errNo() override;
37  virtual winux::String error() override;
38  virtual winux::String escape( winux::String const & str, winux::String const & addQuote = "\'" ) override;
39  virtual winux::String escape( void const * buf, size_t size, winux::String const & addQuote = "\'" ) override;
40  virtual bool exec( winux::String const & sql ) override;
41  virtual bool exec( winux::SharedPointer<IDbStatement> stmt ) override;
42  virtual winux::SharedPointer<IDbResult> query( winux::String const & sql ) override;
44  virtual winux::SharedPointer<IDbResult> listDbs() override;
45  virtual winux::SharedPointer<IDbResult> listFields( winux::String const & tableName ) override;
46  virtual winux::SharedPointer<IDbResult> listTables() override;
47  virtual winux::String tableDdl( winux::String const & tableName ) override;
48  virtual winux::String symbolQuotes( winux::String const & str, bool periodAsSeparator = true ) override;
49  virtual size_t loadSqlFile( winux::IFile * sqlFile, winux::StringArray * arrSql ) override;
50  virtual size_t getPrimaryKey( winux::String const & tableName, winux::StringArray * arrKeyColumn ) override;
51  virtual winux::SharedPointer<IDbStatement> buildStmt( winux::String const & sql, winux::Mixed const & params = winux::mxNull ) override;
52  virtual operator bool() const override { return _mysql != NULL; }
53 
54  operator DbHandle() const { return _mysql; }
55 
56 private:
57  DbHandle _mysql; // 代表MYSQL连接
58  winux::String _hostAddr; // 主机地址
59  int _port; // 端口
60  winux::String _user; // 用户名
61  winux::String _pwd; // 密码
62  winux::String _dbName; // 数据库名
63  winux::String _linkCharset; // 连接校验字符集
64 
66 };
67 
69 {
70 public:
72  MysqlStatement( MysqlConnection * cnn, winux::String const & sql, winux::Mixed const & params = winux::mxNull ) : DbStatement( cnn, sql, params ) { }
73 
74  MysqlConnection * getCnn() const { return static_cast<MysqlConnection*>( this->DbStatement::getCnn() ); }
75 
77 };
78 
80 {
81 public:
83  virtual ~MysqlResult();
84  virtual bool free() override;
85 
86  virtual bool dataSeek( size_t index ) override;
87  virtual bool fetchRow( winux::Mixed * fields, int type = 0 ) override;
88  virtual bool fetchArray( winux::MixedArray * fields ) override;
89  virtual bool fetchMap( winux::StringMixedMap * fields ) override;
90  virtual winux::String fieldName( size_t fieldIndex ) override;
91  virtual size_t fieldsCount() override;
92  virtual size_t rowsCount() override;
93  virtual winux::String fieldType( size_t fieldIndex ) override;
94 
95  bool reset();
96  operator bool() const { return _mysqlRes != NULL; }
97  operator DbResHandle() const { return _mysqlRes; }
98 
99 private:
100  DbResHandle _mysqlRes;
102  winux::StringArray _fieldNames; // 非原始字段名
103  std::vector<winux::uint> _fieldTypes; // 字段类型
104  std::vector<winux::uint> _fieldFlags; // 字段Flag
105 
107 };
108 
110 {
111 public:
112  MysqlModifier( MysqlConnection * cnn, winux::String const & tableName );
113  virtual ~MysqlModifier();
114 
116 };
117 
118 #endif // HAVE_DB_MYSQL
119 
120 } // namespace eiendb
121 
122 #endif // __EIENDB_MYSQL_HPP__
XString< char > AnsiString
Definition: utilities.hpp:257
数据库连接接口
Definition: eiendb_base.hpp:65
void * DbHandle
数据库各种对象资源的指针类型
Definition: eiendb_base.hpp:38
Mixed const mxNull
Mixed(MT_NULL)常量对象
std::map< String, Mixed > StringMixedMap
Definition: utilities.hpp:278
IDbConnection * getCnn() const
XString< tchar > String
Definition: utilities.hpp:261
eiendb数据库错误
Definition: eiendb_base.hpp:42
#define DISABLE_OBJECT_COPY(clsname)
Definition: utilities.hpp:85
MySQL数据库错误
引用计数共享指针
Definition: smartptr.hpp:456
std::vector< Mixed > MixedArray
Definition: utilities.hpp:277
数据结果操作接口
#define EIENDB_DLL
Definition: eiendb_base.hpp:25
MysqlStatement(MysqlConnection *cnn, winux::String const &sql, winux::Mixed const &params=winux::mxNull)
void * DbResHandle
Definition: eiendb_base.hpp:39
MysqlStatement(MysqlConnection *cnn)
混合体,能表示多种类型的值
Definition: utilities.hpp:1440
MySQL数据库错误
Definition: eiendb_base.hpp:52
数据库修改器类通用实现
数据库通用接口
Definition: eiendb_base.hpp:7
数据库语句类通用实现
int getMysqlErrCode() const
文件接口
Definition: filesys.hpp:313
XStringArray< tchar > StringArray
Definition: utilities.hpp:272
MysqlConnection * getCnn() const
MysqlDbError(int mysqlErrNo, winux::AnsiString const &s)