18 bool MatchesSchema (
const QString& baseName,
const QString& schema, QSqlDatabase& db)
21 "SELECT sql FROM sqlite_master WHERE type = 'table' AND name = '%1'"_qs
26 const auto& existingDDL = result.value (0).toString ();
28 auto figureOutFields = [] (
const QString& str)
30 auto firstOpen = str.indexOf (
'(');
31 auto lastClose = str.lastIndexOf (
')');
32 return QStringView { str }.mid (firstOpen, lastClose - firstOpen);
34 auto existing = figureOutFields (existingDDL);
35 auto suggested = figureOutFields (schema);
36 return existing == suggested;
40 template<
typename Record,
typename ImplFactory = SQLiteImplFactory>
43 constexpr auto baseName = Record::ClassName;
44 constexpr auto thisName =
"copy" + baseName;
51 qDebug () << Q_FUNC_INFO
53 << db.connectionName ();
57 qDebug () << Q_FUNC_INFO
59 << db.connectionName ();
69 "INSERT INTO %2 (%1) SELECT %1 FROM %3;"_qs
76 "ALTER TABLE %1 RENAME TO %2;"_qs
77 .arg (thisNameStr, baseNameStr));
Provides database transaction lock.
UTIL_DB_API void Init()
Initializes the transaction.
UTIL_DB_API void Good()
Notifies the lock about successful higher-level operations.
QSqlQuery RunTextQuery(const QSqlDatabase &db, const QString &text)
Runs the given query text on the given db.
bool MatchesSchema(const QString &baseName, const QString &schema, QSqlDatabase &db)
constexpr auto FieldNames
void Migrate(QSqlDatabase &db)
QString ToString() noexcept
constexpr auto JoinTup(auto &&stringsTuple, auto &&sep) noexcept