home *** CD-ROM | disk | FTP | other *** search
/ PC World 1998 October / PCWorld_1998-10_cd.bin / software / prehled / komix / DATA.Z / DBObject.ec < prev    next >
Text File  |  1997-10-15  |  3KB  |  122 lines

  1. /*---------------------------------------------------------------------------
  2.  *
  3.  * Copyright (c) 1994 by Westmount Technology B.V., Delft, The Netherlands.
  4.  *
  5.  * This software is furnished under a license and may be used only in
  6.  * accordance with the terms of such license and with the inclusion of
  7.  * the above copyright notice. This software or any other copies thereof
  8.  * may not be provided or otherwise made available to any other person.
  9.  * No title to and ownership of the software is hereby transferred.
  10.  *
  11.  * The information in this software is subject to change without notice
  12.  * and should not be construed as a commitment by Westmount Technology B.V.
  13.  *
  14.  *---------------------------------------------------------------------------
  15.  *
  16.  *    File        : @(#)DBObject.ec    /main/titanic/1
  17.  *    Original date    : Mon Feb 21 14:49:59 MET 1994
  18.  *    Description    : Base Class for all Database Classes
  19.  *              uses RogueWave class library
  20.  *
  21.  *---------------------------------------------------------------------------
  22.  */
  23. static const char SccsId[]="@(#)DBObject.ec    /main/titanic/1 15 Oct 1997 Copyright 1994 Westmount Technology";
  24.  
  25. #include <string.h>
  26.  
  27. #ifndef DBOBJECT_HXX
  28. #include "DBObject.hxx"
  29. #endif
  30.  
  31. #ifndef INFORMIX_HXX
  32. #include "Informix.hxx"
  33. #endif
  34.  
  35. #ifndef SQLPRINT_HXX
  36. #include "SqlPrint.hxx"
  37. #endif
  38.  
  39. $define MAX_NAME_LEN 80;
  40.  
  41. static unsigned hashInt(const int& i)
  42. {
  43.     return i;
  44. }
  45.  
  46. static unsigned hashName(const RWCString& s)
  47. {
  48.     return s.hash();
  49. }
  50.  
  51. DBObject::DBObject(const RWCString &name) :
  52.     dbState(CREATED),
  53.     className(name)
  54. {
  55. }
  56.  
  57. DBObject::~DBObject()
  58. {
  59. }
  60.  
  61. int DBObject::connectDB(const char *name)
  62. {
  63.     const
  64.     $char *dbName = name;
  65.  
  66.     $WHENEVER SQLERROR CALL sqlprint;
  67.  
  68.     $DATABASE $dbName;
  69.     if (sqlca.sqlcode != 0)
  70.         return -1;
  71.  
  72.     return 0;
  73. }
  74.  
  75. int DBObject::beginWork()
  76. {
  77.     $begin work;
  78.     return sqlca.sqlcode != 0 ? -1 : 0;
  79. }
  80.  
  81. int DBObject::commit()
  82. {
  83.     $commit work;
  84.     return sqlca.sqlcode != 0 ? -1 : 0;
  85. }
  86.  
  87. int DBObject::rollback()
  88. {
  89.     $rollback work;
  90.     return sqlca.sqlcode != 0 ? -1 : 0;
  91. }
  92.  
  93. int DBObject::notFound()
  94. {
  95.     return dbState == SQL_ERROR && sqlca.sqlcode == 100;
  96. }
  97.  
  98. void DBObject::resetState()
  99. {
  100.     dbState = CREATED;
  101. }
  102.  
  103. int DBObject::processSqlStatus()
  104. {
  105.     switch (dbState) {
  106.     case CREATED:
  107.     case NORMAL:
  108.         if (sqlca.sqlcode != 0) {
  109.             dbState = SQL_ERROR;
  110.             return -1;
  111.         } else {
  112.             dbState = NORMAL;
  113.             return 0;
  114.         }
  115.     case SQL_ERROR:
  116.     case TYPE_ERROR:
  117.         return -1;
  118.     }
  119.     return -1;
  120. }
  121.  
  122.