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

#include <SQL.h>

Inheritance diagram for SQLQuery:
Object

Public Member Functions

 SQLQuery (SQLConnection *_conn) __DCL_THROWS1(SQLException *)
 SQLQuery (SQLConnection &_conn) __DCL_THROWS1(SQLException *)
virtual ~SQLQuery ()
void prepare (const String &_sql) __DCL_THROWS1(SQLException *)
void execute () __DCL_THROWS1(SQLException *)
void execute (const String &_sql) __DCL_THROWS1(SQLException *)
void fetch () __DCL_THROWS1(SQLException *)
bool moreResults () __DCL_THROWS1(SQLException *)
bool eof () const
int64_t affectedRows () const
_CONST SQLFieldsfields () _CONST
_CONST SQLParamsparams () _CONST
SQL::Queryhandle () const
SQLConnectionconnection () 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::Query__handle
SQLConnection__connection
SQLFields __fields
SQLParams __params

Additional Inherited Members

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

Detailed Description

Definition at line 275 of file SQL.h.

Constructor & Destructor Documentation

◆ SQLQuery() [1/2]

SQLQuery::SQLQuery ( SQLConnection * _conn)

Definition at line 267 of file SQLQuery.cpp.

268{
269 initialize(_conn);
270}

◆ SQLQuery() [2/2]

SQLQuery::SQLQuery ( SQLConnection & _conn)

Definition at line 272 of file SQLQuery.cpp.

273{
274 initialize(&_conn);
275}

◆ ~SQLQuery()

SQLQuery::~SQLQuery ( )
virtual

Definition at line 277 of file SQLQuery.cpp.

278{
279 __connection->handle()->destroyQueryInstance(__handle);
280}
SQL::Query * __handle
Definition SQL.h:301
SQLConnection * __connection
Definition SQL.h:302

Member Function Documentation

◆ affectedRows()

int64_t SQLQuery::affectedRows ( ) const
inline

Definition at line 96 of file SQL.inl.

97{
98 return __handle->affectedRows();
99}

◆ connection()

SQLConnection * SQLQuery::connection ( ) const
inline

Definition at line 116 of file SQL.inl.

117{
118 return __connection;
119}

◆ eof()

bool SQLQuery::eof ( ) const
inline

Definition at line 91 of file SQL.inl.

92{
93 return __handle->eof();
94}

◆ execute() [1/2]

void SQLQuery::execute ( )

Definition at line 316 of file SQLQuery.cpp.

317{
318 if (!__handle->execute()) {
319#ifdef __DCL_DEBUG
320 throw new SQLException(this, __sql);
321#else
322 throw new SQLException(this, NULL);
323#endif
324 }
325
326 if (__handle->fieldCount() > 0 && __fields.isEmpty())
327 __fields.initialize(this);
328}
#define NULL
Definition Config.h:312
SQLFields __fields
Definition SQL.h:303

◆ execute() [2/2]

void SQLQuery::execute ( const String & _sql)

Definition at line 330 of file SQLQuery.cpp.

331{
332 prepare(_sql);
333 execute();
334}
void prepare(const String &_sql) __DCL_THROWS1(SQLException *)
Definition SQLQuery.cpp:282
void execute() __DCL_THROWS1(SQLException *)
Definition SQLQuery.cpp:316

◆ fetch()

void SQLQuery::fetch ( )

Definition at line 336 of file SQLQuery.cpp.

337{
338 if (!__handle->fetch()) {
339 throw new SQLException(this, NULL);
340 }
341}

◆ fields()

_CONST SQLFields & SQLQuery::fields ( )
inline

Definition at line 101 of file SQL.inl.

102{
103 return __fields;
104}

◆ handle()

SQL::Query * SQLQuery::handle ( ) const
inline

Definition at line 111 of file SQL.inl.

112{
113 return __handle;
114}

◆ moreResults()

bool SQLQuery::moreResults ( )

Definition at line 343 of file SQLQuery.cpp.

344{
345 bool _moreResults = false;
346 if (!__handle->moreResults(&_moreResults)) {
347 throw new SQLException(this, NULL);
348 }
349
350 __fields.clear();
351 if (__handle->fieldCount() > 0) {
352 __fields.initialize(this);
353 }
354
355 return _moreResults;
356}

◆ params()

_CONST SQLParams & SQLQuery::params ( )
inline

Definition at line 106 of file SQL.inl.

107{
108 return __params;
109}
SQLParams __params
Definition SQL.h:304

◆ prepare()

void SQLQuery::prepare ( const String & _sql)

Definition at line 282 of file SQLQuery.cpp.

283{
284#ifdef __DCL_DEBUG
285 __sql = _sql;
286#endif
287
288 __params.clear();
289 __fields.clear();
290
291 String sql;
292 StringArray names;
293 __sql_transform__(_sql, __handle->placeholder(), sql, names);
294 // __DCL_TRACE2(L"[%zd][%ls]\n", names.size(), sql.data());
295
296 ByteString mbs;
297 try {
298 mbs = UTF8Encoder::encode(sql);
299 }
300 catch (CharsetConvertException* _cause) {
301 throw new SQLException(this, _cause);
302 }
303
304 if (!__handle->prepare(mbs, mbs.length(), names.size())) {
305#ifdef __DCL_DEBUG
306 throw new SQLException(this, __sql);
307#else
308 throw new SQLException(this, NULL);
309#endif
310 }
311
312 if (__handle->paramCount() > 0)
313 __params.initialize(this, names);
314}

Member Data Documentation

◆ __connection

SQLConnection* SQLQuery::__connection
protected

Definition at line 302 of file SQL.h.

◆ __fields

SQLFields SQLQuery::__fields
protected

Definition at line 303 of file SQL.h.

◆ __handle

SQL::Query* SQLQuery::__handle
protected

Definition at line 301 of file SQL.h.

◆ __params

SQLParams SQLQuery::__params
protected

Definition at line 304 of file SQL.h.


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