DCL 3.7.4
Loading...
Searching...
No Matches
SQLConnection Class Reference

#include <SQL.h>

Inheritance diagram for SQLConnection:
Object

Public Member Functions

 SQLConnection (SQLDriver *_driver)
 SQLConnection (const String &_driverName) __DCL_THROWS1(SQLDriverException *)
virtual ~SQLConnection ()
void open (const String &_connstr) __DCL_THROWS1(SQLException *)
void close () __DCL_THROWS1(SQLException *)
void execute (const String &_sql) __DCL_THROWS1(SQLException *)
void startTrans () __DCL_THROWS1(SQLException *)
void commitTrans () __DCL_THROWS1(SQLException *)
void rollbackTrans () __DCL_THROWS1(SQLException *)
String getServerInfo () __DCL_THROWS1(SQLException *)
bool canTransact () const
SQL::Connectionhandle () const
SQLDriverdriver () const
bool connected () const
bool inTransaction () const
Public Member Functions inherited from Object
virtual String toString () const
virtual void destroy ()
String className () const
bool isInstanceOf (const std::type_info &typeinfo) const
virtual const std::type_info & typeInfo () const

Protected Attributes

SQL::Connection__handle
SQLDriver__driver
bool __connected

Additional Inherited Members

Protected Member Functions inherited from Object
virtual ~Object ()
 Object ()

Detailed Description

Definition at line 311 of file SQL.h.

Constructor & Destructor Documentation

◆ SQLConnection() [1/2]

SQLConnection::SQLConnection ( SQLDriver * _driver)

Definition at line 44 of file SQLConnection.cpp.

45{
46 __DCL_ASSERT_PARAM(_driver != NULL);
47 initialize(_driver);
48}
#define NULL
Definition Config.h:312
#define __DCL_ASSERT_PARAM(expr)
Definition Object.h:409

◆ SQLConnection() [2/2]

SQLConnection::SQLConnection ( const String & _driverName)

Definition at line 50 of file SQLConnection.cpp.

52{
53 __DCL_ASSERT_PARAM(!_driverName.isEmpty());
54
55 SQLDriver* _driver = SQLDriver::getDriver(_driverName);
56 initialize(_driver);
57}
static SQLDriver * getDriver(const String &_name) __DCL_THROWS1(SQLDriverException *)

◆ ~SQLConnection()

SQLConnection::~SQLConnection ( )
virtual

Definition at line 59 of file SQLConnection.cpp.

60{
61 __DCL_ASSERT(__handle->refCount() == 0);
62 if (__connected) {
63 try {
64 //__DCL_TRACE0(__T("close()\n"));
65 close();
66 }
67 catch (SQLException* e) {
68 __DCL_TRACE1(__T("Warning! %ls\n"), e->toString().data());
69 e->destroy();
70 }
71 }
72
73 __driver->destroyConnection(__handle);
74 //__handle = NULL;
75 //__driver = NULL;
76}
#define __DCL_TRACE1(fmt, arg1)
Definition Object.h:399
#define __DCL_ASSERT(expr)
Definition Object.h:394
#define __T(str)
Definition Object.h:60
virtual void destroy()
Definition Exception.cpp:74
SQLDriver * __driver
Definition SQL.h:344
bool __connected
Definition SQL.h:345
SQL::Connection * __handle
Definition SQL.h:343
void close() __DCL_THROWS1(SQLException *)
virtual String toString() const

Member Function Documentation

◆ canTransact()

bool SQLConnection::canTransact ( ) const

Definition at line 207 of file SQLConnection.cpp.

208{
211 return __handle->canTransact();
212}

◆ close()

void SQLConnection::close ( )

Definition at line 103 of file SQLConnection.cpp.

104{
106
107 if (__connected) {
108 if (inTransaction())
110
111 if (!__handle->close()) {
112 throw new SQLException(this, NULL);
113 }
114
115 __connected = false;
116 }
117}
void rollbackTrans() __DCL_THROWS1(SQLException *)
bool inTransaction() const

◆ commitTrans()

void SQLConnection::commitTrans ( )

Definition at line 152 of file SQLConnection.cpp.

153{
156// __DCL_ASSERT(inTransaction());
157
158 if (!__handle->commitTrans()) {
159 throw new SQLException(this, NULL);
160 }
161}

◆ connected()

bool SQLConnection::connected ( ) const
inline

Definition at line 132 of file SQL.inl.

133{
134 return __connected;
135}

◆ driver()

SQLDriver * SQLConnection::driver ( ) const
inline

Definition at line 127 of file SQL.inl.

128{
129 return __driver;
130}

◆ execute()

void SQLConnection::execute ( const String & _sql)

Definition at line 119 of file SQLConnection.cpp.

120{
123
124 ByteString mbs;
125 try {
126 mbs = UTF8Encoder::encode(_sql);
127 }
128 catch (CharsetConvertException* _cause) {
129 throw new SQLException(this, _cause);
130 }
131
132 if (!__handle->execute(mbs, mbs.length())) {
133#ifdef __DCL_DEBUG
134 throw new SQLException(this, _sql);
135#else
136 throw new SQLException(this, NULL);
137#endif
138 }
139}

◆ getServerInfo()

String SQLConnection::getServerInfo ( )

Definition at line 184 of file SQLConnection.cpp.

185{
188
189 size_t len = 1024;
190 ByteBuffer* buf = ByteBuffer::create(len);
191 if (!__handle->getServerInfo(buf->data(), &len)) {
192 buf->release();
193 throw new SQLException(this, NULL);
194 }
195 buf->__dataLength = len;
196 ByteString r = buf;
197 buf->release();
198
199 try {
200 return UTF8Decoder::decode(r);
201 }
202 catch (CharsetConvertException* _cause) {
203 throw new SQLException(this, _cause);
204 }
205}
IOException *size_t r
Definition MediaInfo.cpp:82

◆ handle()

SQL::Connection * SQLConnection::handle ( ) const
inline

Definition at line 122 of file SQL.inl.

123{
124 return __handle;
125}

◆ inTransaction()

bool SQLConnection::inTransaction ( ) const

Definition at line 174 of file SQLConnection.cpp.

175{
177
178 if (__connected) {
180 }
181 return false;
182}

◆ open()

void SQLConnection::open ( const String & _connstr)

Definition at line 79 of file SQLConnection.cpp.

80{
82 __DCL_ASSERT(__connected == false);
83
84 ByteString mbs;
85 try {
86 mbs = UTF8Encoder::encode(_connstr);
87 }
88 catch (CharsetConvertException* _cause) {
89 throw new SQLException(this, _cause);
90 }
91
92 if (!__handle->open(mbs, mbs.length())) {
93#ifdef __DCL_DEBUG
94 throw new SQLException(this, _connstr);
95#else
96 throw new SQLException(this, NULL);
97#endif
98 }
99
100 __connected = true;
101}

◆ rollbackTrans()

void SQLConnection::rollbackTrans ( )

Definition at line 163 of file SQLConnection.cpp.

164{
167// __DCL_ASSERT(inTransaction());
168
169 if (!__handle->rollbackTrans()) {
170 throw new SQLException(this, NULL);
171 }
172}

◆ startTrans()

void SQLConnection::startTrans ( )

Definition at line 141 of file SQLConnection.cpp.

142{
145// __DCL_ASSERT(!inTransaction());
146
147 if (!__handle->startTrans()) {
148 throw new SQLException(this, NULL);
149 }
150}

Member Data Documentation

◆ __connected

bool SQLConnection::__connected
protected

Definition at line 345 of file SQL.h.

◆ __driver

SQLDriver* SQLConnection::__driver
protected

Definition at line 344 of file SQL.h.

◆ __handle

SQL::Connection* SQLConnection::__handle
protected

Definition at line 343 of file SQL.h.


The documentation for this class was generated from the following files: