| 1 | /*************** Tabxml H Declares Source Code File (.H) ***************/ |
| 2 | /* Name: TABXML.H Version 1.7 */ |
| 3 | /* */ |
| 4 | /* (C) Copyright to the author Olivier BERTRAND 2007-2016 */ |
| 5 | /* */ |
| 6 | /* This file contains the XML table classes declares. */ |
| 7 | /***********************************************************************/ |
| 8 | typedef class XMLDEF *PXMLDEF; |
| 9 | typedef class TDBXML *PTDBXML; |
| 10 | typedef class XMLCOL *PXMLCOL; |
| 11 | |
| 12 | /* --------------------------- XML classes --------------------------- */ |
| 13 | |
| 14 | /***********************************************************************/ |
| 15 | /* XML table. */ |
| 16 | /***********************************************************************/ |
| 17 | class DllExport XMLDEF : public TABDEF { /* Logical table description */ |
| 18 | friend class TDBXML; |
| 19 | friend class TDBXCT; |
| 20 | friend PQRYRES XMLColumns(PGLOBAL, char*, char*, PTOS, bool); |
| 21 | public: |
| 22 | // Constructor |
| 23 | XMLDEF(void); |
| 24 | |
| 25 | // Implementation |
| 26 | virtual const char *GetType(void) {return "XML" ;} |
| 27 | |
| 28 | // Methods |
| 29 | virtual bool DefineAM(PGLOBAL g, LPCSTR am, int poff); |
| 30 | virtual PTDB GetTable(PGLOBAL g, MODE m); |
| 31 | |
| 32 | protected: |
| 33 | // Members |
| 34 | PCSZ Fn; /* Path/Name of corresponding file */ |
| 35 | char *Encoding; /* New XML table file encoding */ |
| 36 | char *Tabname; /* Name of Table node */ |
| 37 | char *Rowname; /* Name of first level nodes */ |
| 38 | char *Colname; /* Name of second level nodes */ |
| 39 | char *Mulnode; /* Name of multiple node */ |
| 40 | char *XmlDB; /* Name of XML DB node */ |
| 41 | char *Nslist; /* List of namespaces to register */ |
| 42 | char *DefNs; /* Dummy name of default namespace */ |
| 43 | char *Attrib; /* Table node attributes */ |
| 44 | char *Hdattr; /* Header node attributes */ |
| 45 | PCSZ Entry; /* Zip entry name or pattern */ |
| 46 | int Coltype; /* Default column type */ |
| 47 | int Limit; /* Limit of multiple values */ |
| 48 | int ; /* n first rows are header rows */ |
| 49 | bool Xpand; /* Put multiple tags in several rows */ |
| 50 | bool Usedom; /* True: DOM, False: libxml2 */ |
| 51 | bool Zipped; /* True: Zipped XML file(s) */ |
| 52 | bool Mulentries; /* True: multiple entries in zip file*/ |
| 53 | }; // end of XMLDEF |
| 54 | |
| 55 | #if defined(INCLUDE_TDBXML) |
| 56 | #include "m_ctype.h" |
| 57 | |
| 58 | /***********************************************************************/ |
| 59 | /* This is the class declaration for the simple XML tables. */ |
| 60 | /***********************************************************************/ |
| 61 | class DllExport TDBXML : public TDBASE { |
| 62 | friend class XMLCOL; |
| 63 | friend class XMULCOL; |
| 64 | friend class XPOSCOL; |
| 65 | friend PQRYRES XMLColumns(PGLOBAL, char*, char*, PTOS, bool); |
| 66 | public: |
| 67 | // Constructor |
| 68 | TDBXML(PXMLDEF tdp); |
| 69 | TDBXML(PTDBXML tdbp); |
| 70 | |
| 71 | // Implementation |
| 72 | virtual AMT GetAmType(void) {return TYPE_AM_XML;} |
| 73 | virtual PTDB Duplicate(PGLOBAL g) {return (PTDB)new(g) TDBXML(this);} |
| 74 | |
| 75 | // Methods |
| 76 | virtual PTDB Clone(PTABS t); |
| 77 | virtual int GetRecpos(void); |
| 78 | virtual int GetProgCur(void) {return N;} |
| 79 | virtual PCSZ GetFile(PGLOBAL g) {return Xfile;} |
| 80 | virtual void SetFile(PGLOBAL g, PCSZ fn) {Xfile = fn;} |
| 81 | virtual void ResetDB(void) {N = 0;} |
| 82 | virtual void ResetSize(void) {MaxSize = -1;} |
| 83 | virtual int RowNumber(PGLOBAL g, bool b = false); |
| 84 | int LoadTableFile(PGLOBAL g, char *filename); |
| 85 | bool Initialize(PGLOBAL g); |
| 86 | bool SetTabNode(PGLOBAL g); |
| 87 | void SetNodeAttr(PGLOBAL g, char *attr, PXNODE node); |
| 88 | bool CheckRow(PGLOBAL g, bool b); |
| 89 | |
| 90 | // Database routines |
| 91 | virtual PCOL MakeCol(PGLOBAL g, PCOLDEF cdp, PCOL cprec, int n); |
| 92 | virtual PCOL InsertSpecialColumn(PCOL colp); |
| 93 | //virtual int GetMaxSame(PGLOBAL g) {return (Xpand) ? Limit : 1;} |
| 94 | virtual int Cardinality(PGLOBAL g); |
| 95 | virtual int GetMaxSize(PGLOBAL g); |
| 96 | //virtual bool NeedIndexing(PGLOBAL g); |
| 97 | virtual bool OpenDB(PGLOBAL g); |
| 98 | virtual int ReadDB(PGLOBAL g); |
| 99 | virtual int WriteDB(PGLOBAL g); |
| 100 | virtual int DeleteDB(PGLOBAL g, int irc); |
| 101 | virtual void CloseDB(PGLOBAL g); |
| 102 | virtual int CheckWrite(PGLOBAL g) {Checked = true; return 0;} |
| 103 | virtual const CHARSET_INFO *data_charset() |
| 104 | {return &my_charset_utf8_general_ci;} |
| 105 | |
| 106 | protected: |
| 107 | // Members |
| 108 | PXDOC Docp; |
| 109 | PXNODE Root; |
| 110 | PXNODE Curp; |
| 111 | PXNODE DBnode; |
| 112 | PXNODE TabNode; |
| 113 | PXNODE RowNode; |
| 114 | PXNODE ColNode; |
| 115 | PXLIST Nlist; |
| 116 | PXLIST Clist; |
| 117 | PFBLOCK To_Xb; // Pointer to XML file block |
| 118 | PCOL Colp; // The multiple column |
| 119 | bool Changed; // After Update, Insert or Delete |
| 120 | bool Checked; // After Update check pass |
| 121 | bool NextSame; // Same next row |
| 122 | bool Xpand; // Put multiple tags in several rows |
| 123 | bool NewRow; // True when inserting a new row |
| 124 | bool Hasnod; // True if rows have subnodes |
| 125 | bool Write; // True for Insert and Update |
| 126 | bool Usedom; // True for DOM, False for libxml2 |
| 127 | bool Bufdone; // True when column buffers allocated |
| 128 | bool Nodedone; // True when column nodes allocated |
| 129 | bool Void; // True if the file does not exist |
| 130 | bool Zipped; // True if Zipped XML file(s) |
| 131 | bool Mulentries; // True if multiple entries in zip file |
| 132 | PCSZ Xfile; // The XML file |
| 133 | char *Enc; // New XML table file encoding |
| 134 | char *Tabname; // Name of Table node |
| 135 | char *Rowname; // Name of first level nodes |
| 136 | char *Colname; // Name of second level nodes |
| 137 | char *Mulnode; // Name of multiple node |
| 138 | char *XmlDB; // Name of XML DB node |
| 139 | char *Nslist; // List of namespaces to register |
| 140 | char *DefNs; // Dummy name of default namespace |
| 141 | char *Attrib; // Table node attribut(s) |
| 142 | char *Hdattr; // Header node attribut(s) |
| 143 | PCSZ Entry; // Zip entry name or pattern |
| 144 | int Coltype; // Default column type |
| 145 | int Limit; // Limit of multiple values |
| 146 | int Header; // n first rows are header rows |
| 147 | int Multiple; // If multiple files |
| 148 | int Nrow; // The table cardinality |
| 149 | int Irow; // The current row index |
| 150 | int Nsub; // The current subrow index |
| 151 | int N; // The current Rowid |
| 152 | }; // end of class TDBXML |
| 153 | |
| 154 | /***********************************************************************/ |
| 155 | /* Class XMLCOL: XDB table access method column descriptor. */ |
| 156 | /***********************************************************************/ |
| 157 | class XMLCOL : public COLBLK { |
| 158 | public: |
| 159 | // Constructors |
| 160 | XMLCOL(PCOLDEF cdp, PTDB tdbp, PCOL cprec, int i, PCSZ am = "XML" ); |
| 161 | XMLCOL(XMLCOL *colp, PTDB tdbp); // Constructor used in copy process |
| 162 | |
| 163 | // Implementation |
| 164 | virtual int GetAmType(void) {return TYPE_AM_XML;} |
| 165 | virtual void SetTo_Val(PVAL valp) {To_Val = valp;} |
| 166 | bool ParseXpath(PGLOBAL g, bool mode); |
| 167 | |
| 168 | // Methods |
| 169 | virtual bool SetBuffer(PGLOBAL g, PVAL value, bool ok, bool check); |
| 170 | virtual void ReadColumn(PGLOBAL g); |
| 171 | virtual void WriteColumn(PGLOBAL g); |
| 172 | bool AllocBuf(PGLOBAL g, bool mode); |
| 173 | void AllocNodes(PGLOBAL g, PXDOC dp); |
| 174 | |
| 175 | protected: |
| 176 | //xmlNodePtr SelectSingleNode(xmlNodePtr node, char *name); |
| 177 | |
| 178 | // Default constructor not to be used |
| 179 | XMLCOL(void) : COLBLK(1) {} |
| 180 | |
| 181 | // Members |
| 182 | PXLIST Nl; |
| 183 | PXLIST Nlx; |
| 184 | PXNODE ColNode; |
| 185 | PXNODE ValNode; |
| 186 | PXNODE Cxnp; |
| 187 | PXNODE Vxnp; |
| 188 | PXATTR Vxap; |
| 189 | PXATTR AttNode; |
| 190 | PTDBXML Tdbp; |
| 191 | char *Valbuf; // To the node value buffer |
| 192 | char *Xname; // The node or attribute name |
| 193 | char* *Nodes; // The intermediate nodes |
| 194 | int Type; // 0: Attribute, 1: Tag, 2: position |
| 195 | int Nod; // The number of intermediate nodes |
| 196 | int Inod; // Index of multiple node |
| 197 | int Rank; // Position |
| 198 | bool Mul; // true for multiple column |
| 199 | bool Checked; // Was checked while Updating |
| 200 | int Long; // Buffer length |
| 201 | int Nx; // The last read row |
| 202 | int Sx; // The last read sub-row |
| 203 | int N; // The number of (multiple) values |
| 204 | PVAL To_Val; // To value used for Update/Insert |
| 205 | }; // end of class XMLCOL |
| 206 | |
| 207 | /***********************************************************************/ |
| 208 | /* Derived class XMLCOLX: used to replace a multiple XMLCOL by the */ |
| 209 | /* derived class XMULCOL that has specialize read and write functions.*/ |
| 210 | /* Note: this works only if the members of the derived class are the */ |
| 211 | /* same than the ones of the original class (NO added members). */ |
| 212 | /***********************************************************************/ |
| 213 | class XMLCOLX : public XMLCOL { |
| 214 | public: |
| 215 | // Fake operator new used to change a filter into a derived filter |
| 216 | void * operator new(size_t size, PXMLCOL colp) {return colp;} |
| 217 | #if !defined(__BORLANDC__) |
| 218 | // Avoid warning C4291 by defining a matching dummy delete operator |
| 219 | void operator delete(void *, size_t size) {} |
| 220 | void operator delete(void *, PXMLCOL) {} |
| 221 | #endif |
| 222 | }; // end of class XMLCOLX |
| 223 | |
| 224 | /***********************************************************************/ |
| 225 | /* Class XMULCOL: XML table access method multiple column descriptor. */ |
| 226 | /***********************************************************************/ |
| 227 | class XMULCOL : public XMLCOLX { |
| 228 | public: |
| 229 | // The constructor must restore Value because XOBJECT has a void |
| 230 | // constructor called by default that set Value to NULL |
| 231 | XMULCOL(PVAL valp) {Value = valp; Mul = true;} |
| 232 | |
| 233 | // Methods |
| 234 | virtual void ReadColumn(PGLOBAL g); |
| 235 | virtual void WriteColumn(PGLOBAL g); |
| 236 | }; // end of class XMULCOL |
| 237 | |
| 238 | /***********************************************************************/ |
| 239 | /* Class XPOSCOL: XML table column accessed by position. */ |
| 240 | /***********************************************************************/ |
| 241 | class XPOSCOL : public XMLCOLX { |
| 242 | public: |
| 243 | // The constructor must restore Value because XOBJECT has a void |
| 244 | // constructor called by default that set Value to NULL |
| 245 | XPOSCOL(PVAL valp) {Value = valp;} |
| 246 | |
| 247 | // Methods |
| 248 | virtual void ReadColumn(PGLOBAL g); |
| 249 | virtual void WriteColumn(PGLOBAL g); |
| 250 | }; // end of class XPOSCOL |
| 251 | |
| 252 | /***********************************************************************/ |
| 253 | /* This is the class declaration for the XML catalog table. */ |
| 254 | /***********************************************************************/ |
| 255 | class TDBXCT : public TDBCAT { |
| 256 | public: |
| 257 | // Constructor |
| 258 | TDBXCT(PXMLDEF tdp); |
| 259 | |
| 260 | protected: |
| 261 | // Specific routines |
| 262 | virtual PQRYRES GetResult(PGLOBAL g); |
| 263 | |
| 264 | // Members |
| 265 | PTOS Topt; |
| 266 | char *Db; |
| 267 | char *Tabn; |
| 268 | }; // end of class TDBXCT |
| 269 | |
| 270 | #endif // INCLUDE_TDBXML |
| 271 | |