--- qsqlresult.orig	2009-09-29 13:04:14.000000000 +0200
+++ qsqlresult.cpp	2009-12-02 16:10:30.312500000 +0100
@@ -111,7 +111,8 @@
     QString executedQuery;
     QHash<int, QSql::ParamType> types;
     QVector<QVariant> values;
-    typedef QHash<QString, int> IndexMap;
+    typedef QVector<int> IndexMapIdxPositions;
+    typedef QHash<QString, IndexMapIdxPositions> IndexMap;
     IndexMap indexes;
 
     typedef QVector<QHolder> QHolderVector;
@@ -120,7 +121,15 @@
 
 QString QSqlResultPrivate::holderAt(int index) const
 {
-    return indexes.key(index);
+    QHashIterator<QString, IndexMapIdxPositions> i(indexes);
+    while(i.hasNext())
+    {
+        i.next();
+        IndexMapIdxPositions val=i.value();
+        if(val.contains(index))
+            return i.key();
+    }
+    return QString();
 }
 
 // return a unique id for bound names
@@ -185,7 +194,8 @@
             int pos = i + 2;
             while (pos < n && qIsAlnum(sql.at(pos)))
                 ++pos;
-            indexes[sql.mid(i, pos - i)] = count++;
+            IndexMapIdxPositions &temp=indexes[sql.mid(i, pos - i)];
+            temp.insert(temp.size(),count++);
             result += QLatin1Char('?');
             i = pos;
         } else {
@@ -639,11 +649,15 @@
         QString holder;
         for (i = d->holders.count() - 1; i >= 0; --i) {
             holder = d->holders.at(i).holderName;
-            val = d->values.value(d->indexes.value(holder));
-            QSqlField f(QLatin1String(""), val.type());
-            f.setValue(val);
-            query = query.replace(d->holders.at(i).holderPos,
-                                   holder.length(), driver()->formatValue(f));
+            QSqlResultPrivate::IndexMapIdxPositions temp=d->indexes.value(holder);
+            if(!temp.isEmpty())
+            {
+                val = d->values.value(temp.first());
+                QSqlField f(QLatin1String(""), val.type());
+                f.setValue(val);
+                query = query.replace(d->holders.at(i).holderPos,
+                                       holder.length(), driver()->formatValue(f));
+            }
         }
     } else {
         QString val;
@@ -683,7 +697,9 @@
 void QSqlResult::bindValue(int index, const QVariant& val, QSql::ParamType paramType)
 {
     d->binds = PositionalBinding;
-    d->indexes[qFieldSerial(index)] = index;
+    QSqlResultPrivate::IndexMapIdxPositions &temp=d->indexes[qFieldSerial(index)];
+    if(!temp.contains(index))
+        temp.insert(temp.size(),index);
     if (d->values.count() <= index)
         d->values.resize(index + 1);
     d->values[index] = val;
@@ -705,19 +721,18 @@
     d->binds = NamedBinding;
     // if the index has already been set when doing emulated named
     // bindings - don't reset it
-    int idx = d->indexes.value(placeholder, -1);
-    if (idx >= 0) {
-        if (d->values.count() <= idx)
-            d->values.resize(idx + 1);
-        d->values[idx] = val;
+    QSqlResultPrivate::IndexMapIdxPositions temp=d->indexes.value(placeholder);
+    if (!temp.isEmpty()) {
+        if (d->values.count() <= temp[0])
+            d->values.resize(temp[0] + 1);
     } else {
         d->values.append(val);
-        idx = d->values.count() - 1;
-        d->indexes[placeholder] = idx;
+        temp.insert(0,d->values.count() - 1);
+        d->indexes[placeholder] = temp;
     }
 
     if (paramType != QSql::In || !d->types.isEmpty())
-        d->types[idx] = paramType;
+        d->types[temp[0]] = paramType;
 }
 
 /*!
@@ -754,8 +769,11 @@
 */
 QVariant QSqlResult::boundValue(const QString& placeholder) const
 {
-    int idx = d->indexes.value(placeholder, -1);
-    return d->values.value(idx);
+    QSqlResultPrivate::IndexMapIdxPositions temp = d->indexes.value(placeholder);
+    if(temp.isEmpty())
+        return QVariant();
+    else
+        return d->values.value(temp.first());
 }
 
 /*!
@@ -776,7 +794,11 @@
 */
 QSql::ParamType QSqlResult::bindValueType(const QString& placeholder) const
 {
-    return d->types.value(d->indexes.value(placeholder, -1), QSql::In);
+    QSqlResultPrivate::IndexMapIdxPositions temp = d->indexes.value(placeholder);
+    if(temp.isEmpty())
+        return QSql::In;
+    else
+        return d->types.value(temp.first(), QSql::In);
 }
 
 /*!
