Changeset f1826af in confclerk_git


Ignore:
Timestamp:
09/25/12 23:24:05 (10 years ago)
Author:
Philipp Spitzer <philipp@…>
Branches:
master, qt5
Children:
95257a6
Parents:
e2c612c
Message:

Schmema update completed. Finally closing ticket #45.

Location:
src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/db.qrc

    re2c612c rf1826af  
    22<qresource>
    33    <file>dbschema001.sql</file>
     4    <file>dbschema000to001.sql</file>
    45</qresource>
    56</RCC>
  • src/sql/sqlengine.cpp

    re2c612c rf1826af  
    8282
    8383bool SqlEngine::updateDbSchemaVersion000To001() {
    84     emit dbError("Upgrade 0 -> 1 not implemented yet");
    85     return false;
     84    return applySqlFile(":/dbschema000to001.sql");
    8685}
    8786
    8887
    8988bool SqlEngine::createCurrentDbSchema() {
    90     QFile file(":/dbschema001.sql");
    91     file.open(QIODevice::ReadOnly | QIODevice::Text);
    92     QString allSqlStatements = file.readAll();
    93     QSqlQuery query(db);
    94     foreach(QString sql, allSqlStatements.split(";")) {
    95         if (sql.trimmed().isEmpty())  // do not execute empty queries like the last character from create_tables.sql
    96             continue;
    97         if (!query.exec(sql)) {
    98             emitSqlQueryError(query);
    99             return false;
    100         }
    101     }
    102     return true;
     89    return applySqlFile(":/dbschema001.sql");
    10390}
    10491
     
    124111    }
    125112    return false;
     113}
     114
     115
     116bool SqlEngine::applySqlFile(const QString sqlFile) {
     117    QFile file(sqlFile);
     118    file.open(QIODevice::ReadOnly | QIODevice::Text);
     119    QString allSqlStatements = file.readAll();
     120    QSqlQuery query(db);
     121    foreach(QString sql, allSqlStatements.split(";")) {
     122        if (sql.trimmed().isEmpty())  // do not execute empty queries like the last character from create_tables.sql
     123            continue;
     124        if (!query.exec(sql)) {
     125            emitSqlQueryError(query);
     126            return false;
     127        }
     128    }
     129    return true;
    126130}
    127131
  • src/sql/sqlengine.h

    re2c612c rf1826af  
    5353        /// otherwise updates the schema if an old one is found. true for success.
    5454        bool createOrUpdateDbSchema();
     55        /// Applies an SQL file
     56        bool applySqlFile(const QString sqlFile);
    5557
    5658        // if a conferneceId != 0 is given, the confernce is updated instead of inserted.
Note: See TracChangeset for help on using the changeset viewer.