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
ZsqlRecord.cpp
Go to the documentation of this file.
1 /*
2  * Zuble - A run-time system for QML/Javascript applications
3  * Copyright (C) 2013, 2014 Bob Dinitto
4  *
5  * Filename: ZsqlRecord.cpp
6  * Created on: 11/9/2014
7  * Author: Bob Dinitto
8  *
9  * Zuble is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22  *
23  */
24 
25 #include "ZsqlRecord.h"
26 #include "zglobal.h"
27 
28 namespace Zbl
29 {
30 
31 ZsqlRecord::ZsqlRecord(QObject *parent) :
32  QObject(parent)
33 {
34 }
35 
36 QVariant ZsqlRecord::value(int i) const
37 {
39  ZBL_SLOT_END_RETURN(m_r.value(i), QVariant(),
41 }
42 
43 QVariant ZsqlRecord::value(const QString& name) const
44 {
46  ZBL_SLOT_END_RETURN(m_r.value(name), QVariant(),
48 }
49 
50 void ZsqlRecord::setValue(int i, const QVariant& val)
51 {
53  m_r.setValue(i, val);
55 }
56 
57 void ZsqlRecord::setValue(const QString& name, const QVariant& val)
58 {
60  m_r.setValue(name, val);
62 }
63 
65 {
67  m_r.setNull(i);
69 
70 }
71 
72 void ZsqlRecord::setNull(const QString& name)
73 {
75  m_r.setNull(name);
77 
78 }
79 
80 bool ZsqlRecord::isNull(int i) const
81 {
83  ZBL_SLOT_END_RETURN(m_r.isNull(i), false,
85 
86 }
87 
88 bool ZsqlRecord::isNull(const QString& name) const
89 {
91  ZBL_SLOT_END_RETURN(m_r.isNull(name), false,
93 }
94 
95 int ZsqlRecord::indexOf(const QString &name) const
96 {
98  ZBL_SLOT_END_RETURN(m_r.indexOf(name), -1,
100 }
101 
102 QString ZsqlRecord::fieldName(int i) const
103 {
105  ZBL_SLOT_END_RETURN(m_r.fieldName(i), QString(),
107 
108 }
109 
110 bool ZsqlRecord::isGenerated(int i) const
111 {
113  ZBL_SLOT_END_RETURN(m_r.isGenerated(i), false,
115 }
116 
117 bool ZsqlRecord::isGenerated(const QString& name) const
118 {
120  ZBL_SLOT_END_RETURN(m_r.isGenerated(name), false,
122 }
123 
124 void ZsqlRecord::setGenerated(const QString& name, bool generated)
125 {
127  m_r.setGenerated(name, generated);
129 }
130 
131 void ZsqlRecord::setGenerated(int i, bool generated)
132 {
134  m_r.setGenerated(i, generated);
136 }
137 
139 {
141  ZBL_SLOT_END_RETURN(m_r.isEmpty(), true,
143 }
144 
145 bool ZsqlRecord::contains(const QString& name) const
146 {
148  ZBL_SLOT_END_RETURN(m_r.contains(name), true,
150 }
151 
153 {
155  m_r.clear();
157 }
158 
160 {
162  m_r.clearValues();
164 }
165 
167 {
169  ZBL_SLOT_END_RETURN(m_r.count(), -1,
171 }
172 
173 QObject* ZsqlRecord::keyValues(QObject* keyFieldsRecord)
174 {
175  ZsqlRecord* newRecord = NULL;
176  ZsqlRecord* keyRecord = NULL;
177 
179  keyRecord = qobject_cast<ZsqlRecord*>(keyFieldsRecord);
180 
181  if(!keyRecord)
182  throw ZblException("ERROR: keyFieldsRecord must be a "
183  "ZsqlRecord object");
184 
185  newRecord = new ZsqlRecord();
186  newRecord->m_r = m_r.keyValues(keyRecord->m_r);
188 
189  if(zThreadErr.isError())
190  {
191  if(newRecord)
192  {
193  newRecord->deleteLater();
194  newRecord = NULL;
195  }
196  }
197 
198  return newRecord;
199 }
200 
201 } // Zbl
202 
Q_INVOKABLE bool contains(const QString &name) const
Definition: ZsqlRecord.cpp:145
Q_INVOKABLE void clear()
Definition: ZsqlRecord.cpp:152
Q_INVOKABLE QObject * keyValues(QObject *keyFieldsRecord)
Definition: ZsqlRecord.cpp:173
Q_INVOKABLE void setNull(int i)
Definition: ZsqlRecord.cpp:64
#define Z_FAC_JS
Definition: zglobal.h:123
Q_INVOKABLE void setValue(int i, const QVariant &val)
Definition: ZsqlRecord.cpp:50
Q_INVOKABLE QString fieldName(int i) const
Definition: ZsqlRecord.cpp:102
ZsqlRecord(QObject *parent=0)
Definition: ZsqlRecord.cpp:31
QSqlRecord m_r
Encapsulated QSqlRecord object.
Definition: ZsqlRecord.h:107
Definition: ZAndGate.cpp:6
Q_INVOKABLE void clearValues()
Definition: ZsqlRecord.cpp:159
Javascript wrapper for a QSqlRecord object.
Definition: ZsqlRecord.h:39
#define ZBL_SLOT_BEGIN_TRY
Definition: zglobal.h:128
#define zThreadErr
where does this show up?
Definition: ZblThreadErr.h:39
#define ZBL_SLOT_END_VOID(facility, code, error_message)
Definition: zglobal.h:134
Q_INVOKABLE bool isEmpty() const
Definition: ZsqlRecord.cpp:138
Q_INVOKABLE void setGenerated(const QString &name, bool generated)
Definition: ZsqlRecord.cpp:124
Q_INVOKABLE int indexOf(const QString &name) const
Definition: ZsqlRecord.cpp:95
Zuble&#39;s Qt Exception Object.
Definition: ZblException.h:45
Q_INVOKABLE bool isNull(int i) const
Definition: ZsqlRecord.cpp:80
int getCount() const
Definition: ZsqlRecord.cpp:166
Q_INVOKABLE bool isGenerated(int i) const
Definition: ZsqlRecord.cpp:110
Q_INVOKABLE QVariant value(int i) const
Definition: ZsqlRecord.cpp:36
#define ZBL_SLOT_END_RETURN(return_success, return_failed, facility, code, error_message)
Definition: zglobal.h:141