Qt 4.8
qdeclarativesqldatabase.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtDeclarative module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #include "private/qdeclarativesqldatabase_p.h"
43 
44 #include "qdeclarativeengine.h"
45 #include "private/qdeclarativeengine_p.h"
46 #include "private/qdeclarativerefcount_p.h"
47 #include "private/qdeclarativeengine_p.h"
48 
49 #include <QtCore/qobject.h>
50 #include <QtScript/qscriptvalue.h>
51 #include <QtScript/qscriptvalueiterator.h>
52 #include <QtScript/qscriptcontext.h>
53 #include <QtScript/qscriptengine.h>
54 #include <QtScript/qscriptclasspropertyiterator.h>
55 #include <QtSql/qsqldatabase.h>
56 #include <QtSql/qsqlquery.h>
57 #include <QtSql/qsqlerror.h>
58 #include <QtSql/qsqlrecord.h>
59 #include <QtCore/qstack.h>
60 #include <QtCore/qcryptographichash.h>
61 #include <QtCore/qsettings.h>
62 #include <QtCore/qdir.h>
63 #include <QtCore/qdebug.h>
64 
67 
69 
71 public:
73  {
74  str_length = engine->toStringHandle(QLatin1String("length"));
75  str_forwardOnly = engine->toStringHandle(QLatin1String("forwardOnly")); // not in HTML5 (an optimization)
76  }
77 
78  QueryFlags queryProperty(const QScriptValue &,
79  const QScriptString &name,
80  QueryFlags flags, uint *)
81  {
82  if (flags & HandlesReadAccess) {
83  if (name == str_length) {
84  return HandlesReadAccess;
85  } else if (name == str_forwardOnly) {
86  return flags;
87  }
88  }
89  if (flags & HandlesWriteAccess)
90  if (name == str_forwardOnly)
91  return flags;
92  return 0;
93  }
94 
96  const QScriptString &name, uint)
97  {
98  QSqlQuery query = qscriptvalue_cast<QSqlQuery>(object.data());
99  if (name == str_length) {
100  int s = query.size();
101  if (s<0) {
102  // Inefficient.
103  if (query.last()) {
104  return query.at()+1;
105  } else {
106  return 0;
107  }
108  } else {
109  return s;
110  }
111  } else if (name == str_forwardOnly) {
112  return query.isForwardOnly();
113  }
114  return engine()->undefinedValue();
115  }
116 
117  void setProperty(QScriptValue &object,
118  const QScriptString &name, uint, const QScriptValue & value)
119  {
120  if (name == str_forwardOnly) {
121  QSqlQuery query = qscriptvalue_cast<QSqlQuery>(object.data());
122  query.setForwardOnly(value.toBool());
123  }
124  }
125 
127  {
128  if (name == str_length) {
131  }
133  }
134 
135 private:
138 };
139 
140 // If the spec changes to allow iteration, check git history...
141 // class QDeclarativeSqlQueryScriptClassPropertyIterator : public QScriptClassPropertyIterator
142 
143 
144 
154 };
155 
156 static const char* sqlerror[] = {
157  "UNKNOWN_ERR",
158  "DATABASE_ERR",
159  "VERSION_ERR",
160  "TOO_LARGE_ERR",
161  "QUOTA_ERR",
162  "SYNTAX_ERR",
163  "CONSTRAINT_ERR",
164  "TIMEOUT_ERR",
165  0
166 };
167 
168 #define THROW_SQL(error, desc) \
169 { \
170  QScriptValue errorValue = context->throwError(desc); \
171  errorValue.setProperty(QLatin1String("code"), error); \
172  return errorValue; \
173 }
174 
176 {
177  QDeclarativeScriptEngine *qmlengine = static_cast<QDeclarativeScriptEngine*>(engine);
179  + QDir::separator() + QLatin1String("Databases");
180 }
181 
183 {
185 }
186 
188 {
190  + connectionName;
191 }
192 
193 
195 {
196  QSqlQuery query = qscriptvalue_cast<QSqlQuery>(context->thisObject().data());
197  int i = context->argument(0).toNumber();
198  if (query.at() == i || query.seek(i)) { // Qt 4.6 doesn't optimize seek(at())
199  QSqlRecord r = query.record();
200  QScriptValue row = engine->newObject();
201  for (int j=0; j<r.count(); ++j) {
202  row.setProperty(r.fieldName(j), QScriptValue(engine,r.value(j).toString()));
203  }
204  return row;
205  }
206  return engine->undefinedValue();
207 }
208 
210 {
211  THROW_SQL(DATABASE_ERR,QDeclarativeEngine::tr("executeSql called outside transaction()"));
212 }
213 
215 {
217  QString sql = context->argument(0).toString();
218  QSqlQuery query(db);
219  bool err = false;
220 
221  QScriptValue result;
222 
223  if (query.prepare(sql)) {
224  if (context->argumentCount() > 1) {
225  QScriptValue values = context->argument(1);
226  if (values.isObject()) {
227  if (values.isArray()) {
228  int size = values.property(QLatin1String("length")).toInt32();
229  for (int i = 0; i < size; ++i)
230  query.bindValue(i, values.property(i).toVariant());
231  } else {
232  for (QScriptValueIterator it(values); it.hasNext();) {
233  it.next();
234  query.bindValue(it.name(),it.value().toVariant());
235  }
236  }
237  } else {
238  query.bindValue(0,values.toVariant());
239  }
240  }
241  if (query.exec()) {
242  result = engine->newObject();
243  QDeclarativeScriptEngine *qmlengine = static_cast<QDeclarativeScriptEngine*>(engine);
244  if (!qmlengine->sqlQueryClass)
245  qmlengine->sqlQueryClass = new QDeclarativeSqlQueryScriptClass(engine);
246  QScriptValue rows = engine->newObject(qmlengine->sqlQueryClass);
247  rows.setData(engine->newVariant(QVariant::fromValue(query)));
249  result.setProperty(QLatin1String("rows"),rows);
250  result.setProperty(QLatin1String("rowsAffected"),query.numRowsAffected());
251  result.setProperty(QLatin1String("insertId"),query.lastInsertId().toString());
252  } else {
253  err = true;
254  }
255  } else {
256  err = true;
257  }
258  if (err)
260  return result;
261 }
262 
264 {
265  QString sql = context->argument(0).toString();
266  if (sql.startsWith(QLatin1String("SELECT"),Qt::CaseInsensitive)) {
267  return qmlsqldatabase_executeSql(context,engine);
268  } else {
269  THROW_SQL(SYNTAX_ERR,QDeclarativeEngine::tr("Read-only Transaction"))
270  }
271 }
272 
274 {
275  if (context->argumentCount() < 2)
276  return engine->undefinedValue();
277 
279  QString from_version = context->argument(0).toString();
280  QString to_version = context->argument(1).toString();
281  QScriptValue callback = context->argument(2);
282 
283  QScriptValue instance = engine->newObject();
284  instance.setProperty(QLatin1String("executeSql"), engine->newFunction(qmlsqldatabase_executeSql,1));
285  QScriptValue tx = engine->newVariant(instance,QVariant::fromValue(db));
286 
287  QString foundvers = context->thisObject().property(QLatin1String("version")).toString();
288  if (from_version!=foundvers) {
289  THROW_SQL(VERSION_ERR,QDeclarativeEngine::tr("Version mismatch: expected %1, found %2").arg(from_version).arg(foundvers));
290  return engine->undefinedValue();
291  }
292 
293  bool ok = true;
294  if (callback.isFunction()) {
295  ok = false;
296  db.transaction();
297  callback.call(QScriptValue(), QScriptValueList() << tx);
298  if (engine->hasUncaughtException()) {
299  db.rollback();
300  } else {
301  if (!db.commit()) {
302  db.rollback();
303  THROW_SQL(UNKNOWN_ERR,QDeclarativeEngine::tr("SQL transaction failed"));
304  } else {
305  ok = true;
306  }
307  }
308  }
309 
310  if (ok) {
311  context->thisObject().setProperty(QLatin1String("version"), to_version, QScriptValue::ReadOnly);
312 #ifndef QT_NO_SETTINGS
314  ini.setValue(QLatin1String("Version"), to_version);
315 #endif
316  }
317 
318  return engine->undefinedValue();
319 }
320 
322 {
324  QScriptValue callback = context->argument(0);
325  if (!callback.isFunction())
326  THROW_SQL(UNKNOWN_ERR,QDeclarativeEngine::tr("transaction: missing callback"));
327 
328  QScriptValue instance = engine->newObject();
329  instance.setProperty(QLatin1String("executeSql"),
331  QScriptValue tx = engine->newVariant(instance,QVariant::fromValue(db));
332 
333  db.transaction();
334  callback.call(QScriptValue(), QScriptValueList() << tx);
335  instance.setProperty(QLatin1String("executeSql"),
337  if (engine->hasUncaughtException()) {
338  db.rollback();
339  } else {
340  if (!db.commit())
341  db.rollback();
342  }
343  return engine->undefinedValue();
344 }
345 
347 {
348  return qmlsqldatabase_transaction_shared(context,engine,false);
349 }
351 {
352  return qmlsqldatabase_transaction_shared(context,engine,true);
353 }
354 
355 /*
356  Currently documented in doc/src/declarative/globalobject.qdoc
357 */
359 {
360 #ifndef QT_NO_SETTINGS
362 
363  QSqlDatabase database;
364 
365  QString dbname = context->argument(0).toString();
366  QString dbversion = context->argument(1).toString();
367  QString dbdescription = context->argument(2).toString();
368  int dbestimatedsize = context->argument(3).toNumber();
369  QScriptValue dbcreationCallback = context->argument(4);
370 
372  md5.addData(dbname.toUtf8());
373  QString dbid(QLatin1String(md5.result().toHex()));
374 
375  QString basename = qmlsqldatabase_databaseFile(dbid, engine);
376  bool created = false;
377  QString version = dbversion;
378 
379  {
380  QSettings ini(basename+QLatin1String(".ini"),QSettings::IniFormat);
381 
382  if (QSqlDatabase::connectionNames().contains(dbid)) {
383  database = QSqlDatabase::database(dbid);
384  version = ini.value(QLatin1String("Version")).toString();
385  if (version != dbversion && !dbversion.isEmpty() && !version.isEmpty())
386  THROW_SQL(VERSION_ERR,QDeclarativeEngine::tr("SQL: database version mismatch"));
387  } else {
388  created = !QFile::exists(basename+QLatin1String(".sqlite"));
389  database = QSqlDatabase::addDatabase(QLatin1String("QSQLITE"), dbid);
390  if (created) {
391  ini.setValue(QLatin1String("Name"), dbname);
392  if (dbcreationCallback.isFunction())
393  version = QString();
394  ini.setValue(QLatin1String("Version"), version);
395  ini.setValue(QLatin1String("Description"), dbdescription);
396  ini.setValue(QLatin1String("EstimatedSize"), dbestimatedsize);
397  ini.setValue(QLatin1String("Driver"), QLatin1String("QSQLITE"));
398  } else {
399  if (!dbversion.isEmpty() && ini.value(QLatin1String("Version")) != dbversion) {
400  // Incompatible
401  THROW_SQL(VERSION_ERR,QDeclarativeEngine::tr("SQL: database version mismatch"));
402  }
403  version = ini.value(QLatin1String("Version")).toString();
404  }
405  database.setDatabaseName(basename+QLatin1String(".sqlite"));
406  }
407  if (!database.isOpen())
408  database.open();
409  }
410 
411  QScriptValue instance = engine->newObject();
412  instance.setProperty(QLatin1String("transaction"), engine->newFunction(qmlsqldatabase_transaction,1));
413  instance.setProperty(QLatin1String("readTransaction"), engine->newFunction(qmlsqldatabase_read_transaction,1));
414  instance.setProperty(QLatin1String("version"), version, QScriptValue::ReadOnly);
415  instance.setProperty(QLatin1String("changeVersion"), engine->newFunction(qmlsqldatabase_change_version,3));
416 
417  QScriptValue result = engine->newVariant(instance,QVariant::fromValue(database));
418 
419  if (created && dbcreationCallback.isFunction()) {
420  dbcreationCallback.call(QScriptValue(), QScriptValueList() << result);
421  }
422 
423  return result;
424 #else
425  return engine->undefinedValue();
426 #endif // QT_NO_SETTINGS
427 }
428 
430 {
431  QScriptValue openDatabase = engine->newFunction(qmlsqldatabase_open_sync, 4);
432  engine->globalObject().setProperty(QLatin1String("openDatabaseSync"), openDatabase);
433 
434  QScriptValue sqlExceptionPrototype = engine->newObject();
435  for (int i=0; sqlerror[i]; ++i)
436  sqlExceptionPrototype.setProperty(QLatin1String(sqlerror[i]),
438 
439  engine->globalObject().setProperty(QLatin1String("SQLException"), sqlExceptionPrototype);
440 }
441 
442 /*
443 HTML5 "spec" says "rs.rows[n]", but WebKit only impelments "rs.rows.item(n)". We do both (and property iterator).
444 We add a "forwardOnly" property that stops Qt caching results (code promises to only go forward
445 through the data.
446 */
447 
QScriptValue newFunction(FunctionSignature signature, int length=0)
Creates a QScriptValue that wraps a native (C++) function.
The QDir class provides access to directory structures and their contents.
Definition: qdir.h:58
The QScriptContext class represents a Qt Script function invocation.
bool mkpath(const QString &dirPath) const
Creates the directory path dirPath.
Definition: qdir.cpp:1477
static QScriptValue qmlsqldatabase_transaction(QScriptContext *context, QScriptEngine *engine)
void setValue(const QString &key, const QVariant &value)
Sets the value of setting key to value.
Definition: qsettings.cpp:3328
static void callback(AuServer *, AuEventHandlerRec *, AuEvent *e, AuPointer p)
Definition: qsound_x11.cpp:170
QString text() const
This is a convenience function that returns databaseText() and driverText() concatenated into a singl...
Definition: qsqlerror.cpp:237
bool isOpen() const
Returns true if the database connection is currently open; otherwise returns false.
QScriptValue property(const QString &name, const ResolveFlags &mode=ResolvePrototype) const
Returns the value of this QScriptValue&#39;s property with the given name, using the given mode to resolv...
QList< QScriptValue > QScriptValueList
Definition: qscriptvalue.h:47
QVariant value(const QString &key, const QVariant &defaultValue=QVariant()) const
Returns the value for setting key.
Definition: qsettings.cpp:3460
T qscriptvalue_cast(const QScriptValue &)
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
QString connectionName() const
Returns the connection name, which may be empty.
The QScriptClass class provides an interface for defining custom behavior of (a class of) Qt Script o...
Definition: qscriptclass.h:43
bool commit()
Commits a transaction to the database if the driver supports transactions and a transaction() has bee...
bool prepare(const QString &query)
Prepares the SQL query query for execution.
Definition: qsqlquery.cpp:903
bool transaction()
Begins a transaction on the database if the driver supports transactions.
bool isFunction() const
Returns true if this QScriptValue is a function; otherwise returns false.
int numRowsAffected() const
Returns the number of rows affected by the result&#39;s SQL statement, or -1 if it cannot be determined...
Definition: qsqlquery.cpp:740
#define it(className, varName)
static QScriptValue qmlsqldatabase_change_version(QScriptContext *context, QScriptEngine *engine)
static QStringList connectionNames()
Returns a list containing the names of all connections.
The QSettings class provides persistent platform-independent application settings.
Definition: qsettings.h:73
static QScriptValue qmlsqldatabase_open_sync(QScriptContext *context, QScriptEngine *engine)
static QString qmlsqldatabase_databasesPath(QScriptEngine *engine)
QDeclarativeSqlQueryScriptClass(QScriptEngine *engine)
QByteArray toUtf8() const Q_REQUIRED_RESULT
Returns a UTF-8 representation of the string as a QByteArray.
Definition: qstring.cpp:4074
qint32 toInt32() const
Returns the signed 32-bit integer value of this QScriptValue, using the conversion rules described in...
QScriptValue property(const QScriptValue &object, const QScriptString &name, uint)
Returns the value of the property with the given name of the given object.
QSqlRecord record() const
Returns a QSqlRecord containing the field information for the current query.
Definition: qsqlquery.cpp:858
The QSqlQuery class provides a means of executing and manipulating SQL statements.
Definition: qsqlquery.h:63
QString toString() const
Returns the string value of this QScriptValue, as defined in ECMA-262 section 9.8, "ToString".
QScriptValue globalObject() const
Returns this engine&#39;s Global Object.
QString toString() const
Returns the variant as a QString if the variant has type() String , Bool , ByteArray ...
Definition: qvariant.cpp:2270
The QSqlDatabase class represents a connection to a database.
Definition: qsqldatabase.h:78
bool startsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string starts with s; otherwise returns false.
Definition: qstring.cpp:3734
static QString tr(const char *sourceText, const char *comment=0, int n=-1)
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
static QScriptValue qmlsqldatabase_read_transaction(QScriptContext *context, QScriptEngine *engine)
The QSqlRecord class encapsulates a database record.
Definition: qsqlrecord.h:58
static QScriptValue qmlsqldatabase_transaction_shared(QScriptContext *context, QScriptEngine *engine, bool readOnly)
The QString class provides a Unicode character string.
Definition: qstring.h:83
QByteArray toHex() const
Returns a hex encoded copy of the byte array.
static QChar separator()
Returns the native directory separator: "/" under Unix (including Mac OS X) and "\\" under Windows...
Definition: qdir.cpp:1831
QScriptString toStringHandle(const QString &str)
Returns a handle that represents the given string, str.
static void qmlsqldatabase_initDatabasesPath(QScriptEngine *engine)
The QScriptString class acts as a handle to "interned" strings in a QScriptEngine.
Definition: qscriptstring.h:38
bool exists() const
Returns true if the file specified by fileName() exists; otherwise returns false. ...
Definition: qfile.cpp:626
void setProperty(QScriptValue &object, const QScriptString &name, uint, const QScriptValue &value)
Sets the property with the given name of the given object to the given value.
The QScriptEngine class provides an environment for evaluating Qt Script code.
QScriptEngine * engine() const
Returns the engine that this QScriptClass is associated with.
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
#define THROW_SQL(error, desc)
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
static QSqlDatabase database(const QString &connectionName=QLatin1String(defaultConnection), bool open=true)
Returns the database connection called connectionName.
QVariant toVariant() const
Returns the QVariant value of this QScriptValue, if it can be converted to a QVariant; otherwise retu...
QueryFlags queryProperty(const QScriptValue &, const QScriptString &name, QueryFlags flags, uint *)
Queries this script class for how access to the property with the given name of the given object shou...
bool toBool() const
Returns the boolean value of this QScriptValue, using the conversion rules described in ECMA-262 sect...
unsigned int uint
Definition: qglobal.h:996
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654
QScriptValue newObject()
Creates a QtScript object of class Object.
void qt_add_qmlsqldatabase(QScriptEngine *engine)
QScriptValue::PropertyFlags propertyFlags(const QScriptValue &, const QScriptString &name, uint)
Returns the flags of the property with the given name of the given object.
quint16 values[128]
static QVariant fromValue(const T &value)
Returns a QVariant containing a copy of value.
Definition: qvariant.h:336
bool last()
Retrieves the last record in the result, if available, and positions the query on the retrieved recor...
Definition: qsqlquery.cpp:703
#define Q_DECLARE_METATYPE(TYPE)
This macro makes the type Type known to QMetaType as long as it provides a public default constructor...
Definition: qmetatype.h:265
void setForwardOnly(bool forward)
Sets forward only mode to forward.
Definition: qsqlquery.cpp:835
int argumentCount() const
Returns the number of arguments passed to the function in this invocation.
static QScriptValue qmlsqldatabase_executeSql_outsidetransaction(QScriptContext *context, QScriptEngine *)
qsreal toNumber() const
Returns the number value of this QScriptValue, as defined in ECMA-262 section 9.3, "ToNumber".
bool rollback()
Rolls back a transaction on the database, if the driver supports transactions and a transaction() has...
QScriptValue data() const
Returns the internal data of this QScriptValue object.
int count() const
Returns the number of fields in the record.
Definition: qsqlrecord.cpp:573
void setProperty(const QString &name, const QScriptValue &value, const PropertyFlags &flags=KeepExistingFlags)
Sets the value of this QScriptValue&#39;s property with the given name to the given value.
static QString qmlsqldatabase_databaseFile(const QString &connectionName, QScriptEngine *engine)
static QScriptValue qmlsqldatabase_executeSql(QScriptContext *context, QScriptEngine *engine)
QSqlError lastError() const
Returns error information about the last error (if any) that occurred with this query.
Definition: qsqlquery.cpp:754
The QScriptValueIterator class provides a Java-style iterator for QScriptValue.
virtual QString name() const
Returns the name of the script class.
PropertyFlags
Definition: qmetaobject_p.h:61
static QSqlDatabase addDatabase(const QString &type, const QString &connectionName=QLatin1String(defaultConnection))
Adds a database to the list of database connections using the driver type and the connection name con...
static QScriptValue qmlsqldatabase_item(QScriptContext *context, QScriptEngine *engine)
void addData(const char *data, int length)
Adds the first length chars of data to the cryptographic hash.
QByteArray result() const
Returns the final hash value.
bool isForwardOnly() const
Returns true if you can only scroll forward through a result set; otherwise returns false...
Definition: qsqlquery.cpp:806
void bindValue(const QString &placeholder, const QVariant &val, QSql::ParamType type=QSql::In)
Set the placeholder placeholder to be bound to value val in the prepared statement.
Definition: qsqlquery.cpp:1030
bool seek(int i, bool relative=false)
Retrieves the record at position index, if available, and positions the query on the retrieved record...
Definition: qsqlquery.cpp:502
int size() const
Returns the size of the result (number of rows returned), or -1 if the size cannot be determined or i...
Definition: qsqlquery.cpp:724
QScriptValue undefinedValue()
Returns a QScriptValue of the primitive type Undefined.
void setDatabaseName(const QString &name)
Sets the connection&#39;s database name to name.
bool exec(const QString &query)
Executes the SQL in query.
Definition: qsqlquery.cpp:355
bool open()
Opens the database connection using the current connection values.
bool isArray() const
Returns true if this QScriptValue is an object of the Array class; otherwise returns false...
QScriptValue thisObject() const
Returns the `this&#39; object associated with this QScriptContext.
static QString toNativeSeparators(const QString &pathName)
Returns pathName with the &#39;/&#39; separators converted to separators that are appropriate for the underly...
Definition: qdir.cpp:812
bool hasUncaughtException() const
Returns true if the last script evaluation resulted in an uncaught exception; otherwise returns false...
int at() const
Returns the current internal position of the query.
Definition: qsqlquery.cpp:420
QString fieldName(int i) const
Returns the name of the field at position index.
Definition: qsqlrecord.cpp:232
The QScriptValue class acts as a container for the Qt Script data types.
Definition: qscriptvalue.h:57
QScriptValue call(const QScriptValue &thisObject=QScriptValue(), const QScriptValueList &args=QScriptValueList())
Calls this QScriptValue as a function, using thisObject as the `this&#39; object in the function call...
QScriptValue argument(int index) const
Returns the function argument at the given index.
QVariant lastInsertId() const
Returns the object ID of the most recent inserted row if the database supports it.
Definition: qsqlquery.cpp:1148
QScriptValue newVariant(const QVariant &value)
Creates a QtScript object holding the given variant value.
bool isObject() const
Returns true if this QScriptValue is of the Object type; otherwise returns false. ...
QVariant value(int i) const
Returns the value of the field located at position index in the record.
Definition: qsqlrecord.cpp:203
The QCryptographicHash class provides a way to generate cryptographic hashes.
void setData(const QScriptValue &data)
Sets the internal data of this QScriptValue object.
static const char * sqlerror[]
static QScriptValue qmlsqldatabase_executeSql_readonly(QScriptContext *context, QScriptEngine *engine)