6#include <QtQml/private/qqmlengine_p.h>
7#include <QtQml/private/qv4global_p.h>
8#include <QtQml/private/qv4scopedvalue_p.h>
9#include <QtQml/private/qv4object_p.h>
10#include <QtQml/private/qv4sqlerrors_p.h>
11#include <QtQml/private/qv4jscall_p.h>
12#include <QtQml/private/qv4objectiterator_p.h>
14#include <QtCore/qfileinfo.h>
15#include <QtCore/qdir.h>
17#include <QtSql/qsqldatabase.h>
18#include <QtSql/qsqlquery.h>
19#include <QtSql/qsqlrecord.h>
20#include <QtSql/qsqlerror.h>
22#if QT_CONFIG(settings)
23#include <QtCore/qsettings.h>
28#define V4THROW_SQL(error, desc) { \
29 QV4::ScopedString v(scope, scope.engine->newString(desc)); \
30 QV4::ScopedObject ex(scope, scope.engine->newErrorObject(v)); \
31 ex->put(QV4::ScopedString(scope, scope.engine->newIdentifier(QStringLiteral("code"))).getPointer(), QV4::ScopedValue(scope, Value::fromInt32(error))); \
32 scope.engine->throwError(ex); \
36#define V4THROW_SQL2(error, desc) { \
37 QV4::ScopedString v(scope, scope.engine->newString(desc)); \
38 QV4::ScopedObject ex(scope, scope.engine->newErrorObject(v)); \
39 ex->put(QV4::ScopedString(scope, scope.engine->newIdentifier(QStringLiteral("code"))).getPointer(), QV4::ScopedValue(scope, Value::fromInt32(error))); \
40 args->setReturnValue(scope.engine->throwError(ex)); \
44#define V4THROW_REFERENCE(string) { \
45 QV4::ScopedString v(scope, scope.engine->newString(QLatin1String(string))); \
46 scope.engine->throwReferenceError(v); \
140 int s =
r->d()->sqlQuery->size();
143 if (
r->d()->sqlQuery->last()) {
144 s =
r->d()->sqlQuery->at() + 1;
170 r->d()->sqlQuery->setForwardOnly(argv[0].toBoolean());
182 if (
r->d()->sqlQuery->at() == (
int)
index ||
r->d()->sqlQuery->seek(
index)) {
186 for (
int ii = 0; ii <
record.count(); ++ii) {
197 *hasProperty =
false;
204 if (!
id.isArrayIndex())
242 if (!
r->d()->inTransaction)
258 if (
query.prepare(sql)) {
278 if (
key->isString()) {
279 query.bindValue(
key->stringValue()->toQString(),
v);
292 rows->setPrototypeUnchecked(
p.getPointer());
294 *rows->d()->database =
db;
295 *rows->d()->sqlQuery = std::move(
query);
296 QSqlQuery *queryPtr = rows->d()->sqlQuery;
327 , inTransactionFlag(transactionFlag)
329 if (inTransactionFlag)
330 *inTransactionFlag =
true;
335 if (inTransactionFlag)
336 *inTransactionFlag =
false;
343 if (inTransactionFlag)
344 *inTransactionFlag =
false;
345 inTransactionFlag =
nullptr;
365 if (from_version != *
r->d()->version)
372 query->setPrototypeUnchecked(
p.getPointer());
375 *
query->d()->version = *
r->d()->version;
385 callback->call(jsCall);
386 rollbackOnException.
clear();
398 w->setPrototypeUnchecked(
p.getPointer());
400 *
w->d()->database =
db;
401 *
w->d()->version = to_version;
402#if QT_CONFIG(settings)
428 w->setPrototypeUnchecked(
p.getPointer());
430 *
w->d()->database =
db;
431 *
w->d()->version = *
r->d()->version;
432 w->d()->readonly = readOnly;
440 callback->
call(jsCall);
441 rollbackOnException.
clear();
469 databaseProto = proto;
687#if QT_CONFIG(settings)
693 QString dbname = (
v = (*args)[0])->toQStringNoThrow();
694 QString dbversion = (
v = (*args)[1])->toQStringNoThrow();
695 QString dbdescription = (
v = (*args)[2])->toQStringNoThrow();
696 int dbestimatedsize = (
v = (*args)[3])->
toInt32();
697 FunctionObject *dbcreationCallback = (
v = (*args)[4])->as<FunctionObject>();
698 QString basename =
args->v4engine()->qmlEngine()->offlineStorageDatabaseFilePath(dbname);
701 const QString message = QQmlEngine::tr(
"LocalStorage: can't create path %1").
706 bool created =
false;
716 if (version != dbversion && !dbversion.
isEmpty() && !version.
isEmpty())
722 if (dbcreationCallback)
744 db->setPrototypeUnchecked(
p.getPointer());
745 *
db->d()->database = database;
746 *
db->d()->version = version;
748 if (created && dbcreationCallback) {
752 dbcreationCallback->
call(jsCall);
755 args->setReturnValue(
db.asReturnedValue());
763#include "moc_qqmllocalstorage_p.cpp"
QString absolutePath() const
Returns the absolute path (a path that starts with "/" or with a drive specification),...
static QString toNativeSeparators(const QString &pathName)
\inmodule QtCore \reentrant
QString fileName() const
Returns the name of the file, excluding the path.
QDir dir() const
Returns the path of the object's parent directory as a QDir object.
bool exists() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
static QQmlEnginePrivate * get(QQmlEngine *e)
QString offlineStorageDatabaseDirectory() const
QString offlineStoragePath
the directory for storing offline user data
Q_INVOKABLE void openDatabaseSync(QQmlV4Function *args)
QV4::PersistentValue rowsProto
QV4::PersistentValue databaseProto
QV4::PersistentValue queryProto
~QQmlSqlDatabaseData() override
QQmlSqlDatabaseData(QV4::ExecutionEngine *engine)
void setValue(QAnyStringView key, const QVariant &value)
Sets the value of setting key to value.
QVariant value(QAnyStringView key, const QVariant &defaultValue) const
Returns the value for setting key.
The QSqlDatabase class handles a connection to a database.
bool open()
Executes a SQL statement on the database and returns a QSqlQuery object.
void setDatabaseName(const QString &name)
Sets the connection's database name to name.
static QStringList connectionNames()
\threadsafe
bool isOpen() const
Returns true if the database connection is currently open; otherwise returns false.
static QSqlDatabase addDatabase(const QString &type, const QString &connectionName=QLatin1StringView(defaultConnection))
\threadsafe
static QSqlDatabase database(const QString &connectionName=QLatin1StringView(defaultConnection), bool open=true)
\threadsafe
The QSqlQuery class provides a means of executing and manipulating SQL statements.
int numRowsAffected() const
Returns the number of rows affected by the result's SQL statement, or -1 if it cannot be determined.
QVariant lastInsertId() const
Returns the object ID of the most recent inserted row if the database supports it.
The QSqlRecord class encapsulates a database record.
\macro QT_RESTRICTED_CAST_FROM_ASCII
bool startsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string starts with s; otherwise returns false.
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
ObjectType::Data * allocate(Args &&... args)
static V4_NEEDS_DESTROY Heap::QQmlSqlDatabaseWrapper * create(QV4::ExecutionEngine *engine)
~QQmlSqlDatabaseWrapper()
static ReturnedValue virtualGet(const Managed *m, PropertyKey id, const Value *receiver, bool *hasProperty)
QString toString() const
Returns the variant as a QString if the variant has a userType() including, but not limited to:
QSet< QString >::iterator it
Combined button and popup list for selecting options.
\qmltype Particle \inqmlmodule QtQuick.Particles
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
static bool contains(const QJsonArray &haystack, unsigned needle)
GLenum GLsizei GLsizei GLint * values
[15]
GLboolean GLboolean GLboolean b
GLsizei const GLfloat * v
[13]
GLfloat GLfloat GLfloat w
[0]
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLuint GLsizei const GLchar * message
GLenum GLenum GLsizei void * row
static ReturnedValue qmlsqldatabase_version(const FunctionObject *b, const Value *thisObject, const QV4::Value *, int)
static ReturnedValue qmlsqldatabase_transaction(const FunctionObject *f, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue qmlsqldatabase_rows_length(const FunctionObject *b, const Value *thisObject, const QV4::Value *, int)
static ReturnedValue qmlsqldatabase_read_transaction(const FunctionObject *f, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue qmlsqldatabase_executeSql(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc)
#define V4THROW_SQL2(error, desc)
static ReturnedValue qmlsqldatabase_rows_setForwardOnly(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc)
#define V4THROW_SQL(error, desc)
static QVariant toSqlVariant(const QV4::ScopedValue &value)
static ReturnedValue qmlsqldatabase_rows_item(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue qmlsqldatabase_rows_forwardOnly(const FunctionObject *b, const Value *thisObject, const QV4::Value *, int)
static ReturnedValue qmlsqldatabase_rows_index(const QQmlSqlDatabaseWrapper *r, ExecutionEngine *v4, quint32 index, bool *hasProperty=nullptr)
static ReturnedValue qmlsqldatabase_transaction_shared(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc, bool readOnly)
#define V4THROW_REFERENCE(string)
static ReturnedValue qmlsqldatabase_changeVersion(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc)
#define V4THROW_REFERENCE(string)
QLatin1StringView QLatin1String
#define QStringLiteral(str)
#define V4_DEFINE_EXTENSION(dataclass, datafunction)
#define RETURN_UNDEFINED()
#define SQLEXCEPTION_UNKNOWN_ERR
#define SQLEXCEPTION_DATABASE_ERR
#define SQLEXCEPTION_VERSION_ERR
#define SQLEXCEPTION_SYNTAX_ERR
static int toInt32(Value v)
#define DEFINE_OBJECT_VTABLE(classname)
#define V4_OBJECT2(DataClass, superClass)
static constexpr ReturnedValue undefined()
static constexpr ReturnedValue null()
MemoryManager * memoryManager
Heap::String * newString(const QString &s=QString())
QV4::ReturnedValue fromVariant(const QVariant &)
Heap::Object * newObject()
Heap::String * newIdentifier(const QString &text)
static QVariant toVariant(const QV4::Value &value, QMetaType typeHint, bool createJSValueForObjectsAndSymbols=true)
QQmlEngine * qmlEngine() const
ReturnedValue throwTypeError()
ReturnedValue call(const JSCallData &data) const
ExecutionEngine * engine() const
bool hasProperty(PropertyKey id) const
QML_NEARLY_ALWAYS_INLINE ReturnedValue asReturnedValue() const
constexpr ReturnedValue asReturnedValue() const
static constexpr VTable::Get virtualGet
static constexpr Value fromInt32(int i)
unsigned int toUInt32() const
static constexpr Value undefinedValue()
QString toQString() const
TransactionRollback(QSqlDatabase *database, bool *transactionFlag)