45 : QObject(parent), m_db(NULL)
47 qDebug(
"ZsqlDatabase::ZsqlDatabase");
49 QQmlEngine::setObjectOwnership(
this, QQmlEngine::CppOwnership);
67 map.insert(
"tabletypeTables",
Tables);
69 map.insert(
"tabletypeViews",
Views);
70 map.insert(
"tabletypeAllTables",
AllTables);
77 m_tags = QVariant::fromValue(map);
121 m_db->setHostName(hostname);
123 ZsqlDatabase::setHostName, setHostName failed)
137 m_db->setDatabaseName(dbName);
153 m_db->setPort(portNumber);
163 m_db->setConnectOptions(options);
170 return m_db->connectOptions();
184 *error =
m_db->lastError();
192 error->deleteLater();
236 QMetaObject::invokeMethod(
this,
"release",
237 Qt::BlockingQueuedConnection
248 const QObjectList& childList(children());
249 const int childCount = childList.count();
250 for(
int i=0; i < childCount; i++)
277 return m_db->tables(QSql::TableType(tableType));
281 return QStringList();
307 query->deleteLater();
314 void ZsqlDatabase::removeQuery(QObject* query)
323 throw ZblException(
"Specified query object isn't a ZsqlQuery object.")
336 query->deleteLater();
345 const QString& connectionName )
347 QWriteLocker lock(&
m_lock);
355 if(connectionName.isEmpty())
360 qDebug(
"ZsqlDatabase::addDatabase - " 361 "Warning: replacing existing database connection: %s",
362 cStr(connectionName));
364 qDebug(
"ZsqlDatabase::addDatabase - " 365 "Warning: current references on connection: %s will dangle",
366 cStr(connectionName));
373 db->
m_db =
new QSqlDatabase(
374 QSqlDatabase::addDatabase(driverType, connectionName));
394 if(connectionName.isEmpty())
397 QWriteLocker lock(&
m_lock);
407 QSqlDatabase::removeDatabase(connectionName);
421 if(connectionName.isEmpty())
424 QReadLocker lock(&
m_lock);
432 "Database can only be accessed by same thread that created it.");
441 const QThread* currentThread = QThread::currentThread();
445 QWriteLocker lock(&
m_lock);
453 if(currentThread == db->thread())
459 QSqlDatabase::removeDatabase(i.key());
509 r->
m_r =
m_db->record(tablename);
static QVariant m_tags
A QVariantMap used to pass ZsqlDatabase enumeration values to Javascript programs.
Q_INVOKABLE bool commit()
Commits a database transaction if supported by the database driver and a transaction() has been start...
QString getDbName() const
void validateDb() const
Checks that the embedded QSqlDatabase object exists and throws a ZblException if not.
static QObject * database(const QString &connectionName)
Obtains a SQL database from the list of database connections. The named connection must have previous...
void setDbName(const QString &hostname)
Q_INVOKABLE void close()
Closes the database connection, freeing associated resources. ZsqlQuery objects created by this datab...
static QObject * addDatabase(const QString &driverType, const QString &connectionName)
Adds a SQL database to the list of database connections.
Q_INVOKABLE bool rollback()
Rolls back a database transaction if supported by the database driver and a transaction() has been st...
static void removeDatabase(const QString &connectionName)
Removes a SQL database from the list of database connections.
ZsqlDatabase(QObject *parent=0)
QSqlRecord m_r
Encapsulated QSqlRecord object.
A javascript wrapper class for QSqlDatabase objects. This object represents a database connection...
QString getConnectOptions()
void setConnectOptions(const QString &options)
A javascript wrapper class for QSqlQuery objects. This object represents a query on a database connec...
Javascript wrapper for a QSqlRecord object.
#define ZBL_SLOT_BEGIN_TRY
Q_INVOKABLE void release()
Releases references from this object to wrapped Qt C++ objects. The C++ objects may be deleted by thi...
Q_INVOKABLE QObject * record(const QString &tablename)
Creates a new ZsqlRecord object for the specified table.
static void removeThreadDatabases()
Removes all SQL databases that were created by the current thread.
#define zThreadErr
where does this show up?
Q_INVOKABLE bool open(const QString &user, const QString &password)
Opens a database connection using the given user name and password.
QString getHostname() const
void validateThread()
Checks to see if this object was created in the current thread and throws a ZblException if not...
QMap< QString, ZsqlDatabase * > ZsqlDbMap
#define ZBL_SLOT_END_VOID(facility, code, error_message)
static ZsqlQuery * newQuery(ZsqlDatabase &database)
Constructs an empty ZsqlQuery object for the specified database connection.
int getPortNumber() const
static ZsqlDbMap m_databaseObjects
A map of SQL database connection wrapper objects.
void createTags()
Create the m_tag object that presents a Javascript interface to ZsqlDatabase enumeration values...
bool inObjectThread(const QObject &object)
static QReadWriteLock m_lock
A lock for multi-threaded data access to m_databaseObjects.
Zuble's Qt Exception Object.
void setHostname(const QString &hostname)
QSqlDatabase * m_db
An encapsulated SQL database object.
Q_INVOKABLE QObject * newQuery()
Creates a new ZsqlQuery object for this database connection.
int portNumber
Number of the port to which the database connection is made.
Q_INVOKABLE bool transaction()
Begins a database transaction if supported by the database driver.
Q_INVOKABLE QObject * record()
Obtains a ZsqlRecord object representing the query result.
Q_INVOKABLE QStringList getTableNames(int tableType) const
Obtain names of tables in the database.
Q_INVOKABLE void release()
Releases references from this object to wrapped Qt C++ objects.
#define ZBL_SLOT_END_RETURN(return_success, return_failed, facility, code, error_message)
A Javascript wrapper for QSqlError objects. (database sprocket)