pg_oid.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /*
  2. * $Id$
  3. *
  4. * PostgreSQL Database Driver for SER
  5. *
  6. * Portions Copyright (C) 2001-2003 FhG FOKUS
  7. * Copyright (C) 2003 August.Net Services, LLC
  8. * Portions Copyright (C) 2005-2008 iptelorg GmbH
  9. *
  10. * This file is part of SER, a free SIP server.
  11. *
  12. * SER is free software; you can redistribute it and/or modify it under the
  13. * terms of the GNU General Public License as published by the Free Software
  14. * Foundation; either version 2 of the License, or (at your option) any later
  15. * version
  16. *
  17. * For a license to use the ser software under conditions other than those
  18. * described here, or to purchase support for this software, please contact
  19. * iptel.org by e-mail at the following addresses: [email protected]
  20. *
  21. * SER is distributed in the hope that it will be useful, but WITHOUT ANY
  22. * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  23. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  24. * details.
  25. *
  26. * You should have received a copy of the GNU General Public License along
  27. * with this program; if not, write to the Free Software Foundation, Inc., 59
  28. * Temple Place, Suite 330, Boston, MA 02111-1307 USA
  29. */
  30. #ifndef _PG_OID_H
  31. #define _PG_OID_H
  32. /** \addtogroup postgres
  33. * @{
  34. */
  35. /** \file
  36. * Data structures and functions implementing support for PostgreSQL Oid
  37. * identifiers.
  38. */
  39. #include <libpq-fe.h>
  40. /** Structure mapping field names to Oids.
  41. * This structure is used to map field names or data type names to their
  42. * Oids/field types.
  43. */
  44. typedef struct pg_type {
  45. Oid oid; /**< PostgreSQL Oid (object identifier) */
  46. char* name; /**< Field name */
  47. } pg_type_t;
  48. /** Enumeration of supported PostreSQL types.
  49. * This is the enumeration of all PostgreSQL types supported
  50. * by this driver, that means this driver will be able to convert
  51. * to and from these types.
  52. *
  53. * This enum is primarilly used as index to arrays of pg_type_t that are
  54. * stored in pg_con structures. Upon connecting to a PostgreSQL server the
  55. * driver retrieves the list of supported data types and oids from the server
  56. * and stores then in an array. Different PostgreSQL servers can have
  57. * different Oids for various data types so we have to have one array that
  58. * maps symbolic names below to Oids per connection/server.
  59. */
  60. enum pg_type_id {
  61. PG_BOOL = 0, /**< Boolean, true/false */
  62. PG_BYTE, /**< Binary data */
  63. PG_CHAR, /**< Single character */
  64. PG_INT8, /**< Integer with 8-byte storage */
  65. PG_INT2, /**< Integer with 2-byte storage */
  66. PG_INT4, /**< Integer with 4-byte storage */
  67. PG_TEXT, /**< Variable-length string, no limit specified */
  68. PG_FLOAT4, /**< Single-precision floating point number, 4-byte storage */
  69. PG_FLOAT8, /**< Double-precision floating point number, 8-byte storage */
  70. PG_INET, /**< IP address/netmask, host address */
  71. PG_BPCHAR, /**< Blank-padded string, fixed storage length */
  72. PG_VARCHAR, /**< Non-blank padded string, variable storage length */
  73. PG_TIMESTAMP, /**< Date and time */
  74. PG_TIMESTAMPTZ, /**< Date and time with time zone */
  75. PG_BIT, /**< Fixed-length bit string */
  76. PG_VARBIT, /**< Variable-length bit string */
  77. PG_ID_MAX /**< Bumper, this must be the last element of the enum */
  78. };
  79. /** Creates a new Oid mapping table.
  80. * The function creates a new Oid mapping table and initalizes the contents
  81. * of the table with values obtained from the PostgreSQL result in parameter.
  82. * Each element of the table maps field type name to oid and vice versa.
  83. * @param res A PostgreSQL result structure used to initialize the array.
  84. * @retval A pointer to the resulting array.
  85. * @retval NULL on error.
  86. */
  87. pg_type_t* pg_new_oid_table(PGresult* res);
  88. /** Frees all memory used by the table
  89. * @param table A pointer to table to be freed
  90. */
  91. void pg_destroy_oid_table(pg_type_t* table);
  92. /** Maps a field type name to Oid.
  93. * @param oid The resulting oid
  94. * @param table The mapping table
  95. * @param name Field type name
  96. * @retval 0 on success
  97. * @retval 1 if the type name is unknown
  98. * @retval -1 on error.
  99. */
  100. int pg_name2oid(Oid* oid, pg_type_t* table, const char* name);
  101. /** Maps a field type name to Oid.
  102. * @param oid The resulting oid
  103. * @param table The mapping table
  104. * @param name Field type name
  105. * @retval 0 on success
  106. * @retval 1 if the type name is unknown
  107. * @retval -1 on error.
  108. */
  109. int pg_oid2name(const char** name, pg_type_t* table, Oid oid);
  110. /** @} */
  111. #endif /* _PG_OID_H */