comparison DBCache.hpp @ 36:2b83559b78db

BUGFIX: batch inserts inserted empty values. BUGFIX: cutoff limit was not observed at cutoff, but cutoff + 1
author Tom Fredrik Blenning Klaussen <bfg@blenning.no>
date Fri, 07 Sep 2012 13:06:10 +0200
parents fda70a362ed5
children f711ddb56ae7
comparison
equal deleted inserted replaced
35:769f43c4c5d0 36:2b83559b78db
15 15
16 #include "ThreadSafeLookup.hpp" 16 #include "ThreadSafeLookup.hpp"
17 #include "UniqueString.hpp" 17 #include "UniqueString.hpp"
18 #include "Exception/SQLException.hpp" 18 #include "Exception/SQLException.hpp"
19 #include "Exception/IOException.hpp" 19 #include "Exception/IOException.hpp"
20
21 20
22 template<typename T> 21 template<typename T>
23 struct SQLGenerator 22 struct SQLGenerator
24 { 23 {
25 }; 24 };
152 static void bindValue(QSqlQuery& query, const QString& value, const QString& prefix = QString()) 151 static void bindValue(QSqlQuery& query, const QString& value, const QString& prefix = QString())
153 { 152 {
154 query.bindValue(valueString(prefix), value); 153 query.bindValue(valueString(prefix), value);
155 } 154 }
156 155
157 static void bindValues(QSqlQuery& query, const QVariantList& value, const QString& prefix = QString()) 156 static void bindValues(QSqlQuery& query, const QVariantList& values, const QString& prefix = QString())
158 { 157 {
159 query.bindValue(valueString(prefix), value); 158 query.bindValue(valueString(prefix), values);
160 } 159 }
161 160
162 static void bindValues(QSqlQuery& query, const QList<UniqueString>& values, const QString& prefix = QString()) 161 static void bindValues(QSqlQuery& query, const QList<UniqueString>& values, const QString& prefix = QString())
163 { 162 {
164 QVariantList list; 163 QVariantList list;
287 QList<Value> values; 286 QList<Value> values;
288 foreach(Key key, unsyncedKeys) { 287 foreach(Key key, unsyncedKeys) {
289 values << *memoryMap.value(key); 288 values << *memoryMap.value(key);
290 } 289 }
291 SQLGenerator<Value>::bindValues(insertQuery, values, "value"); 290 SQLGenerator<Value>::bindValues(insertQuery, values, "value");
292 if (!insertQuery.exec()) { 291 if (!insertQuery.execBatch()) {
293 throw SQLException(insertQuery); 292 throw SQLException(insertQuery);
294 } 293 }
295 insertQuery.finish(); 294 insertQuery.finish();
296 unsyncedKeys.clear(); 295 unsyncedKeys.clear();
297 } 296 }
335 void insert(const Key& key, const Value& value) 334 void insert(const Key& key, const Value& value)
336 { 335 {
337 if (memoryMapped) { 336 if (memoryMapped) {
338 memoryMap.insert(key, value); 337 memoryMap.insert(key, value);
339 unsyncedKeys.append(key); 338 unsyncedKeys.append(key);
340 if (unsyncedKeys.size() > 1024) { 339 if (unsyncedKeys.size() >= 1024) {
341 syncInsert(); 340 syncInsert();
342 } 341 }
343 } 342 }
344 else { 343 else {
345 SQLGenerator<Key>::bindValue(insertQuery, key, "key"); 344 SQLGenerator<Key>::bindValue(insertQuery, key, "key");