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);
63 m_fieldCount=mysql_num_fields(d->mysqlres);
64 d->numRows=mysql_num_rows(d->mysqlres);
68 m_records_in_buf = d->numRows;
69 m_buffering_completed =
true;
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) {
104 m_result = FetchError;
109TQVariant MySqlCursor::value(uint pos) {
110 if (!d->mysqlrow || pos>=m_fieldCount || d->mysqlrow[pos]==0)
113 KexiDB::Field *f = (m_fieldsExpanded && pos<m_fieldsExpanded->count())
114 ? m_fieldsExpanded->at(pos)->field : 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
146 data.resize(m_fieldCount);
147 const uint fieldsExpandedCount = m_fieldsExpanded ? m_fieldsExpanded->count() : UINT_MAX;
148 const uint realCount = TQMIN(fieldsExpandedCount, m_fieldCount);
149 for( uint i=0; i<realCount; i++) {
150 Field *f = m_fieldsExpanded ? m_fieldsExpanded->at(i)->field : 0;
151 if (m_fieldsExpanded && !f)
164 data[i] = TQVariant(TQString::fromUtf8((const char*)d->mysqlrow[i], d->lengths[i]));
169void MySqlCursor::drv_appendCurrentRecordToBuffer() {
173void MySqlCursor::drv_bufferMovePointerNext() {
174 d->mysqlrow=mysql_fetch_row(d->mysqlres);
175 d->lengths=mysql_fetch_lengths(d->mysqlres);
178void MySqlCursor::drv_bufferMovePointerPrev() {
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);
193const char** MySqlCursor::rowData()
const {
198int MySqlCursor::serverResult()
203TQString MySqlCursor::serverResultName()
208void MySqlCursor::drv_clearServerResult()
215TQString MySqlCursor::serverErrorMsg()
Provides database connection, allowing queries and data modification.
Provides database cursor functionality.
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