WARNING: USE THIS SOFTWARE AT YOUR OWN RISK! THIS IS EXPERIMENTAL SOFTWARE NOT INTENDED FOR PRODUCTION USE! Zuble is currently an early stage prototype. As such Zuble is minimally tested and inherently unstable. It is provided for experimental, development, and demonstration purposes only. | Zuble QML Types | Zuble C++ Classes | Zuble Overview |
Zuble
0.1
Zuble Framework C++/QML extension API
|
A javascript wrapper class for QSqlDatabase objects. This object represents a database connection. (database sprocket) More...
#include <ZsqlDatabase.h>
Public Types | |
enum | TableType { Tables = QSql::Tables, SystemTables = QSql::SystemTables, Views = QSql::Views, AllTables = QSql::AllTables } |
enum | NumericalPrecisionPolicy { LowPrecisionInt32 = QSql::LowPrecisionInt32, LowPrecisionInt64 = QSql::LowPrecisionInt64, LowPrecisionDouble = QSql::LowPrecisionDouble, HighPrecision = QSql::HighPrecision } |
Public Member Functions | |
ZsqlDatabase (QObject *parent=0) | |
virtual | ~ZsqlDatabase () |
bool | isValid () const |
bool | isOpen () const |
bool | isOpenError () const |
QString | getHostname () const |
void | setHostname (const QString &hostname) |
QString | getDbName () const |
void | setDbName (const QString &hostname) |
int | getPortNumber () const |
void | setPortNumber (int) |
void | setConnectOptions (const QString &options) |
QString | getConnectOptions () |
QObject * | getLastError () |
QVariant | getTags () |
Q_INVOKABLE bool | open (const QString &user, const QString &password) |
Opens a database connection using the given user name and password. More... | |
Q_INVOKABLE void | close () |
Closes the database connection, freeing associated resources. ZsqlQuery objects created by this database connection are invalidated upon return from this method. More... | |
Q_INVOKABLE QStringList | getTableNames (int tableType) const |
Obtain names of tables in the database. More... | |
Q_INVOKABLE bool | transaction () |
Begins a database transaction if supported by the database driver. More... | |
Q_INVOKABLE bool | commit () |
Commits a database transaction if supported by the database driver and a transaction() has been started. More... | |
Q_INVOKABLE bool | rollback () |
Rolls back a database transaction if supported by the database driver and a transaction() has been started. More... | |
Q_INVOKABLE QObject * | newQuery () |
Creates a new ZsqlQuery object for this database connection. More... | |
Q_INVOKABLE QObject * | record (const QString &tablename) |
Creates a new ZsqlRecord object for the specified table. More... | |
Q_INVOKABLE void | release () |
Releases references from this object to wrapped Qt C++ objects. The C++ objects may be deleted by this function. More... | |
Static Public Member Functions | |
static QObject * | addDatabase (const QString &driverType, const QString &connectionName) |
Adds a SQL database to the list of database connections. More... | |
static void | removeDatabase (const QString &connectionName) |
Removes a SQL database from the list of database connections. More... | |
static void | removeThreadDatabases () |
Removes all SQL databases that were created by the current thread. More... | |
static QObject * | database (const QString &connectionName) |
Obtains a SQL database from the list of database connections. The named connection must have previously been created by a call to addDatabase(). More... | |
Protected Member Functions | |
void | createTags () |
Create the m_tag object that presents a Javascript interface to ZsqlDatabase enumeration values. More... | |
void | validateDb () const |
Checks that the embedded QSqlDatabase object exists and throws a ZblException if not. More... | |
void | validateThread () |
Checks to see if this object was created in the current thread and throws a ZblException if not. More... | |
Protected Attributes | |
QSqlDatabase * | m_db |
An encapsulated SQL database object. More... | |
Static Protected Attributes | |
static ZsqlDbMap | m_databaseObjects |
A map of SQL database connection wrapper objects. More... | |
static QReadWriteLock | m_lock |
A lock for multi-threaded data access to m_databaseObjects. More... | |
static QVariant | m_tags |
A QVariantMap used to pass ZsqlDatabase enumeration values to Javascript programs. More... | |
Properties | |
QString | hostName |
Name of the host to which the database connection is made. More... | |
QString | databaseName |
Name of the database to which the database connection is made. More... | |
int | portNumber |
Number of the port to which the database connection is made. More... | |
QString | connectOptions |
Connect options for the database driver. More... | |
bool | isValid |
Determines if this database connection has a valid database driver. More... | |
bool | isOpen |
Determines if this database connection is currently open. More... | |
bool | isOpenError |
Determines if this database connection is currently open. More... | |
QObject | lastError |
Name of the host to which the database connection is made. More... | |
QVariant | tags |
A Javascript object containing ZsqlDatabase enumeration values. More... | |
Private Types | |
typedef QPointer< ZsqlQuery > | ZsqlQueryPtr |
typedef QMap< QString, ZsqlDatabase * > | ZsqlDbMap |
typedef QList< ZsqlQuery * > | ZsqlQueryList |
Friends | |
class | Zbl::ZsqlQuery |
A javascript wrapper class for QSqlDatabase objects. This object represents a database connection. (database sprocket)
ZsqlDatabase objects are explicitly shared. Their ownership is retained by the zuble c++ plugin. They're deleted when ZsqlDatabase::removeDatabase() is called for that database object or when the ZScriptThread object that created them exits.
Call ZsqlDatabase::release() to delete the encapsulated QSqlDatabase object. Note this action will also call ZsqlQuery::release() on all ZsqlQuery objects created by this object.
ZsqlDatabase object methods are reentrant unless explicitly noted to be "thread-safe". Reentrant methods should only be called by the thread that created the ZsqlDatabase object.
Definition at line 71 of file ZsqlDatabase.h.
|
private |
Definition at line 80 of file ZsqlDatabase.h.
|
private |
Definition at line 81 of file ZsqlDatabase.h.
|
private |
Definition at line 76 of file ZsqlDatabase.h.
Enumerator | |
---|---|
LowPrecisionInt32 | |
LowPrecisionInt64 | |
LowPrecisionDouble | |
HighPrecision |
Definition at line 104 of file ZsqlDatabase.h.
Enumerator | |
---|---|
Tables | |
SystemTables | |
Views | |
AllTables |
Definition at line 92 of file ZsqlDatabase.h.
|
explicit |
Definition at line 44 of file ZsqlDatabase.cpp.
Referenced by addDatabase().
|
virtual |
Definition at line 55 of file ZsqlDatabase.cpp.
|
static |
Adds a SQL database to the list of database connections.
If a connection of the same name exists it is replaced with a new connection. All references to the old connection and it's queries is invalidated.
Javascript programs should call ZblApp::addSqlDatabase().
driverType | a database driver type to use for the connection |
connectionName | a name for the connection |
Definition at line 344 of file ZsqlDatabase.cpp.
Referenced by Zbl::ZblDatabase::sqlAddDatabase().
void Zbl::ZsqlDatabase::close | ( | ) |
Closes the database connection, freeing associated resources. ZsqlQuery objects created by this database connection are invalidated upon return from this method.
Definition at line 215 of file ZsqlDatabase.cpp.
bool Zbl::ZsqlDatabase::commit | ( | ) |
Commits a database transaction if supported by the database driver and a transaction() has been started.
Some databases may fail if an active query is using the database for a SELECT. Make the query inactive first in that case.
Definition at line 485 of file ZsqlDatabase.cpp.
|
protected |
Create the m_tag object that presents a Javascript interface to ZsqlDatabase enumeration values.
Definition at line 60 of file ZsqlDatabase.cpp.
Referenced by ZsqlDatabase().
|
static |
Obtains a SQL database from the list of database connections. The named connection must have previously been created by a call to addDatabase().
Javascript programs should call ZblApp::getSqlDatabase().
driverType | a database driver type to use for the connection |
connectionName | a name for the connection |
engine | the Javascript engine that will own the new ZsqlDatabase object |
Definition at line 415 of file ZsqlDatabase.cpp.
Referenced by Zbl::ZblDatabase::sqlGetDatabase().
QString Zbl::ZsqlDatabase::getConnectOptions | ( | ) |
Definition at line 168 of file ZsqlDatabase.cpp.
QString Zbl::ZsqlDatabase::getDbName | ( | ) | const |
Definition at line 126 of file ZsqlDatabase.cpp.
QString Zbl::ZsqlDatabase::getHostname | ( | ) | const |
Definition at line 110 of file ZsqlDatabase.cpp.
QObject * Zbl::ZsqlDatabase::getLastError | ( | ) |
Definition at line 177 of file ZsqlDatabase.cpp.
Referenced by Zbl::ZsqlQuery::getLastError().
int Zbl::ZsqlDatabase::getPortNumber | ( | ) | const |
Definition at line 142 of file ZsqlDatabase.cpp.
QStringList Zbl::ZsqlDatabase::getTableNames | ( | int | tableType | ) | const |
Obtain names of tables in the database.
tableType | Enumeration specifies type of tables to return. May be one of:
|
Definition at line 265 of file ZsqlDatabase.cpp.
QVariant Zbl::ZsqlDatabase::getTags | ( | ) |
Definition at line 284 of file ZsqlDatabase.cpp.
bool Zbl::ZsqlDatabase::isOpen | ( | ) | const |
Referenced by createTags().
bool Zbl::ZsqlDatabase::isOpenError | ( | ) | const |
Referenced by createTags().
bool Zbl::ZsqlDatabase::isValid | ( | ) | const |
Referenced by createTags().
QObject * Zbl::ZsqlDatabase::newQuery | ( | ) |
Creates a new ZsqlQuery object for this database connection.
Definition at line 289 of file ZsqlDatabase.cpp.
bool Zbl::ZsqlDatabase::open | ( | const QString & | user, |
const QString & | password | ||
) |
Opens a database connection using the given user name and password.
user | the database user name |
password | the password for the specified database user |
Definition at line 207 of file ZsqlDatabase.cpp.
QObject * Zbl::ZsqlDatabase::record | ( | const QString & | tablename | ) |
Creates a new ZsqlRecord object for the specified table.
Definition at line 501 of file ZsqlDatabase.cpp.
void Zbl::ZsqlDatabase::release | ( | ) |
Releases references from this object to wrapped Qt C++ objects. The C++ objects may be deleted by this function.
WARNING: The ZsqlDatabase object can't be used again once this function is called.
Definition at line 223 of file ZsqlDatabase.cpp.
Referenced by removeDatabase(), removeThreadDatabases(), and ~ZsqlDatabase().
|
static |
Removes a SQL database from the list of database connections.
Warning: All ZsqlQuery and ZsqlRecord objects created by this database will be unusable upon return from this method.
Note: this method is thread-safe
Javascript programs should call ZblApp::removeSqlDatabase().
connectionName | name of the connection to remove |
Definition at line 389 of file ZsqlDatabase.cpp.
Referenced by addDatabase(), and Zbl::ZblDatabase::sqlRemoveDatabase().
|
static |
Removes all SQL databases that were created by the current thread.
connectionName | name of the connection to remove |
Definition at line 439 of file ZsqlDatabase.cpp.
bool Zbl::ZsqlDatabase::rollback | ( | ) |
Rolls back a database transaction if supported by the database driver and a transaction() has been started.
Some databases may fail if an active query is using the database for a SELECT. Make the query inactive first in that case.
Definition at line 493 of file ZsqlDatabase.cpp.
void Zbl::ZsqlDatabase::setConnectOptions | ( | const QString & | options | ) |
Definition at line 159 of file ZsqlDatabase.cpp.
void Zbl::ZsqlDatabase::setDbName | ( | const QString & | hostname | ) |
Definition at line 133 of file ZsqlDatabase.cpp.
void Zbl::ZsqlDatabase::setHostname | ( | const QString & | hostname | ) |
Definition at line 117 of file ZsqlDatabase.cpp.
void Zbl::ZsqlDatabase::setPortNumber | ( | int | portNumber | ) |
Definition at line 149 of file ZsqlDatabase.cpp.
bool Zbl::ZsqlDatabase::transaction | ( | ) |
Begins a database transaction if supported by the database driver.
Definition at line 477 of file ZsqlDatabase.cpp.
|
inlineprotected |
Checks that the embedded QSqlDatabase object exists and throws a ZblException if not.
Definition at line 423 of file ZsqlDatabase.h.
Referenced by close(), commit(), createTags(), getConnectOptions(), getDbName(), getHostname(), getLastError(), getPortNumber(), getTableNames(), newQuery(), open(), record(), rollback(), setConnectOptions(), setDbName(), setHostname(), setPortNumber(), and transaction().
|
inlineprotected |
Checks to see if this object was created in the current thread and throws a ZblException if not.
Definition at line 416 of file ZsqlDatabase.h.
Referenced by newQuery().
|
friend |
Definition at line 73 of file ZsqlDatabase.h.
|
staticprotected |
A map of SQL database connection wrapper objects.
A single ZsqlDatabase object is shared among all Javascript references to that named database. Closing or releasing the database invalidates all Javascript references to that ZsqlDatabase object and to any ZsqlQuery objects created by it.
Definition at line 398 of file ZsqlDatabase.h.
Referenced by addDatabase(), database(), removeDatabase(), and removeThreadDatabases().
|
protected |
An encapsulated SQL database object.
Definition at line 387 of file ZsqlDatabase.h.
Referenced by addDatabase(), close(), commit(), createTags(), getConnectOptions(), getDbName(), getHostname(), getLastError(), getPortNumber(), getTableNames(), Zbl::ZsqlQuery::newQuery(), open(), record(), release(), rollback(), setConnectOptions(), setDbName(), setHostname(), setPortNumber(), and transaction().
|
staticprotected |
A lock for multi-threaded data access to m_databaseObjects.
Definition at line 403 of file ZsqlDatabase.h.
Referenced by addDatabase(), database(), removeDatabase(), and removeThreadDatabases().
|
staticprotected |
A QVariantMap used to pass ZsqlDatabase enumeration values to Javascript programs.
This object is automatically converted to a Javascript object by Qt.
Definition at line 412 of file ZsqlDatabase.h.
Referenced by createTags(), and getTags().
|
readwrite |
Connect options for the database driver.
Definition at line 145 of file ZsqlDatabase.h.
|
readwrite |
Name of the database to which the database connection is made.
Definition at line 130 of file ZsqlDatabase.h.
|
readwrite |
Name of the host to which the database connection is made.
Definition at line 122 of file ZsqlDatabase.h.
|
read |
Determines if this database connection is currently open.
Definition at line 161 of file ZsqlDatabase.h.
Referenced by Zbl::ZsqlQuery::newQuery().
|
read |
Determines if this database connection is currently open.
Definition at line 169 of file ZsqlDatabase.h.
|
read |
Determines if this database connection has a valid database driver.
Definition at line 153 of file ZsqlDatabase.h.
Referenced by Zbl::ZsqlQuery::newQuery().
|
read |
Name of the host to which the database connection is made.
Definition at line 177 of file ZsqlDatabase.h.
|
readwrite |
Number of the port to which the database connection is made.
Definition at line 138 of file ZsqlDatabase.h.
|
read |
A Javascript object containing ZsqlDatabase enumeration values.
Definition at line 183 of file ZsqlDatabase.h.
Zuble documentation copyright © 2019 Bob Dinitto. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Zuble is a derivative work of Qt version 5. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.