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

  1. /**************************************************************************
  2.  * Source Id :
  3.  *
  4.  * $Id: db2txt.cc,v 1.3 1993/10/28 07:49:01 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.  *    Convert a dbObject to text format, outputing in index 0 order.
  24.  *
  25.  *  Original Author : Kev
  26.  *
  27.  *-------------------------------------------------------------------------
  28.  * Revision History:
  29.  *
  30.  * $Log: db2txt.cc,v $
  31. // Revision 1.3  1993/10/28  07:49:01  kevinl
  32. // Added diaGRel dbString/dbData support
  33. //
  34. // Revision 1.2  1993/10/18  08:03:10  kevinl
  35. // Spelling mistook
  36. //
  37. // Revision 1.1  1993/10/10  23:25:28  kevinl
  38. // Initial revision
  39. //
  40.  **************************************************************************/
  41.  
  42. #include <iostream.h>
  43. #include <stdlib.h>
  44. #include <diagrel.h>
  45. #include <generate.h>
  46.  
  47. diamondBase theDiamondBase("");
  48.  
  49. #define OUT(data,off,typ) *((typ*)(((char*)data)+off))
  50.  
  51. void
  52. outputField(ostream& o, memServer* ms, void* data, long off, char type, long count)
  53. {
  54.     if (count != 1)
  55.         o << "[" << count << "]";
  56.     o << " ";
  57.     if (type == D_CHAR)
  58.         o << ((char*)data)+off;
  59.     else
  60.         for (int i=0; i<count; i++) {
  61.             switch (type) {
  62.                 case D_SHORT:
  63.                     o << OUT(data,off,short);
  64.                     break;
  65.                 case D_USHORT:
  66.                     o << OUT(data, off, unsigned short);
  67.                     break;
  68.                 case D_DATA:
  69.                 {
  70.                     dbData s;
  71.                     ms->getString(s, OUT(data, off, long));
  72.                     o << s << " @ " << OUT(data, off, long);
  73.                     break;
  74.                 }
  75.                 case D_STRING:
  76.                 {
  77.                     dbString s;
  78.                     ms->getString(s, OUT(data, off, long));
  79.                     o << s << " @ " << OUT(data, off, long);
  80.                     break;
  81.                 }
  82.                 case D_LONG:
  83.                     o << OUT(data, off, long);
  84.                     break;
  85.                 case D_ULONG:
  86.                     o << OUT(data, off, unsigned long);
  87.                     break;
  88.                 case D_DOUBLE:
  89.                     o << OUT(data, off, double);
  90.                     break;
  91.                 case D_FLOAT:
  92.                     o << OUT(data, off, float);
  93.                     break;
  94.                 case D_MONEY:
  95.                     o << OUT(data, off, moneyType);
  96.                     break;
  97.                 case D_DATE:
  98.                     o << OUT(data, off, dateType);
  99.                     break;
  100.                 case D_UNIQUE:
  101.                     o << OUT(data, off, uniqueType);
  102.                     break;
  103.                 default:
  104.                     dbErr("Unknown type");
  105.             }
  106.             off++;
  107.             o << " ";
  108.         }
  109. }
  110.  
  111. int main(int argc, char** argv)
  112. {
  113.     if (argc != 2) {    
  114.         cerr << "Syntax: " << argv[0] << " relation" << endl;
  115.         exit (1);
  116.     }
  117.  
  118.     diaGRel rel(argv[1]);
  119.     if (!rel.ok()) {
  120.         rel.perror("Can't open relation");
  121.         exit (2);
  122.     }
  123.  
  124.     memServer* ms = 0;
  125.     if (rel.numStrings())
  126.     {
  127.         dbString strName = argv[1];
  128.         strName += ".str";
  129.         ms = new memServer(strName);
  130.     }
  131.  
  132.     cout << "REL " << argv[1] << endl;
  133.     rel.begin();
  134.     while (rel.next() != db_eof) {
  135.         cout << "REC " << rel.getRecNum() << endl;
  136.         dbObjData* d = rel.getObjData();
  137.         for (int i = 0; i < d->numFields; i++) {
  138.             cout << "FLD " << d->fieldName[i] << " " << typeName(d->fieldType[i],true);
  139.             outputField(cout, ms, rel.theData, d->fieldOffset[i], d->fieldType[i], d->fieldLength[i] / mySizeOf(d->fieldType[i]));
  140.             cout << endl;
  141.         }
  142.     }
  143.     rel.end();
  144. }
  145.