Query and executeNoQuery method for SQLHelper
This commit is contained in:
@@ -57,3 +57,27 @@ int SQLHelper::QueryCount(QString sql) {
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user