DCL 4.0
Loading...
Searching...
No Matches
MyConnection.h
Go to the documentation of this file.
1#ifndef __DCL_MYSQL_CONNECTION_H__
2#define __DCL_MYSQL_CONNECTION_H__ 20031025_20250414
3
4#include <mysql/mysql.h>
5#include <mysql/mysqld_error.h>
6
7#if MYSQL_VERSION_ID < 32224
8#error "invalid mysql version"
9#endif
10
11__DCL_BEGIN_NAMESPACE
12
13// BLOB_MAXSIZE < 1G
14// see void BytesToHexString in MyParam.cpp
15#define BLOB_MAXSIZE (100 * 1024 * 1024) // 100M
16class MyQuery;
17
19{
21protected:
22 MYSQL* __mysql;
23 bool __storeResult;
24 ByteString __lastErrorMessage;
25
26public:
27 MYSQL* connHandle() const;
28 bool storeResult() const;
29
30 void setErrorStatus(SQL::Error _error, const wchar_t* _filename, int _line);
31 void setErrorStatus(const ByteString& _message, const wchar_t* _filename, int _line);
32
33public:
34 // interface implementation
35 MyConnection(const wchar_t* _serverTitle);
36
37 virtual void destroy();
38 virtual ~MyConnection();
39 virtual bool __open(const char* _pszConnString, size_t _n);
40 virtual bool __close();
41 virtual bool __execute(const char* pszSQL, size_t _n);
42 virtual bool __startTrans();
43 virtual bool __commitTrans();
44 virtual bool __rollbackTrans();
45 virtual bool __createQueryInstance(SQL::Query** _ppQuery);
46 virtual bool __getErrorMessage(char* _buffer, size_t* _size);
47 virtual bool __getServerInfo(char* _buffer, size_t* _size);
48};
49
50inline MYSQL* MyConnection::connHandle() const
51{
52 return __mysql;
53}
54
55inline bool MyConnection::storeResult() const
56{
57 return __storeResult;
58}
59
61 SQL::Error _error,
62 const wchar_t* _filename,
63 int _line
64 )
65{
66 Connection::setErrorStatus(_error, _filename, _line);
67
68 if (_error == SQL::eServerError)
69 __lastErrorMessage = mysql_error(connHandle());
70 else
71 __lastErrorMessage.clear();
72}
73
75 const ByteString& _message,
76 const wchar_t* _filename,
77 int _line
78 )
79{
80 Connection::setErrorStatus(SQL::eServerError, _filename, _line);
81 __lastErrorMessage = _message;
82}
83
84#undef __SET_ERROR
85#define __SET_ERROR(_error) \
86 setErrorStatus(_error, __THIS_FILE__, __LINE__)
87
88#define __SET_ERROR_MSG(_msg) \
89 setErrorStatus(_msg, __THIS_FILE__, __LINE__)
90
91__DCL_END_NAMESPACE
92
93#endif // __DCL_MYSQL_CONNECTION_H__
#define DECLARE_CLASSINFO(class_name)
Definition Object.h:210
virtual bool __startTrans()
bool storeResult() const
virtual bool __rollbackTrans()
void setErrorStatus(SQL::Error _error, const wchar_t *_filename, int _line)
virtual void destroy()
MyConnection(const wchar_t *_serverTitle)
virtual bool __close()
virtual bool __commitTrans()
virtual bool __createQueryInstance(SQL::Query **_ppQuery)
virtual bool __execute(const char *pszSQL, size_t _n)
virtual bool __getServerInfo(char *_buffer, size_t *_size)
MYSQL * connHandle() const
virtual bool __open(const char *_pszConnString, size_t _n)
virtual bool __getErrorMessage(char *_buffer, size_t *_size)
virtual ~MyConnection()
__PROTECTED const wchar_t int _line
Definition SQLCore.h:390
__PROTECTED const wchar_t * _filename
Definition SQLCore.h:390
Error
Definition SQLCore.h:19
@ eServerError
Definition SQLCore.h:21