207 lines
7.8 KiB
C++
Executable File
207 lines
7.8 KiB
C++
Executable File
#ifndef __RECORDSET_H
|
||
#define __RECORDSET_H
|
||
|
||
#ifndef XVT_INCL_XVT
|
||
#include <xvt.h>
|
||
#endif
|
||
|
||
#ifndef __RELATION_H
|
||
#include <relation.h>
|
||
#endif
|
||
|
||
#ifndef __VARIANT_H
|
||
#include <variant.h>
|
||
#endif
|
||
|
||
#define FIELD_NAME(lf, name) TOSTRING(lf) "." name
|
||
#define SUB_FIELD_NAME(lf, name, from, to ) TOSTRING(lf) "." name "[" TOSTRING(from) "," TOSTRING(to) "]"
|
||
#define MAIN_SUB_FIELD_NAME(name, from, to ) name "[" TOSTRING(from) "," TOSTRING(to) "]"
|
||
|
||
struct TRecordset_column_info : public TObject
|
||
{
|
||
TString _name; // Table.Column
|
||
int _width, _pos;
|
||
TFieldtypes _type;
|
||
|
||
void copy(const TRecordset_column_info & i) { _name = i._name; _width = i._width; _pos = i._pos; _type = i._type; }
|
||
virtual TObject* dup() const { return new TRecordset_column_info(*this); }
|
||
|
||
TRecordset_column_info(const TRecordset_column_info & i) {copy(i);}
|
||
TRecordset_column_info() : _width(0), _pos(0), _type(_alfafld) {}
|
||
};
|
||
|
||
///////////////////////////////////////////////////////////
|
||
// TAttributes
|
||
///////////////////////////////////////////////////////////
|
||
|
||
struct TAttributes : public TObject
|
||
{
|
||
XVT_FNTID _font;
|
||
COLOR _back;
|
||
COLOR _fore;
|
||
|
||
public:
|
||
XVT_FNTID get_font() const{ return _font; }
|
||
COLOR get_background() const { return _back; }
|
||
COLOR get_foreground() const { return _fore; }
|
||
void set_font(XVT_FNTID font) { _font = font; }
|
||
void set_background(COLOR back) { _back = back; }
|
||
void set_foreground(COLOR fore) { _fore = fore; }
|
||
|
||
TAttributes() : _font(NULL), _back(COLOR_INVALID), _fore(COLOR_INVALID) {}
|
||
virtual ~TAttributes() {}
|
||
};
|
||
|
||
|
||
///////////////////////////////////////////////////////////
|
||
// TRecordset
|
||
///////////////////////////////////////////////////////////
|
||
|
||
enum TRecordsetExportFormat { fmt_unknown, fmt_html, fmt_text, fmt_campo, fmt_dbf, fmt_as400, fmt_csv };
|
||
|
||
class TRecordset : public TObject
|
||
{
|
||
TAssoc_array _var;
|
||
TString_array _varnames;
|
||
const TRecordset* _parentset;
|
||
char _text_separator;
|
||
bool _disable_variables;
|
||
bool _frozen;
|
||
|
||
protected:
|
||
virtual bool save_as_html(const char* path);
|
||
virtual bool save_as_text(const char* path);
|
||
virtual bool save_as_as400(const char* path) { set_text_separator(' '); return save_as_text(path);}
|
||
virtual bool save_as_csv(const char* path) { set_text_separator(';'); return save_as_text(path);}
|
||
virtual bool save_as_campo(const char* path);
|
||
virtual bool save_as_dbf(const char* table, int mode);
|
||
|
||
void find_and_reset_vars();
|
||
void parsed_text(TString& sql) const;
|
||
//TVariant& get_tmp_var() const;
|
||
bool export_dbf(int logicnum);
|
||
|
||
public: // Absolutely needed methods
|
||
virtual TRecnotype items() const pure;
|
||
virtual bool move_to(TRecnotype pos) pure;
|
||
virtual TRecnotype current_row() const pure;
|
||
virtual void requery() pure;
|
||
bool empty() const { return items() == 0; }
|
||
virtual const TString& query_text() const pure;
|
||
virtual const TString& driver_version() const;
|
||
|
||
virtual char text_separator() const { return _text_separator;}
|
||
virtual void set_text_separator(char sep) { _text_separator = sep;}
|
||
|
||
virtual void freeze(bool on = true) { _frozen = on; }
|
||
virtual void unfreeze() { freeze(false); }
|
||
virtual bool frozen() const { return _frozen; }
|
||
virtual bool not_frozen() const { return !_frozen; }
|
||
|
||
virtual bool move_first() { return move_to(0); }
|
||
virtual bool move_prev() { return move_to(current_row()-1); }
|
||
virtual bool move_next() { return move_to(current_row()+1); }
|
||
virtual bool move_last() { return move_to(items()-1); }
|
||
virtual bool bof() const { return current_row() == TRecnotype(-1); }
|
||
virtual bool eof() const { return current_row() >= items(); }
|
||
|
||
virtual unsigned int columns() const pure;
|
||
virtual const TRecordset_column_info& column_info(unsigned int column) const pure;
|
||
virtual const TRecordset_column_info& add_column_info(const TRecordset_column_info& c) {return c; }
|
||
const TString& get_string(const char* field) const { return get(find_column(field)).as_string(); };
|
||
const TString& get_string_zerofilled(const char* field, const int zero_filled) const;
|
||
int get_int(const char* field) const { return get(find_column(field)).as_int(); }
|
||
long get_long(const char* field) const { return get(find_column(field)).as_int(); }
|
||
bool get_bool(const char* field) const { return get(find_column(field)).as_bool(); }
|
||
real get_real(const char* field) const { return get(find_column(field)).as_real(); }
|
||
TDate get_date(const char* field) const { return get(find_column(field)).as_date(); }
|
||
|
||
virtual const TVariant& get(unsigned int column) const pure;
|
||
|
||
virtual const TString_array& variables() const { return _varnames; }
|
||
virtual const TVariant& get_var(const char* name) const;
|
||
virtual bool set_var(const char* name, const TVariant& var, bool create = false);
|
||
virtual bool ask_variables(bool all);
|
||
|
||
virtual int find_column(const char* column_name) const;
|
||
virtual const TVariant& get(const char* column_name) const;
|
||
virtual bool get_attr(int column, TAttributes & attr, bool header = false) const { return false; }
|
||
bool get_attr(const char* column_name, TAttributes & attr, bool header = false) const { return get_attr(column_name, attr, header); }
|
||
virtual const TToken_string& sheet_head() const;
|
||
|
||
// mode = 0|1=append 2=update 3=update|append 4=zap before writing
|
||
virtual bool save_as(const char* path, TRecordsetExportFormat fmt = fmt_unknown, int mode = 0);
|
||
|
||
// gestione per abilitare o disabilitare variabili
|
||
virtual void disable_variables() { _disable_variables = true; }
|
||
virtual void enable_variables() { _disable_variables = false; }
|
||
|
||
|
||
void set_parent(const TRecordset* rs) { _parentset = rs; }
|
||
TRecordset();
|
||
virtual ~TRecordset() { }
|
||
};
|
||
|
||
///////////////////////////////////////////////////////////
|
||
// TISAM_recordset
|
||
///////////////////////////////////////////////////////////
|
||
|
||
class TISAM_recordset : public TRecordset
|
||
{
|
||
TString _use;
|
||
|
||
TRelation* _relation;
|
||
TCursor* _cursor;
|
||
TArray _column; // Column infos
|
||
|
||
protected:
|
||
TRelation* relation() const;
|
||
|
||
virtual void reset();
|
||
virtual const TVariant& get_field(int logic, const char* field) const;
|
||
virtual void set_custom_filter(TCursor& cursor) const { }
|
||
|
||
public:
|
||
bool valid_cursor() const { return _cursor != NULL; }
|
||
virtual TCursor* cursor() const;
|
||
virtual void freeze(bool on = true) { return cursor()->freeze(on); }
|
||
virtual void unfreeze() { return cursor()->freeze(false); }
|
||
virtual bool frozen() const { return cursor()->frozen(); }
|
||
virtual bool not_frozen() const { return cursor()->not_frozen(); }
|
||
void set(const char* use);
|
||
virtual void requery();
|
||
virtual TRecnotype items() const;
|
||
virtual bool move_to(TRecnotype pos);
|
||
virtual TRecnotype current_row() const;
|
||
virtual unsigned int columns() const;
|
||
virtual const TRecordset_column_info& column_info(unsigned int c) const;
|
||
virtual const TRecordset_column_info& add_column_info(const TRecordset_column_info& c) { _column.add(c); return c; }
|
||
virtual const TVariant& get(unsigned int column) const;
|
||
virtual const TVariant& get(const char* column_name) const;
|
||
virtual const TVariant& get(int logic, const char* field) const { return get_field(logic, field);}
|
||
virtual const TString& driver_version() const;
|
||
virtual const TString& query_text() const { return _use; }
|
||
|
||
// Utility
|
||
/* Ritorna un filtro che pu<70> essere:
|
||
* from_val && to_val: field between
|
||
* solo from_from: field >= from_val
|
||
* solo to_from: field <= to_val */
|
||
static TString& add_between_filter(const TString& field, const TString& from_val, const TString& to_val, TString from_fld = "", TString to_fld = "");
|
||
|
||
TISAM_recordset(const char* use);
|
||
virtual ~TISAM_recordset();
|
||
};
|
||
|
||
///////////////////////////////////////////////////////////
|
||
// Utility
|
||
///////////////////////////////////////////////////////////
|
||
|
||
bool list_custom_files(const char* ext, const char* library, TString_array& files);
|
||
bool select_custom_file(TFilename& path, const char* ext, const char* classe = NULL);
|
||
const TString& logic2table(int logic_num);
|
||
int table2logic(const TString& name);
|
||
TRecordset* create_recordset(const TString& sql);
|
||
|
||
#endif
|