Query and executeNoQuery method for SQLHelper
This commit is contained in:
@@ -57,3 +57,27 @@ int SQLHelper::QueryCount(QString sql) {
|
|||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int SQLHelper::ExecuteNoQuery(QString sql) {
|
||||||
|
QSqlQuery query(*defaultDatabase);
|
||||||
|
qDebug()<<sql;
|
||||||
|
if (query.exec(sql))
|
||||||
|
{
|
||||||
|
return query.numRowsAffected();
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SQLHelper::Query(QString sql,QMap<QString,QVariant>& result) {
|
||||||
|
QSqlQuery query(*defaultDatabase);
|
||||||
|
if (query.exec(sql))
|
||||||
|
{
|
||||||
|
if(query.next())
|
||||||
|
{
|
||||||
|
for(int i=0; i<query.record().count(); i++)
|
||||||
|
{
|
||||||
|
result[query.record().fieldName(i)]=query.record().value(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -16,7 +16,9 @@ public:
|
|||||||
static bool Open();
|
static bool Open();
|
||||||
static bool Open(QSqlDatabase* base);
|
static bool Open(QSqlDatabase* base);
|
||||||
static void Close();
|
static void Close();
|
||||||
|
static void Query(QString sql,QMap<QString,QVariant>& result);
|
||||||
static int QueryCount(QString sql);
|
static int QueryCount(QString sql);
|
||||||
|
static int ExecuteNoQuery(QString sql);
|
||||||
static QSqlTableModel* getTable(const QString & tableName);
|
static QSqlTableModel* getTable(const QString & tableName);
|
||||||
private:
|
private:
|
||||||
static QSqlDatabase* defaultDatabase;
|
static QSqlDatabase* defaultDatabase;
|
||||||
|
|||||||
Reference in New Issue
Block a user