init
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
#include "csqliteplugin.h"
|
||||
#include "cconfigdialog.h"
|
||||
|
||||
#include "cingredient.h"
|
||||
|
||||
#include <QSqlError>
|
||||
#include <QSettings>
|
||||
#include <QSqlQuery>
|
||||
@@ -253,13 +255,58 @@ bool cSQLitePlugin::set(qint32 id, qint16 ingredientNumber, qreal value)
|
||||
return(existsIngredient(id, ingredientNumber));
|
||||
}
|
||||
|
||||
QString cSQLitePlugin::name(qint32 id)
|
||||
{
|
||||
if(!m_bConnected)
|
||||
return("");
|
||||
|
||||
QSqlQuery query(m_db);
|
||||
if(!query.exec(QString("SELECT name FROM ingredient WHERE id=%1").arg(id)))
|
||||
{
|
||||
m_szLastError = query.lastError().text();
|
||||
return("");
|
||||
}
|
||||
query.first();
|
||||
return(query.value("name").toString());
|
||||
}
|
||||
|
||||
QString cSQLitePlugin::group(qint32 id)
|
||||
{
|
||||
if(!m_bConnected)
|
||||
return("");
|
||||
|
||||
QSqlQuery query(m_db);
|
||||
if(!query.exec(QString("SELECT ingredient_group.name FROM ingredient, ingredient_group WHERE ingredient.ingredient_group_id=ingredient_group.id AND ingredient.id=%1").arg(id).arg(id)))
|
||||
{
|
||||
m_szLastError = query.lastError().text();
|
||||
return("");
|
||||
}
|
||||
query.first();
|
||||
return(query.value("name").toString());
|
||||
}
|
||||
|
||||
qreal cSQLitePlugin::get(qint32 id, qint16 ingredientNumber)
|
||||
{
|
||||
if(!m_bConnected)
|
||||
return(-1);
|
||||
|
||||
QSqlQuery query(m_db);
|
||||
if(!query.exec(QString("SELECT value FROM ingredient_values WHERE ingredient_id=%1 AND ingredient_number=%2").arg(id).arg(ingredientNumber)))
|
||||
{
|
||||
m_szLastError = query.lastError().text();
|
||||
return(-1);
|
||||
}
|
||||
query.first();
|
||||
return(query.value("value").toReal());
|
||||
}
|
||||
|
||||
INGREDIENT_LIST cSQLitePlugin::ingredients()
|
||||
{
|
||||
if(!m_bConnected)
|
||||
return(INGREDIENT_LIST());
|
||||
|
||||
QSqlQuery query(m_db);
|
||||
if(!query.exec(QString("SELECT ingredient.name, ingredient_group.name FROM ingredient, ingredient_group WHERE ingredient.ingredient_group_id = ingredient_group.id ORDER BY ingredient_group.name, ingredient.name")))
|
||||
if(!query.exec(QString(QString("SELECT ingredient.id, ingredient.name, ingredient_group.name, calories.value, carbohydrates.value FROM ingredient, ingredient_group, ingredient_values AS calories, ingredient_values AS carbohydrates WHERE ingredient.ingredient_group_id = ingredient_group.id AND calories.ingredient_id = ingredient.id AND calories.ingredient_number = %1 AND carbohydrates.ingredient_id = ingredient.id AND carbohydrates.ingredient_number = %2 ORDER BY ingredient_group.name, ingredient.name").arg(cIngredient::iIngredientCalories).arg(cIngredient::iIngredientCarbohydrates))))
|
||||
{
|
||||
m_szLastError = query.lastError().text();
|
||||
return(INGREDIENT_LIST());
|
||||
@@ -269,8 +316,11 @@ INGREDIENT_LIST cSQLitePlugin::ingredients()
|
||||
while(query.next())
|
||||
{
|
||||
INGREDIENT i;
|
||||
i.szGroup = query.value(1).toString();
|
||||
i.szIngredient = query.value(0).toString();
|
||||
i.iIngredient = query.value(0).toInt();
|
||||
i.szIngredient = query.value(1).toString();
|
||||
i.szGroup = query.value(2).toString();
|
||||
i.dCalories = query.value(3).toDouble();
|
||||
i.dCarbohydrates = query.value(4).toDouble();
|
||||
list.append(i);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user