home *** CD-ROM | disk | FTP | other *** search
/ Complete Linux / Complete Linux.iso / docs / apps / database / postgres / postgre3.z / postgre3 / src / lib / H / tmp / postgres.h < prev    next >
Encoding:
C/C++ Source or Header  |  1993-05-06  |  14.5 KB  |  652 lines

  1. /* ----------------------------------------------------------------
  2.  *   FILE
  3.  *         postgres.h
  4.  *
  5.  *   DESCRIPTION
  6.  *         definition of (and support for) postgres system types.
  7.  *
  8.  *   NOTES
  9.  *    this file will eventually contain the definitions for the
  10.  *    following (and perhaps other) system types:
  11.  *
  12.  *        bool        bytea        char        
  13.  *        char16        dt        int2
  14.  *        int28        int4        oid        
  15.  *        oid8        regproc        text
  16.  *
  17.  *    Currently this file is also the home of struct varlena and
  18.  *    some other stuff.  Some of this may change.  -cim 8/6/90
  19.  *
  20.  *   TABLE OF CONTENTS
  21.  *    1)    simple type definitions
  22.  *    1a)    oid types (currently being reorganized)
  23.  *    2)    array types
  24.  *    3)    name type + support macros    \
  25.  *    4)    datum type + support macros     \ being reorganized
  26.  *    5)    xid type + support macros     /
  27.  *    6)    time types + support macros    /
  28.  *    7)    genbki macros used by catalog/pg_xxx.h files
  29.  *    8)    old types being obsoleted
  30.  *    9)    random SIGNBIT, PSIZE, MAXPGPATH, STATUS macros
  31.  *
  32.  *   IDENTIFICATION
  33.  *       $Header: /private/postgres/src/lib/H/tmp/RCS/postgres.h,v 1.24 1992/07/13 03:34:15 hong Exp $
  34.  * ----------------------------------------------------------------
  35.  */
  36.  
  37. #ifndef PostgresHIncluded        /* include only once */
  38. #define PostgresHIncluded
  39.  
  40. #include "tmp/c.h"
  41.  
  42. /* ----------------------------------------------------------------
  43.  *        Section 1:  simple type definitions
  44.  * ----------------------------------------------------------------
  45.  */
  46.  
  47. /* ----------------
  48.  *    bool
  49.  *
  50.  *    this is defined in c.h at present, but that will change soon.
  51.  *    Boolean should be obsoleted.
  52.  * ----------------
  53.  */
  54. /* XXX put bool here */
  55. #define Boolean bool
  56.  
  57. /* ----------------
  58.  *    dt
  59.  * ----------------
  60.  */
  61. typedef long    dt;
  62.  
  63. /* ----------------
  64.  *    int2
  65.  * ----------------
  66.  */
  67. typedef    int16    int2;
  68.  
  69. /* ----------------
  70.  *    int4
  71.  * ----------------
  72.  */
  73. typedef int32    int4;
  74.  
  75. /* ----------------
  76.  *    float4
  77.  * ----------------
  78.  */
  79. typedef float    float4;
  80.  
  81. /* ----------------
  82.  *    float8
  83.  * ----------------
  84.  */
  85. typedef double    float8;
  86.  
  87. /* ----------------------------------------------------------------
  88.  *        Section 1a:  oid types
  89.  * ----------------------------------------------------------------
  90.  */
  91. /* ----------------
  92.  *    oid
  93.  * ----------------
  94.  */
  95. typedef uint32    oid;
  96.  
  97. #define ObjectId oid
  98. #define InvalidObjectId    0
  99.  
  100. #define ObjectIdIsValid(objectId) \
  101.     ((bool) (objectId != InvalidObjectId))
  102.  
  103. /* ----------------
  104.  *    regproc
  105.  * ----------------
  106.  */
  107. typedef oid regproc;
  108.  
  109. typedef ObjectId RegProcedure;
  110.  
  111. #define RegProcedureIsValid(p) \
  112.     ObjectIdIsValid(p)
  113.  
  114. /* ----------------------------------------------------------------
  115.  *        Section 2:  array types
  116.  * ----------------------------------------------------------------
  117.  */
  118. /* ----------------
  119.  *    struct varlena
  120.  * ----------------
  121.  */
  122. struct varlena {
  123.     long    vl_len;
  124.     char    vl_dat[1];
  125. };
  126.  
  127. #define    VARSIZE(PTR)    (((struct varlena *)(PTR))->vl_len)
  128. #define    VARDATA(PTR)    (((struct varlena *)(PTR))->vl_dat)
  129.  
  130. /* ----------------
  131.  *    bytea
  132.  * ----------------
  133.  */
  134. typedef struct varlena bytea;
  135.  
  136. /* ----------------
  137.  *    char16
  138.  * ----------------
  139.  */
  140. typedef struct char16 {
  141.     char    data[16];
  142. } char16;
  143.  
  144. typedef char16    *Char16;
  145.  
  146. /* ----------------
  147.  *    int28
  148.  * ----------------
  149.  */
  150. typedef struct int28 {
  151.     int2    data[8];
  152. } int28;
  153.  
  154. /* ----------------
  155.  *    oid8
  156.  * ----------------
  157.  */
  158. typedef struct oid8 {
  159.     oid        data[8];
  160. } oid8;
  161.  
  162. /* ----------------
  163.  *    text
  164.  * ----------------
  165.  */
  166. typedef struct varlena text;
  167.  
  168. /* ----------------
  169.  *    stub
  170.  *
  171.  *    this is a new system type used by the rule manager.
  172.  * ----------------
  173.  */
  174. typedef struct varlena stub;
  175.  
  176. /* ----------------
  177.  *    oidint4
  178.  *
  179.  *    this is a new system type used by the file interface.
  180.  * ----------------
  181.  */
  182. typedef struct OidInt4Data {
  183.     ObjectId    oi_oid;
  184.     int32        oi_int4;
  185. } OidInt4Data;
  186.  
  187. typedef struct OidInt4Data    *OidInt4;
  188.  
  189. /* ----------------
  190.  *    oidchar16
  191.  *
  192.  *    this is a new system type used to define indices on two attrs.
  193.  * ----------------
  194.  */
  195. typedef struct OidChar16Data {
  196.     ObjectId    id;
  197.     char16        name;
  198. } OidChar16Data;
  199.  
  200. typedef struct OidChar16Data    *OidChar16;
  201.  
  202. /* ----------------------------------------------------------------
  203.  *        Section 3:  name type + support macros
  204.  * ----------------------------------------------------------------
  205.  */
  206. /* ----------------
  207.  *    name
  208.  *
  209.  *         definition of the catalog/system "name" data type.
  210.  *    This is used by some of the access method and catalog
  211.  *    support code.
  212.  * ----------------
  213.  */
  214. typedef char16        NameData;
  215. typedef NameData    *Name;
  216.  
  217. #define InvalidName    ((Name) NULL)
  218. #define    NameIsValid(name) PointerIsValid(name)
  219.  
  220. /* ----------------------------------------------------------------
  221.  *         Section 4:  datum type + support macros
  222.  * ----------------------------------------------------------------
  223.  */
  224. /*
  225.  * datum.h --
  226.  *    POSTGRES abstract data type datum representation definitions.
  227.  *
  228.  * Note:
  229.  *
  230.  * Port Notes:
  231.  *  Postgres makes the following assumption about machines:
  232.  *
  233.  *  sizeof(Datum) == sizeof(char *) == sizeof(long) == 4
  234.  *
  235.  *  Postgres also assumes that
  236.  *
  237.  *  sizeof(char) == 1
  238.  *
  239.  *  and that 
  240.  *
  241.  *  sizeof(short) == 2
  242.  *
  243.  *  If your machine meets these requirements, Datums should also be checked
  244.  *  to see if the positioning is correct.
  245.  *
  246.  *    This file is MACHINE AND COMPILER dependent!!!
  247.  */
  248.  
  249. #ifndef    DatumIncluded        /* Include this file only once */
  250. #define DatumIncluded    1
  251.  
  252. /*
  253.  * Identification:
  254.  */
  255. #define DATUM_H    "$Header: /private/postgres/src/lib/H/tmp/RCS/postgres.h,v 1.24 1992/07/13 03:34:15 hong Exp $"
  256.  
  257. typedef struct AnyStruct {
  258.     char    character;
  259.     double  largeFloat;
  260. } AnyStruct;
  261.  
  262. typedef unsigned long Datum;
  263. typedef Datum *       DatumPtr;
  264.  
  265. /*
  266.  * We want to pad to the right on Sun computers and to the right on
  267.  * the others.
  268.  * 
  269.  */
  270.  
  271. /*
  272.  * kai: Don't use the right-padding functions on the 386. They break postgres
  273.  * badly!
  274.  */
  275. #ifdef NOTDEF
  276.  
  277. #define GET_1_BYTE(datum)   ((((long) (datum)) & 0xff000000) >> 24)
  278. #define GET_2_BYTES(datum)  ((((long) (datum)) & 0xffff0000) >> 16)
  279. #define GET_4_BYTES(datum)  (datum)
  280. #define SET_1_BYTE(value)   (((long) (value)) << 24)
  281. #define SET_2_BYTES(value)  (((long) (value)) << 16)
  282. #define SET_4_BYTES(value)  (value)
  283.  
  284. #endif
  285.  
  286. #if defined(sequent) || defined(mips) || defined(sun) || defined(sparc) || defined(i386)
  287.  
  288. #define GET_1_BYTE(datum)   (((Datum) (datum)) & 0x000000ff)
  289. #define GET_2_BYTES(datum)  (((Datum) (datum)) & 0x0000ffff)
  290. #define GET_4_BYTES(datum)  ((Datum) (datum))
  291. #define SET_1_BYTE(value)   (((Datum) (value)) & 0x000000ff)
  292. #define SET_2_BYTES(value)  (((Datum) (value)) & 0x0000ffff)
  293. #define SET_4_BYTES(value)  ((Datum) (value))
  294.  
  295. #endif
  296.  
  297. /*
  298.  * DatumGetChar --
  299.  *    Returns character value of a datum.
  300.  */
  301.  
  302. #define DatumGetChar(X) ((char) GET_1_BYTE(X))
  303.  
  304. /*
  305.  * CharGetDatum --
  306.  *    Returns datum representation for a character.
  307.  */
  308.  
  309. #define CharGetDatum(X) ((Datum) SET_1_BYTE(X))
  310.  
  311. /*
  312.  * DatumGetInt8 --
  313.  *    Returns 8-bit integer value of a datum.
  314.  */
  315.  
  316. #define DatumGetInt8(X) ((int8) GET_1_BYTE(X))
  317.  
  318. /*
  319.  * Int8GetDatum --
  320.  *    Returns datum representation for an 8-bit integer.
  321.  */
  322.  
  323. #define Int8GetDatum(X) ((Datum) SET_1_BYTE(X))
  324.  
  325. /*
  326.  * DatumGetUInt8 --
  327.  *    Returns 8-bit unsigned integer value of a datum.
  328.  */
  329.  
  330. #define DatumGetUInt8(X) ((uint8) GET_1_BYTE(X))
  331.  
  332. /*
  333.  * UInt8GetDatum --
  334.  *    Returns datum representation for an 8-bit unsigned integer.
  335.  */
  336.  
  337. #define UInt8GetDatum(X) ((Datum) SET_1_BYTE(X))
  338.  
  339. /*
  340.  * DatumGetInt16 --
  341.  *    Returns 16-bit integer value of a datum.
  342.  */
  343.  
  344. #define DatumGetInt16(X) ((int16) GET_2_BYTES(X))
  345.  
  346. /*
  347.  * Int16GetDatum --
  348.  *    Returns datum representation for a 16-bit integer.
  349.  */
  350.  
  351. #define Int16GetDatum(X) ((Datum) SET_2_BYTES(X))
  352.  
  353. /*
  354.  * DatumGetUInt16 --
  355.  *    Returns 16-bit unsigned integer value of a datum.
  356.  */
  357.  
  358. #define DatumGetUInt16(X) ((uint16) GET_2_BYTES(X))
  359.  
  360. /*
  361.  * UInt16GetDatum --
  362.  *    Returns datum representation for a 16-bit unsigned integer.
  363.  */
  364.  
  365. #define UInt16GetDatum(X) ((Datum) SET_2_BYTES(X))
  366.  
  367. /*
  368.  * DatumGetInt32 --
  369.  *    Returns 32-bit integer value of a datum.
  370.  */
  371.  
  372. #define DatumGetInt32(X) ((int32) GET_4_BYTES(X))
  373.  
  374. /*
  375.  * Int32GetDatum --
  376.  *    Returns datum representation for a 32-bit integer.
  377.  */
  378.  
  379. #define Int32GetDatum(X) ((Datum) SET_4_BYTES(X))
  380.  
  381. /*
  382.  * DatumGetUInt32 --
  383.  *    Returns 32-bit unsigned integer value of a datum.
  384.  */
  385.  
  386. #define DatumGetUInt32(X) ((uint32) GET_4_BYTES(X))
  387.  
  388. /*
  389.  * UInt32GetDatum --
  390.  *    Returns datum representation for a 32-bit unsigned integer.
  391.  */
  392.  
  393. #define UInt32GetDatum(X) ((Datum) SET_4_BYTES(X))
  394.  
  395. /*
  396.  * DatumGetFloat32 --
  397.  *    Returns 32-bit floating point value of a datum.
  398.  */
  399.  
  400. #define DatumGetFloat32(X) ((float32) GET_4_BYTES(X))
  401.  
  402. /*
  403.  * Float32GetDatum --
  404.  *    Returns datum representation for a 32-bit floating point number.
  405.  */
  406.  
  407. #define Float32GetDatum(X) ((Datum) SET_4_BYTES(X))
  408.  
  409. /*
  410.  * DatumGetFloat64 --
  411.  *    Returns 64-bit floating point value of a datum.
  412.  */
  413.  
  414. #define DatumGetFloat64(X) ((float64) GET_4_BYTES(X))
  415.  
  416. /*
  417.  * Float64GetDatum --
  418.  *    Returns datum representation for a 64-bit floating point number.
  419.  */
  420.  
  421. #define Float64GetDatum(X) ((Datum) SET_4_BYTES(X))
  422.  
  423. /*
  424.  * DatumGetPointer --
  425.  *    Returns pointer value of a datum.
  426.  */
  427.  
  428. #define DatumGetPointer(X) ((Pointer) GET_4_BYTES(X))
  429.  
  430. /*
  431.  * PointerGetDatum --
  432.  *    Returns datum representation for a pointer.
  433.  */
  434.  
  435. #define PointerGetDatum(X) ((Datum) SET_4_BYTES(X))
  436.  
  437. /*
  438.  * DatumGetPointerPointer --
  439.  *    Returns pointer to pointer value of a datum.
  440.  */
  441.  
  442. #define DatumGetPointerPointer(X) ((Pointer *) GET_4_BYTES(X))
  443.  
  444. /*
  445.  * PointerPointerGetDatum --
  446.  *    Returns datum representation for a pointer to pointer.
  447.  */
  448.  
  449. #define PointerPointerGetDatum(X) ((Datum) SET_4_BYTES(X))
  450.  
  451. /*
  452.  * DatumGetStructPointer --
  453.  *    Returns pointer to structure value of a datum.
  454.  */
  455.  
  456. #define DatumGetStructPointer(X) ((AnyStruct *) GET_4_BYTES(X))
  457.  
  458. /*
  459.  * StructPointerGetDatum --
  460.  *    Returns datum representation for a pointer to structure.
  461.  */
  462.  
  463. #define StructPointerGetDatum(X) ((Datum) SET_4_BYTES(X))
  464.  
  465. /*
  466.  * DatumGetName --
  467.  *    Returns name value of a datum.
  468.  */
  469.  
  470. #define DatumGetName(X) ((Name) GET_4_BYTES(X))
  471.  
  472. /*
  473.  * NameGetDatum --
  474.  *    Returns datum representation for a name.
  475.  */
  476.  
  477. #define NameGetDatum(X) ((Datum) SET_4_BYTES(X))
  478.  
  479. /*
  480.  * DatumGetObjectId --
  481.  *    Returns object identifier value of a datum.
  482.  */
  483.  
  484. #define DatumGetObjectId(X) ((ObjectId) GET_4_BYTES(X))
  485.  
  486. /*
  487.  * ObjectIdGetDatum --
  488.  *    Returns datum representation for an object identifier.
  489.  */
  490.  
  491. #define ObjectIdGetDatum(X) ((Datum) SET_4_BYTES(X))
  492.  
  493. #endif    /* !defined(DatumIncluded) */
  494.  
  495.  
  496. /* ----------------------------------------------------------------
  497.  *        Section 5: xid type + support macros
  498.  * ----------------------------------------------------------------
  499.  */
  500. /* 
  501.  *    TransactionId definition
  502.  */
  503.  
  504. typedef unsigned long        TransactionId;
  505. #define TransactionIdDataSize    sizeof(long)
  506.  
  507. #define InvalidTransactionId    0
  508. #define NullTransactionIdValue    0
  509.  
  510. typedef unsigned long        TransactionIdValueData;
  511. typedef unsigned long        TransactionIdValue;
  512.  
  513. typedef unsigned short        CommandId;
  514.  
  515. #define FirstCommandId    0
  516.  
  517. #define TransactionMultiplierPerByte    (1 << BitsPerByte)
  518. #define TransactionsPerSecondAdjustment    TransactionMultiplierPerByte    
  519.  
  520. /* ----------------------------------------------------------------
  521.  *        Section 6: some time types + support macros
  522.  *
  523.  *    Note: see nabstime.h for time support macros
  524.  * ----------------------------------------------------------------
  525.  */
  526.  
  527. typedef uint32    Time;            /* XXX this will disappear */
  528.  
  529. typedef uint32    RelativeTime;
  530. #define InvalidRelativeTime    0
  531.  
  532. /* ----------------------------------------------------------------
  533.  *        Section 7: genbki macros used by the
  534.  *               catalog/pg_xxx.h files
  535.  * ----------------------------------------------------------------
  536.  */
  537. #define CATALOG(x) \
  538.     typedef struct CppConcat(FormData_,x)
  539.  
  540. #define DATA(x)
  541. #define DEFINE_INDEX(x)
  542. #define BOOTSTRAP
  543.  
  544. #define BKI_BEGIN
  545. #define BKI_END
  546.  
  547. /* ----------------------------------------------------------------
  548.  *        Section 8: old types being obsoleted
  549.  * ----------------------------------------------------------------
  550.  */
  551. typedef    long    XID;
  552. #define    CID    unsigned short
  553. #define    ABSTIME    long
  554. #define    RELTIME    long
  555.  
  556. #define OID    oid
  557. #define    REGPROC    oid        /* for now */
  558.  
  559. #if defined(sun) || defined(sequent) || defined(mips) || defined(linux)
  560. typedef    char    *DATUM;
  561. #else
  562. typedef    union {
  563.     char    *da_cprt;
  564.     short    *da_shprt;
  565.     long    *da_lprt;
  566.     char    **da_cpprt;
  567.     struct    {
  568.         char    s_c;
  569.         double    s_d;
  570.     }    *da_stptr;
  571.     long    da_long;
  572. }        DATUM;
  573. #endif
  574.  
  575.  
  576. /* ----------------------------------------------------------------
  577.  *        Section 9:  random stuff
  578.  *                SIGNBIT, PSIZE, MAXPGPATH, STATUS...
  579.  * ----------------------------------------------------------------
  580.  */
  581.  
  582. /* msb for int/unsigned */
  583. #define    SIGNBIT    (0x8000)
  584.  
  585. /* msb for char */
  586. #define    CSIGNBIT (1 << 7)
  587.  
  588. /* ----------------
  589.  *    PSIZE
  590.  * ----------------
  591.  */
  592. #define    PSIZE(PTR)    (*((int32 *)(PTR) - 1))
  593. #define    PSIZEALL(PTR)    (*((int32 *)(PTR) - 1) + sizeof (int32))
  594. #define    PSIZESKIP(PTR)    ((char *)((int32 *)(PTR) + 1))
  595. #define    PSIZEFIND(PTR)    ((char *)((int32 *)(PTR) - 1))
  596. #define    PSIZESPACE(LEN)    ((LEN) + sizeof (int32))
  597.  
  598. /* ----------------
  599.  *    global variable which should probably go someplace else.
  600.  * ----------------
  601.  */
  602. #define    MAXPGPATH    128
  603.  
  604. #define STATUS_OK               (0)
  605. #define STATUS_ERROR            (-1)
  606. #define STATUS_NOT_FOUND        (-2)
  607. #define STATUS_INVALID          (-3)
  608. #define STATUS_UNCATALOGUED     (-4)
  609. #define STATUS_REPLACED         (-5)
  610. #define STATUS_NOT_DONE        (-6)
  611. #define STATUS_FOUND            (1)
  612.  
  613. /*
  614.  * The following is a gimmick to pass functions that return void as
  615.  * paramters to other functions.  This type defined here is used as
  616.  * the cast.
  617.  */
  618. typedef Pointer (*VoidFunctionType)();
  619.  
  620. /* ----------------------------------------------------------------
  621.  *    externs
  622.  *
  623.  *    This should be eliminated or moved elsewhere
  624.  * ----------------------------------------------------------------
  625.  */
  626. extern bool NameIsEqual ARGS((Name name1, Name name2));
  627. extern uint32 NameComputeLength ARGS((Name name));
  628.  
  629. extern TransactionId    NullTransactionId;
  630. extern TransactionId    AmiTransactionId;
  631. extern TransactionId    FirstTransactionId;
  632.  
  633. extern bool TransactionIdIsValid ARGS((TransactionId transactionId));
  634. extern void GetNewTransactionId ARGS((TransactionId *xid));
  635. extern TransactionId StringFormTransactionId ARGS((String representation));
  636. extern String TransactionIdFormString ARGS((TransactionId transactionId));
  637. extern void TransactionIdStore
  638.     ARGS((TransactionId    transactionId, TransactionId *destination));
  639. extern void PointerStoreInvalidTransactionId ARGS((Pointer destination));
  640. extern bool TransactionIdEquals ARGS((TransactionId id1,TransactionId id2));
  641. extern bool TransactionIdIsLessThan 
  642.     ARGS((TransactionId    id1, TransactionId id2));
  643. extern bool TransactionIdValueIsValid ARGS((TransactionIdValue value));
  644.  
  645. extern void TransactionIdIncrement ARGS((TransactionId *transactionId));
  646.     
  647. /* ----------------
  648.  *    end of postgres.h
  649.  * ----------------
  650.  */
  651. #endif PostgresHIncluded
  652.