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
ZblDatabase.cpp
Go to the documentation of this file.
1 #include "ZblDatabase.h"
2 #include "ZsqlDatabase.h"
3 #include "zglobal.h"
4 #include "ZblCog.h"
5 
6 
7 namespace Zbl
8 {
9 
11 
12 ZblDatabase::ZblDatabase(QObject *parent):
13  QObject(parent), m_text("I am ZblDatabase!")
14 {
15  // By default, QQuickItem does not draw anything. If you subclass
16  // QQuickItem to create a visual item, you will need to uncomment the
17  // following line and re-implement updatePaintNode()
18 
19  // setFlag(ItemHasContents, true);
20 }
21 
23 {
24 }
25 
26 
28 {
30 
31  zblRegisterType("org.zuble.sprocket.db", 1, 0, "ZblDatabase", ZblDatabase,
33 }
34 
35 
36 
37 QObject* ZblDatabase::newObject(QObject* parent)
38 {
39  // TBD: connect ZblDatabasePlugin to calling thread's ZblScriptThread::beginShutdown
40  // signal and in signal handler call ZsqlDatabase::removeThreadDatabases();
41 
42  return new ZblDatabase(parent);
43 }
44 
45 
47 {
48  return m_text;
49 }
50 
51 void ZblDatabase::setText(const QString& text)
52 {
53  m_text = text;
54 }
55 
56 
57 QObject* ZblDatabase::sqlAddDatabase(const QString& driverType, const QString& connectionName )
58 {
61  connectionName), NULL,
63 }
64 
65 void ZblDatabase::sqlRemoveDatabase(const QString& connectionName )
66 {
68  ZsqlDatabase::removeDatabase(connectionName);
70 }
71 
72 QObject* ZblDatabase::sqlGetDatabase(const QString& connectionName )
73 {
75  ZBL_SLOT_END_RETURN(ZsqlDatabase::database(connectionName), NULL,
77 }
78 
80 {
82  ZBL_SLOT_END_RETURN(QSqlDatabase::connectionNames(), QStringList(),
84 }
85 
86 bool ZblDatabase::sqlContainsConnection(const QString& connectionName )
87 {
89  ZBL_SLOT_END_RETURN(QSqlDatabase::contains(connectionName), false,
91 }
92 
93 bool ZblDatabase::sqlIsDriverAvailable(const QString& driverName)
94 {
96  ZBL_SLOT_END_RETURN(QSqlDatabase::isDriverAvailable(driverName), false,
98 }
99 
100 
101 } // Zbl
102 
103 
104 
static QObject * database(const QString &connectionName)
Obtains a SQL database from the list of database connections. The named connection must have previous...
This class allows QSqlDatabase objects to be accessed directly from QML code. (database sprocket) ...
Definition: ZblDatabase.h:17
static QObject * newObject(QObject *parent)
Sprocket object constructor for creating ZblDatabase objects in javascript background threads...
Definition: ZblDatabase.cpp:37
Q_INVOKABLE QStringList sqlGetConnectionNames()
Obtains the names of SQL database connections.
Definition: ZblDatabase.cpp:79
#define Z_FAC_JS
Definition: zglobal.h:123
QString getText()
Definition: ZblDatabase.cpp:46
static QObject * addDatabase(const QString &driverType, const QString &connectionName)
Adds a SQL database to the list of database connections.
Q_INVOKABLE QObject * sqlGetDatabase(const QString &connectionName)
Obtains a SQL database from the list of database connections. The named connection must have previous...
Definition: ZblDatabase.cpp:72
#define ZBL_REGISTER_LOGGED_OBJECT
Definition: zglobal.h:104
static void removeDatabase(const QString &connectionName)
Removes a SQL database from the list of database connections.
Q_INVOKABLE void sqlRemoveDatabase(const QString &connectionName)
Removes a SQL database from the list of database connections.
Definition: ZblDatabase.cpp:65
Definition: ZAndGate.cpp:6
#define ZBL_SLOT_BEGIN_TRY
Definition: zglobal.h:128
#define ZBL_DEFINE_LOGGED_OBJECT(class_name)
Definition: zglobal.h:99
Q_INVOKABLE bool sqlContainsConnection(const QString &connectionName)
Determines if a named SQL database connection exists.
Definition: ZblDatabase.cpp:86
#define ZBL_SLOT_END_VOID(facility, code, error_message)
Definition: zglobal.h:134
Q_INVOKABLE QObject * sqlAddDatabase(const QString &driverType, const QString &connectionName)
Adds a SQL database to the list of database connections. If a connection of the same name exists it i...
Definition: ZblDatabase.cpp:57
void setText(const QString &text)
Definition: ZblDatabase.cpp:51
Q_INVOKABLE bool sqlIsDriverAvailable(const QString &driverName)
Determines if a named SQL database driver is available.
Definition: ZblDatabase.cpp:93
ZblDatabase(QObject *parent=0)
Definition: ZblDatabase.cpp:12
static void registerType()
Registers ZblDatabase as a QML type.
Definition: ZblDatabase.cpp:27
#define zblRegisterType(uri, versionMajor, versionMinor, qmlName, typeName, createFunc)
Definition: ZblCog.h:36
#define ZBL_SLOT_END_RETURN(return_success, return_failed, facility, code, error_message)
Definition: zglobal.h:141
ZBL_DECLARE_LOGGED_OBJECT QString m_text
Definition: ZblDatabase.h:123