Eneboo - Documentación para desarrolladores
src/libpq/include/postgres.h
Ir a la documentación de este archivo.
00001 /*-------------------------------------------------------------------------
00002  *
00003  * postgres.h
00004  *   Primary include file for PostgreSQL server .c files
00005  *
00006  * This should be the first file included by PostgreSQL backend modules.
00007  * Client-side code should include postgres_fe.h instead.
00008  *
00009  *
00010  * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
00011  * Portions Copyright (c) 1995, Regents of the University of California
00012  *
00013  * $PostgreSQL: pgsql/src/include/postgres.h,v 1.71 2005/04/14 01:38:21 tgl Exp $
00014  *
00015  *-------------------------------------------------------------------------
00016  */
00017 /*
00018  *----------------------------------------------------------------
00019  *  TABLE OF CONTENTS
00020  *
00021  *  When adding stuff to this file, please try to put stuff
00022  *  into the relevant section, or add new sections as appropriate.
00023  *
00024  *   section description
00025  *   ------- ------------------------------------------------
00026  *  1)  variable-length datatypes (TOAST support)
00027  *  2)  datum type + support macros
00028  *  3)  exception handling definitions
00029  *  4)  genbki macros used by catalog/pg_xxx.h files
00030  *
00031  *  NOTES
00032  *
00033  * In general, this file should contain declarations that are widely needed
00034  * in the backend environment, but are of no interest outside the backend.
00035  *
00036  * Simple type definitions live in c.h, where they are shared with
00037  * postgres_fe.h. We do that since those type definitions are needed by
00038  * frontend modules that want to deal with binary data transmission to or
00039  * from the backend.  Type definitions in this file should be for
00040  * representations that never escape the backend, such as Datum or
00041  * TOASTed varlena objects.
00042  *
00043  *----------------------------------------------------------------
00044  */
00045 #ifndef POSTGRES_H
00046 #define POSTGRES_H
00047 
00048 #include "c.h"
00049 #include "utils/elog.h"
00050 #include "utils/palloc.h"
00051 
00052 /* ----------------------------------------------------------------
00053  *    Section 1: variable-length datatypes (TOAST support)
00054  * ----------------------------------------------------------------
00055  */
00056 
00057 /* ----------------
00058  * struct varattrib is the header of a varlena object that may have been
00059  * TOASTed.
00060  * ----------------
00061  */
00062 typedef struct varattrib {
00063   int32  va_header;  /* External/compressed storage */
00064   /* flags and item size */
00065   union {
00066     struct {
00067       int32  va_rawsize;  /* Plain data size */
00068       char  va_data[1];  /* Compressed data */
00069     }   va_compressed;  /* Compressed stored attribute */
00070 
00071     struct {
00072       int32  va_rawsize;  /* Plain data size */
00073       int32  va_extsize;  /* External saved size */
00074       Oid   va_valueid;  /* Unique identifier of value */
00075       Oid   va_toastrelid; /* RelID where to find chunks */
00076     }   va_external; /* External stored attribute */
00077 
00078     char  va_data[1]; /* Plain stored attribute */
00079   }   va_content;
00080 } varattrib;
00081 
00082 #define VARATT_FLAG_EXTERNAL 0x80000000
00083 #define VARATT_FLAG_COMPRESSED 0x40000000
00084 #define VARATT_MASK_FLAGS  0xc0000000
00085 #define VARATT_MASK_SIZE  0x3fffffff
00086 
00087 #define VARATT_SIZEP(_PTR) (((varattrib *)(_PTR))->va_header)
00088 #define VARATT_SIZE(PTR) (VARATT_SIZEP(PTR) & VARATT_MASK_SIZE)
00089 #define VARATT_DATA(PTR) (((varattrib *)(PTR))->va_content.va_data)
00090 #define VARATT_CDATA(PTR) (((varattrib *)(PTR))->va_content.va_compressed.va_data)
00091 
00092 #define VARSIZE(__PTR)  VARATT_SIZE(__PTR)
00093 #define VARDATA(__PTR)  VARATT_DATA(__PTR)
00094 
00095 #define VARATT_IS_EXTENDED(PTR)  \
00096   ((VARATT_SIZEP(PTR) & VARATT_MASK_FLAGS) != 0)
00097 #define VARATT_IS_EXTERNAL(PTR)  \
00098   ((VARATT_SIZEP(PTR) & VARATT_FLAG_EXTERNAL) != 0)
00099 #define VARATT_IS_COMPRESSED(PTR) \
00100   ((VARATT_SIZEP(PTR) & VARATT_FLAG_COMPRESSED) != 0)
00101 
00102 
00103 /* ----------------------------------------------------------------
00104  *    Section 2: datum type + support macros
00105  * ----------------------------------------------------------------
00106  */
00107 
00108 /*
00109  * Port Notes:
00110  * Postgres makes the following assumption about machines:
00111  *
00112  * sizeof(Datum) == sizeof(long) >= sizeof(void *) >= 4
00113  *
00114  * Postgres also assumes that
00115  *
00116  * sizeof(char) == 1
00117  *
00118  * and that
00119  *
00120  * sizeof(short) == 2
00121  *
00122  * If your machine meets these requirements, Datums should also be checked
00123  * to see if the positioning is correct.
00124  */
00125 
00126 typedef unsigned long Datum; /* XXX sizeof(long) >= sizeof(void *) */
00127 
00128 #define SIZEOF_DATUM SIZEOF_UNSIGNED_LONG
00129 typedef Datum *DatumPtr;
00130 
00131 #define GET_1_BYTE(datum) (((Datum) (datum)) & 0x000000ff)
00132 #define GET_2_BYTES(datum) (((Datum) (datum)) & 0x0000ffff)
00133 #define GET_4_BYTES(datum) (((Datum) (datum)) & 0xffffffff)
00134 #define SET_1_BYTE(value) (((Datum) (value)) & 0x000000ff)
00135 #define SET_2_BYTES(value) (((Datum) (value)) & 0x0000ffff)
00136 #define SET_4_BYTES(value) (((Datum) (value)) & 0xffffffff)
00137 
00138 /*
00139  * DatumGetBool
00140  *  Returns boolean value of a datum.
00141  *
00142  * Note: any nonzero value will be considered TRUE.
00143  */
00144 
00145 #define DatumGetBool(X) ((bool) (((Datum) (X)) != 0))
00146 
00147 /*
00148  * BoolGetDatum
00149  *  Returns datum representation for a boolean.
00150  *
00151  * Note: any nonzero value will be considered TRUE.
00152  */
00153 
00154 #define BoolGetDatum(X) ((Datum) ((X) ? 1 : 0))
00155 
00156 /*
00157  * DatumGetChar
00158  *  Returns character value of a datum.
00159  */
00160 
00161 #define DatumGetChar(X) ((char) GET_1_BYTE(X))
00162 
00163 /*
00164  * CharGetDatum
00165  *  Returns datum representation for a character.
00166  */
00167 
00168 #define CharGetDatum(X) ((Datum) SET_1_BYTE(X))
00169 
00170 /*
00171  * Int8GetDatum
00172  *  Returns datum representation for an 8-bit integer.
00173  */
00174 
00175 #define Int8GetDatum(X) ((Datum) SET_1_BYTE(X))
00176 
00177 /*
00178  * DatumGetUInt8
00179  *  Returns 8-bit unsigned integer value of a datum.
00180  */
00181 
00182 #define DatumGetUInt8(X) ((uint8) GET_1_BYTE(X))
00183 
00184 /*
00185  * UInt8GetDatum
00186  *  Returns datum representation for an 8-bit unsigned integer.
00187  */
00188 
00189 #define UInt8GetDatum(X) ((Datum) SET_1_BYTE(X))
00190 
00191 /*
00192  * DatumGetInt16
00193  *  Returns 16-bit integer value of a datum.
00194  */
00195 
00196 #define DatumGetInt16(X) ((int16) GET_2_BYTES(X))
00197 
00198 /*
00199  * Int16GetDatum
00200  *  Returns datum representation for a 16-bit integer.
00201  */
00202 
00203 #define Int16GetDatum(X) ((Datum) SET_2_BYTES(X))
00204 
00205 /*
00206  * DatumGetUInt16
00207  *  Returns 16-bit unsigned integer value of a datum.
00208  */
00209 
00210 #define DatumGetUInt16(X) ((uint16) GET_2_BYTES(X))
00211 
00212 /*
00213  * UInt16GetDatum
00214  *  Returns datum representation for a 16-bit unsigned integer.
00215  */
00216 
00217 #define UInt16GetDatum(X) ((Datum) SET_2_BYTES(X))
00218 
00219 /*
00220  * DatumGetInt32
00221  *  Returns 32-bit integer value of a datum.
00222  */
00223 
00224 #define DatumGetInt32(X) ((int32) GET_4_BYTES(X))
00225 
00226 /*
00227  * Int32GetDatum
00228  *  Returns datum representation for a 32-bit integer.
00229  */
00230 
00231 #define Int32GetDatum(X) ((Datum) SET_4_BYTES(X))
00232 
00233 /*
00234  * DatumGetUInt32
00235  *  Returns 32-bit unsigned integer value of a datum.
00236  */
00237 
00238 #define DatumGetUInt32(X) ((uint32) GET_4_BYTES(X))
00239 
00240 /*
00241  * UInt32GetDatum
00242  *  Returns datum representation for a 32-bit unsigned integer.
00243  */
00244 
00245 #define UInt32GetDatum(X) ((Datum) SET_4_BYTES(X))
00246 
00247 /*
00248  * DatumGetObjectId
00249  *  Returns object identifier value of a datum.
00250  */
00251 
00252 #define DatumGetObjectId(X) ((Oid) GET_4_BYTES(X))
00253 
00254 /*
00255  * ObjectIdGetDatum
00256  *  Returns datum representation for an object identifier.
00257  */
00258 
00259 #define ObjectIdGetDatum(X) ((Datum) SET_4_BYTES(X))
00260 
00261 /*
00262  * DatumGetTransactionId
00263  *  Returns transaction identifier value of a datum.
00264  */
00265 
00266 #define DatumGetTransactionId(X) ((TransactionId) GET_4_BYTES(X))
00267 
00268 /*
00269  * TransactionIdGetDatum
00270  *  Returns datum representation for a transaction identifier.
00271  */
00272 
00273 #define TransactionIdGetDatum(X) ((Datum) SET_4_BYTES((X)))
00274 
00275 /*
00276  * DatumGetCommandId
00277  *  Returns command identifier value of a datum.
00278  */
00279 
00280 #define DatumGetCommandId(X) ((CommandId) GET_4_BYTES(X))
00281 
00282 /*
00283  * CommandIdGetDatum
00284  *  Returns datum representation for a command identifier.
00285  */
00286 
00287 #define CommandIdGetDatum(X) ((Datum) SET_4_BYTES(X))
00288 
00289 /*
00290  * DatumGetPointer
00291  *  Returns pointer value of a datum.
00292  */
00293 
00294 #define DatumGetPointer(X) ((Pointer) (X))
00295 
00296 /*
00297  * PointerGetDatum
00298  *  Returns datum representation for a pointer.
00299  */
00300 
00301 #define PointerGetDatum(X) ((Datum) (X))
00302 
00303 /*
00304  * DatumGetCString
00305  *  Returns C string (null-terminated string) value of a datum.
00306  *
00307  * Note: C string is not a full-fledged Postgres type at present,
00308  * but type input functions use this conversion for their inputs.
00309  */
00310 
00311 #define DatumGetCString(X) ((char *) DatumGetPointer(X))
00312 
00313 /*
00314  * CStringGetDatum
00315  *  Returns datum representation for a C string (null-terminated string).
00316  *
00317  * Note: C string is not a full-fledged Postgres type at present,
00318  * but type output functions use this conversion for their outputs.
00319  * Note: CString is pass-by-reference; caller must ensure the pointed-to
00320  * value has adequate lifetime.
00321  */
00322 
00323 #define CStringGetDatum(X) PointerGetDatum(X)
00324 
00325 /*
00326  * DatumGetName
00327  *  Returns name value of a datum.
00328  */
00329 
00330 #define DatumGetName(X) ((Name) DatumGetPointer(X))
00331 
00332 /*
00333  * NameGetDatum
00334  *  Returns datum representation for a name.
00335  *
00336  * Note: Name is pass-by-reference; caller must ensure the pointed-to
00337  * value has adequate lifetime.
00338  */
00339 
00340 #define NameGetDatum(X) PointerGetDatum(X)
00341 
00342 /*
00343  * DatumGetInt64
00344  *  Returns 64-bit integer value of a datum.
00345  *
00346  * Note: this macro hides the fact that int64 is currently a
00347  * pass-by-reference type. Someday it may be pass-by-value,
00348  * at least on some platforms.
00349  */
00350 
00351 #define DatumGetInt64(X) (* ((int64 *) DatumGetPointer(X)))
00352 
00353 /*
00354  * Int64GetDatum
00355  *  Returns datum representation for a 64-bit integer.
00356  *
00357  * Note: this routine returns a reference to palloc'd space.
00358  */
00359 
00360 extern Datum Int64GetDatum( int64 X );
00361 
00362 /*
00363  * DatumGetFloat4
00364  *  Returns 4-byte floating point value of a datum.
00365  *
00366  * Note: this macro hides the fact that float4 is currently a
00367  * pass-by-reference type. Someday it may be pass-by-value.
00368  */
00369 
00370 #define DatumGetFloat4(X) (* ((float4 *) DatumGetPointer(X)))
00371 
00372 /*
00373  * Float4GetDatum
00374  *  Returns datum representation for a 4-byte floating point number.
00375  *
00376  * Note: this routine returns a reference to palloc'd space.
00377  */
00378 
00379 extern Datum Float4GetDatum( float4 X );
00380 
00381 /*
00382  * DatumGetFloat8
00383  *  Returns 8-byte floating point value of a datum.
00384  *
00385  * Note: this macro hides the fact that float8 is currently a
00386  * pass-by-reference type. Someday it may be pass-by-value,
00387  * at least on some platforms.
00388  */
00389 
00390 #define DatumGetFloat8(X) (* ((float8 *) DatumGetPointer(X)))
00391 
00392 /*
00393  * Float8GetDatum
00394  *  Returns datum representation for an 8-byte floating point number.
00395  *
00396  * Note: this routine returns a reference to palloc'd space.
00397  */
00398 
00399 extern Datum Float8GetDatum( float8 X );
00400 
00401 
00402 /*
00403  * DatumGetFloat32
00404  *  Returns 32-bit floating point value of a datum.
00405  *  This is really a pointer, of course.
00406  *
00407  * XXX: this macro is now deprecated in favor of DatumGetFloat4.
00408  * It will eventually go away.
00409  */
00410 
00411 #define DatumGetFloat32(X) ((float32) DatumGetPointer(X))
00412 
00413 /*
00414  * Float32GetDatum
00415  *  Returns datum representation for a 32-bit floating point number.
00416  *  This is really a pointer, of course.
00417  *
00418  * XXX: this macro is now deprecated in favor of Float4GetDatum.
00419  * It will eventually go away.
00420  */
00421 
00422 #define Float32GetDatum(X) PointerGetDatum(X)
00423 
00424 /*
00425  * DatumGetFloat64
00426  *  Returns 64-bit floating point value of a datum.
00427  *  This is really a pointer, of course.
00428  *
00429  * XXX: this macro is now deprecated in favor of DatumGetFloat8.
00430  * It will eventually go away.
00431  */
00432 
00433 #define DatumGetFloat64(X) ((float64) DatumGetPointer(X))
00434 
00435 /*
00436  * Float64GetDatum
00437  *  Returns datum representation for a 64-bit floating point number.
00438  *  This is really a pointer, of course.
00439  *
00440  * XXX: this macro is now deprecated in favor of Float8GetDatum.
00441  * It will eventually go away.
00442  */
00443 
00444 #define Float64GetDatum(X) PointerGetDatum(X)
00445 
00446 /*
00447  * Int64GetDatumFast
00448  * Float4GetDatumFast
00449  * Float8GetDatumFast
00450  *
00451  * These macros are intended to allow writing code that does not depend on
00452  * whether int64, float4, float8 are pass-by-reference types, while not
00453  * sacrificing performance when they are.  The argument must be a variable
00454  * that will exist and have the same value for as long as the Datum is needed.
00455  * In the pass-by-ref case, the address of the variable is taken to use as
00456  * the Datum.  In the pass-by-val case, these will be the same as the non-Fast
00457  * macros.
00458  */
00459 
00460 #define Int64GetDatumFast(X)  PointerGetDatum(&(X))
00461 #define Float4GetDatumFast(X) PointerGetDatum(&(X))
00462 #define Float8GetDatumFast(X) PointerGetDatum(&(X))
00463 
00464 
00465 /* ----------------------------------------------------------------
00466  *    Section 3: exception handling definitions
00467  *       Assert, Trap, etc macros
00468  * ----------------------------------------------------------------
00469  */
00470 
00471 extern DLLIMPORT bool assert_enabled;
00472 
00473 /*
00474  * USE_ASSERT_CHECKING, if defined, turns on all the assertions.
00475  * - plai  9/5/90
00476  *
00477  * It should _NOT_ be defined in releases or in benchmark copies
00478  */
00479 
00480 /*
00481  * Trap
00482  *  Generates an exception if the given condition is true.
00483  *
00484  */
00485 #define Trap(condition, errorType) \
00486   do { \
00487     if ((assert_enabled) && (condition)) \
00488       ExceptionalCondition(CppAsString(condition), (errorType), \
00489                            __FILE__, __LINE__); \
00490   } while (0)
00491 
00492 /*
00493  * TrapMacro is the same as Trap but it's intended for use in macros:
00494  *
00495  *  #define foo(x) (AssertMacro(x != 0) && bar(x))
00496  *
00497  * Isn't CPP fun?
00498  */
00499 #define TrapMacro(condition, errorType) \
00500   ((bool) ((! assert_enabled) || ! (condition) || \
00501            (ExceptionalCondition(CppAsString(condition), (errorType), \
00502                                  __FILE__, __LINE__))))
00503 
00504 #ifndef USE_ASSERT_CHECKING
00505 #define Assert(condition)
00506 #define AssertMacro(condition) ((void)true)
00507 #define AssertArg(condition)
00508 #define AssertState(condition)
00509 #define assert_enabled 0
00510 #else
00511 #define Assert(condition) \
00512   Trap(!(condition), "FailedAssertion")
00513 
00514 #define AssertMacro(condition) \
00515   ((void) TrapMacro(!(condition), "FailedAssertion"))
00516 
00517 #define AssertArg(condition) \
00518   Trap(!(condition), "BadArgument")
00519 
00520 #define AssertState(condition) \
00521   Trap(!(condition), "BadState")
00522 #endif   /* USE_ASSERT_CHECKING */
00523 
00524 extern int ExceptionalCondition( char *conditionName, char *errorType,
00525                                    char *fileName, int lineNumber );
00526 
00527 /* ----------------------------------------------------------------
00528  *    Section 4: genbki macros used by catalog/pg_xxx.h files
00529  * ----------------------------------------------------------------
00530  */
00531 #define CATALOG(name,oid) typedef struct CppConcat(FormData_,name)
00532 
00533 #define BKI_BOOTSTRAP
00534 #define BKI_SHARED_RELATION
00535 #define BKI_WITHOUT_OIDS
00536 
00537 /* these need to expand into some harmless, repeatable declaration */
00538 #define DATA(x)   extern int no_such_variable
00539 #define DESCR(x)  extern int no_such_variable
00540 
00541 typedef int4 aclitem;   /* PHONY definition for catalog use only */
00542 
00543 #endif   /* POSTGRES_H */
 Todo Clases Namespaces Archivos Funciones Variables 'typedefs' Enumeraciones Valores de enumeraciones Propiedades Amigas 'defines'