Patch level : 10.0 pers
Files correlati : ca2.exe ca2500a.msk Ricompilazione Demo : [ ] Commento : Aggiunto programma di invio a Board git-svn-id: svn://10.65.10.50/branches/R_10_00@23200 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
parent
9f9e20f560
commit
7078caba13
@ -139,6 +139,8 @@ bool TDongle::ssa_login(const char* mod)
|
|||||||
|
|
||||||
const int err = xvt_dongle_sa_login(NULL);
|
const int err = xvt_dongle_sa_login(NULL);
|
||||||
_serno = (err >= 0) ? err : 0xFFFF;
|
_serno = (err >= 0) ? err : 0xFFFF;
|
||||||
|
if (_serno == 0xFFFF && is_power_station())
|
||||||
|
_serno = 0;
|
||||||
if (_serno != 0xFFFF)
|
if (_serno != 0xFFFF)
|
||||||
{
|
{
|
||||||
_hardware =_dongle_ssa;
|
_hardware =_dongle_ssa;
|
||||||
|
@ -62,7 +62,25 @@ XVT_ODBC TODBC_recordset::connection() const
|
|||||||
bool TODBC_recordset::connect(const char* dsn, const char* usr, const char* pwd, const char* dir)
|
bool TODBC_recordset::connect(const char* dsn, const char* usr, const char* pwd, const char* dir)
|
||||||
{
|
{
|
||||||
_dsn = dsn; _usr = usr; _pwd = pwd; _dir = dir;
|
_dsn = dsn; _usr = usr; _pwd = pwd; _dir = dir;
|
||||||
return connection() != NULL;
|
|
||||||
|
bool ok = connection() != NULL;
|
||||||
|
|
||||||
|
if (ok)
|
||||||
|
{
|
||||||
|
const TString& name = driver_version();
|
||||||
|
|
||||||
|
if (name.starts_with("ACEODB"))
|
||||||
|
_driver = ODBC_access;
|
||||||
|
else
|
||||||
|
if (name.starts_with("SQLSRV"))
|
||||||
|
_driver = ODBC_mssql;
|
||||||
|
else
|
||||||
|
if (name.starts_with("MYSQL??"))
|
||||||
|
_driver = ODBC_mysql;
|
||||||
|
else
|
||||||
|
_driver = ODBC_generic;
|
||||||
|
}
|
||||||
|
return ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
const TString& TODBC_recordset::query_text() const
|
const TString& TODBC_recordset::query_text() const
|
||||||
@ -335,6 +353,20 @@ long TODBC_recordset::exec(const char* sql)
|
|||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
long TODBC_recordset::begin()
|
||||||
|
{
|
||||||
|
if (driver() == ODBC_mssql)
|
||||||
|
return exec("BEGIN;");
|
||||||
|
return 0L;
|
||||||
|
}
|
||||||
|
|
||||||
|
long TODBC_recordset::commit()
|
||||||
|
{
|
||||||
|
if (driver() == ODBC_mssql)
|
||||||
|
return exec("COMMIT;");
|
||||||
|
return 0L;
|
||||||
|
}
|
||||||
|
|
||||||
TRecnotype TODBC_recordset::current_row() const
|
TRecnotype TODBC_recordset::current_row() const
|
||||||
{
|
{
|
||||||
return _current_row;
|
return _current_row;
|
||||||
@ -394,6 +426,243 @@ bool TODBC_recordset::set_log_file(const char* fn)
|
|||||||
return xvt_odbc_log_file(h, fn) != 0;
|
return xvt_odbc_log_file(h, fn) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int TODBC_recordset::compare_key(const TISAM_recordset& dbfset)
|
||||||
|
{
|
||||||
|
int cmp = 0;
|
||||||
|
const RecDes& recdes = dbfset.cursor()->curr().rec_des();
|
||||||
|
const int keyno = dbfset.cursor()->key();
|
||||||
|
const KeyDes& keydes = recdes.Ky[keyno-1];
|
||||||
|
const int col = columns();
|
||||||
|
for (int f = 0; f < keydes.NkFields && cmp == 0; f++)
|
||||||
|
{
|
||||||
|
const int nfield = keydes.FieldSeq[f] % MaxFields;
|
||||||
|
const char* fname = recdes.Fd[nfield].Name;
|
||||||
|
cmp = dbfset.get(fname).compare(get(fname));
|
||||||
|
}
|
||||||
|
return cmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
int TODBC_recordset::compare_rec(const TISAM_recordset& dbfset)
|
||||||
|
{
|
||||||
|
int cmp = 0;
|
||||||
|
const RecDes& recdes = dbfset.cursor()->curr().rec_des();
|
||||||
|
const unsigned int nfields = recdes.NFields;
|
||||||
|
const int col = columns();
|
||||||
|
|
||||||
|
for (unsigned int f = 0; f < nfields && cmp == 0; f++)
|
||||||
|
{
|
||||||
|
const TVariant& dbffld = dbfset.get(f);
|
||||||
|
const TVariant& sqlfld = get(f);
|
||||||
|
switch (recdes.Fd[f].TypeF)
|
||||||
|
{
|
||||||
|
case _alfafld:
|
||||||
|
case _memofld:
|
||||||
|
cmp = xvt_str_compare_ignoring_case(dbffld.as_string(), sqlfld.as_string());
|
||||||
|
break;
|
||||||
|
case _realfld:
|
||||||
|
{
|
||||||
|
const real dbfnum = dbffld.as_real();
|
||||||
|
const real sqlnum = dbffld.as_real();
|
||||||
|
if (dbfnum != sqlnum)
|
||||||
|
cmp = dbfnum < sqlnum ? -1 : +1;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case _datefld:
|
||||||
|
{
|
||||||
|
const TDate dbfdate = dbffld.as_date();
|
||||||
|
const TDate sqldate = dbffld.as_date();
|
||||||
|
if (dbfdate != sqldate)
|
||||||
|
cmp = dbfdate < sqldate ? -1 : +1;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
cmp = dbffld.as_int() - sqlfld.as_int();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (cmp != 0)
|
||||||
|
int i = 1;
|
||||||
|
}
|
||||||
|
return cmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
int TODBC_recordset::create_rec(const TISAM_recordset& dbfset)
|
||||||
|
{
|
||||||
|
const TRectype& curr = dbfset.cursor()->curr();
|
||||||
|
const int lf = curr.num();
|
||||||
|
TString table = prefix().get_filename(lf).name_only(); table.upper();
|
||||||
|
TString query(255); query << "INSERT INTO " << table << " VALUES(";
|
||||||
|
TODBC_driver drv = driver();
|
||||||
|
const RecDes& recdes = curr.rec_des();
|
||||||
|
const unsigned int nfields = recdes.NFields;
|
||||||
|
|
||||||
|
for (unsigned int f = 0; f < nfields; f++)
|
||||||
|
{
|
||||||
|
const char* fld = recdes.Fd[f].Name;
|
||||||
|
if (f) query << ',';
|
||||||
|
|
||||||
|
switch (recdes.Fd[f].TypeF)
|
||||||
|
{
|
||||||
|
case _alfafld:
|
||||||
|
case _memofld:
|
||||||
|
quoted_string(query, curr.get(fld));
|
||||||
|
break;
|
||||||
|
case _datefld:
|
||||||
|
if (drv == ODBC_mssql)
|
||||||
|
{
|
||||||
|
query << "CONVERT(datetime,";
|
||||||
|
quoted_string(query, curr.get(fld));
|
||||||
|
query << " ,105)";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
if (drv == ODBC_mysql)
|
||||||
|
quoted_string(query, format("&ld", curr.get_date(fld)));
|
||||||
|
else
|
||||||
|
if (drv == ODBC_access)
|
||||||
|
{
|
||||||
|
query << "CDATE(";
|
||||||
|
quoted_string(query, curr.get(fld));
|
||||||
|
query << ")";
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case _realfld:
|
||||||
|
query << curr.get_real(fld).string(-1,2);
|
||||||
|
break;
|
||||||
|
case _boolfld:
|
||||||
|
query << (curr.get_bool(fld) ? '1' : '0');
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
query << curr.get_long(fld);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
query << ");";
|
||||||
|
// END;";
|
||||||
|
|
||||||
|
TRecnotype row = current_row();
|
||||||
|
const int err = exec(query);
|
||||||
|
|
||||||
|
move_to(row);
|
||||||
|
// while (compare_key(dbfset) != 0 && move_next());
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TODBC_recordset::update_rec(const TISAM_recordset& dbfset)
|
||||||
|
{
|
||||||
|
const TRectype& curr = dbfset.cursor()->curr();
|
||||||
|
const int lf = curr.num();
|
||||||
|
TString table = prefix().get_filename(lf).name_only(); table.upper();
|
||||||
|
TString query; query << "UPDATE " << table << " SET \n";
|
||||||
|
TODBC_driver drv = driver();
|
||||||
|
const RecDes& recdes = curr.rec_des();
|
||||||
|
const unsigned int nfields = recdes.NFields;
|
||||||
|
|
||||||
|
for (unsigned int f = 0; f < nfields; f++)
|
||||||
|
{
|
||||||
|
const char* fld = recdes.Fd[f].Name;
|
||||||
|
if (f) query << ',';
|
||||||
|
query << fld << '=';
|
||||||
|
switch (recdes.Fd[f].TypeF)
|
||||||
|
{
|
||||||
|
case _alfafld:
|
||||||
|
case _memofld:
|
||||||
|
quoted_string(query, curr.get(fld));
|
||||||
|
break;
|
||||||
|
case _datefld:
|
||||||
|
if (drv == ODBC_mssql)
|
||||||
|
{
|
||||||
|
query << "CONVERT(datetime,";
|
||||||
|
quoted_string(query, curr.get(fld));
|
||||||
|
query << " ,105)";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
if (drv == ODBC_mysql)
|
||||||
|
quoted_string(query, format("&ld", curr.get_date(fld)));
|
||||||
|
else
|
||||||
|
if (drv == ODBC_access)
|
||||||
|
{
|
||||||
|
query << "CDATE(";
|
||||||
|
quoted_string(query, curr.get(fld));
|
||||||
|
query << ")";
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case _realfld:
|
||||||
|
query << curr.get_real(fld).string(-1,2);
|
||||||
|
break;
|
||||||
|
case _boolfld:
|
||||||
|
query << (curr.get_bool(fld) ? '1' : '0');
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
query << curr.get_long(fld);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
query << "\nWHERE ";
|
||||||
|
|
||||||
|
const KeyDes& key = recdes.Ky[0];
|
||||||
|
for (int k = 0; k < key.NkFields; k++)
|
||||||
|
{
|
||||||
|
if (k > 0) query << " AND ";
|
||||||
|
const int nf = key.FieldSeq[k] % MaxFields;
|
||||||
|
const char* fname = recdes.Fd[nf].Name;
|
||||||
|
query << fname << '=';
|
||||||
|
if (recdes.Fd[nf].TypeF == _alfafld)
|
||||||
|
query << '\'' << curr.get(fname) << '\'';
|
||||||
|
else
|
||||||
|
query << curr.get(fname);
|
||||||
|
}
|
||||||
|
TRecnotype row = current_row();
|
||||||
|
const int err = exec(query);
|
||||||
|
|
||||||
|
move_to(row);
|
||||||
|
// while (compare_key(dbfset) != 0 && move_next());
|
||||||
|
}
|
||||||
|
|
||||||
|
void TODBC_recordset::remove_rec(const TISAM_recordset& dbfset)
|
||||||
|
{
|
||||||
|
const TRectype& curr = dbfset.cursor()->curr();
|
||||||
|
const int lf = curr.num();
|
||||||
|
TString table = prefix().get_filename(lf).name_only(); table.upper();
|
||||||
|
TString query;
|
||||||
|
query << "DELETE FROM " << table << " WHERE ";
|
||||||
|
|
||||||
|
const RecDes& recdes = dbfset.cursor()->curr().rec_des();
|
||||||
|
const int keyno = dbfset.cursor()->key();
|
||||||
|
const KeyDes& keydes = recdes.Ky[keyno-1];
|
||||||
|
for (int f = 0; f < keydes.NkFields; f++)
|
||||||
|
{
|
||||||
|
if (f) query << " AND ";
|
||||||
|
const int nfield = keydes.FieldSeq[f] % MaxFields;
|
||||||
|
const char* fname = recdes.Fd[nfield].Name;
|
||||||
|
query << fname << '=';
|
||||||
|
switch (recdes.Fd[f].TypeF)
|
||||||
|
{
|
||||||
|
case _alfafld:
|
||||||
|
quoted_string(query, get(fname).as_string());
|
||||||
|
break;
|
||||||
|
case _realfld:
|
||||||
|
case _intfld:
|
||||||
|
case _longfld:
|
||||||
|
case _intzerofld:
|
||||||
|
case _longzerofld:
|
||||||
|
{
|
||||||
|
TString value = get(fname).as_string();
|
||||||
|
|
||||||
|
if (value.blank())
|
||||||
|
value = "0";
|
||||||
|
query << value;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
query << get(fname);
|
||||||
|
break;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
query << ';';
|
||||||
|
exec(query);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
void TODBC_recordset::set(const char* sql)
|
void TODBC_recordset::set(const char* sql)
|
||||||
{
|
{
|
||||||
reset();
|
reset();
|
||||||
|
@ -5,6 +5,12 @@
|
|||||||
#include <recset.h>
|
#include <recset.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
enum TODBC_driver {
|
||||||
|
ODBC_generic,
|
||||||
|
ODBC_mssql,
|
||||||
|
ODBC_access,
|
||||||
|
ODBC_mysql};
|
||||||
|
|
||||||
class TODBC_recordset : public TRecordset
|
class TODBC_recordset : public TRecordset
|
||||||
{
|
{
|
||||||
TString _dsn, _usr, _pwd, _dir;
|
TString _dsn, _usr, _pwd, _dir;
|
||||||
@ -16,11 +22,13 @@ class TODBC_recordset : public TRecordset
|
|||||||
TArray _column;
|
TArray _column;
|
||||||
bool _columns_loaded;
|
bool _columns_loaded;
|
||||||
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
XVT_ODBC connection() const;
|
XVT_ODBC connection() const;
|
||||||
void reset();
|
void reset();
|
||||||
const TArray* row(TRecnotype n);
|
const TArray* row(TRecnotype n);
|
||||||
virtual void parsed_text(TString& sql) const;
|
virtual void parsed_text(TString& sql) const;
|
||||||
|
TODBC_driver _driver;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual TRecnotype items() const;
|
virtual TRecnotype items() const;
|
||||||
@ -41,12 +49,21 @@ public:
|
|||||||
int on_get_rows(int argc, char** values, char** columns);
|
int on_get_rows(int argc, char** values, char** columns);
|
||||||
|
|
||||||
void set(const char* sql);
|
void set(const char* sql);
|
||||||
|
|
||||||
long exec(const char* sql);
|
long exec(const char* sql);
|
||||||
|
long begin();
|
||||||
|
long commit();
|
||||||
|
|
||||||
bool connect(const char* dsn, const char* usr = "", const char* pwd = "", const char* dir = "");
|
bool connect(const char* dsn, const char* usr = "", const char* pwd = "", const char* dir = "");
|
||||||
bool set_log_file(const char* fn);
|
bool set_log_file(const char* fn);
|
||||||
|
const TODBC_driver driver() { return _driver; }
|
||||||
const TString& dsn() const { return _dsn; }
|
int compare_key(const TISAM_recordset& dbfset);
|
||||||
|
int compare_rec(const TISAM_recordset& dbfset);
|
||||||
|
int create_rec(const TISAM_recordset& dbfset);
|
||||||
|
void update_rec(const TISAM_recordset& dbfset);
|
||||||
|
void remove_rec(const TISAM_recordset& dbfset);
|
||||||
|
|
||||||
|
const TString& dsn() const { return _dsn; }
|
||||||
|
|
||||||
TODBC_recordset(const char* sql);
|
TODBC_recordset(const char* sql);
|
||||||
virtual ~TODBC_recordset();
|
virtual ~TODBC_recordset();
|
||||||
|
@ -606,7 +606,7 @@ long daytime()
|
|||||||
// DON'T cache this bool because hostname can be local or server
|
// DON'T cache this bool because hostname can be local or server
|
||||||
static bool is_sirio_station(const char* hostname)
|
static bool is_sirio_station(const char* hostname)
|
||||||
{
|
{
|
||||||
const char* const ranger[] = { "NBKCORRADIW81", "KLINGON", "MOBILE", "PCTRUFFELLI", "SPOCK", NULL };
|
const char* const ranger[] = { "NBKCORRADIW81", "KLINGON", "MOBILE", "PCTRUFFELLI", "SPOCK", "ARCHIMEDE", NULL };
|
||||||
for (int i = 0; ranger[i]; i++)
|
for (int i = 0; ranger[i]; i++)
|
||||||
if (xvt_str_same(hostname, ranger[i]))
|
if (xvt_str_same(hostname, ranger[i]))
|
||||||
return true;
|
return true;
|
||||||
@ -680,3 +680,15 @@ bool expand_sys_vars(TString& str)
|
|||||||
|
|
||||||
return found;
|
return found;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void quoted_string(TString& query, const char* val)
|
||||||
|
{
|
||||||
|
query << '\'';
|
||||||
|
for (const char* c = val; *c; c++)
|
||||||
|
{
|
||||||
|
if (*c == '\'')
|
||||||
|
query << *c;
|
||||||
|
query << *c;
|
||||||
|
}
|
||||||
|
query << '\'';
|
||||||
|
}
|
||||||
|
@ -61,5 +61,6 @@ bool is_power_station();
|
|||||||
bool is_power_reseller(bool power_user_only = false);
|
bool is_power_reseller(bool power_user_only = false);
|
||||||
long daytime();
|
long daytime();
|
||||||
bool expand_sys_vars(TString& str);
|
bool expand_sys_vars(TString& str);
|
||||||
|
void quoted_string(TString& query, const char* val);
|
||||||
|
|
||||||
#endif /* __UTILITY_H */
|
#endif /* __UTILITY_H */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user