QList<QVariantList> TcDataAccess::fetchAllList(const QString &sql, const QVariantList &bind /* = QVariantList() */) { _prepareExec(sql, bind); QList<QVariantList> result; QVariantList row; QSqlRecord rec; while (_query->next()) { rec = _query->record(); if (result.isEmpty()) { for (int i = 0; i < rec.count(); i++) { row << _case(rec.fieldName(i)); } result << row; row.clear(); } for (int i = 0; i < rec.count(); i++) { row << _trim(rec.value(i)); } result << row; row.clear(); } return result; }
QVariant TcDataAccess::fetchOne(const QString &sql, const QVariantList &bind /* = QVariantList() */) { _prepareExec(sql, bind); QVariant val; if (_query->next()) { val = _trim(_query->value(0)); } return val; }
QVariantList TcDataAccess::fetchCol(const QString &sql, const QVariantList &bind /* = QVariantList() */) { _prepareExec(sql, bind); QVariantList rows; while (_query->next()) { rows << _trim(_query->value(0)); } return rows; }
int DataAccess::doDelete(const QString &table, const QString &where /* = QString() */, const QVariantList &bind /* = QVariantList() */) { QString sql = "DELETE FROM " + table; if (!where.isEmpty()) { sql += " WHERE " + where; } QSqlQuery *q = _prepareExec(sql, bind); int iNumRowsAffected = q->numRowsAffected(); delete q; return iNumRowsAffected; }
QVariant DataAccess::fetchOne(const QString &sql, const QVariantList &bind /* = QVariantList() */) { QSqlQuery *q = _prepareExec(sql, bind); QVariant val; if (q->next()) { val = q->value(0); } delete q; return val; }
QVariantList DataAccess::fetchCol(const QString &sql, const QVariantList &bind /* = QVariantList() */) { QSqlQuery *q = _prepareExec(sql, bind); QVariantList rows; while (q->next()) { rows << q->value(0); } delete q; return rows; }
QVariantMap TcDataAccess::fetchRow(const QString &sql, const QVariantList &bind /* = QVariantList() */) { _prepareExec(sql, bind); QVariantMap row; if (_query->next()) { QSqlRecord rec = _query->record(); for (int i = rec.count() - 1; i > -1; i--) { row[_case(rec.fieldName(i))] = _trim(rec.value(i)); } } return row; }
QVariantMap DataAccess::fetchRow(const QString &sql, const QVariantList &bind /* = QVariantList() */) { QSqlQuery *q = _prepareExec(sql, bind); QVariantMap row; if (q->next()) { QSqlRecord rec = q->record(); for (int i = rec.count() - 1; i > -1; i--) { row[rec.fieldName(i)] = rec.value(i); } } delete q; return row; }
QList<QVariantMap> TcDataAccess::fetchAll(const QString &sql, const QVariantList &bind /* = QVariantList() */) { _prepareExec(sql, bind); QList<QVariantMap> result; QVariantMap row; while (_query->next()) { QSqlRecord rec = _query->record(); for (int i = rec.count() - 1; i > -1; i--) { row[_case(rec.fieldName(i))] = _trim(rec.value(i)); } result << row; row.clear(); } return result; }
QList<QVariantMap> DataAccess::fetchAll(const QString &sql, const QVariantList &bind /* = QVariantList() */) { QSqlQuery *q = _prepareExec(sql, bind); QList<QVariantMap> result; QVariantMap row; while (q->next()) { QSqlRecord rec = q->record(); for (int i = rec.count() - 1; i > -1; i--) { row[rec.fieldName(i)] = rec.value(i); } result << row; row.clear(); } delete q; return result; }