245 lines
9.6 KiB
C++
245 lines
9.6 KiB
C++
#pragma once
|
||
|
||
#ifndef __XVTDB_H
|
||
#define __XVTDB_H
|
||
|
||
#include "xvtdb_errors.h"
|
||
|
||
#if defined(DBDLL_EXPORT)
|
||
# define DBDLL __declspec(dllexport)
|
||
#else
|
||
# define DBDLL __declspec(dllimport)
|
||
#endif // DBDLL_EXPORT
|
||
|
||
#define SQLAPIV "SQLAPI++ 4.1.5" // Da tenere aggiornato
|
||
|
||
enum TT_driver
|
||
{
|
||
//! DBMS client is not specified
|
||
TSDB_undefined,
|
||
//! ODBC
|
||
TSDB_ODBC,
|
||
//! Oracle
|
||
TSDB_Oracle,
|
||
//! Microsoft SQL Server
|
||
TSDB_MSSQL,
|
||
//! InterBase or Firebird
|
||
TSDB_InterBase,
|
||
//! SQLBase
|
||
TSDB_SQLBase,
|
||
//! IBM DB2
|
||
TSDB_DB2,
|
||
//! Informix
|
||
TSDB_Informix,
|
||
//! Sybase ASE
|
||
TSDB_Sybase,
|
||
//! MySQL
|
||
TSDB_MySQL,
|
||
//! PostgreSQL
|
||
TSDB_PostgreSQL,
|
||
//! SQLite
|
||
TSDB_SQLite,
|
||
//! SQL Anywere
|
||
TSDB_SQLAnywhere
|
||
};
|
||
|
||
enum iso_lvl { unknown = -1, uncommitted, committed, rr, serializable };
|
||
|
||
#define P_CONN_VOID void *
|
||
#define P_COMM_VOID void *
|
||
|
||
long xvt_rcs_get_items(P_CONN_VOID con, const char* query);
|
||
/******************************************************************************
|
||
* TXvt_recordset : DataBase redcordset *
|
||
* Wrapper base di SACommand e SAConnection, classe per l'esecuzione di query *
|
||
* permette una connessione a vari DB tramite molteplici drivers *
|
||
******************************************************************************/
|
||
class DBDLL TXvt_recordset
|
||
{
|
||
protected:
|
||
/**< Recordset */
|
||
P_COMM_VOID _recset;
|
||
/**< Oggetto della connessione */
|
||
P_CONN_VOID _con;
|
||
/**< Database */
|
||
const char* _db;
|
||
/**< Utente */
|
||
const char* _usr;
|
||
/**< Password */
|
||
const char* _psw;
|
||
/**< Driver */
|
||
TT_driver _drv;
|
||
/**< Query */
|
||
const char* _query{};
|
||
/**< Ultima stringa con codice di errore ricevuto */
|
||
const char* _string_error;
|
||
/**< Ultima stringa con codice di errore ricevuto full text */
|
||
const char* _string_error_full_text;
|
||
/**< Ultimo codice di errore ricevuto */
|
||
long _code_error;
|
||
/**< Numero record corrente */
|
||
long _recno;
|
||
/**< Indica se l'oggetto <20> bloccato, in tal caso non si possono fare set/exec */
|
||
bool _freezed;
|
||
/**< Indica se il cursore <20> caricato */
|
||
bool _loaded;
|
||
|
||
const bool check_permission();
|
||
|
||
private:
|
||
// Disabilito il copy constructor
|
||
TXvt_recordset(const TXvt_recordset& nope);
|
||
|
||
public:
|
||
/**< Costruttore, crea un oggetto vuoto, PERICOLOSO!! Ricordarsi di inizializzarlo opportunamente con il metodo connect() e set() */
|
||
TXvt_recordset();
|
||
/**< Costruttore, crea un oggetto dai parametri di connessione passati */
|
||
TXvt_recordset(const char* db, const char* user, const char* pass, TT_driver tipo_db, const char * query = "", const bool ex = false, const bool freezed = false);
|
||
static TT_driver str_to_driver(const char* tipo_db);
|
||
/**< Costruttore, crea un oggetto dai parametri di connessione passati, chiama costruttore con TT_driver */
|
||
TXvt_recordset(const char* db, const char* user, const char* pass, const char* tipo_db, const char * query = "", const bool ex = false, const bool freezed = false);
|
||
/**< Distruttore */
|
||
~TXvt_recordset();
|
||
|
||
/**************************************************************************************************
|
||
* Gestione Connection *
|
||
**************************************************************************************************/
|
||
|
||
// Funzioni fondamentali
|
||
|
||
/**< Eseguo la connessione
|
||
* Esempio parametri da passare con MSSQL:
|
||
* db = SERVER@DATABASE (NBKDELLI7TOLLAR\MSSQLSERVER14@project_vahlalla)
|
||
* user = Piero
|
||
* pass = Angela
|
||
* driver = TSDB_MSSQL
|
||
*/
|
||
int connect(const char* db, const char* user, const char* pass, TT_driver tipo_db);
|
||
/* Mi scollego */
|
||
void disconnect();
|
||
/**< Esegue la commit, di default in caso di errore viene chiamato il metodo rollback() */
|
||
bool commit(bool auto_roll = true);
|
||
/**< Esegue il rollback all'ultimo commit */
|
||
bool rollback();
|
||
|
||
// Setters
|
||
|
||
/**< Imposto il tipo di client che utilizzo */
|
||
void set_client(TT_driver client) const;
|
||
// Imposto una opzione generica dellla connessione
|
||
void set_con_option(const char* opt, const char* val) const;
|
||
/**< Abilito/Disabilito l'autocommit, (disabilitato di default) */
|
||
void set_autocommit(bool ac) const;
|
||
/**< Imposta la visibilit<69> delle transazioni (vedi Funzione) */
|
||
void set_visibility(iso_lvl vis = committed);
|
||
|
||
|
||
// Getters
|
||
/**< Ritorna se la conessione <20> connessa */
|
||
const bool is_connect() const;
|
||
/**< Ritorna se la connessione <20> attiva */
|
||
const bool is_alive() const;
|
||
/**< Ritorna la visibilit<69> impostata */
|
||
int get_visibility() const;
|
||
/**< Ritorna se <20> attivo l'autocommit, true -> attivo, false -> disattivo o sconosciuto */
|
||
bool get_autocommit() const;
|
||
/**< Ritorna il valore dell'opzione specificata */
|
||
const char* get_option(const char* opt) const;
|
||
/**< Ritorno la versione del Client che sto utilizzando */
|
||
long get_client_v() const;
|
||
/**< Ritorno la versione del Server che sto utilizzando */
|
||
const char* get_server_v() const;
|
||
/**< Ritorno la versione del Server che sto utilizzando in formato numerico */
|
||
long get_server_vn() const;
|
||
/**< Ritorno se il recordset <20> carico */
|
||
bool is_loaded() const;
|
||
/**< Ritorno il numero di elementi nella query */
|
||
long items();
|
||
|
||
/**************************************************************************************************
|
||
* Gestione Recordset *
|
||
**************************************************************************************************/
|
||
|
||
// Conguration
|
||
/**< Imposta la query ricevuta nel recordset */
|
||
bool set(const char* query);
|
||
/**< Esegue la query impostata nel recordset, se viene passato autoF == true esegue anche un comando Next() */
|
||
bool exec(bool auto_f = true);
|
||
/**< Unisce le funzioni Set e Exec, riceve la query */
|
||
bool set_exec(const char* query, bool auto_f = true);
|
||
/**< Si sposta avanti di un record, in caso di esito negativo valorizza _stringError e _codeError */
|
||
bool next();
|
||
/**< Si sposta indietro di un record, in caso di esito negativo valorizza _stringError e _codeError */
|
||
bool prev();
|
||
/**< Si sposta avanti di un record, in caso di esito negativo valorizza _stringError e _codeError */
|
||
bool first();
|
||
/**< Si sposta al primo record, in caso di esito negativo valorizza _stringError e _codeError */
|
||
bool last();
|
||
/**< Si sposta alla posizione n, in caso di esito negativo valorizza _stringError e _codeError */
|
||
bool go(int new_pos);
|
||
/**< Ritorna il numero di righe affette dall'ultima query */
|
||
const int rows_affected() const;
|
||
|
||
// Getters
|
||
/**< Ritorna il valore nel campo (field) in formato (int) */
|
||
int get_int(const char* field);
|
||
/**< Ritorna il valore nel campo (field) in formato (short) */
|
||
short get_short(const char* field);
|
||
/**< Ritorna il valore nel campo (field) in formato (long) */
|
||
long get_long(const char* field);
|
||
/**< Ritorna il valore nel campo (field) in formato (double) */
|
||
double get_double(const char* field);
|
||
/**< Ritorna il valore nel campo (field) in formato (bool) */
|
||
bool get_bool(const char* field);
|
||
/**< Ritorna il valore nel campo (field) in formato (const char *)->(DD-MM-YYYY) */
|
||
const char* get_date(const char* field);
|
||
/**< Ritorna il valore nel campo (field) passato in formato (const char *) */
|
||
const char* get(const char* field);
|
||
/**< Ritorna il valore del campo numero (field) passato, in formato (const char *) */
|
||
const char* get(unsigned int field);
|
||
/**< Ritorna il valore nel campo (field) in formato (char) */
|
||
char get_char(const char* field);
|
||
/**< Ritorna il numero di campi dopo l'ultimo comando di esecuzione effettuato; se il risultato esiste */
|
||
int get_num_fields() const;
|
||
/**< Ritorna il nome del campo numero (column) */
|
||
const char* get_name_field(unsigned column) const;
|
||
/**< Ritorna la grandezza del campo numero (column) */
|
||
int get_width_field(unsigned column) const;
|
||
/**< Ritorna il tipo del campo numero (column) */
|
||
const char* get_type_field(unsigned column) const;
|
||
/**< Ritorna la precisione del campo numero (column) */
|
||
int get_precision_field(unsigned column) const;
|
||
/**< Ritorna il numero di cifre dopo la virgola del campo numero (column) */
|
||
int get_scale_field(unsigned column) const;
|
||
/**< Ritorna la posizione attuale */
|
||
long pos() const { return _recno; }
|
||
|
||
// Error Handling
|
||
/**< Ritorno l'ultimo codice errore segnalato in formato numerico) */
|
||
long get_code_error(bool erase = true);
|
||
/**< Ritorno l'ultima stringa di errore segnalato in formato (const char *) */
|
||
const char* get_string_error(bool erase = true);
|
||
/**< Ritorno l'ultima stringa di errore (full text) segnalato in formato (const char *) */
|
||
const char* get_text_error(bool erase = true);
|
||
//char * getCharPointer(const char * field) { return const_cast<char*>(static_cast<const char*>(recset.Field(field).asString())); }
|
||
|
||
// Utilities
|
||
/**< Controlla se il cursore <20> bloccato */
|
||
const bool is_freezed() const { return _freezed; }
|
||
/**< Congela il cursore */
|
||
void freeze() { _freezed = true; }
|
||
/**< Scongela il cursore */
|
||
void defrost() { _freezed = false; }
|
||
|
||
/* Funzioni tenute per compatibilt<6C>: */
|
||
/**< Scongela il cursore */
|
||
void unfreeze() { defrost(); }
|
||
/**< Ritornano se <20> congelato o meno, attenzione: i valori di ritorno non sono const!*/
|
||
bool frozen() const { return is_freezed(); }
|
||
bool not_frozen() const { return !is_freezed(); }
|
||
/**< Imposta l'errore di record congelato */
|
||
const bool set_error_freezed();
|
||
};
|
||
|
||
|
||
#endif |