#include "sql_functions.hpp"
sql_functions
::sql_functions( const QString database
){
/**
* Create structure :
* - to store data for SQL request
* - to store data for statistics
**/
s_req = new Struct_Request;
s_stats = new Struct_Statistic;
first_call = true;
m_database = database;
}
sql_functions::~sql_functions()
{
delete s_req;
delete s_stats;
}
void sql_functions
::exec( const int request_type,
QString movie_title,
QString type,
QString borrower_name,
{
/** Clear data field in request structure **/
s_req->data.clear();
if ( first_call )
{
first_call = false;
}
else
{
}
m_db.setDatabaseName( m_database );
/** If no error occured, SQL request is executed **/
if ( m_db.open() )
{
switch( request_type )
{
case RequestSQL::DISPLAY_ALL :
s_req->data.exec( "SELECT type,titre,dvd_en_pret,bluray_en_pret,dvd_prete_a,bluray_prete_a,est_combo "
"FROM films ORDER BY titre COLLATE NOCASE;" );
break;
case RequestSQL::DISPLAY_DVD :
s_req->data.exec( "SELECT type,titre,dvd_en_pret,bluray_en_pret,dvd_prete_a,bluray_prete_a,est_combo
"FROM films WHERE type IN ('DVD') ORDER BY titre COLLATE NOCASE;" );
break;
case RequestSQL::DISPLAY_BLURAY :
s_req->data.exec( "SELECT type,titre,dvd_en_pret,bluray_en_pret,dvd_prete_a,bluray_prete_a,est_combo "
"FROM films WHERE type IN ('BLURAY') ORDER BY titre COLLATE NOCASE;" );
break;
default:
break;
}
/** close database **/
m_db.close();
}
}
#include "sql_functions.hpp"
sql_functions::sql_functions( const QString database )
{
/**
* Create structure :
* - to store data for SQL request
* - to store data for statistics
**/
s_req = new Struct_Request;
s_stats = new Struct_Statistic;
first_call = true;
m_database = database;
}
sql_functions::~sql_functions()
{
delete s_req;
delete s_stats;
}
void sql_functions::exec( const int request_type, QString movie_title, QString type, QString borrower_name,
QString Id_movie_update )
{
/** Clear data field in request structure **/
s_req->data.clear();
QSqlDatabase m_db;
if ( first_call )
{
m_db = QSqlDatabase::addDatabase( "QSQLITE" );
first_call = false;
}
else
{
m_db = QSqlDatabase::database();
}
m_db.setDatabaseName( m_database );
/** If no error occured, SQL request is executed **/
if ( m_db.open() )
{
s_req->data = QSqlQuery( m_db );
switch( request_type )
{
case RequestSQL::DISPLAY_ALL :
s_req->data.exec( "SELECT type,titre,dvd_en_pret,bluray_en_pret,dvd_prete_a,bluray_prete_a,est_combo "
"FROM films ORDER BY titre COLLATE NOCASE;" );
break;
case RequestSQL::DISPLAY_DVD :
s_req->data.exec( "SELECT type,titre,dvd_en_pret,bluray_en_pret,dvd_prete_a,bluray_prete_a,est_combo
"FROM films WHERE type IN ('DVD') ORDER BY titre COLLATE NOCASE;" );
break;
case RequestSQL::DISPLAY_BLURAY :
s_req->data.exec( "SELECT type,titre,dvd_en_pret,bluray_en_pret,dvd_prete_a,bluray_prete_a,est_combo "
"FROM films WHERE type IN ('BLURAY') ORDER BY titre COLLATE NOCASE;" );
break;
default:
break;
}
/** close database **/
m_db.close();
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks