42 #include "private/qdeclarativesqldatabase_p.h" 45 #include "private/qdeclarativeengine_p.h" 46 #include "private/qdeclarativerefcount_p.h" 47 #include "private/qdeclarativeengine_p.h" 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> 80 QueryFlags flags,
uint *)
100 int s = query.
size();
168 #define THROW_SQL(error, desc) \ 170 QScriptValue errorValue = context->throwError(desc); \ 171 errorValue.setProperty(QLatin1String("code"), error); \ 198 if (query.
at() == i || query.
seek(i)) {
201 for (
int j=0; j<r.
count(); ++j) {
229 for (
int i = 0; i < size; ++i)
288 if (from_version!=foundvers) {
312 #ifndef QT_NO_SETTINGS 325 if (!callback.isFunction())
360 #ifndef QT_NO_SETTINGS 376 bool created =
false;
385 if (version != dbversion && !dbversion.
isEmpty() && !version.
isEmpty())
419 if (created && dbcreationCallback.
isFunction()) {
426 #endif // QT_NO_SETTINGS 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.
The QScriptContext class represents a Qt Script function invocation.
bool mkpath(const QString &dirPath) const
Creates the directory path dirPath.
static QScriptValue qmlsqldatabase_transaction(QScriptContext *context, QScriptEngine *engine)
void setValue(const QString &key, const QVariant &value)
Sets the value of setting key to value.
static void callback(AuServer *, AuEventHandlerRec *, AuEvent *e, AuPointer p)
QString text() const
This is a convenience function that returns databaseText() and driverText() concatenated into a singl...
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's property with the given name, using the given mode to resolv...
QList< QScriptValue > QScriptValueList
QVariant value(const QString &key, const QVariant &defaultValue=QVariant()) const
Returns the value for setting key.
T qscriptvalue_cast(const QScriptValue &)
#define QT_END_NAMESPACE
This macro expands to.
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...
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.
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's SQL statement, or -1 if it cannot be determined...
QScriptString str_forwardOnly
#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.
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.
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.
The QSqlQuery class provides a means of executing and manipulating SQL statements.
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's Global Object.
QString offlineStoragePath
QString toString() const
Returns the variant as a QString if the variant has type() String , Bool , ByteArray ...
The QSqlDatabase class represents a connection to a database.
bool startsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string starts with s; otherwise returns false.
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.
static QScriptValue qmlsqldatabase_transaction_shared(QScriptContext *context, QScriptEngine *engine, bool readOnly)
The QString class provides a Unicode character string.
QScriptClass * sqlQueryClass
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...
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.
bool exists() const
Returns true if the file specified by fileName() exists; otherwise returns false. ...
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.
#define THROW_SQL(error, desc)
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
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...
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
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.
static QVariant fromValue(const T &value)
Returns a QVariant containing a copy of value.
bool last()
Retrieves the last record in the result, if available, and positions the query on the retrieved recor...
void setForwardOnly(bool forward)
Sets forward only mode to forward.
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.
void setProperty(const QString &name, const QScriptValue &value, const PropertyFlags &flags=KeepExistingFlags)
Sets the value of this QScriptValue'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.
The QScriptValueIterator class provides a Java-style iterator for QScriptValue.
virtual QString name() const
Returns the name of the script class.
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...
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.
bool seek(int i, bool relative=false)
Retrieves the record at position index, if available, and positions the query on the retrieved record...
int size() const
Returns the size of the result (number of rows returned), or -1 if the size cannot be determined or i...
QScriptValue undefinedValue()
Returns a QScriptValue of the primitive type Undefined.
void setDatabaseName(const QString &name)
Sets the connection's database name to name.
bool exec(const QString &query)
Executes the SQL in query.
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' object associated with this QScriptContext.
static QString toNativeSeparators(const QString &pathName)
Returns pathName with the '/' separators converted to separators that are appropriate for the underly...
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.
QString fieldName(int i) const
Returns the name of the field at position index.
The QScriptValue class acts as a container for the Qt Script data types.
QScriptValue call(const QScriptValue &thisObject=QScriptValue(), const QScriptValueList &args=QScriptValueList())
Calls this QScriptValue as a function, using thisObject as the `this' 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.
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.
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)