home *** CD-ROM | disk | FTP | other *** search
/ PC World 1997 November / PCWorld_1997-11_cd.bin / software / programy / komix / DATA.Z / DBObject.ec < prev    next >
Text File  |  1996-05-31  |  3KB  |  124 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    1.4
  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    1.4 17 Oct 1995 Copyright 1994 Westmount Technology";
  24.  
  25. #include "stream.h"
  26.  
  27. #include <string.h>
  28.  
  29. #ifndef DBOBJECT_HXX
  30. #include "DBObject.hxx"
  31. #endif
  32.  
  33. #ifndef INFORMIX_HXX
  34. #include "Informix.hxx"
  35. #endif
  36.  
  37. #ifndef SQLPRINT_HXX
  38. #include "SqlPrint.hxx"
  39. #endif
  40.  
  41. $define MAX_NAME_LEN 80;
  42.  
  43. static unsigned hashInt(const int& i)
  44. {
  45.     return i;
  46. }
  47.  
  48. static unsigned hashName(const RWCString& s)
  49. {
  50.     return s.hash();
  51. }
  52.  
  53. DBObject::DBObject(const RWCString &name) :
  54.     dbState(CREATED),
  55.     className(name)
  56. {
  57. }
  58.  
  59. DBObject::~DBObject()
  60. {
  61. }
  62.  
  63. int DBObject::connectDB(const char *name)
  64. {
  65.     const
  66.     $char *dbName = name;
  67.  
  68.     $WHENEVER SQLERROR CALL sqlprint;
  69.  
  70.     $DATABASE $dbName;
  71.     if (sqlca.sqlcode != 0)
  72.         return -1;
  73.  
  74.     return 0;
  75. }
  76.  
  77. int DBObject::beginWork()
  78. {
  79.     $begin work;
  80.     return sqlca.sqlcode != 0 ? -1 : 0;
  81. }
  82.  
  83. int DBObject::commit()
  84. {
  85.     $commit work;
  86.     return sqlca.sqlcode != 0 ? -1 : 0;
  87. }
  88.  
  89. int DBObject::rollback()
  90. {
  91.     $rollback work;
  92.     return sqlca.sqlcode != 0 ? -1 : 0;
  93. }
  94.  
  95. int DBObject::notFound()
  96. {
  97.     return dbState == SQL_ERROR && sqlca.sqlcode == 100;
  98. }
  99.  
  100. void DBObject::resetState()
  101. {
  102.     dbState = CREATED;
  103. }
  104.  
  105. int DBObject::processSqlStatus()
  106. {
  107.     switch (dbState) {
  108.     case CREATED:
  109.     case NORMAL:
  110.         if (sqlca.sqlcode != 0) {
  111.             dbState = SQL_ERROR;
  112.             return -1;
  113.         } else {
  114.             dbState = NORMAL;
  115.             return 0;
  116.         }
  117.     case SQL_ERROR:
  118.     case TYPE_ERROR:
  119.         return -1;
  120.     }
  121.     return -1;
  122. }
  123.  
  124.