comparison SqliteDBLink.cpp @ 92:f49023c61dac

Support for bulk insertion.
author Tom Fredrik Blenning Klaussen <bfg@bfgconsult.no>
date Mon, 21 Oct 2013 20:03:39 +0200
parents 7b7a959c993b
children 308a718812ba
comparison
equal deleted inserted replaced
91:a5788991ca9f 92:f49023c61dac
83 } 83 }
84 return NONE; 84 return NONE;
85 } 85 }
86 86
87 void SqliteDBLink::addFile(const QString& path, quint64 size, 87 void SqliteDBLink::addFile(const QString& path, quint64 size,
88 const QDateTime& dtime, const QByteArray& hash) 88 const QDateTime& dtime, const QByteArray& hash,
89 { 89 bool lazy)
90 addFile(DBInfo(path, size, dtime, hash)); 90 {
91 addFile(DBInfo(path, size, dtime, hash), lazy);
91 } 92 }
92 93
93 bool SqliteDBLink::tryAddFile(const DBInfo& dbinfo) 94 bool SqliteDBLink::tryAddFile(const DBInfo& dbinfo)
94 { 95 {
95 if (exists(dbinfo.path())) 96 if (exists(dbinfo.path()))
104 return true; 105 return true;
105 } 106 }
106 107
107 void SqliteDBLink::updateFile(const QString& path, 108 void SqliteDBLink::updateFile(const QString& path,
108 quint64 size, const QDateTime& dtime, 109 quint64 size, const QDateTime& dtime,
109 const QByteArray& hash) 110 const QByteArray& hash, bool lazy)
110 { 111 {
111 updateFile(DBInfo(path, size, dtime, hash)); 112 updateFile(DBInfo(path, size, dtime, hash), lazy);
112 } 113 }
113 114
114 void SqliteDBLink::updateFile(const DBInfo& dbinfo) 115 void SqliteDBLink::updateFile(const DBInfo& dbinfo, bool lazy)
115 { 116 {
116 QSqlQuery query(db); 117 QSqlQuery query(db);
117 query.prepare("UPDATE files " 118 query.prepare("UPDATE files "
118 "SET size=:size, mtime=:mtime, checksum=:checksum " 119 "SET size=:size, mtime=:mtime, checksum=:checksum "
119 "WHERE path=:path"); 120 "WHERE path=:path");
124 if (!query.exec()) { 125 if (!query.exec()) {
125 throw SQLException(query); 126 throw SQLException(query);
126 } 127 }
127 } 128 }
128 129
129 void SqliteDBLink::addFile(const DBInfo& dbinfo) 130 void SqliteDBLink::addFile(const DBInfo& dbinfo, bool lazy)
130 { 131 {
131 if (!tryAddFile(dbinfo)) { 132 if (!tryAddFile(dbinfo)) {
132 abort(); //Should throw exception 133 abort(); //Should throw exception
133 } 134 }
134 } 135 }