21#include "mysqlcursor.h"
22#include "mysqlconnection.h"
23#include "mysqlconnection_p.h"
24#include <kexidb/error.h>
25#include <kexidb/utils.h>
34MySqlCursor::MySqlCursor(
KexiDB::Connection* conn,
const TQString& statement, uint cursor_options)
35 :
Cursor(conn,statement,cursor_options)
36 , d( new MySqlCursorData(conn) )
38 m_options |= Buffered;
44 :
Cursor( conn, query, options )
45 , d( new MySqlCursorData(conn) )
47 m_options |= Buffered;
52MySqlCursor::~MySqlCursor() {
56bool MySqlCursor::drv_open() {
60 if(mysql_real_query(d->mysql,
m_sql.utf8(), strlen(
m_sql.utf8())) == 0) {
61 if(mysql_errno(d->mysql) == 0) {
62 d->mysqlres= mysql_store_result(d->mysql);
64 d->numRows=mysql_num_rows(d->mysqlres);
75 setError(ERR_DB_SPECIFIC,TQString::fromUtf8(mysql_error(d->mysql)));
79bool MySqlCursor::drv_close() {
80 mysql_free_result(d->mysqlres);
94void MySqlCursor::drv_getNextRecord() {
96 if (
at() < d->numRows &&
at() >=0) {
97 d->lengths=mysql_fetch_lengths(d->mysqlres);
100 else if (
at() >= d->numRows) {
109TQVariant MySqlCursor::value(uint pos) {
110 if (!d->mysqlrow || pos>=
m_fieldCount || d->mysqlrow[pos]==0)
125 return TQVariant( TQCString((const char*)d->mysqlrow[pos], d->lengths[pos]).toInt() );
126 else if (f->isFPNumericType())
127 return TQVariant( TQCString((const char*)d->mysqlrow[pos], d->lengths[pos]).toDouble() );
130 return TQVariant(TQString::fromUtf8((const char*)d->mysqlrow[pos], d->lengths[pos]));*/
137void MySqlCursor::storeCurrentRow(
RowData &data)
const
148 const uint realCount = TQMIN(fieldsExpandedCount,
m_fieldCount);
149 for( uint i=0; i<realCount; i++) {
164 data[i] = TQVariant(TQString::fromUtf8((const char*)d->mysqlrow[i], d->lengths[i]));
174 d->mysqlrow=mysql_fetch_row(d->mysqlres);
175 d->lengths=mysql_fetch_lengths(d->mysqlres);
180 mysql_data_seek(d->mysqlres,m_at-1);
181 d->mysqlrow=mysql_fetch_row(d->mysqlres);
182 d->lengths=mysql_fetch_lengths(d->mysqlres);
186void MySqlCursor::drv_bufferMovePointerTo(TQ_LLONG to) {
188 mysql_data_seek(d->mysqlres, to);
189 d->mysqlrow=mysql_fetch_row(d->mysqlres);
190 d->lengths=mysql_fetch_lengths(d->mysqlres);
Provides database connection, allowing queries and data modification.
Provides database cursor functionality.
int m_records_in_buf
number of records currently stored in the buffer
virtual TQString serverResultName()
char m_result
result of a row fetching
QueryColumnInfo::Vector * m_fieldsExpanded
Useful e.g. for value(int) method when we need access to schema def.
virtual void drv_appendCurrentRecordToBuffer()=0
virtual int serverResult()
uint m_fieldCount
cached field count information
virtual void drv_bufferMovePointerNext()=0
virtual void drv_bufferMovePointerPrev()=0
virtual const char ** rowData() const =0
virtual TQString serverErrorMsg()
bool m_buffering_completed
true if we already have all records stored in the buffer
virtual void drv_clearServerResult()=0
TQString m_sql
used to store of actually executed SQL statement
virtual void setError(int code=ERR_OTHER, const TQString &msg=TQString())
KexiDB::QuerySchema provides information about database query.
High-level database connectivity library with database backend drivers.
TQVariant cstringToVariant(const char *data, KexiDB::Field *f, int length=-1)
TQValueVector< TQVariant > RowData
structure for storing single record with type information