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.

190 lines
7.6 KiB

  1. /************** TabPivot H Declares Source Code File (.H) **************/
  2. /* Name: TABPIVOT.H Version 1.5 */
  3. /* */
  4. /* (C) Copyright to the author Olivier BERTRAND 2005-2013 */
  5. /* */
  6. /* This file contains the PIVOT classes declares. */
  7. /***********************************************************************/
  8. typedef class PIVOTDEF *PPIVOTDEF;
  9. typedef class TDBPIVOT *PTDBPIVOT;
  10. typedef class FNCCOL *PFNCCOL;
  11. typedef class SRCCOL *PSRCCOL;
  12. /***********************************************************************/
  13. /* This class is used to generate PIVOT table column definitions. */
  14. /***********************************************************************/
  15. class PIVAID : public CSORT {
  16. friend class FNCCOL;
  17. friend class SRCCOL;
  18. public:
  19. // Constructor
  20. PIVAID(const char *tab, const char *src, const char *picol,
  21. const char *fncol, const char *host, const char *db,
  22. const char *user, const char *pwd, int port);
  23. // Methods
  24. PQRYRES MakePivotColumns(PGLOBAL g);
  25. // The sorting function
  26. virtual int Qcompare(int *, int *);
  27. protected:
  28. // Members
  29. MYSQLC Myc; // MySQL connection class
  30. char *Host; // Host machine to use
  31. char *User; // User logon info
  32. char *Pwd; // Password logon info
  33. char *Database; // Database to be used by server
  34. PQRYRES Qryp; // Points to Query result block
  35. char *Tabname; // Name of source table
  36. char *Tabsrc; // SQL of source table
  37. char *Picol; // Pivot column name
  38. char *Fncol; // Function column name
  39. PVBLK Rblkp; // The value block of the pivot column
  40. int Port; // MySQL port number
  41. }; // end of class PIVAID
  42. /* -------------------------- PIVOT classes -------------------------- */
  43. /***********************************************************************/
  44. /* PIVOT: table that provides a view of a source table where the */
  45. /* pivot column is expended in as many columns as there are distinct */
  46. /* values in it and containing the function value matching other cols.*/
  47. /***********************************************************************/
  48. /***********************************************************************/
  49. /* PIVOT table. */
  50. /***********************************************************************/
  51. class PIVOTDEF : public PRXDEF { /* Logical table description */
  52. friend class TDBPIVOT;
  53. public:
  54. // Constructor
  55. PIVOTDEF(void);
  56. // Implementation
  57. virtual const char *GetType(void) {return "PIVOT";}
  58. // Methods
  59. virtual bool DefineAM(PGLOBAL g, LPCSTR am, int poff);
  60. virtual PTDB GetTable(PGLOBAL g, MODE m);
  61. protected:
  62. // Members
  63. char *Host; /* Host machine to use */
  64. char *User; /* User logon info */
  65. char *Pwd; /* Password logon info */
  66. char *DB; /* Database to be used by server */
  67. char *Tabname; /* Name of source table */
  68. char *Tabsrc; /* The source table SQL description */
  69. char *Picol; /* The pivot column */
  70. char *Fncol; /* The function column */
  71. char *Function; /* The function applying to group by */
  72. bool GBdone; /* True if tabname as group by format */
  73. bool Accept; /* TRUE if no match is accepted */
  74. int Port; /* MySQL port number */
  75. }; // end of PIVOTDEF
  76. /***********************************************************************/
  77. /* This is the class declaration for the PIVOT table. */
  78. /***********************************************************************/
  79. class TDBPIVOT : public TDBPRX {
  80. friend class FNCCOL;
  81. public:
  82. // Constructor
  83. TDBPIVOT(PPIVOTDEF tdp);
  84. // Implementation
  85. virtual AMT GetAmType(void) {return TYPE_AM_PIVOT;}
  86. // Methods
  87. virtual int GetRecpos(void) {return N;}
  88. virtual void ResetDB(void) {N = 0;}
  89. virtual int RowNumber(PGLOBAL g, bool b = FALSE);
  90. // Database routines
  91. virtual PCOL MakeCol(PGLOBAL g, PCOLDEF cdp, PCOL cprec, int n);
  92. virtual int GetMaxSize(PGLOBAL g);
  93. virtual bool OpenDB(PGLOBAL g);
  94. virtual int ReadDB(PGLOBAL g);
  95. virtual int WriteDB(PGLOBAL g);
  96. virtual int DeleteDB(PGLOBAL g, int irc);
  97. virtual void CloseDB(PGLOBAL g);
  98. protected:
  99. // Internal routines
  100. bool FindDefaultColumns(PGLOBAL g);
  101. bool GetSourceTable(PGLOBAL g);
  102. bool MakePivotColumns(PGLOBAL g);
  103. bool MakeViewColumns(PGLOBAL g);
  104. // Members
  105. char *Host; // Host machine to use
  106. char *User; // User logon info
  107. char *Pwd; // Password logon info
  108. char *Database; // Database to be used by server
  109. char *Tabname; // Name of source table
  110. char *Tabsrc; // SQL of source table
  111. char *Picol; // Pivot column name
  112. char *Fncol; // Function column name
  113. char *Function; // The function applying to group by
  114. PCOL Fcolp; // To the function column in source
  115. PCOL Xcolp; // To the pivot column in source
  116. PCOL Dcolp; // To the dump column
  117. bool GBdone; // True when subtable is "Group by"
  118. bool Accept; // TRUE if no match is accepted
  119. int Mult; // Multiplication factor
  120. int Ncol; // The number of generated columns
  121. int N; // The current table index
  122. int M; // The occurence rank
  123. int Port; // MySQL port number
  124. BYTE FileStatus; // 0: First 1: Rows 2: End-of-File
  125. BYTE RowFlag; // 0: Ok, 1: Same, 2: Skip
  126. }; // end of class TDBPIVOT
  127. /***********************************************************************/
  128. /* Class FNCCOL: for the multiple generated column. */
  129. /***********************************************************************/
  130. class FNCCOL : public COLBLK {
  131. friend class TDBPIVOT;
  132. public:
  133. // Constructor
  134. FNCCOL(PCOLDEF cdp, PTDB tdbp, PCOL cprec, int i);
  135. // Implementation
  136. virtual int GetAmType(void) {return TYPE_AM_FNC;}
  137. // Methods
  138. virtual void Reset(void) {}
  139. bool InitColumn(PGLOBAL g);
  140. bool CompareColumn(void);
  141. protected:
  142. // Member
  143. PVAL Hval; // The value containing the header
  144. PCOL Xcolp;
  145. }; // end of class FNCCOL
  146. /***********************************************************************/
  147. /* Class SRCCOL: for other source columns. */
  148. /***********************************************************************/
  149. class SRCCOL : public PRXCOL {
  150. friend class TDBPIVOT;
  151. public:
  152. // Constructors
  153. SRCCOL(PCOLDEF cdp, PTDB tdbp, PCOL cprec, int n);
  154. // Implementation
  155. virtual int GetAmType(void) {return TYPE_AM_SRC;}
  156. // Methods
  157. virtual void Reset(void) {}
  158. void SetColumn(void);
  159. bool Init(PGLOBAL g);
  160. bool CompareLast(void);
  161. protected:
  162. // Default constructor not to be used
  163. SRCCOL(void) {}
  164. // Members
  165. }; // end of class SRCCOL