[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [kdb] src: Fix: Switching off the visibility of query fields hides data in the last field
From:       Jaroslaw Staniek <staniek () kde ! org>
Date:       2016-02-29 23:21:26
Message-ID: E1aaX82-0005Dj-0E () scm ! kde ! org
[Download RAW message or body]

Git commit a1d47334f8ae29067c02a039d118eca3e5c4f58d by Jaroslaw Staniek.
Committed on 29/02/2016 at 23:16.
Pushed by staniek into branch 'master'.

Fix: Switching off the visibility of query fields hides data in the last field

This is a fix for Query Designer with SQLite/MySQL/PostreSQL/Sybase.

See https://bugs.kde.org/attachment.cgi?id=96684 for test file

BUG:346839
FIXED-IN:2.9.11

Test Plan:
Try the minimal example from https://bugs.kde.org/attachment.cgi?id=96684, open \
query1 in design mode, set Visible=off for id and a fields, switch to data view. \
Field b has data loaded after this fix.

Differential Revision: https://phabricator.kde.org/D829

(from calligra.git)

M  +9    -8    src/KDbCursor.cpp
M  +3    -3    src/KDbCursor.h
M  +31   -16   src/KDbQuerySchema.cpp
M  +19   -3    src/KDbQuerySchema.h
M  +15   -1    src/KDbQuerySchema_p.cpp
M  +10   -1    src/KDbQuerySchema_p.h
M  +11   -12   src/drivers/mysql/MysqlCursor.cpp
M  +3    -3    src/drivers/postgresql/PostgresqlCursor.cpp
M  +6    -14   src/drivers/sqlite/SqliteCursor.cpp
M  +6    -5    src/drivers/sybase/SybaseCursor.cpp

http://commits.kde.org/kdb/a1d47334f8ae29067c02a039d118eca3e5c4f58d

diff --git a/src/KDbCursor.cpp b/src/KDbCursor.cpp
index c288b1c..4037ce0 100644
--- a/src/KDbCursor.cpp
+++ b/src/KDbCursor.cpp
@@ -1,5 +1,5 @@
 /* This file is part of the KDE project
-   Copyright (C) 2003-2010 Jarosław Staniek <staniek@kde.org>
+   Copyright (C) 2003-2016 Jarosław Staniek <staniek@kde.org>
 
    This program is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
@@ -74,15 +74,16 @@ void KDbCursor::init()
 
     if (m_query) {
         //get list of all fields
-        m_fieldsExpanded = new KDbQueryColumnInfo::Vector();
-        *m_fieldsExpanded = m_query->fieldsExpanded(
-                                m_containsRecordIdInfo ? \
                KDbQuerySchema::WithInternalFieldsAndRecordId : \
                KDbQuerySchema::WithInternalFields);
-        m_logicalFieldCount = m_fieldsExpanded->count()
+        m_visibleFieldsExpanded = new KDbQueryColumnInfo::Vector();
+        *m_visibleFieldsExpanded = m_query->visibleFieldsExpanded(
+                    m_containsRecordIdInfo ? \
KDbQuerySchema::WithInternalFieldsAndRecordId +                                       \
: KDbQuerySchema::WithInternalFields); +        m_logicalFieldCount = \
                m_visibleFieldsExpanded->count()
                               - m_query->internalFields().count() - \
                (m_containsRecordIdInfo ? 1 : 0);
-        m_fieldCount = m_fieldsExpanded->count();
+        m_fieldCount = m_visibleFieldsExpanded->count();
         m_fieldsToStoreInRecord = m_fieldCount;
     } else {
-        m_fieldsExpanded = 0;
+        m_visibleFieldsExpanded = 0;
         m_logicalFieldCount = 0;
         m_fieldCount = 0;
         m_fieldsToStoreInRecord = 0;
@@ -114,7 +115,7 @@ KDbCursor::~KDbCursor()
             kdbCritical() << "can be destroyed with Conenction::deleteCursor(), not \
with delete operator!";  }
     }
-    delete m_fieldsExpanded;
+    delete m_visibleFieldsExpanded;
     delete m_queryParameters;
 }
 
diff --git a/src/KDbCursor.h b/src/KDbCursor.h
index 17ed93f..2fa3434 100644
--- a/src/KDbCursor.h
+++ b/src/KDbCursor.h
@@ -1,5 +1,5 @@
 /* This file is part of the KDE project
-   Copyright (C) 2003-2010 Jarosław Staniek <staniek@kde.org>
+   Copyright (C) 2003-2016 Jarosław Staniek <staniek@kde.org>
 
    This program is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
@@ -322,8 +322,8 @@ protected:
     bool m_buffering_completed;   //!< true if we already have all records stored in \
the buffer  //</members related to buffering>
 
-    //! Useful e.g. for value(int) method when we need access to schema def.
-    KDbQueryColumnInfo::Vector* m_fieldsExpanded;
+    //! Useful e.g. for value(int) method to obtain access to schema definition.
+    KDbQueryColumnInfo::Vector* m_visibleFieldsExpanded;
 
     //! Used by setOrderByColumnList()
     KDbQueryColumnInfo::Vector* m_orderByColumnList;
diff --git a/src/KDbQuerySchema.cpp b/src/KDbQuerySchema.cpp
index b324e41..3220261 100644
--- a/src/KDbQuerySchema.cpp
+++ b/src/KDbQuerySchema.cpp
@@ -1,5 +1,5 @@
 /* This file is part of the KDE project
-   Copyright (C) 2003-2014 Jarosław Staniek <staniek@kde.org>
+   Copyright (C) 2003-2016 Jarosław Staniek <staniek@kde.org>
 
    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
@@ -979,28 +979,33 @@ KDbQueryColumnInfo* KDbQuerySchema::columnInfo(const QString& \
identifier, bool e  : d->columnInfosByName.value(identifier);
 }
 
-KDbQueryColumnInfo::Vector KDbQuerySchema::fieldsExpanded(FieldsExpandedOptions \
options) const +KDbQueryColumnInfo::Vector KDbQuerySchema::fieldsExpandedInternal(
+        FieldsExpandedOptions options, bool onlyVisible) const
 {
     computeFieldsExpanded();
+    KDbQueryColumnInfo::Vector *realFieldsExpanded = onlyVisible ? \
d->visibleFieldsExpanded +                                                            \
                : d->fieldsExpanded;
     if (options == WithInternalFields || options == WithInternalFieldsAndRecordId) {
         //a ref to a proper pointer (as we cache the vector for two cases)
         KDbQueryColumnInfo::Vector*& tmpFieldsExpandedWithInternal =
-            (options == WithInternalFields) ? d->fieldsExpandedWithInternal : \
d->fieldsExpandedWithInternalAndRecordId; +            (options == \
WithInternalFields) ? +                (onlyVisible ? \
d->visibleFieldsExpandedWithInternal : d->fieldsExpandedWithInternal) +              \
: (onlyVisible ? d->visibleFieldsExpandedWithInternalAndRecordId : \
d->fieldsExpandedWithInternalAndRecordId);  //special case
         if (!tmpFieldsExpandedWithInternal) {
             //glue expanded and internal fields and cache it
-            const int size = d->fieldsExpanded->count()
-                              + (d->internalFields ? d->internalFields->count() : 0)
-                              + ((options == WithInternalFieldsAndRecordId) ? 1 : 0) \
/*ROWID*/; +            const int internalFieldCount = d->internalFields ? \
d->internalFields->size() : 0; +            const int fieldsExpandedVectorSize = \
realFieldsExpanded->size(); +            const int size = fieldsExpandedVectorSize + \
internalFieldCount +                             + ((options == \
                WithInternalFieldsAndRecordId) ? 1 : 0) /*ROWID*/;
             tmpFieldsExpandedWithInternal = new KDbQueryColumnInfo::Vector(size);
-            const int fieldsExpandedVectorSize = d->fieldsExpanded->size();
-            for (int i = 0; i < fieldsExpandedVectorSize; i++) {
-                (*tmpFieldsExpandedWithInternal)[i] = d->fieldsExpanded->at(i);
+            for (int i = 0; i < fieldsExpandedVectorSize; ++i) {
+                (*tmpFieldsExpandedWithInternal)[i] = realFieldsExpanded->at(i);
             }
-            const int internalFieldCount = d->internalFields ? \
d->internalFields->size() : 0;  if (internalFieldCount > 0) {
-                for (int i = 0; i < internalFieldCount; i++) {
-                    (*tmpFieldsExpandedWithInternal)[fieldsExpandedVectorSize + i] = \
d->internalFields->at(i); +                for (int i = 0; i < internalFieldCount; \
++i) { +                    KDbQueryColumnInfo *info = d->internalFields->at(i);
+                    (*tmpFieldsExpandedWithInternal)[fieldsExpandedVectorSize + i] = \
info;  }
             }
             if (options == WithInternalFieldsAndRecordId) {
@@ -1014,17 +1019,18 @@ KDbQueryColumnInfo::Vector \
KDbQuerySchema::fieldsExpanded(FieldsExpandedOptions  return \
*tmpFieldsExpandedWithInternal;  }
 
-    if (options == Default)
-        return *d->fieldsExpanded;
+    if (options == Default) {
+        return *realFieldsExpanded;
+    }
 
     //options == Unique:
     QSet<QString> columnsAlreadyFound;
-    const int fieldsExpandedCount(d->fieldsExpanded->count());
+    const int fieldsExpandedCount(realFieldsExpanded->count());
     KDbQueryColumnInfo::Vector result(fieldsExpandedCount);   //initial size is set
     //compute unique list
     int uniqueListCount = 0;
     for (int i = 0; i < fieldsExpandedCount; i++) {
-        KDbQueryColumnInfo *ci = d->fieldsExpanded->at(i);
+        KDbQueryColumnInfo *ci = realFieldsExpanded->at(i);
         if (!columnsAlreadyFound.contains(ci->aliasOrName())) {
             columnsAlreadyFound.insert(ci->aliasOrName());
             result[uniqueListCount++] = ci;
@@ -1224,11 +1230,14 @@ void KDbQuerySchema::computeFieldsExpanded() const
     //prepare clean vector for expanded list, and a map for order information
     if (!d->fieldsExpanded) {
         d->fieldsExpanded = new KDbQueryColumnInfo::Vector(list.count());
+        d->visibleFieldsExpanded = new KDbQueryColumnInfo::Vector(list.count());
         d->columnsOrderExpanded = new QHash<KDbQueryColumnInfo*, int>();
     } else {//for future:
         qDeleteAll(*d->fieldsExpanded);
         d->fieldsExpanded->clear();
         d->fieldsExpanded->resize(list.count());
+        d->visibleFieldsExpanded->clear();
+        d->visibleFieldsExpanded->resize(list.count());
         d->columnsOrderExpanded->clear();
     }
 
@@ -1240,9 +1249,14 @@ void KDbQuerySchema::computeFieldsExpanded() const
     d->columnInfosByName.clear();
     d->columnInfosByNameExpanded.clear();
     i = -1;
+    int visibleIndex = -1;
     foreach(KDbQueryColumnInfo* ci, list) {
         i++;
         (*d->fieldsExpanded)[i] = ci;
+        if (ci->visible) {
+            ++visibleIndex;
+            (*d->visibleFieldsExpanded)[visibleIndex] = ci;
+        }
         d->columnsOrderExpanded->insert(ci, i);
         //remember field by name/alias/table.name if there's no such string yet in \
d->columnInfosByNameExpanded  if (!ci->alias.isEmpty()) {
@@ -1287,6 +1301,7 @@ void KDbQuerySchema::computeFieldsExpanded() const
             }
         }
     }
+    d->visibleFieldsExpanded->resize(visibleIndex + 1);
 
     //remove duplicates for lookup fields
     QHash<QString, int> lookup_dict; //used to fight duplicates and to update \
                KDbQueryColumnInfo::indexForVisibleLookupValue()
diff --git a/src/KDbQuerySchema.h b/src/KDbQuerySchema.h
index b70f2e6..16331b8 100644
--- a/src/KDbQuerySchema.h
+++ b/src/KDbQuerySchema.h
@@ -1,5 +1,5 @@
 /* This file is part of the KDE project
-   Copyright (C) 2003-2014 Jarosław Staniek <staniek@kde.org>
+   Copyright (C) 2003-2016 Jarosław Staniek <staniek@kde.org>
 
    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
@@ -525,7 +525,7 @@ public:
      explicitly specify "t2.name" as the identifier to get the second column. */
     KDbQueryColumnInfo* columnInfo(const QString& identifier, bool expanded = true) \
const;  
-    /*! Options used in fieldsExpanded(). */
+    /*! Options used in fieldsExpanded() and visibleFieldsExpanded(). */
     enum FieldsExpandedOptions {
         Default,                      //!< All fields are returned even if \
                duplicated
         Unique,                       //!< Unique list of fields is returned
@@ -575,7 +575,18 @@ public:
      This method's result is cached by KDbQuerySchema object.
     @todo js: UPDATE CACHE!
     */
-    KDbQueryColumnInfo::Vector fieldsExpanded(FieldsExpandedOptions options = \
Default) const; +    inline KDbQueryColumnInfo::Vector fieldsExpanded(
+            FieldsExpandedOptions options = Default) const
+    {
+        return fieldsExpandedInternal(options, false);
+    }
+
+    /*! Like fieldsExpanded() but returns only visible fields. */
+    inline KDbQueryColumnInfo::Vector visibleFieldsExpanded(
+            FieldsExpandedOptions options = Default) const
+    {
+        return fieldsExpandedInternal(options, true);
+    }
 
     /*! @return list of fields internal fields used for lookup columns. */
     KDbQueryColumnInfo::Vector internalFields() const;
@@ -762,6 +773,11 @@ protected:
 
     void computeFieldsExpanded() const;
 
+    //! Used by fieldsExpanded(FieldsExpandedOptions)
+    //! and visibleFieldsExpanded(FieldsExpandedOptions options).
+    KDbQueryColumnInfo::Vector fieldsExpandedInternal(FieldsExpandedOptions options,
+                                                      bool onlyVisible) const;
+
     Private * const d;
 };
 
diff --git a/src/KDbQuerySchema_p.cpp b/src/KDbQuerySchema_p.cpp
index 18bc8ac..8cd6992 100644
--- a/src/KDbQuerySchema_p.cpp
+++ b/src/KDbQuerySchema_p.cpp
@@ -1,5 +1,5 @@
 /* This file is part of the KDE project
-   Copyright (C) 2003-2014 Jarosław Staniek <staniek@kde.org>
+   Copyright (C) 2003-2016 Jarosław Staniek <staniek@kde.org>
 
    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
@@ -28,9 +28,12 @@ KDbQuerySchema::Private::Private(KDbQuerySchema* q, Private* copy)
         , maxIndexWithAlias(-1)
         , visibility(64)
         , fieldsExpanded(0)
+        , visibleFieldsExpanded(0)
         , internalFields(0)
         , fieldsExpandedWithInternalAndRecordId(0)
+        , visibleFieldsExpandedWithInternalAndRecordId(0)
         , fieldsExpandedWithInternal(0)
+        , visibleFieldsExpandedWithInternal(0)
         , orderByColumnList(0)
         , autoincFields(0)
         , columnsOrder(0)
@@ -48,6 +51,7 @@ KDbQuerySchema::Private::Private(KDbQuerySchema* q, Private* copy)
         *this = *copy;
         // <clear, so computeFieldsExpanded() will re-create it>
         fieldsExpanded = 0;
+        visibleFieldsExpanded = 0;
         internalFields = 0;
         columnsOrder = 0;
         columnsOrderWithoutAsterisks = 0;
@@ -59,7 +63,9 @@ KDbQuerySchema::Private::Private(KDbQuerySchema* q, Private* copy)
         columnInfosByName.clear();
         ownedVisibleColumns = 0;
         fieldsExpandedWithInternalAndRecordId = 0;
+        visibleFieldsExpandedWithInternalAndRecordId = 0;
         fieldsExpandedWithInternal = 0;
+        visibleFieldsExpandedWithInternal = 0;
         pkeyFieldsOrder = 0;
         fakeRecordIdCol = 0;
         fakeRecordIdField = 0;
@@ -100,7 +106,9 @@ KDbQuerySchema::Private::~Private()
         delete internalFields;
     }
     delete fieldsExpandedWithInternalAndRecordId;
+    delete visibleFieldsExpandedWithInternalAndRecordId;
     delete fieldsExpandedWithInternal;
+    delete visibleFieldsExpandedWithInternal;
 }
 
 //static
@@ -148,6 +156,8 @@ void KDbQuerySchema::Private::clearCachedData()
         qDeleteAll(*fieldsExpanded);
         delete fieldsExpanded;
         fieldsExpanded = 0;
+        delete visibleFieldsExpanded; // NO qDeleteAll, items not owned
+        visibleFieldsExpanded = 0;
         if (internalFields) {
             qDeleteAll(*internalFields);
             delete internalFields;
@@ -155,8 +165,12 @@ void KDbQuerySchema::Private::clearCachedData()
         }
         delete fieldsExpandedWithInternalAndRecordId;
         fieldsExpandedWithInternalAndRecordId = 0;
+        delete visibleFieldsExpandedWithInternalAndRecordId;
+        visibleFieldsExpandedWithInternalAndRecordId = 0;
         delete fieldsExpandedWithInternal;
         fieldsExpandedWithInternal = 0;
+        delete visibleFieldsExpandedWithInternal;
+        visibleFieldsExpandedWithInternal = 0;
     }
 }
 
diff --git a/src/KDbQuerySchema_p.h b/src/KDbQuerySchema_p.h
index 24cc3c5..0bc7843 100644
--- a/src/KDbQuerySchema_p.h
+++ b/src/KDbQuerySchema_p.h
@@ -1,5 +1,5 @@
 /* This file is part of the KDE project
-   Copyright (C) 2003-2014 Jarosław Staniek <staniek@kde.org>
+   Copyright (C) 2003-2016 Jarosław Staniek <staniek@kde.org>
 
    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
@@ -132,6 +132,9 @@ public:
     /*! Temporary field vector for using in fieldsExpanded() */
     KDbQueryColumnInfo::Vector *fieldsExpanded;
 
+    /*! Like fieldsExpanded but only visible column infos; infos are not owned. */
+    KDbQueryColumnInfo::Vector *visibleFieldsExpanded;
+
     /*! Temporary field vector containing internal fields used for lookup columns. \
*/  KDbQueryColumnInfo::Vector *internalFields;
 
@@ -139,10 +142,16 @@ public:
      Contains not auto-deleted items.*/
     KDbQueryColumnInfo::Vector *fieldsExpandedWithInternalAndRecordId;
 
+    /*! Like fieldsExpandedWithInternalAndRecordId but only contains visible column \
infos; infos are not owned.*/ +    KDbQueryColumnInfo::Vector \
*visibleFieldsExpandedWithInternalAndRecordId; +
     /*! Temporary, used to cache sum of expanded fields and internal fields used for \
lookup columns.  Contains not auto-deleted items.*/
     KDbQueryColumnInfo::Vector *fieldsExpandedWithInternal;
 
+    /*! Like fieldsExpandedWithInternal but only contains visible column infos; \
infos are not owned.*/ +    KDbQueryColumnInfo::Vector \
*visibleFieldsExpandedWithInternal; +
     /*! A list of fields for ORDER BY section. @see \
KDbQuerySchema::orderByColumnList(). */  KDbOrderByColumnList* orderByColumnList;
 
diff --git a/src/drivers/mysql/MysqlCursor.cpp b/src/drivers/mysql/MysqlCursor.cpp
index 901db76..3b924f8 100644
--- a/src/drivers/mysql/MysqlCursor.cpp
+++ b/src/drivers/mysql/MysqlCursor.cpp
@@ -1,6 +1,6 @@
 /* This file is part of the KDE project
    Copyright (C) 2003 Joseph Wenninger<jowenn@kde.org>
-   Copyright (C) 2005-2010 Jarosław Staniek <staniek@kde.org>
+   Copyright (C) 2005-2016 Jarosław Staniek <staniek@kde.org>
 
    This program is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
@@ -100,8 +100,8 @@ QVariant MysqlCursor::value(int pos)
     if (!d->mysqlrow || pos >= m_fieldCount || d->mysqlrow[pos] == 0)
         return QVariant();
 
-    KDbField *f = (m_fieldsExpanded && pos < m_fieldsExpanded->count())
-                       ? m_fieldsExpanded->at(pos)->field : 0;
+    KDbField *f = (m_visibleFieldsExpanded && pos < \
m_visibleFieldsExpanded->count()) +                       ? \
m_visibleFieldsExpanded->at(pos)->field : 0;  
 //! @todo js: use MYSQL_FIELD::type here!
 
@@ -119,15 +119,14 @@ bool MysqlCursor::drv_storeCurrentRecord(KDbRecordData* data) \
const  if (d->numRows == 0)
         return false;
 
-//! @todo js: use MYSQL_FIELD::type here!
-//!           see SqliteCursor::storeCurrentRecord()
-
-    const int fieldsExpandedCount = m_fieldsExpanded ? m_fieldsExpanded->count() : \
                INT_MAX;
-    const int realCount = qMin(fieldsExpandedCount, m_fieldsToStoreInRecord);
-    for (int i = 0; i < realCount; i++) {
-        KDbField *f = m_fieldsExpanded ? m_fieldsExpanded->at(i)->field : 0;
-        if (m_fieldsExpanded && !f)
-            continue;
+    if (!m_visibleFieldsExpanded) {//simple version: without types
+        for (int i = 0; i < m_fieldCount; ++i) {
+            (*data)[i] = QString::fromUtf8(d->mysqlrow[i], d->lengths[i]);
+        }
+        return true;
+    }
+    for (int i = 0; i < m_fieldCount; ++i) {
+        KDbField *f = m_visibleFieldsExpanded->at(i)->field;
         bool ok;
         (*data)[i] = KDb::cstringToVariant(d->mysqlrow[i], f ? f->type() : \
KDbField::Text,  &ok, d->lengths[i]);
diff --git a/src/drivers/postgresql/PostgresqlCursor.cpp \
b/src/drivers/postgresql/PostgresqlCursor.cpp index 4a9b23c..760747a 100644
--- a/src/drivers/postgresql/PostgresqlCursor.cpp
+++ b/src/drivers/postgresql/PostgresqlCursor.cpp
@@ -1,6 +1,6 @@
 /* This file is part of the KDE project
    Copyright (C) 2003 Adam Pigg <adam@piggz.co.uk>
-   Copyright (C) 2010 Jarosław Staniek <staniek@kde.org>
+   Copyright (C) 2016 Jarosław Staniek <staniek@kde.org>
 
    This program is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
@@ -220,8 +220,8 @@ QVariant PostgresqlCursor::pValue(int pos) const
 //  postgresqlWarning() << "PostgresqlCursor::value - ERROR: requested position is \
greater than the number of fields";  const qint64 row = at();
 
-    KDbField *f = (m_fieldsExpanded && pos < qMin(m_fieldsExpanded->count(), \
                m_fieldCount))
-                       ? m_fieldsExpanded->at(pos)->field : 0;
+    KDbField *f = (m_visibleFieldsExpanded && pos < \
qMin(m_visibleFieldsExpanded->count(), m_fieldCount)) +                       ? \
m_visibleFieldsExpanded->at(pos)->field : 0;  // postgresqlDebug() << "pos:" << pos;
 
     const QVariant::Type type = m_realTypes[pos];
diff --git a/src/drivers/sqlite/SqliteCursor.cpp \
b/src/drivers/sqlite/SqliteCursor.cpp index be39fd8..2edc1f9 100644
--- a/src/drivers/sqlite/SqliteCursor.cpp
+++ b/src/drivers/sqlite/SqliteCursor.cpp
@@ -1,5 +1,5 @@
 /* This file is part of the KDE project
-   Copyright (C) 2003-2010 Jarosław Staniek <staniek@kde.org>
+   Copyright (C) 2003-2016 Jarosław Staniek <staniek@kde.org>
 
    This program is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
@@ -303,22 +303,14 @@ const char ** SqliteCursor::recordData() const
 
 bool SqliteCursor::drv_storeCurrentRecord(KDbRecordData* data) const
 {
-    if (!m_fieldsExpanded) {//simple version: without types
+    if (!m_visibleFieldsExpanded) {//simple version: without types
         for (int i = 0; i < m_fieldCount; i++) {
             (*data)[i] = QString::fromUtf8((const \
char*)sqlite3_column_text(d->prepared_st_handle, i));  }
         return true;
     }
-    const int maxCount = qMin(m_fieldCount, m_fieldsExpanded->count());
-    // i - visible field's index, j - physical index
-    for (int i = 0, j = 0; i < m_fieldCount; i++, j++) {
-        while (j < maxCount && !m_fieldsExpanded->at(j)->visible)
-            j++;
-        if (j >= (maxCount /*+(m_containsROWIDInfo ? 1 : 0)*/)) {
-            //ERR!
-            break;
-        }
-        KDbField *f = (i >= m_fieldCount) ? 0 : m_fieldsExpanded->at(j)->field;
+    for (int i = 0; i < m_fieldCount; ++i) {
+        KDbField *f = m_visibleFieldsExpanded->at(i)->field;
 //  sqliteDebug() << "col=" << (col ? *col : 0);
         (*data)[i] = d->getValue(f, i);
     }
@@ -330,8 +322,8 @@ QVariant SqliteCursor::value(int i)
     if (i < 0 || i > (m_fieldCount - 1)) //range checking
         return QVariant();
 //! @todo allow disable range checking! - performance reasons
-    KDbField *f = (m_fieldsExpanded && i < m_fieldsExpanded->count())
-                       ? m_fieldsExpanded->at(i)->field : 0;
+    KDbField *f = (m_visibleFieldsExpanded && i < m_visibleFieldsExpanded->count())
+                  ? m_visibleFieldsExpanded->at(i)->field : 0;
     return d->getValue(f, i); //, i==m_logicalFieldCount/*ROWID*/);
 }
 
diff --git a/src/drivers/sybase/SybaseCursor.cpp \
b/src/drivers/sybase/SybaseCursor.cpp index df5b03a..72aa803 100644
--- a/src/drivers/sybase/SybaseCursor.cpp
+++ b/src/drivers/sybase/SybaseCursor.cpp
@@ -143,8 +143,8 @@ QVariant SybaseCursor::value(int pos)
     if (!d->dbProcess || pos >= m_fieldCount)
         return QVariant();
 
-    KDbField *f = (m_fieldsExpanded && pos < m_fieldsExpanded->count())
-                       ? m_fieldsExpanded->at(pos)->field : 0;
+    KDbField *f = (m_visibleFieldsExpanded && pos < \
m_visibleFieldsExpanded->count()) +                       ? \
m_visibleFieldsExpanded->at(pos)->field : 0;  
     // db-library indexes its columns from 1
     pos = pos + 1;
@@ -178,11 +178,12 @@ bool SybaseCursor::drv_storeCurrentRecord(KDbRecordData* data) \
const  // if (d->numRows<=0)
 //  return false;
 
-    const int fieldsExpandedCount = m_fieldsExpanded ? m_fieldsExpanded->count() : \
INT_MAX; +    const int fieldsExpandedCount = m_visibleFieldsExpanded
+                                    ? m_visibleFieldsExpanded->count() : INT_MAX;
     const int realCount = qMin(fieldsExpandedCount, m_fieldsToStoreInRecord);
     for (int i = 0; i < realCount; i++) {
-        KDbField *f = m_fieldsExpanded ? m_fieldsExpanded->at(i)->field : 0;
-        if (m_fieldsExpanded && !f)
+        KDbField *f = m_visibleFieldsExpanded ? \
m_visibleFieldsExpanded->at(i)->field : 0; +        if (m_visibleFieldsExpanded && \
!f)  continue;
 
         long int columnDataLength = dbdatlen(d->dbProcess, i + 1);


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic