--- qsqlresult.orig	2009-09-29 13:04:14.000000000 +0200
+++ qsqlresult.cpp	2009-12-03 10:05:26.375000000 +0100
@@ -111,7 +111,8 @@
     QString executedQuery;
     QHash<int, QSql::ParamType> types;
     QVector<QVariant> values;
-    typedef QHash<QString, int> IndexMap;
+    typedef QVector<int> IndexMapPositions;
+    typedef QHash<QString, IndexMapPositions> IndexMap;
     IndexMap indexes;
 
     typedef QVector<QHolder> QHolderVector;
@@ -120,7 +121,15 @@
 
 QString QSqlResultPrivate::holderAt(int index) const
 {
-    return indexes.key(index);
+    QHashIterator<QString, IndexMapPositions> i(indexes);
+    while(i.hasNext())
+    {
+        i.next();
+        IndexMapPositions 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++;
+            IndexMapPositions &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::IndexMapPositions 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::IndexMapPositions &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,25 @@
     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::IndexMapPositions temp=d->indexes.value(placeholder);
+    if (!temp.isEmpty()) {
+        for(int i=0;i<temp.size();i++)
+        {
+            if (d->values.count() <= temp[i])
+                d->values.resize(temp[i] + 1);
+            d->values[temp[i]] = val;
+        }
     } 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;
+    {
+        for(int i=0;i<temp.size();i++)
+            d->types[temp[i]] = paramType;
+    }
 }
 
 /*!
@@ -754,8 +776,11 @@
 */
 QVariant QSqlResult::boundValue(const QString& placeholder) const
 {
-    int idx = d->indexes.value(placeholder, -1);
-    return d->values.value(idx);
+    QSqlResultPrivate::IndexMapPositions temp = d->indexes.value(placeholder);
+    if(temp.isEmpty())
+        return QVariant();
+    else
+        return d->values.value(temp.first());
 }
 
 /*!
@@ -776,7 +801,11 @@
 */
 QSql::ParamType QSqlResult::bindValueType(const QString& placeholder) const
 {
-    return d->types.value(d->indexes.value(placeholder, -1), QSql::In);
+    QSqlResultPrivate::IndexMapPositions temp = d->indexes.value(placeholder);
+    if(temp.isEmpty())
+        return QSql::In;
+    else
+        return d->types.value(temp.first(), QSql::In);
 }
 
 /*!
