102 lines
2.5 KiB
C++
102 lines
2.5 KiB
C++
|
#include "fplib01.h"
|
|||
|
#include <prefix.h>
|
|||
|
#include <config.h>
|
|||
|
#include <utility.h>
|
|||
|
#include <scanner.h>
|
|||
|
#include <xvt.h>
|
|||
|
#include <diction.h>
|
|||
|
#include "text.h"
|
|||
|
#include <isam.h>
|
|||
|
|
|||
|
void set_connection(SSimple_query& s)
|
|||
|
{
|
|||
|
if (s.sq_connect(
|
|||
|
TString() << ini_get_string(CONFIG_DITTA, "fp", "ip") << "@" << ini_get_string(CONFIG_DITTA, "fp", "db"),
|
|||
|
ini_get_string(CONFIG_DITTA, "fp", "usr"),
|
|||
|
decode(ini_get_string(CONFIG_DITTA, "fp", "psw")),
|
|||
|
TSDB_MSSQL) != NOERR)
|
|||
|
fatal_box("Impossibile connettersi al DB esterno");
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
SSimple_query& db()
|
|||
|
{
|
|||
|
static SSimple_query* db = nullptr;
|
|||
|
|
|||
|
if (db == nullptr)
|
|||
|
{
|
|||
|
db = new SSimple_query();
|
|||
|
set_connection(*db);
|
|||
|
// Non utilizzo l'autocommit, viene gestito manualmente
|
|||
|
db->sq_set_autocommit(false);
|
|||
|
}
|
|||
|
return *db;
|
|||
|
}
|
|||
|
|
|||
|
string getline(ifstream& f);
|
|||
|
|
|||
|
bool check_tables()
|
|||
|
{
|
|||
|
/*
|
|||
|
* Da questo programma in poi verr<EFBFBD> utilizzato un sistema diverso per la creazione e aggiornamento delle tabelle
|
|||
|
* Verranno utilizzati dei file.sql aggiornati con il numero di patch, leggermente scomodo durante la creazione ma facile per i controlli successivamente
|
|||
|
*/
|
|||
|
SLIST files = xvt_fsys_list_files(".sql", "sql/fp0/", false);
|
|||
|
TLocalisamfile tabmod(LF_TABMOD);
|
|||
|
tabmod.put("MOD", "FP");
|
|||
|
tabmod.put("COD", "SQL");
|
|||
|
tabmod.put("CODTAB", "VERSION");
|
|||
|
TString version;
|
|||
|
if (tabmod.read() == NOERR)
|
|||
|
version = tabmod.get("S0");
|
|||
|
for(SLIST_ELT file = xvt_slist_get_first(files); file; file = xvt_slist_get_next(files, file))
|
|||
|
{
|
|||
|
TString file_version = TFilename(file->str).name_only();
|
|||
|
file_version = file_version.mid(2, 4);
|
|||
|
if (file_version <= version)
|
|||
|
continue;
|
|||
|
ifstream f(file->str);
|
|||
|
if(f.is_open())
|
|||
|
{
|
|||
|
string s;
|
|||
|
while(!f.eof())
|
|||
|
{
|
|||
|
s += getline(f);
|
|||
|
// Cerco un ;
|
|||
|
const int limiter = s.find(';') + 1;
|
|||
|
if(limiter > 0)
|
|||
|
{
|
|||
|
string query = s.substr(0, limiter);
|
|||
|
s.erase(0, limiter);
|
|||
|
if(!db().sq_set_exec(query) || !db().sq_commit())
|
|||
|
{
|
|||
|
fatal_box("Impossibile eseguire/salvare la query:\n%s\n%s", query.c_str(), db().sq_get_string_error());
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
cantread_box(file->str);
|
|||
|
return false;
|
|||
|
}
|
|||
|
// Salvo su tabmod
|
|||
|
tabmod.zero();
|
|||
|
tabmod.put("MOD", "FP");
|
|||
|
tabmod.put("COD", "SQL");
|
|||
|
tabmod.put("CODTAB", "VERSION");
|
|||
|
tabmod.put("S0", file_version);
|
|||
|
if(tabmod.rewrite_write() != NOERR && !yesno_box("Attenzione! Errore di aggiornamento versione di Database in Campo, continuare? %s", file_version))
|
|||
|
{
|
|||
|
return false;
|
|||
|
}
|
|||
|
}
|
|||
|
return true;
|
|||
|
}
|
|||
|
|
|||
|
string getline(ifstream& f)
|
|||
|
{
|
|||
|
string app;
|
|||
|
getline(f, app);
|
|||
|
return app;
|
|||
|
}
|