Patch level : 12.0 no-patch
Files correlati : include, xvtext Commento : - Aggiunto else mancante - Sistemato TDB_recordset con funzioni mancanti - Aggiunte funzioni di supporto in TXvt_recordset e SSimple_query
This commit is contained in:
parent
e776e2256c
commit
711ecf527b
@ -740,7 +740,7 @@ TRecordset* create_recordset(const TString& sql)
|
||||
if (sql.starts_with("CSV", true))
|
||||
rex = new TCSV_recordset(sql); else
|
||||
if (sql.starts_with("AS400", true))
|
||||
rex = new TAS400_recordset(sql);
|
||||
rex = new TAS400_recordset(sql); else
|
||||
if (sql.starts_with("CONNECT", true))
|
||||
rex = new TDB_recordset(sql);
|
||||
else
|
||||
|
@ -73,7 +73,7 @@ TFieldtypes SSimple_query::sq_get_type_field(const unsigned column) const
|
||||
if (type == "dtDouble")
|
||||
return _realfld;
|
||||
if (type == "dtNumeric")
|
||||
return _realfld;
|
||||
return _rec.get_scale_field(column) ? _realfld : _intfld;
|
||||
if (type == "dtDateTime")
|
||||
return _datefld;
|
||||
if (type == "dtString")
|
||||
@ -219,7 +219,11 @@ bool TDB_recordset::set_connection(const char* conn_str) const
|
||||
// Ritorna true se si connette
|
||||
bool TDB_recordset::connect(const char * db, const char * user, const char * pass, const TT_driver tipo_db) const
|
||||
{
|
||||
return _rec->sq_connect(db, user, pass, tipo_db) == NOERR;
|
||||
const bool connected = _rec->sq_connect(db, user, pass, tipo_db) == NOERR;
|
||||
// Nel dubbio setto entrambi
|
||||
_rec->sq_set_con_option("UseDynamicCursor", "True");
|
||||
_rec->sq_set_con_option("Scrollable", "True");
|
||||
return connected;
|
||||
}
|
||||
|
||||
TT_driver TDB_recordset::str_to_driver(const char* tipo_db)
|
||||
@ -265,11 +269,16 @@ TT_driver TDB_recordset::str_to_driver(const char* tipo_db)
|
||||
return TSDB_undefined;
|
||||
}
|
||||
|
||||
void TDB_recordset::set_loaded()
|
||||
bool TDB_recordset::set_loaded()
|
||||
{
|
||||
_is_loaded = true;
|
||||
_items = _rec->sq_items();
|
||||
_ncolumns = _rec->sq_get_num_fields();
|
||||
bool ok = false;
|
||||
if (!_sql.empty() && _rec->sq_exec(false))
|
||||
{
|
||||
ok = _is_loaded = true;
|
||||
_items = _rec->sq_items();
|
||||
_ncolumns = _rec->sq_get_num_fields();
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
|
||||
void TDB_recordset::unset_loaded()
|
||||
@ -312,10 +321,8 @@ bool TDB_recordset::move_to(TRecnotype pos)
|
||||
if (pos > tot)
|
||||
row = tot;
|
||||
|
||||
if (!_is_loaded) {
|
||||
if (!_sql.empty() && ((ok = _rec->sq_exec())))
|
||||
set_loaded();
|
||||
}
|
||||
if (!_is_loaded)
|
||||
ok = set_loaded();
|
||||
|
||||
if( ok && ((ok = _rec->sq_go(row))) )
|
||||
_current_row = pos;
|
||||
@ -327,10 +334,8 @@ bool TDB_recordset::move_next()
|
||||
{
|
||||
bool ok = true;
|
||||
|
||||
if (!_is_loaded) {
|
||||
if (!_sql.empty() && ((ok = _rec->sq_exec())))
|
||||
set_loaded();
|
||||
}
|
||||
if (!_is_loaded)
|
||||
ok = set_loaded();
|
||||
|
||||
if (ok && _rec->sq_next())
|
||||
{
|
||||
@ -344,7 +349,7 @@ const TString_array TDB_recordset::get_next_row()
|
||||
{
|
||||
if (move_next())
|
||||
return get_row();
|
||||
return TArray().destroy();
|
||||
return TString_array();
|
||||
}
|
||||
|
||||
const TString_array TDB_recordset::get_row(TRecnotype n)
|
||||
@ -373,13 +378,19 @@ const TString_array TDB_recordset::get_row(TRecnotype n)
|
||||
|
||||
void TDB_recordset::requery()
|
||||
{
|
||||
|
||||
_items = 0;
|
||||
_current_row = -1;
|
||||
_row.destroy();
|
||||
_column.destroy();
|
||||
}
|
||||
|
||||
unsigned TDB_recordset::columns() const
|
||||
{
|
||||
if(!_is_loaded)
|
||||
return _rec->sq_get_num_fields();
|
||||
if (!_is_loaded)
|
||||
{
|
||||
TDB_recordset* my_self = const_cast<TDB_recordset*>(this);
|
||||
my_self->set_loaded();
|
||||
}
|
||||
return _ncolumns;
|
||||
}
|
||||
|
||||
@ -391,12 +402,15 @@ const TRecordset_column_info& TDB_recordset::column_info(const unsigned column)
|
||||
info._name = _rec->sq_get_name_field(column); // TString
|
||||
info._width = _rec->sq_get_width_field(column); // int
|
||||
info._type = _rec->sq_get_type_field(column); // TFieldtypes
|
||||
return info;
|
||||
info._pos = column;
|
||||
}
|
||||
else
|
||||
{
|
||||
info._name.cut(0); // TString
|
||||
info._width = 0; // int
|
||||
info._type = _alfafld; // TFieldtypes
|
||||
info._pos = 0;
|
||||
}
|
||||
info._name.cut(0); // TString
|
||||
info._width = 0; // int
|
||||
info._type = _alfafld; // TFieldtypes
|
||||
info._pos = 0;
|
||||
return info;
|
||||
}
|
||||
|
||||
@ -408,11 +422,15 @@ const TVariant& TDB_recordset::get(unsigned int column) const
|
||||
{
|
||||
last_get = column;
|
||||
field = _rec->sq_get(column);
|
||||
return field;
|
||||
}
|
||||
return field;
|
||||
}
|
||||
|
||||
const TVariant& TDB_recordset::get(const char* name) const
|
||||
{
|
||||
return TRecordset::get(name);
|
||||
}
|
||||
|
||||
bool TDB_recordset::is_connected() const
|
||||
{
|
||||
return _rec->sq_is_connect();
|
||||
|
@ -86,7 +86,7 @@ public:
|
||||
void sq_set_client(int client) { _rec.set_client(static_cast<TT_driver>(client)); }
|
||||
void sq_set_client(const TT_driver client) { _rec.set_client(client); }
|
||||
// Imposto una opzione generica della connessione
|
||||
void sq_set_con_option(const char* opt) { _rec.set_con_option(opt); }
|
||||
void sq_set_con_option(const char* opt, const char* val) { _rec.set_con_option(opt, val); }
|
||||
/**< Abilito/Disabilito l'autocommit, (disabilitato di default) */
|
||||
void sq_set_autocommit(const bool ac) { _rec.set_autocommit(ac); }
|
||||
/** Imposta la visibilità delle transazioni (vedi Funzione) */
|
||||
@ -225,11 +225,11 @@ protected:
|
||||
bool connect(const char * db, const char * user, const char * pass, const TT_driver tipo_db) const;
|
||||
bool connect(const char * db, const char * user, const char * pass, const char * tipo_db) const;
|
||||
static TT_driver str_to_driver(const char* tipo_db);
|
||||
void set_loaded();
|
||||
bool set_loaded();
|
||||
void unset_loaded();
|
||||
|
||||
public:
|
||||
void freeze(const bool on = true);;
|
||||
void freeze(const bool on = true);
|
||||
void reset();
|
||||
bool set(const char* sql);
|
||||
bool move_to(TRecnotype pos) override; // Pure
|
||||
@ -243,8 +243,9 @@ public:
|
||||
const TString_array get_row(TRecnotype n = -1);
|
||||
const TString_array get_next_row();
|
||||
const TString& query_text() const override { return _sql; }
|
||||
|
||||
const TString& driver_version() const override { return _rec->sq_get_client_v(); };
|
||||
const TVariant& get(unsigned int column) const override; // Pure
|
||||
const TVariant& get(const char* name) const override; // Pure
|
||||
const TRecordset_column_info& column_info(unsigned int column) const override; // Pure
|
||||
|
||||
// Ritorna la connessione attuale
|
||||
|
@ -248,9 +248,9 @@ void TXvt_recordset::set_client(TT_driver client) const
|
||||
_CON(_con)->setClient(static_cast<SAClient_t>(client));
|
||||
}
|
||||
|
||||
void TXvt_recordset::set_con_option(const char* opt) const
|
||||
void TXvt_recordset::set_con_option(const char* opt, const char* val) const
|
||||
{
|
||||
_CON(_con)->setOption(opt);
|
||||
_CON(_con)->setOption(opt) = val;
|
||||
}
|
||||
|
||||
void TXvt_recordset::set_autocommit(const bool ac) const
|
||||
@ -377,7 +377,7 @@ bool TXvt_recordset::exec(const bool auto_f)
|
||||
{
|
||||
_RCS(_recset)->Execute();
|
||||
_loaded = true;
|
||||
_recno = DEFAULT_ERR_NUMBER;
|
||||
_recno = -1;
|
||||
// Se trovo almeno un "select" faccio l'autofetch
|
||||
SAString s = _RCS(_recset)->CommandText(); s.MakeUpper();
|
||||
ok = s.Find("SELECT") != SIZE_MAX && auto_f ? next() : true;
|
||||
@ -654,19 +654,19 @@ int TXvt_recordset::get_num_fields() const
|
||||
|
||||
const char* TXvt_recordset::get_name_field(const unsigned column) const
|
||||
{
|
||||
auto& f_name = _RCS(_recset)->Field(column);
|
||||
SAField& f_name = _RCS(_recset)->Field(column + 1);
|
||||
return static_cast<const char *>(f_name.Name());
|
||||
}
|
||||
|
||||
int TXvt_recordset::get_width_field(const unsigned column) const
|
||||
{
|
||||
auto& f_name = _RCS(_recset)->Field(column);
|
||||
SAField& f_name = _RCS(_recset)->Field(column + 1);
|
||||
return static_cast<int>(f_name.FieldSize());
|
||||
}
|
||||
|
||||
const char* TXvt_recordset::get_type_field(const unsigned column) const
|
||||
{
|
||||
auto& f_name = _RCS(_recset)->Field(column);
|
||||
SAField& f_name = _RCS(_recset)->Field(column + 1);
|
||||
const auto type = f_name.FieldType();
|
||||
|
||||
switch(type)
|
||||
@ -708,6 +708,18 @@ const char* TXvt_recordset::get_type_field(const unsigned column) const
|
||||
}
|
||||
}
|
||||
|
||||
int TXvt_recordset::get_precision_field(const unsigned column) const
|
||||
{
|
||||
SAField& f_name = _RCS(_recset)->Field(column + 1);
|
||||
return f_name.FieldPrecision();
|
||||
}
|
||||
|
||||
int TXvt_recordset::get_scale_field(const unsigned column) const
|
||||
{
|
||||
SAField& f_name = _RCS(_recset)->Field(column + 1);
|
||||
return f_name.FieldScale();
|
||||
}
|
||||
|
||||
long TXvt_recordset::get_code_error(const bool erase)
|
||||
{
|
||||
const long app = _code_error;
|
||||
|
@ -127,7 +127,7 @@ public:
|
||||
/**< 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;
|
||||
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à delle transazioni (vedi Funzione) */
|
||||
@ -207,6 +207,10 @@ public:
|
||||
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; }
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user