21 bool MatchesSchema (
const QString& baseName,
const QString& schema, QSqlDatabase& db)
24 QString {
"SELECT sql FROM sqlite_master WHERE type = 'table' AND name = '%1'" }
29 const auto& existingDDL = result.value (0).toString ();
31 auto figureOutFields = [] (
const QString& str)
33 auto firstOpen = str.indexOf (
'(');
34 auto lastClose = str.lastIndexOf (
')');
35 return str.midRef (firstOpen, lastClose - firstOpen);
37 auto existing = figureOutFields (existingDDL);
38 auto suggested = figureOutFields (schema);
39 return existing == suggested;
43 template<
typename Record,
typename ImplFactory = SQLiteImplFactory>
46 const auto& baseName = Record::ClassName ();
48 const auto& thisName =
"copy" + baseName;
49 const auto& schema = detail::AdaptCreateTable<ImplFactory, Record> (detail::BuildCachedFieldsData<Record> (thisName));
53 qDebug () << Q_FUNC_INFO
55 << db.connectionName ();
59 qDebug () << Q_FUNC_INFO
61 << db.connectionName ();
68 const auto&
fields = detail::GetFieldsNames<Record> {} ().join (
", ");
71 QString {
"INSERT INTO %2 (%1) SELECT %1 FROM %3;" }
77 QString {
"DROP TABLE %1;" }
80 QString {
"ALTER TABLE %1 RENAME TO %2;" }