2017-10-26 10:28:19 +00:00
|
|
|
|
#include "xvtdb.h"
|
|
|
|
|
#include <sqlapi.h>
|
2018-02-09 13:29:55 +00:00
|
|
|
|
#include <string> // sprintf_s
|
2017-10-26 10:28:19 +00:00
|
|
|
|
|
|
|
|
|
#define _CON(a) ((SAConnection *)a)
|
|
|
|
|
#define _RCS(a) ((SACommand *)a)
|
|
|
|
|
#define _ERR(a) ((SAException *)a)
|
|
|
|
|
|
2018-12-11 14:16:34 +01:00
|
|
|
|
#define _CPY_STR(from,to) (to = strdup(from));
|
|
|
|
|
#define _GET_ERROR(from,to) _CPY_STR(from,to)
|
|
|
|
|
|
|
|
|
|
|
2017-10-26 10:28:19 +00:00
|
|
|
|
/******************************************************************************
|
2018-02-09 13:29:55 +00:00
|
|
|
|
* TXvt_recordset *
|
2017-10-26 10:28:19 +00:00
|
|
|
|
* Classe per esecuzioni di query temporanee (wrapper semplice per SACommand) *
|
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
2018-07-06 16:30:37 +02:00
|
|
|
|
TXvt_recordset::TXvt_recordset() : _freezed(false)
|
2017-10-26 10:28:19 +00:00
|
|
|
|
{
|
|
|
|
|
_con = new SAConnection;
|
|
|
|
|
_recset = new SACommand;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_RCS(_recset)->setConnection(_CON(_con));
|
|
|
|
|
}
|
|
|
|
|
catch (SAException &x)
|
|
|
|
|
{
|
2019-02-11 14:47:45 +01:00
|
|
|
|
_code_error = x.ErrNativeCode();
|
|
|
|
|
_GET_ERROR(x.ErrMessage(), _string_error);
|
|
|
|
|
_GET_ERROR(x.ErrText(), _string_error_full_text);
|
2017-10-26 10:28:19 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TXvt_recordset::TXvt_recordset(const char* db, const char* user, const char* pass, TT_driver tipoDb, const char * query, const bool ex, const bool freezed)
|
2018-07-06 16:30:37 +02:00
|
|
|
|
: _db(db), _usr(user), _psw(pass), _drv(tipoDb), _freezed(false)
|
2017-10-26 10:28:19 +00:00
|
|
|
|
{
|
|
|
|
|
_con = new SAConnection;
|
2018-02-09 13:29:55 +00:00
|
|
|
|
if(connect(db, user, pass, tipoDb) == NOERR)
|
2017-10-26 10:28:19 +00:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_recset = new SACommand;
|
|
|
|
|
_RCS(_recset)->setConnection(_CON(_con));
|
|
|
|
|
// if (query[0] != '\0')
|
|
|
|
|
if (query && *query)
|
|
|
|
|
{
|
|
|
|
|
set(query);
|
|
|
|
|
if (ex)
|
|
|
|
|
{
|
|
|
|
|
exec();
|
|
|
|
|
// Terribile da vedere, ma ho fatto una funzione apposta e la voglio usare per Diana!
|
|
|
|
|
if(freezed)
|
|
|
|
|
freeze();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (SAException &x)
|
|
|
|
|
{
|
2019-02-11 14:47:45 +01:00
|
|
|
|
_code_error = x.ErrNativeCode();
|
|
|
|
|
_GET_ERROR(x.ErrMessage(), _string_error);
|
|
|
|
|
_GET_ERROR(x.ErrText(), _string_error_full_text);
|
2017-10-26 10:28:19 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TXvt_recordset::~TXvt_recordset()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2018-07-06 16:30:37 +02:00
|
|
|
|
// Se non <20> connesso viene lanciata l'eccezione
|
2018-02-09 13:29:55 +00:00
|
|
|
|
if(_CON(_con)->isConnected())
|
2017-10-26 10:28:19 +00:00
|
|
|
|
_CON(_con)->Disconnect();
|
|
|
|
|
}
|
2018-02-09 13:29:55 +00:00
|
|
|
|
catch (...) {}
|
2018-07-06 16:30:37 +02:00
|
|
|
|
// Prima cancellare il recordset POI la connessione
|
|
|
|
|
delete _recset;
|
|
|
|
|
delete _con;
|
2017-10-26 10:28:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* PRIVATE FUNCTIONS **************************************************************************************************/
|
|
|
|
|
|
|
|
|
|
const bool TXvt_recordset::checkPermission()
|
|
|
|
|
{
|
2018-02-09 13:29:55 +00:00
|
|
|
|
bool err = is_freezed();
|
|
|
|
|
if (err)
|
|
|
|
|
setErrorFreezed();
|
2017-10-26 10:28:19 +00:00
|
|
|
|
return !err;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* PUBLIC FUNCTIONS **************************************************************************************************/
|
|
|
|
|
|
|
|
|
|
/**************************************************************************************************
|
|
|
|
|
* Gestione Connection *
|
|
|
|
|
**************************************************************************************************/
|
|
|
|
|
|
|
|
|
|
int TXvt_recordset::connect(const char* db, const char* user, const char* pass, TT_driver tipoDb)
|
|
|
|
|
{
|
2018-02-09 13:29:55 +00:00
|
|
|
|
if (_con != NULL)
|
|
|
|
|
{
|
|
|
|
|
// Se <20> gi<67> connesso lo scollego
|
|
|
|
|
if (_CON(_con)->isConnected())
|
|
|
|
|
_CON(_con)->Disconnect();
|
|
|
|
|
|
|
|
|
|
SAString dbAddress = db;
|
|
|
|
|
SAString usr = user;
|
|
|
|
|
SAString psw = pass;
|
|
|
|
|
SAClient_t dbDriver = (SAClient_t)tipoDb;
|
|
|
|
|
if (dbAddress.IsEmpty() || usr.IsEmpty())
|
|
|
|
|
{
|
2019-02-11 14:47:45 +01:00
|
|
|
|
_code_error = NOT_INITIALIZED;
|
|
|
|
|
_string_error = NOT_INITIALIZEDS;
|
2018-02-09 13:29:55 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
// Mi collego
|
|
|
|
|
_CON(_con)->Connect(dbAddress, usr, psw, dbDriver);
|
|
|
|
|
// Imposto che non si possono vedere i record non committati
|
|
|
|
|
_CON(_con)->setIsolationLevel(SA_ReadCommitted);
|
|
|
|
|
return NOERR;
|
|
|
|
|
}
|
|
|
|
|
catch (SAException &x)
|
|
|
|
|
{
|
2019-02-11 14:47:45 +01:00
|
|
|
|
_code_error = x.ErrNativeCode();
|
|
|
|
|
_GET_ERROR(x.ErrMessage(), _string_error);
|
|
|
|
|
_GET_ERROR(x.ErrText(), _string_error_full_text);
|
2018-02-09 13:29:55 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2019-02-11 14:47:45 +01:00
|
|
|
|
_code_error = NOT_INITIALIZED;
|
|
|
|
|
_string_error = NOT_INITIALIZEDS;
|
2018-02-09 13:29:55 +00:00
|
|
|
|
}
|
2019-02-11 14:47:45 +01:00
|
|
|
|
return _code_error;
|
2017-10-26 10:28:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TXvt_recordset::disconnect()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_CON(_con)->Disconnect();
|
|
|
|
|
}
|
|
|
|
|
catch(SAException &x)
|
|
|
|
|
{
|
2019-02-11 14:47:45 +01:00
|
|
|
|
_code_error = x.ErrNativeCode();
|
|
|
|
|
_GET_ERROR(x.ErrMessage(), _string_error);
|
|
|
|
|
_GET_ERROR(x.ErrText(), _string_error_full_text);
|
2017-10-26 10:28:19 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TXvt_recordset::commit(bool autoRoll)
|
|
|
|
|
{
|
2018-02-09 13:29:55 +00:00
|
|
|
|
CHECK_FREEZED
|
2017-10-26 10:28:19 +00:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_CON(_con)->Commit();
|
|
|
|
|
}
|
|
|
|
|
catch (SAException &x)
|
|
|
|
|
{
|
|
|
|
|
if (autoRoll)
|
|
|
|
|
{
|
|
|
|
|
rollback();
|
|
|
|
|
}
|
2019-02-11 14:47:45 +01:00
|
|
|
|
_code_error = x.ErrNativeCode();
|
|
|
|
|
_GET_ERROR(x.ErrMessage(), _string_error);
|
|
|
|
|
_GET_ERROR(x.ErrText(), _string_error_full_text);
|
2017-10-26 10:28:19 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TXvt_recordset::rollback()
|
|
|
|
|
{
|
2018-02-09 13:29:55 +00:00
|
|
|
|
CHECK_FREEZED
|
2017-10-26 10:28:19 +00:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_CON(_con)->Rollback();
|
|
|
|
|
}
|
|
|
|
|
catch (SAException &x)
|
|
|
|
|
{
|
2019-02-11 14:47:45 +01:00
|
|
|
|
_code_error = x.ErrNativeCode();
|
|
|
|
|
_GET_ERROR(x.ErrMessage(), _string_error);
|
|
|
|
|
_GET_ERROR(x.ErrText(), _string_error_full_text);
|
2017-10-26 10:28:19 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TXvt_recordset::setClient(TT_driver client)
|
|
|
|
|
{
|
|
|
|
|
_CON(_con)->setClient((SAClient_t) client);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TXvt_recordset::setConOption(const char* opt)
|
|
|
|
|
{
|
|
|
|
|
_CON(_con)->setOption(opt);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TXvt_recordset::setAutocommit(bool ac)
|
|
|
|
|
{
|
|
|
|
|
_CON(_con)->setAutoCommit(ac ? SA_AutoCommitOn : SA_AutoCommitOff);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TXvt_recordset::setVisibility(isoLvl vis)
|
|
|
|
|
{
|
|
|
|
|
/* La libreria attuale supporta diversi tipi di visibilit<69>, per mantenere una compatibilit<69> massima
|
|
|
|
|
* (evitando inutili seghe mentali) consiglio di usare i primi due, di default la classe imposta "Read committed"
|
|
|
|
|
* Tipi di isolazione:
|
|
|
|
|
* 0 -> Read uncommitted.
|
|
|
|
|
* 1 -> Read committed.
|
|
|
|
|
* 2 -> Repeatable read.
|
|
|
|
|
* 3 -> Serializable.
|
|
|
|
|
*/
|
|
|
|
|
_CON(_con)->setIsolationLevel((SAIsolationLevel_t)vis);
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-09 13:29:55 +00:00
|
|
|
|
const bool TXvt_recordset::isConnect() const
|
2017-10-26 10:28:19 +00:00
|
|
|
|
{
|
|
|
|
|
return _CON(_con)->isConnected();
|
|
|
|
|
}
|
2018-02-09 13:29:55 +00:00
|
|
|
|
const bool TXvt_recordset::isAlive() const
|
2017-10-26 10:28:19 +00:00
|
|
|
|
{
|
|
|
|
|
return _CON(_con)->isAlive();
|
|
|
|
|
}
|
|
|
|
|
int TXvt_recordset::getVisibility()
|
|
|
|
|
{
|
|
|
|
|
return (isoLvl)_CON(_con)->IsolationLevel();
|
|
|
|
|
}
|
|
|
|
|
bool TXvt_recordset::getAutocommit()
|
|
|
|
|
{
|
|
|
|
|
return _CON(_con)->AutoCommit() == SA_AutoCommitOn;
|
|
|
|
|
}
|
|
|
|
|
const char* TXvt_recordset::getOption(const char* opt)
|
|
|
|
|
{
|
|
|
|
|
return _CON(_con)->Option(opt);
|
|
|
|
|
}
|
|
|
|
|
long TXvt_recordset::getClientV()
|
|
|
|
|
{
|
|
|
|
|
return _CON(_con)->ClientVersion();
|
|
|
|
|
}
|
|
|
|
|
const char* TXvt_recordset::getServerV()
|
|
|
|
|
{
|
|
|
|
|
return _CON(_con)->ServerVersionString();
|
|
|
|
|
}
|
|
|
|
|
long TXvt_recordset::getServerVN()
|
|
|
|
|
{
|
|
|
|
|
return _CON(_con)->ServerVersion();
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-09 13:29:55 +00:00
|
|
|
|
bool TXvt_recordset::isLoaded() const
|
|
|
|
|
{
|
|
|
|
|
return _loaded;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
long TXvt_recordset::items()
|
|
|
|
|
{
|
|
|
|
|
// Per non creare casini utilizzo una funzione apposita che mi ritorna il numero
|
|
|
|
|
P_CONN_VOID conn = new SAConnection;
|
|
|
|
|
char q[500];
|
|
|
|
|
long items;
|
|
|
|
|
|
|
|
|
|
// Connetto la nuova istanza
|
|
|
|
|
_CON(conn)->Connect(_db, _usr, _psw, (SAClient_t)_drv);
|
|
|
|
|
|
|
|
|
|
// Controllo sia tutto a posto
|
|
|
|
|
|
|
|
|
|
// Creo la query
|
|
|
|
|
strcat_s(q, sizeof(q), "SELECT COUNT(*) ");
|
|
|
|
|
strcat_s(q, sizeof(q), (strstr(_query, "FROM") != NULL ? strstr(_query, "FROM") : strstr(_query, "from"))); // Serve?
|
|
|
|
|
|
|
|
|
|
items = xvt_rcs_get_items(conn, q);
|
|
|
|
|
if(conn != _con)
|
|
|
|
|
delete conn;
|
|
|
|
|
return items;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
long xvt_rcs_get_items(P_CONN_VOID con, const char* query)
|
|
|
|
|
{
|
|
|
|
|
P_COMM_VOID rcs = new SACommand(_CON(con));
|
|
|
|
|
_RCS(rcs)->setCommandText(query);
|
|
|
|
|
long r = 0;
|
|
|
|
|
for(bool ok = _RCS(rcs)->FetchFirst(); ok; ok = _RCS(rcs)->FetchNext())
|
|
|
|
|
r++;
|
|
|
|
|
delete rcs;
|
|
|
|
|
return r;
|
|
|
|
|
}
|
2017-10-26 10:28:19 +00:00
|
|
|
|
|
|
|
|
|
/**************************************************************************************************
|
|
|
|
|
* Gestione Recordset *
|
|
|
|
|
**************************************************************************************************/
|
|
|
|
|
bool TXvt_recordset::set(const char* query)
|
|
|
|
|
{
|
2018-02-09 13:29:55 +00:00
|
|
|
|
CHECK_FREEZED
|
2017-10-26 10:28:19 +00:00
|
|
|
|
try
|
|
|
|
|
{
|
2018-02-09 13:29:55 +00:00
|
|
|
|
_query = query;
|
2017-10-26 10:28:19 +00:00
|
|
|
|
_RCS(_recset)->setCommandText(query);
|
|
|
|
|
}
|
|
|
|
|
catch (SAException &x)
|
|
|
|
|
{
|
2019-02-11 14:47:45 +01:00
|
|
|
|
_code_error = x.ErrNativeCode();
|
|
|
|
|
_GET_ERROR(x.ErrMessage(), _string_error);
|
|
|
|
|
_GET_ERROR(x.ErrText(), _string_error_full_text);
|
2017-10-26 10:28:19 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TXvt_recordset::exec(bool autoF)
|
|
|
|
|
{
|
2018-02-09 13:29:55 +00:00
|
|
|
|
CHECK_FREEZED
|
2018-07-06 16:30:37 +02:00
|
|
|
|
bool ok = false;
|
2017-10-26 10:28:19 +00:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_RCS(_recset)->Execute();
|
|
|
|
|
_recno = -1;
|
2018-07-06 16:30:37 +02:00
|
|
|
|
// Se trovo almeno un "select" faccio l'autofetch
|
|
|
|
|
SAString s = _RCS(_recset)->CommandText(); s.MakeUpper();
|
|
|
|
|
ok = s.Find("SELECT") != SIZE_MAX && autoF ? next() : true;
|
2017-10-26 10:28:19 +00:00
|
|
|
|
}
|
|
|
|
|
catch (SAException &x)
|
|
|
|
|
{
|
2019-02-11 14:47:45 +01:00
|
|
|
|
_code_error = x.ErrNativeCode();
|
|
|
|
|
_GET_ERROR(x.ErrMessage(), _string_error);
|
|
|
|
|
_GET_ERROR(x.ErrText(), _string_error_full_text);
|
2018-07-06 16:30:37 +02:00
|
|
|
|
ok = false;
|
2017-10-26 10:28:19 +00:00
|
|
|
|
}
|
2018-07-06 16:30:37 +02:00
|
|
|
|
return ok;
|
2017-10-26 10:28:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-11-09 11:01:56 +00:00
|
|
|
|
bool TXvt_recordset::setExec(const char* query, bool autoF)
|
|
|
|
|
{
|
|
|
|
|
set(query);
|
|
|
|
|
return exec(autoF);
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-26 10:28:19 +00:00
|
|
|
|
bool TXvt_recordset::next()
|
|
|
|
|
{
|
|
|
|
|
bool fetched = false;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if(_RCS(_recset)->FetchNext())
|
|
|
|
|
{
|
|
|
|
|
fetched = true;
|
|
|
|
|
_recno++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
catch (SAException &x)
|
|
|
|
|
{
|
2019-02-11 14:47:45 +01:00
|
|
|
|
_code_error = x.ErrNativeCode();
|
|
|
|
|
_GET_ERROR(x.ErrMessage(), _string_error);
|
|
|
|
|
_GET_ERROR(x.ErrText(), _string_error_full_text);
|
2017-10-26 10:28:19 +00:00
|
|
|
|
}
|
|
|
|
|
return fetched;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TXvt_recordset::prev()
|
|
|
|
|
{
|
|
|
|
|
bool fetched = false;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (_RCS(_recset)->FetchPrior())
|
|
|
|
|
{
|
|
|
|
|
fetched = true;
|
|
|
|
|
_recno--;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (SAException &x)
|
|
|
|
|
{
|
2019-02-11 14:47:45 +01:00
|
|
|
|
_code_error = x.ErrNativeCode();
|
|
|
|
|
_GET_ERROR(x.ErrMessage(), _string_error);
|
|
|
|
|
_GET_ERROR(x.ErrText(), _string_error_full_text);
|
2017-10-26 10:28:19 +00:00
|
|
|
|
}
|
|
|
|
|
return fetched;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TXvt_recordset::first()
|
|
|
|
|
{
|
|
|
|
|
bool fetched = false;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (_RCS(_recset)->FetchFirst())
|
|
|
|
|
{
|
|
|
|
|
fetched = true;
|
|
|
|
|
_recno = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (SAException &x)
|
|
|
|
|
{
|
2019-02-11 14:47:45 +01:00
|
|
|
|
_code_error = x.ErrNativeCode();
|
|
|
|
|
_GET_ERROR(x.ErrMessage(), _string_error);
|
|
|
|
|
_GET_ERROR(x.ErrText(), _string_error_full_text);
|
2017-10-26 10:28:19 +00:00
|
|
|
|
}
|
|
|
|
|
return fetched;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TXvt_recordset::last()
|
|
|
|
|
{
|
|
|
|
|
/* La vita sarebbe molto bella se potessi chiamare la funzione FetchLast(),
|
|
|
|
|
// siccome non so la posizione del record eseguo ciclicamente Next
|
|
|
|
|
// _RCS(_recset)->FetchLast();
|
|
|
|
|
while (Next())
|
|
|
|
|
{
|
|
|
|
|
_recno++;
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
bool fetched = false;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (_RCS(_recset)->FetchLast())
|
|
|
|
|
{
|
|
|
|
|
fetched = true;
|
|
|
|
|
_recno = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (SAException &x)
|
|
|
|
|
{
|
2019-02-11 14:47:45 +01:00
|
|
|
|
_code_error = x.ErrNativeCode();
|
|
|
|
|
_GET_ERROR(x.ErrMessage(), _string_error);
|
|
|
|
|
_GET_ERROR(x.ErrText(), _string_error_full_text);
|
2017-10-26 10:28:19 +00:00
|
|
|
|
}
|
|
|
|
|
return fetched;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TXvt_recordset::go(int newPos)
|
|
|
|
|
{
|
|
|
|
|
// Controllo che la nuova posizione non sia fuori dal limite inferiore (Non so quanto <20> grande il recordset)
|
|
|
|
|
bool result = newPos >= 0 ? true : false;
|
|
|
|
|
|
|
|
|
|
// Se la posizione <20> minore mi sposto indietro
|
|
|
|
|
while (newPos < _recno && result)
|
|
|
|
|
{
|
|
|
|
|
result = prev();
|
|
|
|
|
}
|
|
|
|
|
// Se la posizione <20> maggiore mi sposto in avanti
|
|
|
|
|
while (newPos > _recno && result)
|
|
|
|
|
{
|
|
|
|
|
result = next();
|
|
|
|
|
}
|
|
|
|
|
/*
|
|
|
|
|
// Controllo finale per prevenire errori
|
|
|
|
|
if (newPos == _recno)
|
|
|
|
|
return true;
|
|
|
|
|
else
|
|
|
|
|
return false;
|
|
|
|
|
*/
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-09 13:29:55 +00:00
|
|
|
|
const int TXvt_recordset::rowsAffected()
|
|
|
|
|
{
|
|
|
|
|
return _RCS(_recset)->RowsAffected();
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-26 10:28:19 +00:00
|
|
|
|
int TXvt_recordset::get_int(const char* field)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return static_cast<int>(_RCS(_recset)->Field(field).asLong());
|
|
|
|
|
}
|
|
|
|
|
catch (SAException &x)
|
|
|
|
|
{
|
2019-02-11 14:47:45 +01:00
|
|
|
|
_code_error = x.ErrNativeCode();
|
|
|
|
|
_GET_ERROR(x.ErrMessage(), _string_error);
|
|
|
|
|
_GET_ERROR(x.ErrText(), _string_error_full_text);
|
2017-10-26 10:28:19 +00:00
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
short TXvt_recordset::get_short(const char* field)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return _RCS(_recset)->Field(field).asShort();
|
|
|
|
|
}
|
|
|
|
|
catch (SAException &x)
|
|
|
|
|
{
|
2019-02-11 14:47:45 +01:00
|
|
|
|
_code_error = x.ErrNativeCode();
|
|
|
|
|
_GET_ERROR(x.ErrMessage(), _string_error);
|
|
|
|
|
_GET_ERROR(x.ErrText(), _string_error_full_text);
|
2017-10-26 10:28:19 +00:00
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
long TXvt_recordset::get_long(const char* field)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return _RCS(_recset)->Field(field).asLong();
|
|
|
|
|
}
|
|
|
|
|
catch (SAException &x)
|
|
|
|
|
{
|
2019-02-11 14:47:45 +01:00
|
|
|
|
_code_error = x.ErrNativeCode();
|
|
|
|
|
_GET_ERROR(x.ErrMessage(), _string_error);
|
|
|
|
|
_GET_ERROR(x.ErrText(), _string_error_full_text);
|
2017-10-26 10:28:19 +00:00
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
double TXvt_recordset::get_double(const char* field)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return _RCS(_recset)->Field(field).asDouble();
|
|
|
|
|
}
|
|
|
|
|
catch (SAException &x)
|
|
|
|
|
{
|
2019-02-11 14:47:45 +01:00
|
|
|
|
_code_error = x.ErrNativeCode();
|
|
|
|
|
_GET_ERROR(x.ErrMessage(), _string_error);
|
|
|
|
|
_GET_ERROR(x.ErrText(), _string_error_full_text);
|
2017-10-26 10:28:19 +00:00
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TXvt_recordset::get_bool(const char* field)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return _RCS(_recset)->Field(field).asBool();
|
|
|
|
|
}
|
|
|
|
|
catch (SAException &x)
|
|
|
|
|
{
|
2019-02-11 14:47:45 +01:00
|
|
|
|
_code_error = x.ErrNativeCode();
|
|
|
|
|
_GET_ERROR(x.ErrMessage(), _string_error);
|
|
|
|
|
_GET_ERROR(x.ErrText(), _string_error_full_text);
|
2017-10-26 10:28:19 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/*
|
|
|
|
|
real TXvt_recordset::GetReal(const char * field)
|
|
|
|
|
{
|
|
|
|
|
return Get(field);
|
|
|
|
|
}
|
|
|
|
|
*/
|
2018-02-09 13:29:55 +00:00
|
|
|
|
const char* TXvt_recordset::get_date(const char * field)
|
2017-10-26 10:28:19 +00:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
SADateTime app = _RCS(_recset)->Field(field).asDateTime();
|
2019-02-25 12:42:51 +01:00
|
|
|
|
static char date[9];
|
|
|
|
|
sprintf_s(date, sizeof(date), "%04d%02d%02d", app.GetYear(), app.GetMonth(), app.GetDay());
|
2017-10-26 10:28:19 +00:00
|
|
|
|
return date;
|
|
|
|
|
}
|
|
|
|
|
catch (SAException &x)
|
|
|
|
|
{
|
2019-02-11 14:47:45 +01:00
|
|
|
|
_code_error = x.ErrNativeCode();
|
|
|
|
|
_GET_ERROR(x.ErrMessage(), _string_error);
|
|
|
|
|
_GET_ERROR(x.ErrText(), _string_error_full_text);
|
2017-10-26 10:28:19 +00:00
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const char* TXvt_recordset::get(const char* field)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return static_cast<const char *>(_RCS(_recset)->Field(field).asString());
|
|
|
|
|
}
|
|
|
|
|
catch (SAException &x)
|
|
|
|
|
{
|
2019-02-11 14:47:45 +01:00
|
|
|
|
_code_error = x.ErrNativeCode();
|
|
|
|
|
_GET_ERROR(x.ErrMessage(), _string_error);
|
|
|
|
|
_GET_ERROR(x.ErrText(), _string_error_full_text);
|
2017-10-26 10:28:19 +00:00
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
char TXvt_recordset::get_char(const char* field)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return _RCS(_recset)->Field(field).asString()[0];
|
|
|
|
|
}
|
|
|
|
|
catch (SAException &x)
|
|
|
|
|
{
|
2019-02-11 14:47:45 +01:00
|
|
|
|
_code_error = x.ErrNativeCode();
|
|
|
|
|
_GET_ERROR(x.ErrMessage(), _string_error);
|
|
|
|
|
_GET_ERROR(x.ErrText(), _string_error_full_text);
|
2017-10-26 10:28:19 +00:00
|
|
|
|
return '\0';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-09 13:29:55 +00:00
|
|
|
|
long TXvt_recordset::get_code_error(bool erase)
|
2017-10-26 10:28:19 +00:00
|
|
|
|
{
|
2019-02-11 14:47:45 +01:00
|
|
|
|
long app = _code_error;
|
2017-10-26 10:28:19 +00:00
|
|
|
|
if (erase)
|
2019-02-11 14:47:45 +01:00
|
|
|
|
_code_error = NOERR;
|
2017-10-26 10:28:19 +00:00
|
|
|
|
return app;
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-09 13:29:55 +00:00
|
|
|
|
const char* TXvt_recordset::get_string_error(bool erase)
|
2017-10-26 10:28:19 +00:00
|
|
|
|
{
|
2018-12-11 14:16:34 +01:00
|
|
|
|
static char* app;
|
|
|
|
|
|
|
|
|
|
if (app != nullptr)
|
|
|
|
|
delete app;
|
|
|
|
|
|
2019-02-11 14:47:45 +01:00
|
|
|
|
_CPY_STR(_string_error, app);
|
|
|
|
|
|
|
|
|
|
if (erase)
|
|
|
|
|
_string_error = "";
|
|
|
|
|
return app;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const char* TXvt_recordset::get_text_error(bool erase)
|
|
|
|
|
{
|
|
|
|
|
static char* app;
|
|
|
|
|
|
|
|
|
|
if (app != nullptr)
|
|
|
|
|
delete app;
|
|
|
|
|
|
|
|
|
|
_CPY_STR(_string_error_full_text, app);
|
2018-12-11 14:16:34 +01:00
|
|
|
|
|
2017-10-26 10:28:19 +00:00
|
|
|
|
if (erase)
|
2019-02-11 14:47:45 +01:00
|
|
|
|
_string_error_full_text = "";
|
2017-10-26 10:28:19 +00:00
|
|
|
|
return app;
|
2018-02-09 13:29:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const bool TXvt_recordset::setErrorFreezed()
|
|
|
|
|
{
|
2019-02-11 14:47:45 +01:00
|
|
|
|
_code_error = ERROR_FREEZED;
|
|
|
|
|
_string_error = _string_error_full_text = ERROR_FREEZEDS;
|
2018-02-09 13:29:55 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|