home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 22 gnu / 22-gnu.zip / db02_src.zip / diarel.cc < prev    next >
C/C++ Source or Header  |  1993-11-05  |  7KB  |  289 lines

  1. /**************************************************************************
  2.  * Source Id :
  3.  *
  4.  * $Id: diarel.cc,v 1.28 1993/10/05 07:33:35 kevinl Exp $
  5.  *-------------------------------------------------------------------------
  6.  * Project Notes :
  7.  *
  8.  *  Diamond Base
  9.  *  ============
  10.  *      A solid database implementation, spurred on by the continuing
  11.  *  Metal (Lead) Base saga.
  12.  *
  13.  *  Project Team :
  14.  *        A. Davison
  15.  *        K. Lentin
  16.  *        D. Platt
  17.  *
  18.  *    Project Commenced : 05-02-1993
  19.  *
  20.  *-------------------------------------------------------------------------
  21.  *  Module Notes :
  22.  *
  23.  * The diaRel is inherited into application classes to provide database
  24.  * functionality.
  25.  *
  26.  *  Original Author : Daz
  27.  *
  28.  *-------------------------------------------------------------------------
  29.  * Revision History:
  30.  *
  31.  * $Log: diarel.cc,v $
  32. // Revision 1.28  1993/10/05  07:33:35  kevinl
  33. // Now handles dbObjData
  34. //
  35. // Revision 1.27  1993/08/29  13:08:35  kevinl
  36. // Problems with relation assignment
  37. //
  38. // Revision 1.26  1993/06/23  05:21:22  kevinl
  39. // Mallocs are now in angular brackets
  40. //
  41. // Revision 1.25  1993/06/20  13:42:15  kevinl
  42. // Fixed multiple mallocs
  43. // Removed dbErr call in diaErr.
  44. //
  45. // Revision 1.24  1993/05/26  01:01:39  kevinl
  46. // MALLOC_H_MISSING
  47. //
  48. // Revision 1.23  1993/05/11  14:44:50  kevinl
  49. // Added version number output
  50. //
  51. // Revision 1.22  1993/05/06  04:00:19  kevinl
  52. // SASC define for malloc.h
  53. //
  54. // Revision 1.21  1993/05/03  01:35:06  kevinl
  55. // Global is called theDiamondBase now.
  56. //
  57. // Revision 1.20  1993/05/01  14:40:05  kevinl
  58. // Cast to long incalls to trans
  59. //
  60. // Revision 1.19  1993/04/27  07:19:18  kevinl
  61. // Added write
  62. //
  63. // Revision 1.18  1993/04/26  01:20:56  kevinl
  64. // Comments
  65. //
  66. // Revision 1.17  1993/04/15  04:21:52  kevinl
  67. // Moved malloc.h
  68. //
  69. // Revision 1.16  1993/04/14  05:49:26  kevinl
  70. // Sees was passing ti_find by mistake
  71. //
  72. // Revision 1.15  1993/04/13  12:05:53  kevinl
  73. // seekFirst & Last were not doing seeks.
  74. //
  75. // Revision 1.14  1993/04/11  05:49:02  kevinl
  76. // Rationalised find/seek/peek methods etc
  77. //
  78. // Revision 1.13  1993/04/09  13:00:29  kevinl
  79. // Stats can be called from diaRel now.
  80. //
  81. // Revision 1.12  1993/04/04  23:58:59  kevinl
  82. // Destructor to detach
  83. //
  84. // Revision 1.11  1993/04/01  04:24:26  kevinl
  85. // Added/changed transactions
  86. // Now we have get, extract and find
  87. //
  88. // Revision 1.10  1993/03/30  14:38:35  kevinl
  89. // Modified index passing to database transactions
  90. //
  91. // Revision 1.9  1993/03/29  23:27:37  kevinl
  92. // Now holds it's own copy of last error
  93. //
  94. // Revision 1.8  1993/03/29  08:06:10  darrenp
  95. // Removed bogus error reporting
  96. // malloc lib
  97. //
  98. // Revision 1.7  1993/03/28  10:39:54  kevinl
  99. // Modified for diaErr
  100. //
  101. // Revision 1.6  1993/03/28  04:53:59  root
  102. // more error code standardization.
  103. //
  104. // Revision 1.5  1993/03/26  06:15:57  darrenp
  105. // standardised error codes.
  106. //
  107. // Revision 1.4  1993/03/26  05:49:24  darrenp
  108. // changed error codes.
  109. //
  110. // Revision 1.3  1993/03/25  22:17:07  davison
  111. // (i) Fixed calls to "regRel". Now called attach.
  112. // (ii) Fixed up default initialisers.
  113. // (iii) Added a crude test for the add() primitive.
  114. //
  115. // Revision 1.2  1993/03/24  06:16:38  kevinl
  116. // Changed constructor to remove pTransferArea
  117. //
  118.  **************************************************************************/
  119.  
  120. #if !defined(MALLOC_H_MISSING) && !defined(MALLOC_H_INCLUDED)
  121. extern "C" {
  122. #include <malloc.h>
  123. }
  124. #define MALLOC_H_INCLUDED
  125. #endif
  126.  
  127. #include <diarel.h>
  128.  
  129. char* diaVerStr(void)
  130. {
  131.     return "$Id: diarel.cc,v 1.28 1993/10/05 07:33:35 kevinl Exp $";
  132. }
  133.  
  134. // The diamondBase must be declared by the app programmer
  135. extern diamondBase theDiamondBase;
  136.  
  137. char* diaRel::verStr(void)
  138. {
  139.     return diaVerStr();
  140. }
  141.  
  142. // diaRel keeps its own status so that each relation can be queried
  143. // separately for status.
  144. // perror uses dbErr to print out the stored error
  145.  
  146. void diaRel::perror(char* err)
  147. {
  148.     dbErr(err, status);
  149. }
  150.  
  151. // Set's the last error
  152. dbError diaRel::diaErr(dbError err)
  153. {
  154.     // This was destroying any extraErr string by calling dbErr
  155.     //return dbErr(status=err);
  156.     return status=err;
  157. }
  158.  
  159. // Attach to the diamondBase
  160. // We pass in the relation name, a pointer to this diaRel and get back the
  161. // reference id inside the diamondBase for future communication with
  162. // diamondBase.
  163.  
  164. diaRel::diaRel(const char *name)
  165. {
  166.     diaErr(theDiamondBase.attach(
  167.         name,
  168.         this,
  169.         refId,
  170.         objData
  171.     ));
  172. }
  173.  
  174. // Say goodbye to the diamondBase
  175.  
  176. diaRel::~diaRel()
  177. {
  178.     theDiamondBase.detach(refId);
  179. }
  180.  
  181. // This must NOT copy refId.
  182. // Make sure all additional fields are included here.
  183.  
  184. diaRel& diaRel::operator=(diaRel& X) {
  185.     if (&X != this) {
  186.         status = X.status;
  187.     }
  188.     return *this;
  189. }
  190.  
  191. // The following functions simply call the diamondBase, passing in the
  192. // reference id we were returned when we attached and the transaction type we
  193. // are requesting.
  194.  
  195. dbError diaRel::add(void) 
  196.     return diaErr(theDiamondBase.trans(refId,diamondBase::ti_add)); 
  197. }
  198.  
  199. dbError diaRel::seek(void) 
  200.     return diaErr(theDiamondBase.trans(refId,diamondBase::ti_seek)); 
  201. }
  202.  
  203. dbError diaRel::find(void) 
  204.     return diaErr(theDiamondBase.trans(refId,diamondBase::ti_find)); 
  205. }
  206.  
  207. dbError diaRel::del(void) 
  208.     return diaErr(theDiamondBase.trans(refId,diamondBase::ti_del)); 
  209. }
  210.  
  211. dbError diaRel::write(void) 
  212.     return diaErr(theDiamondBase.trans(refId,diamondBase::ti_write));
  213. }
  214.  
  215. dbError diaRel::put(void) 
  216.     return diaErr(theDiamondBase.trans(refId,diamondBase::ti_put));
  217. }
  218.  
  219. dbError diaRel::begin(int idx) 
  220. {
  221.     return diaErr(theDiamondBase.trans(refId,diamondBase::ti_begin, (long)idx));
  222. }
  223.  
  224. dbError diaRel::end(void) 
  225. {
  226.     return diaErr(theDiamondBase.trans(refId,diamondBase::ti_end));
  227. }
  228.  
  229. dbError diaRel::extract(void) 
  230. {
  231.     return diaErr(theDiamondBase.trans(refId,diamondBase::ti_extract));
  232. }
  233.  
  234. dbError diaRel::get(int idx) 
  235. {
  236.     return diaErr(theDiamondBase.trans(refId,diamondBase::ti_get,(long)idx));
  237. }
  238.  
  239. dbError diaRel::seekFirst(void) 
  240. {
  241.     return diaErr(theDiamondBase.trans(refId,diamondBase::ti_seekFirst));
  242. }
  243.  
  244. dbError diaRel::first(void) 
  245. {
  246.     return diaErr(theDiamondBase.trans(refId,diamondBase::ti_first));
  247. }
  248.  
  249. dbError diaRel::seekLast(void) 
  250. {
  251.     return diaErr(theDiamondBase.trans(refId,diamondBase::ti_seekLast));
  252. }
  253.  
  254. dbError diaRel::last(void) 
  255. {
  256.     return diaErr(theDiamondBase.trans(refId,diamondBase::ti_last));
  257. }
  258.  
  259. dbError diaRel::next(void) 
  260. {
  261.     return diaErr(theDiamondBase.trans(refId,diamondBase::ti_next));
  262. }
  263.  
  264. dbError diaRel::prev(void) 
  265. {
  266.     return diaErr(theDiamondBase.trans(refId,diamondBase::ti_prev));
  267. }
  268.  
  269. dbError diaRel::peekPrev(void) 
  270. {
  271.     return diaErr(theDiamondBase.trans(refId,diamondBase::ti_peekPrev));
  272. }
  273.  
  274. dbError diaRel::peekNext(void) 
  275. {
  276.     return diaErr(theDiamondBase.trans(refId,diamondBase::ti_peekNext));
  277. }
  278.  
  279. void diaRel::stats(void)
  280. {
  281.     diaErr(theDiamondBase.trans(refId,diamondBase::ti_stats));
  282. }
  283.