2
0

glue.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /*
  2. Copyright (c) 2007-2023, Bruce A Henderson
  3. All rights reserved.
  4. Redistribution and use in source and binary forms, with or without
  5. modification, are permitted provided that the following conditions are met:
  6. * Redistributions of source code must retain the above copyright
  7. notice, this list of conditions and the following disclaimer.
  8. * Redistributions in binary form must reproduce the above copyright
  9. notice, this list of conditions and the following disclaimer in the
  10. documentation and/or other materials provided with the distribution.
  11. * Neither the name of the author nor the
  12. names of its contributors may be used to endorse or promote products
  13. derived from this software without specific prior written permission.
  14. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY
  15. EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  16. WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  17. DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
  18. DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  19. (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  20. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  21. ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  22. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  23. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  24. */
  25. #include <libpq-fe.h>
  26. #include <stdlib.h>
  27. void bmx_pgsql_PQfinish(PGconn * handle) {
  28. PQfinish(handle);
  29. }
  30. PGconn * bmx_pgsql_PQconnectdb(const char * conninfo) {
  31. return PQconnectdb(conninfo);
  32. }
  33. int bmx_pgsql_PQstatus(const PGconn * handle) {
  34. return PQstatus(handle);
  35. }
  36. char * bmx_pgsql_PQerrorMessage(const PGconn * handle) {
  37. return PQerrorMessage(handle);
  38. }
  39. PGresult * bmx_pgsql_PQexec(PGconn * handle, const char * query) {
  40. return PQexec(handle, query);
  41. }
  42. int bmx_pgsql_PQresultStatus(const PGresult * result) {
  43. return PQresultStatus(result);
  44. }
  45. void bmx_pgsql_PQclear(PGresult * result) {
  46. PQclear(result);
  47. }
  48. int bmx_pgsql_PQntuples(PGresult * result) {
  49. return PQntuples(result);
  50. }
  51. int bmx_pgsql_PQnfields(PGresult * result) {
  52. return PQnfields(result);
  53. }
  54. char * bmx_pgsql_PQcmdTuples(PGresult * result) {
  55. return PQcmdTuples(result);
  56. }
  57. char * bmx_pgsql_PQfname(PGresult * result, int index) {
  58. return PQfname(result, index);
  59. }
  60. int bmx_pgsql_PQftype(PGresult * result, int index) {
  61. return PQftype(result, index);
  62. }
  63. int bmx_pgsql_PQfsize(PGresult * result, int index) {
  64. return PQfsize(result, index);
  65. }
  66. int bmx_pgsql_PQfmod(PGresult * result, int index) {
  67. return PQfmod(result, index);
  68. }
  69. int bmx_pgsql_PQgetisnull(PGresult * result, int row, int index) {
  70. return PQgetisnull(result, row, index);
  71. }
  72. char * bmx_pgsql_PQgetvalue(PGresult * result, int row, int index) {
  73. return PQgetvalue(result, row, index);
  74. }
  75. int bmx_pgsql_PQgetlength(PGresult * result, int row, int index) {
  76. return PQgetlength(result, row, index);
  77. }
  78. PGresult * bmx_pgsql_PQprepare(PGconn * conn, const char * stmtName, const char * query) {
  79. return PQprepare(conn, stmtName, query, 0, NULL);
  80. }
  81. //PGresult * bmx_pgsql_PQdescribePrepared(PGconn * conn, const char * stmtName) {
  82. // return PQdescribePrepared(conn, stmtName);
  83. //}
  84. char ** bmx_pgsql_createParamValues(int size) {
  85. return malloc(size * sizeof(char*));
  86. }
  87. int * bmx_pgsql_createParamInts(int size) {
  88. return malloc(size * sizeof(int));
  89. }
  90. void bmx_pgsql_deleteParamValues(const char * const * arr) {
  91. free(arr);
  92. }
  93. void bmx_pgsql_deleteParamInts(int * arr) {
  94. free(arr);
  95. }
  96. void bmx_pgsql_setNullParam(char * * params, int index) {
  97. params[index] = 0;
  98. }
  99. void bmx_pgsql_setParam(char * * params, int * lengths, int * formats, int index, char * text, int length) {
  100. params[index] = text;
  101. lengths[index] = length;
  102. formats[index] = 0;
  103. }
  104. void bmx_pgsql_setParamBinary(char * * params, int * lengths, int * formats, int index, char * data, int length) {
  105. params[index] = data;
  106. lengths[index] = length;
  107. formats[index] = 1;
  108. }
  109. PGresult * bmx_pgsql_PQexecPrepared(PGconn * conn, const char * stmtName, int nParams, const char * const * params, int * lengths, int * formats) {
  110. return PQexecPrepared(conn, stmtName, nParams, params, lengths, formats, 0);
  111. }
  112. unsigned char * bmx_pgsql_PQunescapeBytea(unsigned char * data, size_t * length) {
  113. return PQunescapeBytea(data, length);
  114. }
  115. void bmx_pgsql_PQfreemem(void * data) {
  116. PQfreemem(data);
  117. }
  118. unsigned int bmx_pgsql_PQoidValue(PGresult * result) {
  119. Oid value = PQoidValue(result);
  120. if (value != InvalidOid) {
  121. return (unsigned int)value;
  122. }
  123. return -1;
  124. }