comparison src/util.cpp @ 252:4d2b37a0acf2

Move SQL table creation from schema array to util-module.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 08 May 2018 15:00:17 +0300
parents 4f947840c806
children eadffc38ab43
comparison
equal deleted inserted replaced
251:ede0fde2ae6e 252:4d2b37a0acf2
133 QStringLiteral("SQL OK %1").arg(where)); 133 QStringLiteral("SQL OK %1").arg(where));
134 } 134 }
135 return true; 135 return true;
136 } 136 }
137 } 137 }
138
139
140 bool slConditionallyCreateSQLTables(QSqlDatabase &db, const SLSQLSchemaDef *schema, const int nschema)
141 {
142 for (int ntable = 0; ntable < nschema; ntable++)
143 {
144 const SLSQLSchemaDef &table = schema[ntable];
145 if (!db.tables().contains(table.name))
146 {
147 // Attempt to create the table
148 QSqlQuery tcreate(db);
149 QString sql =
150 QStringLiteral("CREATE TABLE %1 (%2)").
151 arg(table.name).
152 arg(table.schema);
153
154 tcreate.exec(sql);
155
156 if (!slCheckAndReportSQLError(
157 sql, tcreate.lastError(), true))
158 return false;
159
160 tcreate.finish();
161 }
162 }
163
164 return true;
165 }