ado_postgresql_2.0.0_27870ba6/src/postgresql/pq.ads

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
-----------------------------------------------------------------------
--  pq -- Postgresql libpq thin binding
--  Copyright (C) 2018 Stephane Carrez
--  Written by Stephane Carrez (Stephane.Carrez@gmail.com)
--
--  Licensed under the Apache License, Version 2.0 (the "License");
--  you may not use this file except in compliance with the License.
--  You may obtain a copy of the License at
--
--      http://www.apache.org/licenses/LICENSE-2.0
--
--  Unless required by applicable law or agreed to in writing, software
--  distributed under the License is distributed on an "AS IS" BASIS,
--  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
--  See the License for the specific language governing permissions and
--  limitations under the License.
-----------------------------------------------------------------------
with Interfaces.C.Strings;
with System;
package PQ is

   pragma Linker_Options ("-lpq");

   subtype chars_ptr is Interfaces.C.Strings.chars_ptr;

   type PGconn_Access is new System.Address;

   Null_PGconn : constant PGconn_Access := PGconn_Access (System.Null_Address);

   type PGresult_Access is new System.Address;

   Null_PGresult : constant PGresult_Access := PGresult_Access (System.Null_Address);

   type ConnStatusType is
     (
      CONNECTION_OK,
      CONNECTION_BAD,
      --  Non-blocking mode only below here

      --  The existence of these should never be relied upon - they should only
      --  be used for user feedback or similar purposes.

      --  Waiting for connection to be made.
      CONNECTION_STARTED,

      --  Connection OK; waiting to send.
      CONNECTION_MADE,

      --  Waiting for a response from the postmaster.
      CONNECTION_AWAITING_RESPONSE,

      --  Received authentication; waiting for backend startup.
      CONNECTION_AUTH_OK,

      --  Negotiating environment.
      CONNECTION_SETENV,

      --  Negotiating SSL.
      CONNECTION_SSL_STARTUP,

      --  Internal state: connect() needed
      CONNECTION_NEEDED
     );

   type ExecStatusType is
     (
      --  empty query string was executed
      PGRES_EMPTY_QUERY,

      --  a query command that doesn't return anything was executed properly by the backend
      PGRES_COMMAND_OK,

      --  a query command that returns tuples was executed properly by the backend, PGresult
      --  contains the result tuples
      PGRES_TUPLES_OK,

      --  Copy Out data transfer in progress
      PGRES_COPY_OUT,

      --  Copy In data transfer in progress
      PGRES_COPY_IN,

      --  an unexpected response was recv'd from the backend
      PGRES_BAD_RESPONSE,

      --  notice or warning message
      PGRES_NONFATAL_ERROR,

      --  query failed
      PGRES_FATAL_ERROR,

      --  Copy In/Out data transfer in progress
      PGRES_COPY_BOTH,

      --  single tuple from larger resultset
      PGRES_SINGLE_TUPLE
     );

   function PQconnectdb (Conninfo : in chars_ptr) return PGconn_Access
     with Import => True, Convention => C, Link_Name => "PQconnectdb";

   function PQstatus (Conn : in PGconn_Access) return ConnStatusType
     with Import => True, Convention => C, Link_Name => "PQstatus";

   function PQerrorMessage (Conn : in PGconn_Access) return chars_ptr
     with Import => True, Convention => C, Link_Name => "PQerrorMessage";

   procedure PQfinish (Conn : PGconn_Access)
     with Import => True, Convention => C, Link_Name => "PQfinish";

   function PQexec (Conn : PGconn_Access;
                    SQL  : Interfaces.C.Strings.chars_ptr) return PGresult_Access
     with Import => True, Convention => C, Link_Name => "PQexec";

   procedure PQclear (Result : in PGresult_Access)
     with Import => True, Convention => C, Link_Name => "PQclear";

   function PQresultStatus (Result : in PGresult_Access) return ExecStatusType
     with Import => True, Convention => C, Link_Name => "PQresultStatus";

   function PQresultErrorMessage (Result : in PGresult_Access) return chars_ptr
     with Import => True, Convention => C, Link_Name => "PQresultErrorMessage";

   function PQcmdTuples (Result : in PGresult_Access) return chars_ptr
     with Import => True, Convention => C, Link_Name => "PQcmdTuples";

   function PQntuples (Result : in PGresult_Access) return Interfaces.C.int
     with Import => True, Convention => C, Link_Name => "PQntuples";

   function PQnfields (Result : in PGresult_Access) return Interfaces.C.int
     with Import => True, Convention => C, Link_Name => "PQnfields";

   function PQfname (Result : in PGresult_Access;
                     Column_Number : in Interfaces.C.int) return chars_ptr
     with Import => True, Convention => C, Link_Name => "PQfname";

   function PQfsize (Result : in PGresult_Access;
                     Column_Number : in Interfaces.C.int) return Interfaces.C.int
     with Import => True, Convention => C, Link_Name => "PQfsize";

   function PQgetvalue (Result        : in PGresult_Access;
                        Row_Number    : in Interfaces.C.int;
                        Column_Number : in Interfaces.C.int) return chars_ptr
     with Import => True, Convention => C, Link_Name => "PQgetvalue";

   function PQgetisnull (Result        : in PGresult_Access;
                         Row_Number    : in Interfaces.C.int;
                         Column_Number : in Interfaces.C.int) return Interfaces.C.int
     with Import => True, Convention => C, Link_Name => "PQgetisnull";

   function PQgetlength (Result        : in PGresult_Access;
                         Row_Number    : in Interfaces.C.int;
                         Column_Number : in Interfaces.C.int) return Interfaces.C.int
     with Import => True, Convention => C, Link_Name => "PQgetlength";

end PQ;