43 : QObject(parent),m_q(query)
61 map.insert(
"paramtypeIn",
In);
62 map.insert(
"paramtypeOut",
Out);
63 map.insert(
"paramtypeInOut",
InOut);
64 map.insert(
"paramtypeBinary",
Binary);
69 m_tags = QVariant::fromValue(map);
74 if(paramType != QSql::In
75 && paramType != QSql::Out
76 && paramType != QSql::InOut
77 && paramType != QSql::Binary
81 "ERROR: paramType is an invalid QSql::ParamType value: %1")
91 throw ZblException(
"ZsqlQuery::validateGetTableModel - ERROR: inactive query");
94 throw ZblException(
"ZsqlQuery::validateGetTableModel - ERROR: non-SELECT query");
97 throw ZblException(
"ZsqlQuery::validateGetTableModel - ERROR: no data in query");
103 throw ZblException(
"ZsqlQuery::tableModel - Error: null model object");
111 const int colCount = metaRow.count();
115 for(
int i=0; i<colCount; i++)
117 model->
addRole(i, metaRow.at(i));
129 for(
int col=0; col < colCount; col++)
131 QList<QVariant> rowData;
133 rowData.append(
m_q->value(col));
135 row.insert(col, rowData);
138 rowList.push_back(row);
140 }
while(
m_q->next());
142 QVariant vRows = QVariant::fromValue(rowList);
162 q =
new QSqlQuery(*database.
m_db);
210 m_q->bindValue(placeholder, value, (QSql::ParamTypeFlag)paramType);
284 m_q->setForwardOnly(forward);
315 resultType, QObject* tableModel)
323 "QSqlQuery::exec - Error: only ZsqlQuery::TableModel " 324 "result type is currently supported. Sorry.");
328 "QSqlQuery::exec - Error: you must pass a ZTableModel " 329 "object as argument 3 to receive the query data.");
333 ok =
m_q->exec(query);
372 QSqlRecord rec(
m_q->record());
374 int fieldCount = rec.count();
376 for(
int i=0; i<fieldCount; i++)
377 metaRow.append(rec.fieldName(i));
390 const int colCount = metaRow.size();
392 jsRow = m_zApp->engine().newArray(colCount);
394 for(
int i = 0; i<colCount; i++)
395 jsRow.setProperty(i, QJSValue(metaRow[i]));
405 const int colCount = metaRow.size();
407 for(
int i = 0; i<colCount; i++)
408 jsRow.append(QVariant(metaRow[i]));
424 *error =
m_q->lastError();
432 error->deleteLater();
468 m_q->setNumericalPrecisionPolicy(QSql::NumericalPrecisionPolicy(policy));
473 throw ZblException(QString(
"Invalid NumericalPrecisionPolicy value: %1")
601 if(mode != QSqlQuery::ValuesAsRows
602 && mode != QSqlQuery::ValuesAsColumns
605 throw ZblException(QString(
"ERROR: invalid mode: %1 is not a " 606 "QSqlQuery::BatchExecutionMode value!").arg(mode));
617 m_q->bindValue(pos, val, QSql::ParamType(type));
626 m_q->addBindValue(val, QSql::ParamType(type));
ZsqlQuery(QSqlQuery *query, QObject *parent=0)
Q_INVOKABLE void addBindValue(const QVariant &val, ZsqlQuery::ParamType=In)
Adds the value val to the list of values when using positional value binding.
Q_INVOKABLE void bindValue(const QString &placeholder, const QVariant &value, int paramType)
bool isValid
Determines if this database connection has a valid database driver.
Q_INVOKABLE bool execBatch(int mode=ValuesAsRows)
Executes a previously prepared SQL query in a batch.
QVariant metaRow
Returns the ID of the last inserted row.
void setNumericalPrecisionPolicy(int policy)
Q_INVOKABLE void finish()
Instruct the database driver that no more data will be fetched from this query until it is re-execute...
QVariant getLastInsertId() const
void createTags()
Create the m_tag object that presents a Javascript interface for ZsqlQuery enumeration values...
Q_INVOKABLE bool seek(int i, bool relative=false)
Q_INVOKABLE bool populateTableModel(QObject *model)
Populates an empty ZTableModel object with the query result.
void queryResult(QObject *qResult)
bool isForwardOnly() const
Q_INVOKABLE bool last()
Retrieves the last record in the result, if available, and positions the query on the retrieved recor...
Q_INVOKABLE bool first()
Retrieves the first record in the result, if available, and positions the query on the retrieved reco...
void initGetTableModel()
Checks that the embedded QSqlQuery object can populate a Zuble table model from it's result sets and ...
Q_INVOKABLE void clear()
Clears the result set and releases any resources held by the query. Sets the query state to inactive...
QSqlRecord m_r
Encapsulated QSqlRecord object.
QVariant getTags()
Obtains a javascript dictionary object that maps constants, enumerations and flags for use with ZsqlQ...
A javascript wrapper class for QSqlDatabase objects. This object represents a database connection...
QString getExecutedQuery() const
Q_INVOKABLE void appendRows(QVariant data)
int numRowsAffected() const
int getNumericalPrecisionPolicy() const
A javascript wrapper class for QSqlQuery objects. This object represents a query on a database connec...
bool getTableModel(ZTableModel *model)
QMap< int, QList< QVariant > > ZRoleRow
Represents a single row (or column for column headers) of data cell values for multiple roles...
Javascript wrapper for a QSqlRecord object.
#define ZBL_SLOT_BEGIN_TRY
static QVariant m_tags
A QVariantMap used to pass ZsqlQuery enumeration values to Javascript programs.
QString lastQuery() const
QSqlQuery * m_q
Encapsulated QSqlQuery object.
QVariant getBoundValues() const
QList< QString > zMetaRow
void setForwardOnly(bool forward)
#define zThreadErr
where does this show up?
This two dimensional table model is used to store and manipulate data.
#define ZBL_SLOT_END_VOID(facility, code, error_message)
static ZsqlQuery * newQuery(ZsqlDatabase &database)
Constructs an empty ZsqlQuery object for the specified database connection.
Q_INVOKABLE bool next()
Retrieves the next record in the result, if available, and positions the query on the retrieved recor...
void ensureParamType(int paramType)
Checks the specified value and throws a ZblException if it isn't a ZsqlQuery::ParamType value...
QVariant getJsMetaRow() const
Q_INVOKABLE void setColumnCount(int count)
Sets the number of columns the table will contain. This method may block the current thread...
Q_INVOKABLE QVariant value(const QString &name) const
Zuble's Qt Exception Object.
Q_INVOKABLE QVariant boundValue(const QString &placeholder) const
Q_INVOKABLE bool prepare(const QString &query)
zMetaRow getMetaRow() const
Q_INVOKABLE bool isNull(int field) const
Q_INVOKABLE bool addRole(int roleNumber)
Adds the specified role to the data model. This method may block the current thread.
QSqlDatabase * m_db
An encapsulated SQL database object.
QList< QMap< int, QList< QVariant > > > ZRoleRowList
Represents multiple rows of data cell values for multiple roles for multiple columns.
Q_INVOKABLE QObject * record()
Obtains a ZsqlRecord object representing the query result.
Q_INVOKABLE bool nextResult()
Discards the current result set and navigates to the next if available.
void validateQuery() const
Checks that the embedded QSqlQuery object exists and throws a ZblException if not.
Q_INVOKABLE bool previous()
Retrieves the previous record in the result, if available, and positions the query on the retrieved r...
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)
bool isOpen
Determines if this database connection is currently open.
A Javascript wrapper for QSqlError objects. (database sprocket)