aboutsummaryrefslogtreecommitdiffstats
path: root/src/imports
diff options
context:
space:
mode:
authorShawn Rutledge <shawn.rutledge@qt.io>2017-01-09 17:06:25 +0100
committerShawn Rutledge <shawn.rutledge@qt.io>2017-02-02 13:19:57 +0000
commitf96b77bf46a29b1c09d6ebff2f18a475c7ca0b2f (patch)
tree3367d385eb85ba80bad41b155a48057a548c02e8 /src/imports
parent6ba26317d0fc0573aca7638eda8bdb91e52d1ab3 (diff)
add QQmlEngine::offlineStorageDatabaseFilePath(db), use in LocalStorage
This is C++ API to get the actual storage path for a particular database. [ChangeLog][QtQml] Added QQmlEngine::offlineStorageDatabaseFilePath(dbName) to allow getting the actual storage path for a particular database. Task-number: QTBUG-52013 Change-Id: I1cbd9454c537f08c97f4dafc06fd6b14e81c51af Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'src/imports')
-rw-r--r--src/imports/localstorage/plugin.cpp37
1 files changed, 8 insertions, 29 deletions
diff --git a/src/imports/localstorage/plugin.cpp b/src/imports/localstorage/plugin.cpp
index d3ea93c80a..433b7fe430 100644
--- a/src/imports/localstorage/plugin.cpp
+++ b/src/imports/localstorage/plugin.cpp
@@ -219,24 +219,6 @@ QQmlSqlDatabaseData::~QQmlSqlDatabaseData()
{
}
-static QString qmlsqldatabase_databasesPath(QV4::ExecutionEngine *engine)
-{
- return engine->qmlEngine()->offlineStoragePath() +
- QDir::separator() + QLatin1String("Databases");
-}
-
-static void qmlsqldatabase_initDatabasesPath(QV4::ExecutionEngine *engine)
-{
- QString databasesPath = qmlsqldatabase_databasesPath(engine);
- if (!QDir().mkpath(databasesPath))
- qWarning() << "LocalStorage: can't create path - " << databasesPath;
-}
-
-static QString qmlsqldatabase_databaseFile(const QString& connectionName, QV4::ExecutionEngine *engine)
-{
- return qmlsqldatabase_databasesPath(engine) + QDir::separator() + connectionName;
-}
-
static ReturnedValue qmlsqldatabase_rows_index(const QQmlSqlDatabaseWrapper *r, ExecutionEngine *v4, quint32 index, bool *hasProperty = 0)
{
Scope scope(v4);
@@ -450,7 +432,8 @@ static ReturnedValue qmlsqldatabase_changeVersion(CallContext *ctx)
if (ok) {
*w->d()->version = to_version;
#if QT_CONFIG(settings)
- QSettings ini(qmlsqldatabase_databaseFile(db.connectionName(), scope.engine) + QLatin1String(".ini"), QSettings::IniFormat);
+ const QQmlEnginePrivate *enginePrivate = QQmlEnginePrivate::get(scope.engine->qmlEngine());
+ QSettings ini(enginePrivate->offlineStorageDatabaseDirectory() + db.connectionName() + QLatin1String(".ini"), QSettings::IniFormat);
ini.setValue(QLatin1String("Version"), to_version);
#endif
}
@@ -723,24 +706,20 @@ void QQuickLocalStorage::openDatabaseSync(QQmlV4Function *args)
if (scope.engine->qmlEngine()->offlineStoragePath().isEmpty())
V4THROW_SQL2(SQLEXCEPTION_DATABASE_ERR, QQmlEngine::tr("SQL: can't create database, offline storage is disabled."));
- qmlsqldatabase_initDatabasesPath(scope.engine);
-
- QSqlDatabase database;
-
QV4::ScopedValue v(scope);
QString dbname = (v = (*args)[0])->toQStringNoThrow();
QString dbversion = (v = (*args)[1])->toQStringNoThrow();
QString dbdescription = (v = (*args)[2])->toQStringNoThrow();
int dbestimatedsize = (v = (*args)[3])->toInt32();
FunctionObject *dbcreationCallback = (v = (*args)[4])->as<FunctionObject>();
-
- QCryptographicHash md5(QCryptographicHash::Md5);
- md5.addData(dbname.toUtf8());
- QString dbid(QLatin1String(md5.result().toHex()));
-
- QString basename = qmlsqldatabase_databaseFile(dbid, scope.engine);
+ QString basename = args->v4engine()->qmlEngine()->offlineStorageDatabaseFilePath(dbname);
+ QFileInfo dbFile(basename);
+ if (!QDir().mkpath(dbFile.dir().absolutePath()))
+ V4THROW_SQL2(SQLEXCEPTION_DATABASE_ERR, QQmlEngine::tr("LocalStorage: can't create path ") + dbFile.dir().absolutePath());
+ QString dbid = dbFile.fileName();
bool created = false;
QString version = dbversion;
+ QSqlDatabase database;
{
QSettings ini(basename+QLatin1String(".ini"),QSettings::IniFormat);