From kde-commits Sun Feb 27 18:24:05 2005 From: Jaroslaw Staniek Date: Sun, 27 Feb 2005 18:24:05 +0000 To: kde-commits Subject: koffice/kexi/kexidb/drivers Message-Id: <20050227182405.6A08B148A2 () office ! kde ! org> X-MARC-Message: https://marc.info/?l=kde-commits&m=110952866023663 CVS commit by staniek: KexiDB - mysql/sqlite drivers: fixed problem with xxxxConnection::value(int) when we're using raw sql statements (so expanded field list is empty) (thx to dipesh for the report) M +33 -19 mySQL/mysqlcursor.cpp 1.17 M +3 -2 sqlite/sqlitecursor.cpp 1.39 --- koffice/kexi/kexidb/drivers/mySQL/mysqlcursor.cpp #1.16:1.17 @@ -1,19 +1,20 @@ /* This file is part of the KDE project -Copyright (C) 2003 Joseph Wenninger + Copyright (C) 2003 Joseph Wenninger + Copyright (C) 2005 Jaroslaw Staniek -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU Library General Public -License as published by the Free Software Foundation; either -version 2 of the License, or (at your option) any later version. + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -Library General Public License for more details. + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. -You should have received a copy of the GNU Library General Public License -along with this program; see the file COPYING. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, -Boston, MA 02111-1307, USA. + You should have received a copy of the GNU Library General Public License + along with this program; see the file COPYING. If not, write to + the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ @@ -109,8 +110,21 @@ void MySqlCursor::drv_getNextRecord() { // This isn't going to work right now as it uses d->mysqlrow QVariant MySqlCursor::value(uint pos) { - if (!d->mysqlrow) return QVariant(); - if (pos>=m_fieldCount) return QVariant(); - if (d->mysqlrow[pos]==0) return QVariant(); - //js TODO: encode for type using m_fieldsExpanded like in SQLiteCursor::value() + if (!d->mysqlrow || pos>=m_fieldCount || d->mysqlrow[pos]==0) + return QVariant(); + + KexiDB::Field *f = (m_fieldsExpanded && poscount()) + ? m_fieldsExpanded->at(pos)->field : 0; + +//! @todo js: handle DateTime, Date, Time, BLOB types! + + //from most to least frequently used types: + if (!f || f->isTextType()) + return QVariant( QString::fromUtf8((const char*)d->mysqlrow[pos]) ); + else if (f->isIntegerType()) + return QVariant( QCString((const char*)d->mysqlrow[pos]).toInt() ); + else if (f->isFPNumericType()) + return QVariant( QCString((const char*)d->mysqlrow[pos]).toDouble() ); + + //default return QVariant(QString::fromUtf8((const char*)d->mysqlrow[pos])); } --- koffice/kexi/kexidb/drivers/sqlite/sqlitecursor.cpp #1.38:1.39 @@ -1,4 +1,4 @@ /* This file is part of the KDE project - Copyright (C) 2003 Jaroslaw Staniek + Copyright (C) 2003-2005 Jaroslaw Staniek This program is free software; you can redistribute it and/or @@ -532,5 +532,6 @@ QVariant SQLiteCursor::value(uint i) //TODO: allow disable range checking! - performance reasons // const KexiDB::Field *f = m_query ? m_query->field(i) : 0; - KexiDB::Field *f = m_fieldsExpanded ? m_fieldsExpanded->at(i)->field : 0; + KexiDB::Field *f = (m_fieldsExpanded && icount()) + ? m_fieldsExpanded->at(i)->field : 0; #ifdef SQLITE2 //from most to least frequently used types: