home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / cppsql.zip / SQLSRC.ZIP / SQLTAB.HPP < prev   
Text File  |  1992-09-18  |  10KB  |  273 lines

  1. // :H1 SQLTAB.HPP: START OF SPECIFICATIONS
  2. //----------------------------------------------------------------------
  3. //
  4. //  Module Name: SQLTAB.HPP
  5. //
  6. //  Description: SQL Table Interface.
  7. //
  8. //  Product Classification:
  9. //    IBM Internal Use Only
  10. //    (C) Copyright IBM Corp. 1992
  11. //
  12. //  Status: New
  13. //
  14. //  Initial Author: George L. Havens
  15. //
  16. //  Function: To provide an interface for tables to SQL databases.
  17. //
  18. //  Notes: None.
  19. //
  20. //  Dependencies: Requires PORTABLE.H include.
  21. //                Requires SQLDA.H include.
  22. //
  23. //  Restrictions: None.
  24. //
  25. //  Compiler: Zortech C++
  26. //
  27. // Change Activity -----------------------------------------------------
  28. //
  29. // $MOD(module) COMP(component) PROD(product): Description...
  30. //
  31. // FLAG  REASON  VERS  DATE  WHO   DESCRIPTION
  32. // ---- -------- ---- ------ ---   -----------
  33. //               V100 920224 GLH : Initial level
  34. //
  35. // END-OF-SPECIFICATIONS -----------------------------------------------
  36.  
  37. #ifndef XX_SQLTAB
  38. #define XX_SQLTAB
  39.  
  40. class Table
  41.   {
  42.     public:
  43. //----------------------------------------------------------------------
  44. //
  45. //  Function Name: Table constructor
  46. //
  47. //  Purpose: This method will create an SQL table object.
  48. //
  49. //  Description: This method will create an SQL table object. It
  50. //               will create a SQLDA structure for the table
  51. //               format specified.
  52. //
  53. //  Input:
  54. //    name       Table name
  55. //    format     table format
  56. //               format must be a string using %d, %ld, or %#s
  57. //               where # is the string length not including the 0 terminator
  58. //    col        column names seperated by ','
  59. //  Output:
  60. //    none
  61. //
  62. //----------------------------------------------------------------------
  63.       Table (const CHAR *name, const CHAR *format, const CHAR *col);
  64. //----------------------------------------------------------------------
  65. //
  66. //  Function Name: Create
  67. //
  68. //  Purpose: This method will create an SQL table.
  69. //
  70. //  Description: This method will create an SQL table by using
  71. //               dynamic SQL.
  72. //
  73. //  Input:
  74. //    none
  75. //
  76. //  Output:
  77. //    return code 0 = successful, not 0 = error
  78. //
  79. //----------------------------------------------------------------------
  80.       SHORT Create (VOID);
  81. //----------------------------------------------------------------------
  82. //
  83. //  Function Name: Insert
  84. //
  85. //  Purpose: This method will insert data into an SQL table.
  86. //
  87. //  Description: This method will insert a variable data into the
  88. //               table columns.
  89. //
  90. //  Input:
  91. //    num_cols   number of colums to insert (must match number of columns
  92. //               in the table description)
  93. //    variable data to be inserted
  94. //
  95. //  Output:
  96. //    return code 0 = successful, not 0 = error
  97. //
  98. //----------------------------------------------------------------------
  99.       SHORT Insert (SHORT num_cols, ...);
  100. //----------------------------------------------------------------------
  101. //
  102. //  Function Name: Search
  103. //
  104. //  Purpose: This method will search an SQL table for a specified value(s).
  105. //
  106. //  Description: This method will search for a match on the specified
  107. //               value(s). This is done by building a SELECT record
  108. //               for the specified values. If multiple conditions
  109. //               are specified they are AND'ed together.
  110. //
  111. //  Input:
  112. //    initial    initial search with this format?
  113. //    format     table format
  114. //               format must be a string using %d, %ld, or %#s for
  115. //               fields to be searched and %*d, %*ld, and %*#s for
  116. //               those not being searched.
  117. //               # is the string length to search not including the
  118. //               0 terminator. If no fields to be searched are specified
  119. //               the next row will be returned.
  120. //
  121. //    variable   pointers where to store EVERY field in the row
  122. //    variable   data to be seached for match
  123. //  Output:
  124. //    return code 0 = successful, not 0 = error
  125. //
  126. //----------------------------------------------------------------------
  127.       SHORT Search (BOOLEAN beginning, const CHAR *, ...);
  128. //----------------------------------------------------------------------
  129. //
  130. //  Function Name: Delete
  131. //
  132. //  Purpose: This method will search an SQL table for a specified value(s)
  133. //           and delete the rows found.
  134. //
  135. //  Description: This method will search for a match on the specified
  136. //               value(s). This is done by building a DELETE record
  137. //               for the specified values. If multiple conditions
  138. //               are specified they are AND'ed together.
  139. //
  140. //  Input:
  141. //    format     table format
  142. //               format must be a string using %d, %ld, or %#s for
  143. //               fields to be searched and %*d, %*ld, and %*#s for
  144. //               those not being searched.
  145. //               # is the string length to search not including the
  146. //               0 terminator. If no fields to be searched are specified
  147. //               all the rows will be deleted.
  148. //    variable   data to be seached for match
  149. //  Output:
  150. //    return code 0 = successful, not 0 = error
  151. //
  152. //----------------------------------------------------------------------
  153.       SHORT Delete (const CHAR *, ...);
  154. //----------------------------------------------------------------------
  155. //
  156. //  Function Name: DeleteCurrent
  157. //
  158. //  Purpose: This method will delete the current row found by using the
  159. //           search statement.
  160. //
  161. //  Description: This method will delete the current row that was found using
  162. //               the search statement. This is done by building a DELETE
  163. //               current record.
  164. //
  165. //  Input:
  166. //    none
  167. //
  168. //  Output:
  169. //    return code 0 = successful, not 0 = error
  170. //
  171. //----------------------------------------------------------------------
  172.       SHORT DeleteCurrent (VOID);
  173. //----------------------------------------------------------------------
  174. //
  175. //  Function Name: Index 
  176. //
  177. //  Purpose: This method will create an index for the specified columns.  
  178. //
  179. //  Description: This method will create an index for the specified  
  180. //               columns using the SQL create index command. Only one index       
  181. //               can be created per table.
  182. //
  183. //  Input:
  184. //    format     table format
  185. //               format must be a string using %d, %ld, or %#s for
  186. //               fields to be searched and %*d, %*ld, and %*#s for
  187. //               those not being indexed.
  188. //               # is the string length to search not including the
  189. //               0 terminator. If no fields to be indexed are specified
  190. //               an error will be returned.
  191. //  Output:
  192. //    return code 0 = successful, not 0 = error
  193. //
  194. //----------------------------------------------------------------------
  195.       SHORT Index (const CHAR *);
  196. //----------------------------------------------------------------------
  197. //
  198. //  Function Name: Error
  199. //
  200. //  Purpose: This method will return the last error that occurred.
  201. //
  202. //  Description: This method will return the internal error codes
  203. //               to the caller.
  204. //
  205. //  Input:
  206. //    rc_a       where to return last return code
  207. //    id_a       where to return last statement that had error
  208. //
  209. //  Output:
  210. //    none
  211. //
  212. //----------------------------------------------------------------------
  213. inline VOID Error (SHORT& rc_a, SHORT& id_a)
  214.         {
  215.           // set current return code and location
  216.           rc_a = rc;
  217.           id_a = (rc == 0) ? 0 : id;
  218.         }
  219. //----------------------------------------------------------------------
  220. //
  221. //  Function Name: Table destructor
  222. //
  223. //  Purpose: This method will delete an table object.
  224. //
  225. //  Description: This method will delete the table object and
  226. //               release the table name.
  227. //
  228. //  Input:
  229. //    none
  230. //
  231. //  Output:
  232. //    none
  233. //
  234. //----------------------------------------------------------------------
  235.       ~Table ();
  236.  
  237.     private:
  238.       CHAR    *table;                  // table name
  239.       CHAR    *columns;                // column names
  240.       struct sqlda *var;               // sqlda variables
  241.       SHORT   cols;                    // number of columns in table
  242.       BOOLEAN record_found;            // record was found during search
  243.       SHORT   rc;                      // return code
  244.       #define SQLTAB_MEMORY_ERROR              -10001
  245.       #define SQLTAB_NO_PERCENT_ERROR          -10002
  246.       #define SQLTAB_INVALID_NUMBER_OF_COLUMNS -10003
  247.       #define SQLTAB_INVALID_FORMAT_STRING     -10004
  248.       #define SQLTAB_NO_SEARCH_DONE            -10005
  249.       #define SQLTAB_NO_RECORD                 100    // SQL error code
  250.       SHORT   id;                      // id of where last error occurred
  251.       #define SQLTAB_ID_1      1
  252.       #define SQLTAB_ID_2      2
  253.       #define SQLTAB_ID_3      3
  254.       #define SQLTAB_ID_4      4
  255.       #define SQLTAB_ID_5      5
  256.       #define SQLTAB_ID_6      6
  257.       #define SQLTAB_ID_7      7
  258.       #define SQLTAB_ID_8      8
  259.       #define SQLTAB_ID_9      9
  260.       #define SQLTAB_ID_10     10
  261.       #define SQLTAB_ID_11     11
  262.       #define SQLTAB_ID_12     12
  263.       #define SQLTAB_ID_13     13
  264.       #define SQLTAB_ID_14     14
  265.       #define SQLTAB_ID_15     15
  266.       #define SQLTAB_ID_16     16
  267. //    #define SQLTAB_ID_17     17   // available for use
  268.       #define SQLTAB_ID_18     18
  269.       #define SQLTAB_ID_19     19
  270.       #define SQLTAB_ID_20     20
  271.   };
  272. #endif
  273.