186 lines
10 KiB
C
186 lines
10 KiB
C
|
/**********************************************************************************
|
|||
|
* ######\ *
|
|||
|
* ## __##\ *
|
|||
|
* ## / \__| ######\ ######\####\ ######\ ######\ *
|
|||
|
* ## | \____##\ ## _## _##\ ## __##\ ## __##\ *
|
|||
|
* ## | ####### |## / ## / ## |## / ## |## / ## | *
|
|||
|
* ## | ##\ ## __## |## | ## | ## |## | ## |## | ## | *
|
|||
|
* \###### |\####### |## | ## | ## |####### |\###### | *
|
|||
|
* \______/ \_______|\__| \__| \__|## ____/ \______/ *
|
|||
|
* ## | *
|
|||
|
* ## | *
|
|||
|
* \__| *
|
|||
|
**********************************************************************************/
|
|||
|
|
|||
|
|
|||
|
/********************************************************************************************************************************
|
|||
|
* 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<EFBFBD> famosi DB attualmente esistenti) *
|
|||
|
********************************************************************************************************************************/
|
|||
|
|
|||
|
#ifndef __TSDB_H
|
|||
|
#define __TSDB_H
|
|||
|
|
|||
|
#ifndef __XVTDB_H
|
|||
|
#include <xvtdb.h>
|
|||
|
#endif
|
|||
|
|
|||
|
|
|||
|
// Tolla tools
|
|||
|
#ifndef __TTOOLS_H
|
|||
|
#include <ttools.h>
|
|||
|
#endif
|
|||
|
|
|||
|
#ifndef __STRINGS_H
|
|||
|
#include <strings.h>
|
|||
|
#endif // !__STRINGS_H
|
|||
|
|
|||
|
#ifndef __DATE_H
|
|||
|
#include <date.h>
|
|||
|
#endif // !__DATE_H
|
|||
|
|
|||
|
#ifndef __REAL_H
|
|||
|
#include <real.h>
|
|||
|
#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<EFBFBD> da non aver *
|
|||
|
* problemi come durante il passaggio da ISAM a SQL (spero). *
|
|||
|
* Se ti stai domandando perch<EFBFBD> non <EFBFBD> stata usata l'ereditariet<EFBFBD> (magari con *
|
|||
|
* un bel ": private TXvt_recordset" cos<EFBFBD> da bloccare il tutto) <EFBFBD> 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 <20> 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 <20> 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<69> delle transazioni (vedi Funzione) */
|
|||
|
void sqSetVisibility(isoLvl vis = committed) { _rec.setVisibility(vis); }
|
|||
|
// Getters
|
|||
|
/** Ritorna se la conessione <20> connessa */
|
|||
|
const bool sqIsConnect() const { return _rec.isConnect(); }
|
|||
|
/**< Ritorna se la connessione <20> attiva */
|
|||
|
const bool sqIsAlive() const { return _rec.isAlive(); }
|
|||
|
/** Ritorna la visibilit<69> impostata */
|
|||
|
const int sqGetVisibility() { return _rec.getVisibility(); }
|
|||
|
/**< Ritorna se <20> 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 <20> 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<const char *>(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<const char*>(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<char*>(static_cast<const char*>(recset.Field(field).asString())); }
|
|||
|
};
|
|||
|
|
|||
|
#endif
|