home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / database / cdb114.zip / DBMGR.H < prev    next >
Text File  |  1991-03-09  |  12KB  |  264 lines

  1. /*
  2.  *  dbmgr.h
  3.  *
  4.  *  This file contains structures, macros and #defines for
  5.  *  the database layout.
  6.  *
  7.  *  Copyright (C) 1989, 1990, 1991 by Daytris.  All rights reserved.
  8.  */
  9.  
  10. extern short    cdb( short, ...);
  11. extern char     dbpath[];
  12.  
  13. typedef char            CHAR;
  14. typedef unsigned char   UCHAR;
  15. typedef short           INT;
  16. typedef unsigned short  UINT;
  17. typedef long            LONG;
  18. typedef unsigned long   ULONG;
  19.  
  20. #define NBRHANDLES      12      /* Maximum number of file handles       */
  21. #define MAXKEY          8       /* Maximum # of keys per key record     */
  22. #define KEYPAGESIZE     512     /* Key page buffer size                 */
  23. #define NBRPAGES        16      /* Number of key page buffers           */
  24. #define DATAPAGESIZE    2048    /* Data page buffer size                */
  25. #define DATASLOTSIZE    1024    /* Data file slot buffer size           */
  26.  
  27. /* Field index structure defines */
  28. #define KEY_FIELD       0x01
  29. #define SET_KEY_FIELD   0x01
  30.  
  31. /* Handle index structure defines */
  32. #define FILE_MODIFIED   0x01
  33.  
  34. /* Key file index structure defines */
  35. #define PAGE_FULL       0x01
  36.  
  37. /* Error defines */
  38. #define E_INVALIDCASE   -2
  39. #define E_DOS           -1
  40. #define E_NORECNAME     1
  41. #define E_NOFLDNAME     2
  42. #define E_INVALIDSET    3
  43. #define E_NOTAKEY       4
  44. #define E_NOTFOUND      5
  45. #define E_NEXTGUESS     6
  46. #define E_NOCURRENT     7
  47. #define E_NONEXT        8
  48. #define E_NOPREV        9
  49. #define E_NOMEMBER      10
  50. #define E_NOOWNER       11
  51.  
  52. /* DBC call defines */
  53. #define D_OPEN                  0
  54. #define D_CLOSE                 1
  55. #define D_FLUSH                 2
  56. #define D_GET_CURRENCY          3
  57. #define D_UPDATE_CURRENCY       4
  58. #define D_FIND_FIRST_RECORD     5
  59. #define D_FIND_LAST_RECORD      6
  60. #define D_FIND_NEXT_RECORD      7
  61. #define D_FIND_PREV_RECORD      8
  62. #define D_FIND_RECORD_BY_KEY    9
  63. #define D_GET_FIRST_RECORD      10
  64. #define D_GET_LAST_RECORD       11
  65. #define D_GET_NEXT_RECORD       12
  66. #define D_GET_PREV_RECORD       13
  67. #define D_GET_RECORD_BY_KEY     14
  68. #define D_GET_CURRENT_RECORD    15
  69. #define D_ADD_RECORD            16
  70. #define D_UPDATE_RECORD         17
  71. #define D_DELETE_RECORD         18
  72. #define D_FIND_FIRST_SET        19
  73. #define D_FIND_LAST_SET         20
  74. #define D_FIND_NEXT_SET         21
  75. #define D_FIND_PREV_SET         22
  76. #define D_GET_FIRST_SET         23
  77. #define D_GET_LAST_SET          24
  78. #define D_GET_NEXT_SET          25
  79. #define D_GET_PREV_SET          26
  80. #define D_GET_SET_OWNER         27
  81. #define D_ADD_SET               28
  82. #define D_DELETE_SET            29
  83.  
  84. /* DataBase Macros */
  85. #define DbOpen(a)                       cdb(D_OPEN, a)
  86. #define DbClose()                       cdb(D_CLOSE)
  87. #define DbFlush()                       cdb(D_FLUSH)
  88. #define DbRecordGetCurrency(a,b)        cdb(D_GET_CURRENCY,a,b)
  89. #define DbRecordUpdCurrency(a,b)        cdb(D_UPDATE_CURRENCY,a,b)
  90. #define DbRecordFindFirst(a,b)          cdb(D_FIND_FIRST_RECORD,a,b)
  91. #define DbRecordFindLast(a,b)           cdb(D_FIND_LAST_RECORD,a,b)
  92. #define DbRecordFindNext(a,b)           cdb(D_FIND_NEXT_RECORD,a,b)
  93. #define DbRecordFindPrev(a,b)           cdb(D_FIND_PREV_RECORD,a,b)
  94. #define DbRecordFindByKey(a,b,c)        cdb(D_FIND_RECORD_BY_KEY,a,b,c)
  95. #define DbRecordGetFirst(a,b,c)         cdb(D_GET_FIRST_RECORD,a,b,c)
  96. #define DbRecordGetLast(a,b,c)          cdb(D_GET_LAST_RECORD,a,b,c)
  97. #define DbRecordGetNext(a,b,c)          cdb(D_GET_NEXT_RECORD,a,b,c)
  98. #define DbRecordGetPrev(a,b,c)          cdb(D_GET_PREV_RECORD,a,b,c)
  99. #define DbRecordGetByKey(a,b,c,d)       cdb(D_GET_RECORD_BY_KEY,a,b,c,d)
  100. #define DbRecordGetCurrent(a,b,c)       cdb(D_GET_CURRENT_RECORD,a,b,c)
  101. #define DbRecordAdd(a,b)                cdb(D_ADD_RECORD,a,b)
  102. #define DbRecordUpdate(a,b)             cdb(D_UPDATE_RECORD,a,b)
  103. #define DbRecordDelete(a)               cdb(D_DELETE_RECORD,a)
  104. #define DbSetFindFirst(a,b)             cdb(D_FIND_FIRST_SET,a,b)
  105. #define DbSetFindLast(a,b)              cdb(D_FIND_LAST_SET,a,b)
  106. #define DbSetFindNext(a,b)              cdb(D_FIND_NEXT_SET,a,b)
  107. #define DbSetFindPrev(a,b)              cdb(D_FIND_PREV_SET,a,b)
  108. #define DbSetGetFirst(a,b,c)            cdb(D_GET_FIRST_SET,a,b,c)
  109. #define DbSetGetLast(a,b,c)             cdb(D_GET_LAST_SET,a,b,c)
  110. #define DbSetGetNext(a,b,c)             cdb(D_GET_NEXT_SET,a,b,c)
  111. #define DbSetGetPrev(a,b,c)             cdb(D_GET_PREV_SET,a,b,c)
  112. #define DbSetGetOwner(a,b,c)            cdb(D_GET_SET_OWNER,a,b,c)
  113. #define DbSetAdd(a,b)                   cdb(D_ADD_SET,a,b)
  114. #define DbSetDelete(a,b)                cdb(D_DELETE_SET,a,b)
  115.  
  116.  
  117. /* DataBase structures and unions */
  118. union  type
  119.     {
  120.     CHAR                charval;
  121.     INT                 intval;
  122.     LONG                longval;
  123.     float               floatval;
  124.     double              doubleval;
  125.     CHAR                *ptrval;
  126.     UCHAR               ucharval;
  127.     UINT                uintval;
  128.     ULONG               ulongval;
  129.     };
  130.  
  131. struct dbheader                         /* 128 bytes                    */
  132.     {               
  133.     CHAR                title[96];      /* DBD title                    */
  134.     UINT                totrecs;        /* Total number of records      */
  135.     UINT                totowns;        /* Total number of owners       */
  136.     UINT                totmems;        /* Total number of members      */
  137.     UINT                totflds;        /* Total number of fields       */
  138.     CHAR                prefix[6];      /* File prefix description      */
  139.     CHAR                filler[18];
  140.     };
  141.  
  142. struct record_index                     /* 46 bytes                     */
  143.     {
  144.     UINT                firstown;       /* First owner                  */
  145.     UINT                nbrowns;        /* Number of owners             */
  146.     UINT                firstmem;       /* First member                 */
  147.     UINT                nbrmems;        /* Number of members            */
  148.     UINT                firstfld;       /* First field                  */
  149.     UINT                nbrflds;        /* Number of fields             */
  150.     UINT                reclen;         /* Record length                */
  151.     CHAR                recname[32];    /* Record name                  */
  152.     };
  153.  
  154. struct owner_index                      /* 4 bytes                      */
  155.     {
  156.     UINT                nextown;        /* Next owner                   */
  157.     UINT                ownnum;         /* Owner record number          */
  158.     };
  159.  
  160. struct member_index                     /* 8 bytes                      */
  161.     {
  162.     UINT                nextmem;        /* Next member                  */
  163.     UINT                memnum;         /* Member record number         */
  164.     UINT                memkeyfld;      /* Key field number for set     */
  165.     UINT                memflags;       /* Bit 0 - key field present    */
  166.     };
  167.  
  168. struct field_index                      /* 40 bytes                     */
  169.     {
  170.     UCHAR               fldtype;        /* Field type  Bit 0 - char     */
  171.                                         /*             Bit 1 - int      */
  172.                                         /*             Bit 2 - short    */
  173.                                         /*             Bit 3 - long     */
  174.                                         /*             Bit 4 - float    */
  175.                                         /*             Bit 5 - double   */
  176.                                         /*             Bit 7 - unsigned */
  177.     UINT                fldlen;         /* Field length                 */
  178.     UINT                flddim;         /* Field dimension              */
  179.     CHAR                fldname[32];    /* Field name                   */
  180.     UINT                fldkey;         /* Key number of data struct    */
  181.     UCHAR               fldflags;       /* Bit 0 - key field            */
  182.     };
  183.  
  184. /* Field casting defines */
  185. #define FLDTYPE_CHAR            0x01
  186. #define FLDTYPE_INT             0x02
  187. #define FLDTYPE_SHORT           0x04
  188. #define FLDTYPE_LONG            0x08
  189. #define FLDTYPE_FLOAT           0x10
  190. #define FLDTYPE_DOUBLE          0x20
  191. #define FLDTYPE_UNSIGNED        0x80
  192.  
  193. struct  key_file_index                  /* 32 bytes                     */
  194.     {
  195.     CHAR        name[12];               /* Key file name                */
  196.     UINT        nextavailpage;          /* Next available page          */
  197.     UINT        firstdelpage;           /* First page in the delete     */
  198.                                         /* chain.                       */
  199.     UINT        pagenbr[MAXKEY];        /* Key 1st page index           */
  200.     };
  201.  
  202. struct  key_page_index                  /* 10 bytes                     */
  203.     {
  204.     UINT        prevpage;               /* Previous page in sort tree   */
  205.     UINT        nextpage;               /* Next page in sort tree       */
  206.     UINT        slotsused;              /* Number of slots used on page */
  207.     UINT        slotsize;               /* Size of key slot             */
  208.     UINT        flags;                  /* Bit 0 - page is full         */
  209.     };
  210.  
  211. struct  data_file_index                 /* 32 bytes                     */
  212.     {
  213.     CHAR        name[12];               /* Data file name               */
  214.     ULONG       nextavailslot;          /* Next available slot          */
  215.     ULONG       firstdelslot;           /* First slot in the delete     */
  216.                                         /* chain.                       */
  217.     UINT        slotsize;               /* Size of data slot            */
  218.     CHAR        filler[10];
  219.     };
  220.  
  221. struct  data_slot_index                 /* 6 bytes                      */
  222.     {
  223.     UINT        offsettodata;           /* Offset to actual data        */
  224.     ULONG       nextdel;                /* DBA of next member in the    */
  225.                                         /* delete chain.                */
  226.     };
  227.  
  228. struct  ownptr_index                    /* 8 bytes                      */
  229.     {
  230.     ULONG       firstmem;               /* Dba of first member          */
  231.     ULONG       lastmem;                /* Dba of last member           */
  232.     };
  233.  
  234. struct  memptr_index                    /* 12 bytes                     */
  235.     {
  236.     ULONG       owndba;                 /* Dba of owner record          */
  237.     ULONG       prevmem;                /* Dba of prev member in chain  */
  238.     ULONG       nextmem;                /* Dba of next member in chain  */
  239.     };
  240.  
  241. struct handle_index                     /* 4 bytes                      */
  242.     {
  243.     INT         handle;                 /* Handle number                */
  244.     UINT        flags;                  /* Bit 0 - set if modified      */
  245.     };
  246.  
  247. struct page_index                       /* 518 bytes                    */
  248.     {
  249.     UINT        recnbr;                 /* Record number                */
  250.     UINT        fldnbr;                 /* Field number                 */
  251.     UINT        diskpagenbr;            /* Page number                  */
  252.     CHAR        buffer[KEYPAGESIZE];    /* Data buffer                  */
  253.     };
  254.  
  255. struct currency_index                   /* 36 bytes                     */
  256.     {
  257.     struct 
  258.         {
  259.         UINT    page;
  260.         UINT    slot;
  261.         } keydba[MAXKEY];               /* Array of key dba's           */
  262.     ULONG       datadba;                /* Data database address        */
  263.     };
  264.