Patch level : 12.0 690
Files correlati : mr Commento : - Sistemata esportazione tabella p01b per Compass - Revert modifiche a recordset, creavano problemi, si perdevano records - Aggiunto boolean _disable_variables che disabilita le variabili in recordset
This commit is contained in:
parent
1ad2ea8fc6
commit
85f6b2a5cc
@ -88,41 +88,6 @@ const TString& TODBC_recordset::query_text() const
|
||||
return _sql;
|
||||
}
|
||||
|
||||
const TString& TODBC_recordset::query_text_var() const
|
||||
{
|
||||
|
||||
// INSERT INTO POPPO (COL1, COL2) VALUES (SELECT COL3, COL4 FROM PAPPO WHERE COL5 = #VAR4)
|
||||
// INSERT INTO POPPO (COL1, COL2) VALUES (SELECT COL3, COL4 FROM PAPPO WHERE COL5 = '#VAR4')
|
||||
// #VAR4')
|
||||
|
||||
// Conto quanti separatori ho
|
||||
int num_sep = 0;
|
||||
int pos = _sql.find(query_text_separator());
|
||||
for (; pos > 0; pos = _sql.find(query_text_separator(), pos + 1))
|
||||
num_sep++;
|
||||
|
||||
if(num_sep == 0 || num_sep % 2 != 0)
|
||||
{
|
||||
return _sql;
|
||||
}
|
||||
|
||||
// Se sono pari tolgo dalla mia query tutte le variabili all'interno dei separatori per non farle chiedere all'utente
|
||||
TString& sql = get_tmp_string();
|
||||
TString wrk_sql = _sql;
|
||||
sql.cut(0);
|
||||
|
||||
// cerco il primo query_text_separator(), nel nostro caso è l'apice e mi sposto
|
||||
for (int qts = wrk_sql.find(query_text_separator()); qts > 0; qts = wrk_sql.find(query_text_separator())) // Cerco tutti i separatori
|
||||
{
|
||||
sql << wrk_sql.left(qts - 1);
|
||||
wrk_sql.ltrim(qts);
|
||||
qts = wrk_sql.find(query_text_separator());
|
||||
wrk_sql.ltrim(qts);
|
||||
}
|
||||
|
||||
return sql;
|
||||
}
|
||||
|
||||
const TString& TODBC_recordset::driver_version() const
|
||||
{
|
||||
TString& tmp = get_tmp_string(50);
|
||||
@ -752,7 +717,6 @@ void TODBC_recordset::set(const char* sql)
|
||||
|
||||
TODBC_recordset::TODBC_recordset(const char* sql, const bool freezed) : _freezed(freezed), _loaded(false)
|
||||
{
|
||||
TRecordset::set_query_text_separator('\'');
|
||||
set(sql);
|
||||
}
|
||||
|
||||
|
@ -40,7 +40,6 @@ public:
|
||||
virtual TRecnotype current_row() const;
|
||||
virtual void requery();
|
||||
virtual const TString& query_text() const;
|
||||
virtual const TString& query_text_var() const;
|
||||
virtual const TString& driver_version() const;
|
||||
virtual void freeze(const bool on) { _freezed = on; }
|
||||
|
||||
|
@ -623,7 +623,7 @@ void TRecordset::find_and_reset_vars()
|
||||
_var.destroy();
|
||||
_varnames.destroy();
|
||||
|
||||
const TString& sql = query_text_var();
|
||||
const TString& sql = query_text();
|
||||
int diesis = sql.find('#'); // cerco il primo #
|
||||
for ( ; diesis > 0; diesis = sql.find('#', diesis+1)) // Cerco tutti i #
|
||||
{
|
||||
@ -716,6 +716,9 @@ bool ask_variable(const char* name, TVariant& var)
|
||||
|
||||
bool TRecordset::ask_variables(bool all)
|
||||
{
|
||||
if (_disable_variables)
|
||||
return true;
|
||||
|
||||
const bool ok = variables().items() > 0;
|
||||
if (ok) // Se ci sono variabili faccio le sostituzioni
|
||||
{
|
||||
@ -737,7 +740,7 @@ bool TRecordset::ask_variables(bool all)
|
||||
const TString& TRecordset::driver_version() const
|
||||
{ return EMPTY_STRING; }
|
||||
|
||||
TRecordset::TRecordset() : _parentset(NULL), _text_separator('\t')
|
||||
TRecordset::TRecordset() : _parentset(NULL), _text_separator('\t'), _disable_variables(false)
|
||||
{ }
|
||||
|
||||
///////////////////////////////////////////////////////////
|
||||
|
@ -63,7 +63,7 @@ class TRecordset : public TObject
|
||||
TString_array _varnames;
|
||||
const TRecordset* _parentset;
|
||||
char _text_separator;
|
||||
char _query_text_separator;
|
||||
bool _disable_variables;
|
||||
|
||||
protected:
|
||||
virtual bool save_as_html(const char* path);
|
||||
@ -85,14 +85,10 @@ public: // Absolutely needed methods
|
||||
virtual void requery() pure;
|
||||
bool empty() const { return items() == 0; }
|
||||
virtual const TString& query_text() const pure;
|
||||
virtual const TString& query_text_var() const { return query_text(); }
|
||||
virtual const TString& driver_version() const;
|
||||
|
||||
virtual char text_separator() const { return _text_separator;}
|
||||
virtual void set_text_separator(char sep) { _text_separator = sep;}
|
||||
|
||||
virtual char query_text_separator() const { return _query_text_separator; }
|
||||
virtual void set_query_text_separator(char sep) { _query_text_separator = sep; }
|
||||
|
||||
virtual void freeze() {}
|
||||
virtual bool move_first() { return move_to(0); }
|
||||
@ -121,6 +117,11 @@ public: // Absolutely needed methods
|
||||
// mode = 0|1=append 2=update 3=update|append 4=zap before writing
|
||||
virtual bool save_as(const char* path, TRecordsetExportFormat fmt = fmt_unknown, int mode = 0);
|
||||
|
||||
// gestione per abilitare o disabilitare variabili
|
||||
virtual void disable_variables() { _disable_variables = true; }
|
||||
virtual void enable_variables() { _disable_variables = false; }
|
||||
|
||||
|
||||
void set_parent(const TRecordset* rs) { _parentset = rs; }
|
||||
TRecordset();
|
||||
virtual ~TRecordset() { }
|
||||
|
@ -82,6 +82,8 @@ protected:
|
||||
bool test() const;
|
||||
//bool o01b(const TString& DSN) const; Messa in pausa
|
||||
|
||||
void log_to_file(TString func, TString msg) const;
|
||||
|
||||
public:
|
||||
virtual void main_loop();
|
||||
void setTable(TToken_string s) { tables = s; }
|
||||
@ -163,6 +165,7 @@ bool TCampass_app::setParameters(TString dsn, TString utente, TString password)
|
||||
TString TCampass_app::startExport(TString prefixTables) const
|
||||
{
|
||||
TODBC_recordset sqlset("", true);
|
||||
sqlset.disable_variables();
|
||||
// Controllo la connessione
|
||||
if (!sqlset.connect(DSN, usr, psw))
|
||||
return "";
|
||||
@ -181,6 +184,7 @@ TString TCampass_app::startExport(TString prefixTables) const
|
||||
void TCampass_app::endExport(TString id) const
|
||||
{
|
||||
TODBC_recordset sqlset("", true);
|
||||
sqlset.disable_variables();
|
||||
sqlset.connect(DSN, usr, psw);
|
||||
//Preparo la query
|
||||
TString sqlQuery; sqlQuery << "UPDATE RunImp SET DWEND = CURRENT_TIMESTAMP WHERE IDRUNIMP = '" << id << "'";
|
||||
@ -191,6 +195,7 @@ void TCampass_app::endExport(TString id) const
|
||||
bool TCampass_app::emptyTables(const TString& DSN, const TString& usr, const TString& psw) const
|
||||
{
|
||||
TODBC_recordset sqlset("");
|
||||
sqlset.disable_variables();
|
||||
TString table;
|
||||
|
||||
if (!sqlset.connect(DSN, usr, psw))
|
||||
@ -222,6 +227,7 @@ TString TCampass_app::esporta(const TString& DSN, const TString& usr, const TStr
|
||||
logFile << getTime() << " - Test connessione\n";
|
||||
|
||||
TODBC_recordset sqlset("");
|
||||
sqlset.disable_variables();
|
||||
if (!sqlset.connect(DSN, usr, psw))
|
||||
return "Connessione fallita!";
|
||||
|
||||
@ -254,7 +260,7 @@ TString TCampass_app::esporta(const TString& DSN, const TString& usr, const TStr
|
||||
endExport(p02);
|
||||
|
||||
logFile << getTime() << " - Fine esportazione P02!\n";
|
||||
|
||||
|
||||
// INIZIO P01
|
||||
|
||||
logFile << getTime() << " - Inizio esportazione P01:\n";
|
||||
@ -265,10 +271,11 @@ TString TCampass_app::esporta(const TString& DSN, const TString& usr, const TStr
|
||||
else
|
||||
logFile << getTime() << " - Esportata tabella P01A\n";
|
||||
|
||||
|
||||
if(!p01b(p01)) errors << "ERRORE TABELLA: P01B\n"; // P01B
|
||||
else
|
||||
logFile << getTime() << " - Esportata tabella P01B\n";
|
||||
|
||||
|
||||
if(!p01c(p01)) errors << "ERRORE TABELLA: P01C\n"; // O01A
|
||||
else
|
||||
logFile << getTime() << " - Esportata tabella P01C\n";
|
||||
@ -276,7 +283,7 @@ TString TCampass_app::esporta(const TString& DSN, const TString& usr, const TStr
|
||||
endExport(p01);
|
||||
|
||||
logFile << getTime() << " - Fine esportazione P01!\n";
|
||||
|
||||
|
||||
// INIZIO O02
|
||||
|
||||
logFile << getTime() << " - Inizio esportazione O02:\n";
|
||||
@ -338,6 +345,7 @@ TString TCampass_app::esporta(const TString& DSN, const TString& usr, const TStr
|
||||
endExport(a01);
|
||||
|
||||
logFile << getTime() << " - Fine esportazione A01!\n";
|
||||
|
||||
}
|
||||
|
||||
if(m->get_bool(B_IMPORT))
|
||||
@ -359,6 +367,7 @@ TString TCampass_app::esporta(const TString& DSN, const TString& usr, const TStr
|
||||
bool TCampass_app::test() const
|
||||
{
|
||||
TODBC_recordset sqlset("", true);
|
||||
sqlset.disable_variables();
|
||||
// Controllo la connessione
|
||||
if (!sqlset.connect(DSN, usr, psw))
|
||||
return false;
|
||||
@ -410,11 +419,24 @@ bool TCampass_app::test() const
|
||||
return true;
|
||||
}
|
||||
|
||||
void TCampass_app::log_to_file(TString func, TString msg) const
|
||||
{
|
||||
ofstream log_file;
|
||||
log_file.open("Campass_error_log.txt", ios::app);
|
||||
if (!log_file.is_open())
|
||||
return;
|
||||
|
||||
log_file << getTime() << " - " << func << " - " << msg << "\n";
|
||||
|
||||
log_file.close();
|
||||
}
|
||||
|
||||
|
||||
// Non sono molto sicuro del suo funzionamento
|
||||
bool TCampass_app::a01a(const TString id) const
|
||||
{
|
||||
TODBC_recordset sqlset("", true);
|
||||
sqlset.disable_variables();
|
||||
// Controllo la connessione
|
||||
if (!sqlset.connect(DSN, usr, psw))
|
||||
return false;
|
||||
@ -493,6 +515,7 @@ bool TCampass_app::o01a(const TString id) const
|
||||
{
|
||||
long totalItems = 0;
|
||||
TODBC_recordset sqlset("", true);
|
||||
sqlset.disable_variables();
|
||||
// Controllo la connessione
|
||||
if (!sqlset.connect(DSN, usr, psw))
|
||||
return false;
|
||||
@ -589,6 +612,7 @@ bool TCampass_app::o01c(const TString id) const
|
||||
{
|
||||
long totalItems = 0;
|
||||
TODBC_recordset sqlset("", true);
|
||||
sqlset.disable_variables();
|
||||
// Controllo la connessione
|
||||
if (!sqlset.connect(DSN, usr, psw))
|
||||
return false;
|
||||
@ -655,6 +679,7 @@ bool TCampass_app::o01c(const TString id) const
|
||||
bool TCampass_app::o01e(const TString id) const
|
||||
{
|
||||
TODBC_recordset sqlset("", true);
|
||||
sqlset.disable_variables();
|
||||
// Controllo la connessione
|
||||
if (!sqlset.connect(DSN, usr, psw))
|
||||
return false;
|
||||
@ -713,6 +738,7 @@ bool TCampass_app::o01e(const TString id) const
|
||||
bool TCampass_app::o02a(const TString CodNum, const TString id) const
|
||||
{
|
||||
TODBC_recordset sqlset("", true);
|
||||
sqlset.disable_variables();
|
||||
// Controllo la connessione
|
||||
if (!sqlset.connect(DSN, usr, psw))
|
||||
return false;
|
||||
@ -776,6 +802,7 @@ bool TCampass_app::o02a(const TString CodNum, const TString id) const
|
||||
bool TCampass_app::o02c(const TString CodNum, const TString id) const
|
||||
{
|
||||
TODBC_recordset sqlset("", true);
|
||||
sqlset.disable_variables();
|
||||
// Controllo la connessione
|
||||
if (!sqlset.connect(DSN, usr, psw))
|
||||
return false;
|
||||
@ -835,6 +862,7 @@ bool TCampass_app::o02c(const TString CodNum, const TString id) const
|
||||
bool TCampass_app::o03a(const TString id) const
|
||||
{
|
||||
TODBC_recordset sqlset("", true);
|
||||
sqlset.disable_variables();
|
||||
// Controllo la connessione
|
||||
if (!sqlset.connect(DSN, usr, psw))
|
||||
return false;
|
||||
@ -871,6 +899,7 @@ bool TCampass_app::o03a(const TString id) const
|
||||
bool TCampass_app::p01a(const TString id) const
|
||||
{
|
||||
TODBC_recordset sqlset("", true);
|
||||
sqlset.disable_variables();
|
||||
// Controllo la connessione
|
||||
if (!sqlset.connect(DSN, usr, psw))
|
||||
return false;
|
||||
@ -976,48 +1005,51 @@ bool TCampass_app::p01a(const TString id) const
|
||||
bool TCampass_app::p01b(const TString id) const
|
||||
{
|
||||
TODBC_recordset sqlset("", true);
|
||||
sqlset.disable_variables();
|
||||
// Controllo la connessione
|
||||
if (!sqlset.connect(DSN, usr, psw))
|
||||
return false;
|
||||
TRelation anamag(LF_ANAMAG), tab(LF_TAB);
|
||||
TString msg("Esportazione tabella "); msg << "P01B";
|
||||
TString msg("Esportazione tabella P01B");
|
||||
// Anamag
|
||||
TCursor curAna(&anamag);
|
||||
const int items = curAna.items();
|
||||
TISAM_recordset isamrec_ana("USE ANAMAG");
|
||||
|
||||
const int items = isamrec_ana.items();
|
||||
|
||||
// Tab
|
||||
|
||||
|
||||
TProgress_monitor p(items, msg);
|
||||
|
||||
bool ok = true;
|
||||
|
||||
// Adesso inserisco tutta la bella roba
|
||||
for (curAna = 0; curAna.pos() < items && !p.is_cancelled(); ++curAna)
|
||||
|
||||
for (bool ok = isamrec_ana.move_first(); isamrec_ana.cursor()->pos() < items; isamrec_ana.move_next())
|
||||
{
|
||||
int num = curAna.pos();
|
||||
// Aggiorno il Progress Monitor
|
||||
if (!p.add_status())
|
||||
break;
|
||||
p.add_status();
|
||||
|
||||
// Prendo la riga di TAB
|
||||
TRectype rowAna = curAna.curr();
|
||||
|
||||
// Dichiaro la stringa
|
||||
TString sqlQuery;
|
||||
static TString sqlQuery;
|
||||
sqlQuery.cut(0);
|
||||
|
||||
if(rowAna.get("USER3") != "")
|
||||
if (!isamrec_ana.get("USER3").is_empty())
|
||||
{
|
||||
TString cparam; cparam << toNumber(rowAna.get("USER3")) << "x" << toNumber(rowAna.get("USER4"));
|
||||
TString cparam; cparam << toNumber(isamrec_ana.get("USER3").as_string()) << "x" << toNumber(isamrec_ana.get("USER4").as_string());
|
||||
// Inserisco Tutto
|
||||
sqlQuery << "INSERT INTO P01B ( IKRUNIMP, CStr, CART, CPARAM, CPARVAL ) \
|
||||
VALUES('" << id << "','DBS','" << toEscape(rowAna.get("CODART")) << "','MISREA','" << toEscape(cparam) << "');";
|
||||
VALUES('" << id << "','DBS','" << toEscape(isamrec_ana.get("CODART").as_string()) << "','MISREA','" << toEscape(cparam) << "');";
|
||||
}
|
||||
|
||||
// Inizio a eseguire quello che ho qua
|
||||
if(sqlQuery != "" && sqlset.exec(sqlQuery) != 1)
|
||||
return false;
|
||||
if (sqlQuery.full() && sqlset.exec(sqlQuery) != 1)
|
||||
{
|
||||
TString msg = "Impossibile esportare l'articolo "; msg << isamrec_ana.get("CODART").as_string();
|
||||
log_to_file("p01b - MISREA", msg);
|
||||
}
|
||||
|
||||
sqlQuery.cut(0);
|
||||
TString anamagCod(rowAna.get("CODART")), filtroCodTab;
|
||||
|
||||
TString anamagCod(isamrec_ana.get("CODART").as_string()), filtroCodTab;
|
||||
filtroCodTab << "3" << anamagCod.sub(6,12);
|
||||
// Tab *******************************************************************************************************************************************************
|
||||
// Filtri
|
||||
@ -1028,29 +1060,32 @@ bool TCampass_app::p01b(const TString id) const
|
||||
TCursor curTab(&tab, "", 1, &filtroTab, &filtroTab);
|
||||
// Items
|
||||
const int itemsTab = curTab.items();
|
||||
if (itemsTab > 0)
|
||||
bool yeah = true;
|
||||
|
||||
for (curTab = 0; curTab.pos() < itemsTab && !p.is_cancelled(); ++curTab)
|
||||
{
|
||||
TRectype rowTab = curTab.curr();
|
||||
sqlQuery << "INSERT INTO P01B ( IKRUNIMP, CStr, CART, CPARAM, CPARVAL ) \
|
||||
VALUES('" << id << "','DBS','" << toEscape(rowAna.get("CODART")) << "','FORING','" << rowTab.get("S0") << "');";
|
||||
VALUES('" << id << "','DBS','" << toEscape(isamrec_ana.get("CODART").as_string()) << "','FORING','" << rowTab.get("S0") << "');";
|
||||
|
||||
// Per ogni giro lancio una exec altrimenti rischio di sfondare il limite di caratteri
|
||||
if(sqlQuery != "" && sqlset.exec(sqlQuery) != 1)
|
||||
return false;
|
||||
|
||||
if (sqlQuery != "" && sqlset.exec(sqlQuery) != 1)
|
||||
{
|
||||
TString msg = "Impossibile esportare l'articolo "; msg << isamrec_ana.get("CODART").as_string();
|
||||
log_to_file("p01b - FORING", msg);
|
||||
}
|
||||
sqlQuery.cut(0);
|
||||
}
|
||||
return sqlset.commit() != -1;
|
||||
|
||||
ok &= sqlset.commit() != -1;
|
||||
}
|
||||
|
||||
return sqlset.commit() != -1;
|
||||
return ok;
|
||||
}
|
||||
|
||||
bool TCampass_app::p02a(const TString id) const
|
||||
{
|
||||
TODBC_recordset sqlset("", true);
|
||||
sqlset.disable_variables();
|
||||
// Controllo la connessione
|
||||
if (!sqlset.connect(DSN, usr, psw))
|
||||
return false;
|
||||
@ -1091,6 +1126,7 @@ bool TCampass_app::p02a(const TString id) const
|
||||
bool TCampass_app::p01c(const TString id) const
|
||||
{
|
||||
TODBC_recordset sqlset("", true);
|
||||
sqlset.disable_variables();
|
||||
// Controllo la connessione
|
||||
if (!sqlset.connect(DSN, usr, psw))
|
||||
return false;
|
||||
@ -1145,6 +1181,7 @@ bool TCampass_app::p01c(const TString id) const
|
||||
bool TCampass_app::c09a() const
|
||||
{
|
||||
TODBC_recordset sqlset("", true);
|
||||
sqlset.disable_variables();
|
||||
if (!sqlset.connect(DSN, usr, psw))
|
||||
return false;
|
||||
TString sqlQuery = "SELECT TOP 1 * \
|
||||
|
Loading…
x
Reference in New Issue
Block a user