Patch level : 12.0 986

Files correlati     : f90.exe
Commento            :
- Modifica creazione query per creazione prospetto integrativo: aggiunti doppi apici.
- Aggiunta possibilita' di salvare messaggio di errore in sqlite.
This commit is contained in:
Simone Palacino 2020-07-29 16:28:47 +02:00
parent 379ea2b68c
commit aacae42ac9
4 changed files with 48 additions and 6 deletions

View File

@ -19,6 +19,9 @@
#define IS_ITALIANO(statopaiv) ((statopaiv) == "IT" || !(statopaiv).full())
// Controlla eventuali apostrofi e li raddoppia
const char* check_str(const TString& str);
const TDate today(TODAY);
struct annesso_t
@ -535,7 +538,7 @@ class TProspetto_recset final : public TSQL_recordset
TString* _totimponibile;
TString* _totimposta;
static void format_string(TString& str_out, const TString& str) { str_out.cut(0) << "'" << str << "'"; }
static void format_string(TString& str_out, const TString& str) { str_out.cut(0) << "'" << check_str(str) << "'"; }
static void format_string(TString& str_out, const char* str) { format_string(str_out, TString(str)); }
static void format_string(TString& str_out, const TDate& date) { TString dt; dt << date.date2ansi(); format_string(str_out, dt); }
@ -570,7 +573,4 @@ public:
TF9Prospetto_integr();
};
// Controlla eventuali apostrofi e li raddoppia
const char* check_str(const TString& str);
#endif // #ifndef __F901001_H

View File

@ -1,4 +1,5 @@
#include <Windows.h>
#include <iostream>
#include "f9lib.h"
@ -593,7 +594,20 @@ bool TF9Prospetto_integr::operator()(const char* numreg_acq, const char* numreg_
{
TFilename fprosp; fprosp.tempdir().slash_terminate() << make_name_rep();
TProspetto_recset* _prosp_rs = new TProspetto_recset(numreg_acq, numreg_ven);
_items = _prosp_rs->items();
if (_items > 0)
{
if (!_prosp_rs->last_exec())
{
ofstream fout("TF9Prospetto_integr_error.txt");
fout << _prosp_rs->get_err_msg();
fout.close();
return false;
}
}
else
return false;
_rep.set_recordset(_prosp_rs);
_book.add(_rep);

View File

@ -16,6 +16,7 @@ class TSQLite : public TObject
{
sqlite3* _handle;
TFilename _currdb;
TString _last_err_msg;
protected:
TVariant& get_sql_value(const TRectype& curr, const RecFieldDes& fd, TVariant& tmp) const;
@ -39,6 +40,8 @@ public:
bool exists(const char* table);
bool parse_select_from(const char* szSql);
TString get_last_err_msg(bool erase = true);
TSQLite();
virtual ~TSQLite();
} _TheDataBase;
@ -115,6 +118,9 @@ bool TSQLite::exec(const char* sql, sqlite3_callback callback, void* jolly, bool
char* errmsg = NULL;
const int rc = sqlite3_exec(_handle, sql, callback, jolly, &errmsg);
if(rc != SQLITE_OK)
_last_err_msg.cut(0) << sql << "\n - " << errmsg;
if (errmsg != NULL)
{
if (show_error)
@ -399,6 +405,17 @@ bool TSQLite::parse_select_from(const char* szSql)
return true;
}
TString TSQLite::get_last_err_msg(const bool erase)
{
if (erase)
{
TString a = _last_err_msg;
_last_err_msg.cut(0);
return a;
}
return _last_err_msg;
}
TSQLite::TSQLite() : _handle(NULL)
{ }
@ -503,7 +520,8 @@ TRecnotype TSQL_recordset::items() const
TString sql; parsed_text(sql);
TPerformance_profiler prof("SQL query");
//_TheDataBase.exec("PRAGMA show_datatypes=ON;", NULL, NULL);
_TheDataBase.exec(sql, query_get_items, (TSQL_recordset*)this);
TSQL_recordset& a = *(TSQL_recordset*)this;
a._last_exec = _TheDataBase.exec(sql, query_get_items, (TSQL_recordset*)this);
//_TheDataBase.exec("PRAGMA show_datatypes=OFF;", NULL, NULL);
}
return _items;
@ -586,7 +604,8 @@ bool TSQL_recordset::move_to(TRecnotype n)
_first_row = n;
sql << "\nLIMIT " << _pagesize << " OFFSET " << _first_row << ';';
}
_TheDataBase.exec(sql, query_get_rows, this);
_last_exec = _TheDataBase.exec(sql, query_get_rows, this);
}
return true;
@ -630,6 +649,11 @@ const TString& TSQL_recordset::driver_version() const
return tmp;
}
TString TSQL_recordset::get_err_msg(const bool erase)
{
return _TheDataBase.get_last_err_msg(erase);
}
TSQL_recordset::TSQL_recordset(const char* sql)
{
set(sql);

View File

@ -16,6 +16,7 @@ class TSQL_recordset : public TRecordset
TRecnotype _first_row, _pagesize, _items, _current_row;
TArray _column;
TArray _page;
bool _last_exec;
protected:
virtual void reset();
@ -32,6 +33,9 @@ public: // TRecordset
virtual const TString& query_text() const { return _sql; }
virtual const TString& driver_version() const;
static TString get_err_msg(bool erase = true);
bool last_exec() const { return _last_exec; }
public:
void set(const char* sql);