aboutsummaryrefslogtreecommitdiffstats
path: root/src/declarative
diff options
context:
space:
mode:
authorCharles Yin <charles.yin@nokia.com>2012-01-24 16:07:24 +1000
committerQt by Nokia <qt-info@nokia.com>2012-01-25 06:32:34 +0100
commitb2869013fdfb76d60ce8750e24614111f78fef5c (patch)
treec57ec9c0cfc1226c1ac9d66735ddd267b20cffca /src/declarative
parent149f6afe321ce59aebe4ce2f9dddd1881d0ac22b (diff)
Move sqldatabase into a module API plugin
Change-Id: Icd0bbfe16804abf1bbadbabddf3a30b5b18df30c Reviewed-by: Martin Jones <martin.jones@nokia.com>
Diffstat (limited to 'src/declarative')
-rw-r--r--src/declarative/qml/qdeclarativeengine.cpp12
-rw-r--r--src/declarative/qml/qdeclarativesqldatabase.cpp63
-rw-r--r--src/declarative/qml/qdeclarativesqldatabase_p.h2
-rw-r--r--src/declarative/qml/v8/qv8engine.cpp4
-rw-r--r--src/declarative/qml/v8/qv8sqlerrors.cpp64
-rw-r--r--src/declarative/qml/v8/qv8sqlerrors_p.h77
-rw-r--r--src/declarative/qml/v8/v8.pri4
7 files changed, 168 insertions, 58 deletions
diff --git a/src/declarative/qml/qdeclarativeengine.cpp b/src/declarative/qml/qdeclarativeengine.cpp
index 54f17ca48d..ade01cfe89 100644
--- a/src/declarative/qml/qdeclarativeengine.cpp
+++ b/src/declarative/qml/qdeclarativeengine.cpp
@@ -74,6 +74,9 @@
#include "qdeclarativeincubator.h"
#include <private/qv8profilerservice_p.h>
+#include <QtCore/qstandardpaths.h>
+#include <QtCore/qsettings.h>
+
#include <QtCore/qmetaobject.h>
#include <QNetworkAccessManager>
#include <QDebug>
@@ -454,6 +457,11 @@ void QDeclarativeEnginePrivate::init()
QDeclarativeDebugTrace::initialize();
QDebugMessageService::instance();
}
+
+ QString dataLocation = QStandardPaths::writableLocation(QStandardPaths::DataLocation);
+ offlineStoragePath = dataLocation.replace(QLatin1Char('/'), QDir::separator()) +
+ QDir::separator() + QLatin1String("QML") +
+ QDir::separator() + QLatin1String("OfflineStorage");
}
QDeclarativeWorkerScriptEngine *QDeclarativeEnginePrivate::getWorkerScriptEngine()
@@ -1543,13 +1551,13 @@ bool QDeclarativeEngine::importPlugin(const QString &filePath, const QString &ur
void QDeclarativeEngine::setOfflineStoragePath(const QString& dir)
{
Q_D(QDeclarativeEngine);
- qt_qmlsqldatabase_setOfflineStoragePath(d->v8engine(), dir);
+ d->offlineStoragePath = dir;
}
QString QDeclarativeEngine::offlineStoragePath() const
{
Q_D(const QDeclarativeEngine);
- return qt_qmlsqldatabase_getOfflineStoragePath(d->v8engine());
+ return d->offlineStoragePath;
}
static void voidptr_destructor(void *v)
diff --git a/src/declarative/qml/qdeclarativesqldatabase.cpp b/src/declarative/qml/qdeclarativesqldatabase.cpp
index 5f7100e49b..fd4356efd9 100644
--- a/src/declarative/qml/qdeclarativesqldatabase.cpp
+++ b/src/declarative/qml/qdeclarativesqldatabase.cpp
@@ -59,31 +59,10 @@
#include <QtCore/qdebug.h>
#include <private/qv8engine_p.h>
+#include <private/qv8sqlerrors_p.h>
QT_BEGIN_NAMESPACE
-enum SqlException {
- UNKNOWN_ERR,
- DATABASE_ERR,
- VERSION_ERR,
- TOO_LARGE_ERR,
- QUOTA_ERR,
- SYNTAX_ERR,
- CONSTRAINT_ERR,
- TIMEOUT_ERR
-};
-
-static const char* sqlerror[] = {
- "UNKNOWN_ERR",
- "DATABASE_ERR",
- "VERSION_ERR",
- "TOO_LARGE_ERR",
- "QUOTA_ERR",
- "SYNTAX_ERR",
- "CONSTRAINT_ERR",
- "TIMEOUT_ERR",
- 0
-};
#define THROW_SQL(error, desc)
@@ -109,7 +88,6 @@ struct QDeclarativeSqlDatabaseData {
QDeclarativeSqlDatabaseData(QV8Engine *engine);
~QDeclarativeSqlDatabaseData();
- QString offlineStoragePath;
v8::Persistent<v8::Function> constructor;
v8::Persistent<v8::Function> queryConstructor;
v8::Persistent<v8::Function> rowsConstructor;
@@ -201,7 +179,7 @@ QDeclarativeSqlDatabaseData::~QDeclarativeSqlDatabaseData()
static QString qmlsqldatabase_databasesPath(QV8Engine *engine)
{
- return QDeclarativeSqlDatabaseData::data(engine)->offlineStoragePath +
+ return engine->engine()->offlineStoragePath() +
QDir::separator() + QLatin1String("Databases");
}
@@ -264,14 +242,14 @@ static v8::Handle<v8::Value> qmlsqldatabase_executeSql(const v8::Arguments& args
QV8Engine *engine = r->engine;
if (!r->inTransaction)
- V8THROW_SQL(DATABASE_ERR,QDeclarativeEngine::tr("executeSql called outside transaction()"));
+ V8THROW_SQL(SQLEXCEPTION_DATABASE_ERR,QDeclarativeEngine::tr("executeSql called outside transaction()"));
QSqlDatabase db = r->database;
QString sql = engine->toString(args[0]);
if (r->readonly && !sql.startsWith(QLatin1String("SELECT"),Qt::CaseInsensitive)) {
- V8THROW_SQL(SYNTAX_ERR, QDeclarativeEngine::tr("Read-only Transaction"));
+ V8THROW_SQL(SQLEXCEPTION_SYNTAX_ERR, QDeclarativeEngine::tr("Read-only Transaction"));
}
QSqlQuery query(db);
@@ -319,7 +297,7 @@ static v8::Handle<v8::Value> qmlsqldatabase_executeSql(const v8::Arguments& args
err = true;
}
if (err)
- V8THROW_SQL(DATABASE_ERR,query.lastError().text());
+ V8THROW_SQL(SQLEXCEPTION_DATABASE_ERR,query.lastError().text());
return result;
}
@@ -341,7 +319,7 @@ static v8::Handle<v8::Value> qmlsqldatabase_changeVersion(const v8::Arguments& a
v8::Handle<v8::Value> callback = args[2];
if (from_version != r->version)
- V8THROW_SQL(VERSION_ERR, QDeclarativeEngine::tr("Version mismatch: expected %1, found %2").arg(from_version).arg(r->version));
+ V8THROW_SQL(SQLEXCEPTION_VERSION_ERR, QDeclarativeEngine::tr("Version mismatch: expected %1, found %2").arg(from_version).arg(r->version));
v8::Local<v8::Object> instance = QDeclarativeSqlDatabaseData::data(engine)->queryConstructor->NewInstance();
QV8SqlDatabaseResource *r2 = new QV8SqlDatabaseResource(engine);
@@ -366,7 +344,7 @@ static v8::Handle<v8::Value> qmlsqldatabase_changeVersion(const v8::Arguments& a
return v8::Handle<v8::Value>();
} else if (!db.commit()) {
db.rollback();
- V8THROW_SQL(UNKNOWN_ERR,QDeclarativeEngine::tr("SQL transaction failed"));
+ V8THROW_SQL(SQLEXCEPTION_UNKNOWN_ERR,QDeclarativeEngine::tr("SQL transaction failed"));
} else {
ok = true;
}
@@ -394,7 +372,7 @@ static v8::Handle<v8::Value> qmlsqldatabase_transaction_shared(const v8::Argumen
QV8Engine *engine = r->engine;
if (args.Length() == 0 || !args[0]->IsFunction())
- V8THROW_SQL(UNKNOWN_ERR,QDeclarativeEngine::tr("transaction: missing callback"));
+ V8THROW_SQL(SQLEXCEPTION_UNKNOWN_ERR,QDeclarativeEngine::tr("transaction: missing callback"));
QSqlDatabase db = r->database;
v8::Handle<v8::Function> callback = v8::Handle<v8::Function>::Cast(args[0]);
@@ -467,7 +445,7 @@ static v8::Handle<v8::Value> qmlsqldatabase_open_sync(const v8::Arguments& args)
database = QSqlDatabase::database(dbid);
version = ini.value(QLatin1String("Version")).toString();
if (version != dbversion && !dbversion.isEmpty() && !version.isEmpty())
- V8THROW_SQL(VERSION_ERR, QDeclarativeEngine::tr("SQL: database version mismatch"));
+ V8THROW_SQL(SQLEXCEPTION_VERSION_ERR, QDeclarativeEngine::tr("SQL: database version mismatch"));
} else {
created = !QFile::exists(basename+QLatin1String(".sqlite"));
database = QSqlDatabase::addDatabase(QLatin1String("QSQLITE"), dbid);
@@ -482,7 +460,7 @@ static v8::Handle<v8::Value> qmlsqldatabase_open_sync(const v8::Arguments& args)
} else {
if (!dbversion.isEmpty() && ini.value(QLatin1String("Version")) != dbversion) {
// Incompatible
- V8THROW_SQL(VERSION_ERR,QDeclarativeEngine::tr("SQL: database version mismatch"));
+ V8THROW_SQL(SQLEXCEPTION_VERSION_ERR,QDeclarativeEngine::tr("SQL: database version mismatch"));
}
version = ini.value(QLatin1String("Version")).toString();
}
@@ -517,11 +495,6 @@ static v8::Handle<v8::Value> qmlsqldatabase_open_sync(const v8::Arguments& args)
QDeclarativeSqlDatabaseData::QDeclarativeSqlDatabaseData(QV8Engine *engine)
{
- QString dataLocation = QStandardPaths::writableLocation(QStandardPaths::DataLocation);
- offlineStoragePath = dataLocation.replace(QLatin1Char('/'), QDir::separator()) +
- QDir::separator() + QLatin1String("QML") +
- QDir::separator() + QLatin1String("OfflineStorage");
-
{
v8::Local<v8::FunctionTemplate> ft = v8::FunctionTemplate::New();
ft->InstanceTemplate()->SetHasExternalResource(true);
@@ -559,12 +532,6 @@ void *qt_add_qmlsqldatabase(QV8Engine *engine)
v8::Local<v8::Function> openDatabase = V8FUNCTION(qmlsqldatabase_open_sync, engine);
engine->global()->Set(v8::String::New("openDatabaseSync"), openDatabase);
- v8::PropertyAttribute attributes = (v8::PropertyAttribute)(v8::ReadOnly | v8::DontEnum | v8::DontDelete);
- v8::Local<v8::Object> sqlExceptionPrototype = v8::Object::New();
- for (int i=0; sqlerror[i]; ++i)
- sqlExceptionPrototype->Set(v8::String::New(sqlerror[i]), v8::Integer::New(i), attributes);
- engine->global()->Set(v8::String::New("SQLException"), sqlExceptionPrototype);
-
return (void *)new QDeclarativeSqlDatabaseData(engine);
}
@@ -574,16 +541,6 @@ void qt_rem_qmlsqldatabase(QV8Engine * /* engine */, void *d)
delete data;
}
-void qt_qmlsqldatabase_setOfflineStoragePath(QV8Engine *engine, const QString &path)
-{
- QDeclarativeSqlDatabaseData::data(engine)->offlineStoragePath = path;
-}
-
-QString qt_qmlsqldatabase_getOfflineStoragePath(const QV8Engine *engine)
-{
- return QDeclarativeSqlDatabaseData::data(const_cast<QV8Engine *>(engine))->offlineStoragePath;
-}
-
/*
HTML5 "spec" says "rs.rows[n]", but WebKit only impelments "rs.rows.item(n)". We do both (and property iterator).
We add a "forwardOnly" property that stops Qt caching results (code promises to only go forward
diff --git a/src/declarative/qml/qdeclarativesqldatabase_p.h b/src/declarative/qml/qdeclarativesqldatabase_p.h
index cf093eefad..a878b38742 100644
--- a/src/declarative/qml/qdeclarativesqldatabase_p.h
+++ b/src/declarative/qml/qdeclarativesqldatabase_p.h
@@ -62,8 +62,6 @@ class QV8Engine;
void *qt_add_qmlsqldatabase(QV8Engine *engine);
void qt_rem_qmlsqldatabase(QV8Engine *engine, void *);
-void qt_qmlsqldatabase_setOfflineStoragePath(QV8Engine *engine, const QString &);
-QString qt_qmlsqldatabase_getOfflineStoragePath(const QV8Engine *);
QT_END_NAMESPACE
diff --git a/src/declarative/qml/v8/qv8engine.cpp b/src/declarative/qml/v8/qv8engine.cpp
index e7fe2c713d..efb500c5d7 100644
--- a/src/declarative/qml/v8/qv8engine.cpp
+++ b/src/declarative/qml/v8/qv8engine.cpp
@@ -58,6 +58,8 @@
#include "qscript_impl_p.h"
#include "qv8domerrors_p.h"
+#include "qv8sqlerrors_p.h"
+
Q_DECLARE_METATYPE(QJSValue)
Q_DECLARE_METATYPE(QList<int>)
@@ -618,6 +620,8 @@ void QV8Engine::initializeGlobal(v8::Handle<v8::Object> global)
qt_add_domexceptions(this);
m_xmlHttpRequestData = qt_add_qmlxmlhttprequest(this);
+
+ qt_add_sqlexceptions(this);
m_sqlDatabaseData = qt_add_qmlsqldatabase(this);
{
diff --git a/src/declarative/qml/v8/qv8sqlerrors.cpp b/src/declarative/qml/v8/qv8sqlerrors.cpp
new file mode 100644
index 0000000000..1aa3e771de
--- /dev/null
+++ b/src/declarative/qml/v8/qv8sqlerrors.cpp
@@ -0,0 +1,64 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the QtDeclarative module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qv8sqlerrors_p.h"
+#include "qv8engine_p.h"
+
+QT_BEGIN_NAMESPACE
+
+void qt_add_sqlexceptions(QV8Engine *engine)
+{
+ // SQL Exception
+ v8::PropertyAttribute attributes = (v8::PropertyAttribute)(v8::ReadOnly | v8::DontEnum | v8::DontDelete);
+
+ v8::Local<v8::Object> sqlexception = v8::Object::New();
+ sqlexception->Set(v8::String::New("UNKNOWN_ERR"), v8::Integer::New(SQLEXCEPTION_UNKNOWN_ERR), attributes);
+ sqlexception->Set(v8::String::New("DATABASE_ERR"), v8::Integer::New(SQLEXCEPTION_DATABASE_ERR), attributes);
+ sqlexception->Set(v8::String::New("VERSION_ERR"), v8::Integer::New(SQLEXCEPTION_VERSION_ERR), attributes);
+ sqlexception->Set(v8::String::New("TOO_LARGE_ERR"), v8::Integer::New(SQLEXCEPTION_TOO_LARGE_ERR), attributes);
+ sqlexception->Set(v8::String::New("QUOTA_ERR"), v8::Integer::New(SQLEXCEPTION_QUOTA_ERR), attributes);
+ sqlexception->Set(v8::String::New("SYNTAX_ERR"), v8::Integer::New(SQLEXCEPTION_SYNTAX_ERR), attributes);
+ sqlexception->Set(v8::String::New("CONSTRAINT_ERR"), v8::Integer::New(SQLEXCEPTION_CONSTRAINT_ERR), attributes);
+ sqlexception->Set(v8::String::New("TIMEOUT_ERR"), v8::Integer::New(SQLEXCEPTION_TIMEOUT_ERR), attributes);
+ engine->global()->Set(v8::String::New("SQLException"), sqlexception);
+}
+
+QT_END_NAMESPACE
diff --git a/src/declarative/qml/v8/qv8sqlerrors_p.h b/src/declarative/qml/v8/qv8sqlerrors_p.h
new file mode 100644
index 0000000000..4ca36a8d46
--- /dev/null
+++ b/src/declarative/qml/v8/qv8sqlerrors_p.h
@@ -0,0 +1,77 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the QtDeclarative module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QV8SQLERRORS_P_H
+#define QV8SQLERRORS_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QtCore/qglobal.h>
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+#define SQLEXCEPTION_UNKNOWN_ERR 1
+#define SQLEXCEPTION_DATABASE_ERR 2
+#define SQLEXCEPTION_VERSION_ERR 3
+#define SQLEXCEPTION_TOO_LARGE_ERR 4
+#define SQLEXCEPTION_QUOTA_ERR 5
+#define SQLEXCEPTION_SYNTAX_ERR 6
+#define SQLEXCEPTION_CONSTRAINT_ERR 7
+#define SQLEXCEPTION_TIMEOUT_ERR 8
+
+class QV8Engine;
+void qt_add_sqlexceptions(QV8Engine *engine);
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif // QV8SQLERRORS_P_H
diff --git a/src/declarative/qml/v8/v8.pri b/src/declarative/qml/v8/v8.pri
index 99ecf90983..72416c4dbb 100644
--- a/src/declarative/qml/v8/v8.pri
+++ b/src/declarative/qml/v8/v8.pri
@@ -23,6 +23,7 @@ HEADERS += \
$$PWD/../../../3rdparty/javascriptcore/DateMath.h \
$$PWD/qv8engine_impl_p.h \
$$PWD/qv8domerrors_p.h \
+ $$PWD/qv8sqlerrors_p.h \
$$PWD/qdeclarativebuiltinfunctions_p.h
SOURCES += \
@@ -40,4 +41,5 @@ SOURCES += \
$$PWD/qv8bindings.cpp \
$$PWD/../../../3rdparty/javascriptcore/DateMath.cpp \
$$PWD/qv8domerrors.cpp \
- $$PWD/qdeclarativebuiltinfunctions.cpp
+ $$PWD/qv8sqlerrors.cpp \
+ $$PWD/qdeclarativebuiltinfunctions.cpp \ No newline at end of file