diff options
author | Bea Lam <bea.lam@nokia.com> | 2010-12-10 04:22:45 (GMT) |
---|---|---|
committer | Bea Lam <bea.lam@nokia.com> | 2010-12-10 04:26:34 (GMT) |
commit | a0fabfac2ddd0b4e52a1d06623a0864f836cba71 (patch) | |
tree | 7c23bf8f7fef61e79aa699756744b0fb337892c3 | |
parent | 7adfc78d6eac0ca50149abbc6129dc891d320439 (diff) | |
download | Qt-a0fabfac2ddd0b4e52a1d06623a0864f836cba71.zip Qt-a0fabfac2ddd0b4e52a1d06623a0864f836cba71.tar.gz Qt-a0fabfac2ddd0b4e52a1d06623a0864f836cba71.tar.bz2 |
Fix broken database creation caused by previous fix
16447b1193fedf5fdcf1f3d270fa73c5036a1ba0 removed unused directory but
the fix meant that the base Databases directory was no longer
automatically created.
Task-number: QTBUG-15909
-rw-r--r-- | src/declarative/qml/qdeclarativesqldatabase.cpp | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/src/declarative/qml/qdeclarativesqldatabase.cpp b/src/declarative/qml/qdeclarativesqldatabase.cpp index 3f53111..bda02a5 100644 --- a/src/declarative/qml/qdeclarativesqldatabase.cpp +++ b/src/declarative/qml/qdeclarativesqldatabase.cpp @@ -172,16 +172,23 @@ static const char* sqlerror[] = { return errorValue; \ } - -static QString databaseFile(const QString& connectionName, QScriptEngine *engine) +static QString qmlsqldatabase_databasesPath(QScriptEngine *engine) { QDeclarativeScriptEngine *qmlengine = static_cast<QDeclarativeScriptEngine*>(engine); - QString basename = qmlengine->offlineStoragePath - + QDir::separator() + QLatin1String("Databases") + QDir::separator(); - basename += connectionName; - return basename; + return qmlengine->offlineStoragePath + + QDir::separator() + QLatin1String("Databases"); } +static void qmlsqldatabase_initDatabasesPath(QScriptEngine *engine) +{ + QDir().mkpath(qmlsqldatabase_databasesPath(engine)); +} + +static QString qmlsqldatabase_databaseFile(const QString& connectionName, QScriptEngine *engine) +{ + return qmlsqldatabase_databasesPath(engine) + QDir::separator() + + connectionName; +} static QScriptValue qmlsqldatabase_item(QScriptContext *context, QScriptEngine *engine) @@ -302,7 +309,7 @@ static QScriptValue qmlsqldatabase_change_version(QScriptContext *context, QScri if (ok) { context->thisObject().setProperty(QLatin1String("version"), to_version, QScriptValue::ReadOnly); - QSettings ini(databaseFile(db.connectionName(),engine)+QLatin1String(".ini"),QSettings::IniFormat); + QSettings ini(qmlsqldatabase_databaseFile(db.connectionName(),engine) + QLatin1String(".ini"), QSettings::IniFormat); ini.setValue(QLatin1String("Version"), to_version); } @@ -348,6 +355,8 @@ static QScriptValue qmlsqldatabase_read_transaction(QScriptContext *context, QSc */ static QScriptValue qmlsqldatabase_open_sync(QScriptContext *context, QScriptEngine *engine) { + qmlsqldatabase_initDatabasesPath(engine); + QSqlDatabase database; QString dbname = context->argument(0).toString(); @@ -360,7 +369,7 @@ static QScriptValue qmlsqldatabase_open_sync(QScriptContext *context, QScriptEng md5.addData(dbname.toUtf8()); QString dbid(QLatin1String(md5.result().toHex())); - QString basename = databaseFile(dbid,engine); + QString basename = qmlsqldatabase_databaseFile(dbid, engine); bool created = false; QString version = dbversion; |