You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

246 lines
11 KiB

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