comparison src/util.cpp @ 255:55581d90c55d

Change API for slCheckAndReportSQLError().
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 10 Oct 2018 13:21:51 +0300
parents 0e0ad52994ca
children df3f902588af
comparison
equal deleted inserted replaced
254:0e0ad52994ca 255:55581d90c55d
112 // 112 //
113 // Check if an SQL error has occured (for given QSqlError) and 113 // Check if an SQL error has occured (for given QSqlError) and
114 // report it to stdout if so. Return "false" if error has occured, 114 // report it to stdout if so. Return "false" if error has occured,
115 // true otherwise. 115 // true otherwise.
116 // 116 //
117 bool slCheckAndReportSQLError(const QString where, const QSqlError &err, bool report) 117 bool slCheckAndReportSQLError(const QSqlQuery &query, const QString where, bool report)
118 { 118 {
119 const QSqlError err = query.lastError();
119 if (err.isValid()) 120 if (err.isValid())
120 { 121 {
121 // If an error has occured, log it 122 // If an error has occured, log it
122 slLog("ERROR", 123 slLog("ERROR",
123 QStringLiteral("SQL %1: %2"). 124 QStringLiteral("SQL %1: %2").
152 arg(table.schema); 153 arg(table.schema);
153 154
154 tcreate.exec(sql); 155 tcreate.exec(sql);
155 156
156 if (!slCheckAndReportSQLError( 157 if (!slCheckAndReportSQLError(
157 sql, tcreate.lastError(), true)) 158 tcreate, sql, true))
158 return false; 159 return false;
159 160
160 tcreate.finish(); 161 tcreate.finish();
161 162
162 // If any inserts are specified, do them 163 // If any inserts are specified, do them
172 arg(str); 173 arg(str);
173 174
174 insert.exec(sql); 175 insert.exec(sql);
175 176
176 if (!slCheckAndReportSQLError( 177 if (!slCheckAndReportSQLError(
177 sql, insert.lastError(), true)) 178 insert, sql, true))
178 return false; 179 return false;
179 180
180 insert.finish(); 181 insert.finish();
181 } 182 }
182 } 183 }