From cd301ea04cc6ded9e6468a50c655e028265c796d Mon Sep 17 00:00:00 2001 From: mtollari Date: Fri, 9 Feb 2018 13:52:46 +0000 Subject: [PATCH] Patch level : 12.0 no-patch Files correlati : Commento : Aggiunti ttools e tsdb dalla versione 13 alla 12 con il wrapper SSimpleQuery git-svn-id: svn://10.65.10.50/branches/R_10_00@24362 c028cbd2-c16b-5b4b-a496-9718f37d4682 --- src/include/dbrset.cpp | 25 ------ src/include/dbrset.h | 22 ----- src/include/tsdb.cpp | 7 ++ src/include/tsdb.h | 186 +++++++++++++++++++++++++++++++++++++++++ src/include/ttools.cpp | 13 +++ src/include/ttools.h | 14 ++++ 6 files changed, 220 insertions(+), 47 deletions(-) delete mode 100644 src/include/dbrset.cpp delete mode 100644 src/include/dbrset.h create mode 100644 src/include/tsdb.cpp create mode 100644 src/include/tsdb.h create mode 100644 src/include/ttools.cpp create mode 100644 src/include/ttools.h diff --git a/src/include/dbrset.cpp b/src/include/dbrset.cpp deleted file mode 100644 index 4e8ff90ce..000000000 --- a/src/include/dbrset.cpp +++ /dev/null @@ -1,25 +0,0 @@ -#include - - - real TDB_recordset::get_real(const char * field) - { - return real(get(field)); - } - - TDate TDB_recordset::get_date(const char * field) - { - /* - static TString dateApp; - dateApp.cut(0) << get(field); - */ -#ifdef DBG - message_box("Data da testare!"); -#endif - // Ritorna un campo formato da YYYY-MM-DD:T**** - return getDate(field);//TDate(dateApp.left(10)); - } - - TVariant TDB_recordset::get_variant(const char * field) - { - return TVariant(get(field)); - } \ No newline at end of file diff --git a/src/include/dbrset.h b/src/include/dbrset.h deleted file mode 100644 index f64dbd476..000000000 --- a/src/include/dbrset.h +++ /dev/null @@ -1,22 +0,0 @@ -#include -#include - -/****************************************************************************** - * TDB_recordset : DataBase redcordset * - * Wrapper di TXvt_recordset, aggiunge la compatibilità ai tipi di Agalib * - ******************************************************************************/ - -class TDB_recordset : public TObject, TXvt_recordset -{ -public: - // Getters - /**< Ritorna il valore nel campo (field) in formato (real) */ - real get_real(const char * field); - /**< Ritorna il valore nel campo (field) in formato (TDate) */ - TDate get_date(const char * field); - /**< Ritorna il valore nel campo (field) in formato (TVariant) */ - TVariant get_variant(const char * field); - - TDB_recordset(); - TDB_recordset(const char* db, const char* user, const char* pass, TT_driver tipoDb, const char * query = "", bool ex = false); -}; \ No newline at end of file diff --git a/src/include/tsdb.cpp b/src/include/tsdb.cpp new file mode 100644 index 000000000..800078bde --- /dev/null +++ b/src/include/tsdb.cpp @@ -0,0 +1,7 @@ +#include + + +/****************************************************************************** + * SSimpleQuery * + * Classe per esecuzioni di query temporanee (wrapper semplice per SACommand) * + ******************************************************************************/ \ No newline at end of file diff --git a/src/include/tsdb.h b/src/include/tsdb.h new file mode 100644 index 000000000..922529e29 --- /dev/null +++ b/src/include/tsdb.h @@ -0,0 +1,186 @@ +/********************************************************************************** + * ######\ * + * ## __##\ * + * ## / \__| ######\ ######\####\ ######\ ######\ * + * ## | \____##\ ## _## _##\ ## __##\ ## __##\ * + * ## | ####### |## / ## / ## |## / ## |## / ## | * + * ## | ##\ ## __## |## | ## | ## |## | ## |## | ## | * + * \###### |\####### |## | ## | ## |####### |\###### | * + * \______/ \_______|\__| \__| \__|## ____/ \______/ * + * ## | * + * ## | * + * \__| * + **********************************************************************************/ + + +/******************************************************************************************************************************** + * TSDB.H * + * Inizio sviluppo: 13.10.2016 * + * Autore: Tolla * + * Descrizione: * + * La seguente libreria ha due scopi: * + * - Implementare una serie di funzioni che emulino interamente il funzionamento attuale di campo in Visual FoxPro su MSQL * + * - Creare delle nuove API per gestire il database in MSQL con cui verranno riscritti i programmi * + * Librerie esterne utilizzate: * + * - SQLAPI++ (Permette la gestione dei più famosi DB attualmente esistenti) * + ********************************************************************************************************************************/ + +#ifndef __TSDB_H +#define __TSDB_H + +#ifndef __XVTDB_H +#include +#endif + + +// Tolla tools +#ifndef __TTOOLS_H +#include +#endif + +#ifndef __STRINGS_H +#include +#endif // !__STRINGS_H + +#ifndef __DATE_H +#include +#endif // !__DATE_H + +#ifndef __REAL_H +#include +#endif // !__REAL_H + +#define CHIAVE_ID_ "_ID_" + +/******************************************************************************** + * SSimpleQuery (Sirio Simple Query) * + * "Wrapper" di TXvt_recordset, implementa OGNI funzione in modo tale da * + * poterlo sostituire brutalmente in qualsiasi momento così da non aver * + * problemi come durante il passaggio da ISAM a SQL (spero). * + * Se ti stai domandando perchè non è stata usata l'ereditarietà (magari con * + * un bel ": private TXvt_recordset" così da bloccare il tutto) è per bloccare * + * qualsiasi riferimento a questa classe in eventuali reimplementazioni future. * + * Preferisco scrivere un po' di codice ridondante adesso che andare a fare * + * salti mortali dopo * + ********************************************************************************/ +class SSimpleQuery +{ +protected: + TXvt_recordset _rec; + /**< Costruttore, accetta in ingresso una connessione, volendo è anche possibile impostare una query ed eseguirla. Attenzione! Non risponde se la query ha avuto un esito positivo o negativo! */ + //SSimpleQuery(P_CONN_VOID &c, const char * query = "", bool ex = false); + +public: + /**< Costruttore, non inizializza nulla, da caricare successivamente */ + SSimpleQuery() {} + /**< Costruttore, Accetta in ingresso dei parametri per la connessione, volendo è anche possibile impostare una query ed eseguirla. Attenzione! Non risponde se la query ha avuto un esito positivo o negativo! */ + SSimpleQuery(const char* db, const char* user, const char* pass, TT_driver tipoDb, const char * query = "", const bool ex = false, const bool freezed = false) : _rec(db, user, pass, tipoDb, query, ex, freezed) {} + /**< Distruttore */ + virtual ~SSimpleQuery() {} + + // Connection functions + /**< Eseguo la connessione */ + int sqConnect(const char* db, const char* user, const char* pass, TT_driver tipoDb) { return _rec.connect(db, user, pass, tipoDb); } + /* Mi scollego */ + void sqDisconnect() { _rec.disconnect(); } + /**< Esegue la commit, di default in caso di errore viene chiamato il metodo rollback() */ + const bool sqCommit(bool autoRoll = true) { return _rec.commit(); } + /**< Esegue il rollback all'ultimo commit */ + const bool sqRollback() { _rec.rollback(); } + /**< Imposto il tipo di client che utilizzo */ + void sqSetClient(int client) { _rec.setClient((TT_driver)client); } + void sqSetClient(TT_driver client) { _rec.setClient(client); } + // Imposto una opzione generica dellla connessione + void sqSetConOption(const char* opt) { _rec.setConOption(opt); } + /**< Abilito/Disabilito l'autocommit, (disabilitato di default) */ + void sqSetAutocommit(bool ac) { _rec.setAutocommit(ac); } + /** Imposta la visibilità delle transazioni (vedi Funzione) */ + void sqSetVisibility(isoLvl vis = committed) { _rec.setVisibility(vis); } + // Getters + /** Ritorna se la conessione è connessa */ + const bool sqIsConnect() const { return _rec.isConnect(); } + /**< Ritorna se la connessione è attiva */ + const bool sqIsAlive() const { return _rec.isAlive(); } + /** Ritorna la visibilità impostata */ + const int sqGetVisibility() { return _rec.getVisibility(); } + /**< Ritorna se è attivo l'autocommit, true -> attivo, false -> disattivo o sconosciuto */ + const bool sqGetAutocommit() { return _rec.getAutocommit(); } + /**< Ritorna il valore dell'opzione specificata */ + const char* sqGetOption(const char* opt) { return _rec.getOption(opt); } + /**< Ritorno la versione del Client che sto utilizzando */ + const long sqGetClientV() { return _rec.getClientV(); } + /**< Ritorno la versione del Server che sto utilizzando */ + const char* sqGetServerV() { return _rec.getServerV(); } + /**< Ritorno la versione del Server che sto utilizzando in formato numerico */ + const long sqGetServerVN() { return _rec.getServerVN(); } + /**< Ritorno se il recordset è carico */ + const bool sqIsLoaded() const { return _rec.isLoaded(); } + /** Ritorno il numero di elementi nella query */ + const long sqItems() { _rec.items(); } + + // Conguration + /**< Imposta la query ricevuta come (const char *) nel recordset */ + bool sqSet(const char* query) { return _rec.set(query); } + /**< Imposta la query ricevuta come (string) nel recordset */ + bool sqSet(string query) { return _rec.set(query.c_str()); } + /**< Imposta la query ricevuta come (TString) nel recordset */ + bool sqSet(TString& query) { return _rec.set(static_cast(query)); } + /**< Esegue la query impostata nel recordset, se viene passato autoF == true esegue anche un comando sqNext() */ + bool sqExec(bool autoF = true) { return _rec.exec(autoF); } + /**< Unisce le funzioni sqSet e sqExec, riceve la query come (const char *) */ + bool sqSetExec(const char* query, bool autoF = true) { _rec.set(query); return _rec.exec(autoF); } + /**< Unisce le funzioni sqSet e sqExec, riceve la query come (string) */ + bool sqSetExec(string query, bool autoF = true) { _rec.set(query.c_str()); return _rec.exec(autoF); } + /**< Unisce le funzioni sqSet e sqExec, riceve la query come (TString) */ + bool sqSetExec(TString& query, bool autoF = true); + /**< Si sposta avanti di un record, in caso di esito negativo valorizza _stringError e _codeError */ + bool sqNext() { return _rec.next(); } + /**< Si sposta indietro di un record, in caso di esito negativo valorizza _stringError e _codeError */ + bool sqPrev() { return _rec.prev(); } + /**< Si sposta avanti di un record, in caso di esito negativo valorizza _stringError e _codeError */ + bool sqFirst() { return _rec.first(); } + /**< Si sposta al primo record, in caso di esito negativo valorizza _stringError e _codeError */ + bool sqLast() { return _rec.last(); } + /**< Si sposta alla posizione n, in caso di esito negativo valorizza _stringError e _codeError */ + bool sqGo(int newPos) { return _rec.go(newPos); } + /**< Ritorna il numero di righe affette dall'ultima query */ + const int sqRowsAffected() { return _rec.rowsAffected(); } + + + // Getters + /**< Ritorna il valore nel campo (field) in formato (int) */ + int sqGetInt(const char* field) { return _rec.get_int(field); } + /**< Ritorna il valore nel campo (field) in formato (short) */ + short sqGetShort(const char* field) { return _rec.get_short(field); } + /**< Ritorna il valore nel campo (field) in formato (long) */ + long sqGetLong(const char* field) { return _rec.get_long(field); } + /**< Ritorna il valore nel campo (field) in formato (double) */ + double sqGetDouble(const char* field) { return _rec.get_double(field); } + /**< Ritorna il valore nel campo (field) in formato (bool) */ + bool sqGetBool(const char* field) { return _rec.get_bool(field); } + /**< Ritorna il valore nel campo (field) in formato (TDate) */ + TDate sqGetDate(const char* field); + /**< Ritorna il valore nel campo (field) in formato (real) */ + real sqGetReal(const char* field); + /**< Ritorna il valore nel campo (field) in formato (SADateTime), Campo non gestisce le ore */ + //SADateTime sqGetDateTime(const char* field) { get_short(field); } + /**< Ritorna il valore nel campo (field) passato come (const char *) in formato (const char *) */ + const char* sqGet(const char* field) { return _rec.get(field); } + /**< Ritorna il valore nel campo (field) passato come (string) in formato (const char *) */ + const char* sqGet(string field) { return _rec.get(field.c_str()); } + /**< Ritorna il valore nel campo (field) passato come (TString) in formato (const char *) */ + const char* sqGet(TString& field) { return _rec.get(static_cast(field)); } + /**< Ritorna il valore nel campo (field) in formato (char) */ + char sqGetChar(const char* field) { return _rec.get_char(field); } + /**< Ritorna la posizione attuale */ + long sqPos() const { return _rec.pos(); } + + // Error Getters + /**< Ritorno l'ultimo codice errore segnalato in formato /int) */ + long sqGetCodeError(bool erase = true) { return _rec.get_code_error(erase); } + /**< Ritorno l'ultima stringa di errore segnalato in formato (const char *) */ + const char* sqGetStringError(bool erase = true) { return _rec.get_string_error(erase); } + //char * getCharPointer(const char * field) { return const_cast(static_cast(recset.Field(field).asString())); } +}; + +#endif \ No newline at end of file diff --git a/src/include/ttools.cpp b/src/include/ttools.cpp new file mode 100644 index 000000000..ee4d01668 --- /dev/null +++ b/src/include/ttools.cpp @@ -0,0 +1,13 @@ +#include + + +std::string toString(long int n) +{ +#if __cplusplus < 201103 + std::stringstream elPollo; + elPollo << n; + return elPollo.str(); +#else + return std::to_string(n); +#endif // __cplusplus < 201103 +} diff --git a/src/include/ttools.h b/src/include/ttools.h new file mode 100644 index 000000000..eafb7d905 --- /dev/null +++ b/src/include/ttools.h @@ -0,0 +1,14 @@ +/********************************************************************************** + * Tolla Tools! Set di funzioni utili implementate per la nuova Release di Campo * + **********************************************************************************/ +#ifndef __TTOOLS_H +#define __TTOOLS_H + +#include +#include + +/**< Trasforma un int in una string +* Questa funzione capisce la versione di C++ che si sta utilizzando e ritorna il risultato corretto */ +std::string toString(long int n); + +#endif // !__TTOOLS_H \ No newline at end of file