From 06199613390e1ed47847639646613a01af00a39b Mon Sep 17 00:00:00 2001 From: Ali Bendriss Date: Wed, 7 Jan 2009 15:11:31 +0000 Subject: [PATCH] Initial commit --- COPYING.LESSER | 165 +++++ Makefile | 24 + README | 17 + backlit.gpr | 46 ++ demo/Makefile | 21 + demo/demo.grp | 52 ++ demo/simple_demo.adb | 203 ++++++ gpl-3.0.txt | 674 ++++++++++++++++++ src/backlit-client-statment.adb | 420 +++++++++++ src/backlit-client-statment.ads | 307 +++++++++ src/backlit-client.adb | 336 +++++++++ src/backlit-client.ads | 225 ++++++ src/backlit-thin.ads | 1455 +++++++++++++++++++++++++++++++++++++++ src/backlit.ads | 28 + 14 files changed, 3973 insertions(+) create mode 100644 COPYING.LESSER create mode 100644 Makefile create mode 100644 README create mode 100644 backlit.gpr create mode 100644 demo/Makefile create mode 100644 demo/demo.grp create mode 100644 demo/simple_demo.adb create mode 100644 gpl-3.0.txt create mode 100644 src/backlit-client-statment.adb create mode 100644 src/backlit-client-statment.ads create mode 100644 src/backlit-client.adb create mode 100644 src/backlit-client.ads create mode 100644 src/backlit-thin.ads create mode 100644 src/backlit.ads diff --git a/COPYING.LESSER b/COPYING.LESSER new file mode 100644 index 0000000..fc8a5de --- /dev/null +++ b/COPYING.LESSER @@ -0,0 +1,165 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + + This version of the GNU Lesser General Public License incorporates +the terms and conditions of version 3 of the GNU General Public +License, supplemented by the additional permissions listed below. + + 0. Additional Definitions. + + As used herein, "this License" refers to version 3 of the GNU Lesser +General Public License, and the "GNU GPL" refers to version 3 of the GNU +General Public License. + + "The Library" refers to a covered work governed by this License, +other than an Application or a Combined Work as defined below. + + An "Application" is any work that makes use of an interface provided +by the Library, but which is not otherwise based on the Library. +Defining a subclass of a class defined by the Library is deemed a mode +of using an interface provided by the Library. + + A "Combined Work" is a work produced by combining or linking an +Application with the Library. The particular version of the Library +with which the Combined Work was made is also called the "Linked +Version". + + The "Minimal Corresponding Source" for a Combined Work means the +Corresponding Source for the Combined Work, excluding any source code +for portions of the Combined Work that, considered in isolation, are +based on the Application, and not on the Linked Version. + + The "Corresponding Application Code" for a Combined Work means the +object code and/or source code for the Application, including any data +and utility programs needed for reproducing the Combined Work from the +Application, but excluding the System Libraries of the Combined Work. + + 1. Exception to Section 3 of the GNU GPL. + + You may convey a covered work under sections 3 and 4 of this License +without being bound by section 3 of the GNU GPL. + + 2. Conveying Modified Versions. + + If you modify a copy of the Library, and, in your modifications, a +facility refers to a function or data to be supplied by an Application +that uses the facility (other than as an argument passed when the +facility is invoked), then you may convey a copy of the modified +version: + + a) under this License, provided that you make a good faith effort to + ensure that, in the event an Application does not supply the + function or data, the facility still operates, and performs + whatever part of its purpose remains meaningful, or + + b) under the GNU GPL, with none of the additional permissions of + this License applicable to that copy. + + 3. Object Code Incorporating Material from Library Header Files. + + The object code form of an Application may incorporate material from +a header file that is part of the Library. You may convey such object +code under terms of your choice, provided that, if the incorporated +material is not limited to numerical parameters, data structure +layouts and accessors, or small macros, inline functions and templates +(ten or fewer lines in length), you do both of the following: + + a) Give prominent notice with each copy of the object code that the + Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the object code with a copy of the GNU GPL and this license + document. + + 4. Combined Works. + + You may convey a Combined Work under terms of your choice that, +taken together, effectively do not restrict modification of the +portions of the Library contained in the Combined Work and reverse +engineering for debugging such modifications, if you also do each of +the following: + + a) Give prominent notice with each copy of the Combined Work that + the Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the Combined Work with a copy of the GNU GPL and this license + document. + + c) For a Combined Work that displays copyright notices during + execution, include the copyright notice for the Library among + these notices, as well as a reference directing the user to the + copies of the GNU GPL and this license document. + + d) Do one of the following: + + 0) Convey the Minimal Corresponding Source under the terms of this + License, and the Corresponding Application Code in a form + suitable for, and under terms that permit, the user to + recombine or relink the Application with a modified version of + the Linked Version to produce a modified Combined Work, in the + manner specified by section 6 of the GNU GPL for conveying + Corresponding Source. + + 1) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (a) uses at run time + a copy of the Library already present on the user's computer + system, and (b) will operate properly with a modified version + of the Library that is interface-compatible with the Linked + Version. + + e) Provide Installation Information, but only if you would otherwise + be required to provide such information under section 6 of the + GNU GPL, and only to the extent that such information is + necessary to install and execute a modified version of the + Combined Work produced by recombining or relinking the + Application with a modified version of the Linked Version. (If + you use option 4d0, the Installation Information must accompany + the Minimal Corresponding Source and Corresponding Application + Code. If you use option 4d1, you must provide the Installation + Information in the manner specified by section 6 of the GNU GPL + for conveying Corresponding Source.) + + 5. Combined Libraries. + + You may place library facilities that are a work based on the +Library side by side in a single library together with other library +facilities that are not Applications and are not covered by this +License, and convey such a combined library under terms of your +choice, if you do both of the following: + + a) Accompany the combined library with a copy of the same work based + on the Library, uncombined with any other library facilities, + conveyed under the terms of this License. + + b) Give prominent notice with the combined library that part of it + is a work based on the Library, and explaining where to find the + accompanying uncombined form of the same work. + + 6. Revised Versions of the GNU Lesser General Public License. + + The Free Software Foundation may publish revised and/or new versions +of the GNU Lesser General Public License from time to time. Such new +versions will be similar in spirit to the present version, but may +differ in detail to address new problems or concerns. + + Each version is given a distinguishing version number. If the +Library as you received it specifies that a certain numbered version +of the GNU Lesser General Public License "or any later version" +applies to it, you have the option of following the terms and +conditions either of that published version or of any later version +published by the Free Software Foundation. If the Library as you +received it does not specify a version number of the GNU Lesser +General Public License, you may choose any version of the GNU Lesser +General Public License ever published by the Free Software Foundation. + + If the Library as you received it specifies that a proxy can decide +whether future versions of the GNU Lesser General Public License shall +apply, that proxy's public statement of acceptance of any version is +permanent authorization for you to choose that version for the +Library. diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..acb0715 --- /dev/null +++ b/Makefile @@ -0,0 +1,24 @@ +CC = gcc +GNATMAKE = gnatmake +RM = rm -f +MKDIR = mkdir -p + +default: build + +clean: + $(RM) -r ali + $(RM) -r lib + $(RM) -r obj + $(RM) -r src-interface + +rep: + $(MKDIR) ali lib obj src-interface + +build: rep + $(GNATMAKE) -P backlit.gpr + +check: rep + $(GNATMAKE) -gnatv -P backlit.gpr + +style: rep + $(GNATMAKE) -gnaty -P backlit.gpr diff --git a/README b/README new file mode 100644 index 0000000..5dd7aad --- /dev/null +++ b/README @@ -0,0 +1,17 @@ +Backlit is an Ada interface for libpq +the C application programmer's interface to PostgreSQL. + +libpq is a set of library functions that allow client programs to +pass queries to the PostgreSQL backend server and +to receive the results of these queries. + +backlit-thin.ads is a complete and direct mapping of the libpq C interface, +but you may prefer to use the others package which are more Ada like. +Please check the demo directory for some examples of the library usage. + +For the moment the library is only able to process +text-format parameters. Binary format parameters will be added in the future. + +Contact : +Ali Bendriss + diff --git a/backlit.gpr b/backlit.gpr new file mode 100644 index 0000000..00b5ca2 --- /dev/null +++ b/backlit.gpr @@ -0,0 +1,46 @@ +project Backlit is + + Version := "1"; + + for Source_Dirs use (".","src"); + for Exec_Dir use "obj"; + for Object_Dir use "obj"; + + for Library_Kind use "relocatable"; + for Library_Version use "libbacklit.so." & Version; + +-- Library_Auto_Init := "False"; + + for Library_Src_Dir use "src-interface"; +-- The sources of the Interface Units of the library, +-- necessary to an Ada client of the library, +-- will be copied to the designated directory, +-- called Interface Copy directory. + + for Library_Name use "backlit"; + for Library_Dir use "lib"; + + for Library_Interface use ("backlit", + "backlit.thin", + "backlit.client", + "backlit.client.statment"); +-- Attribute Library_Interface has a non empty string list value, +-- each string in the list designating a unit contained in an immediate +-- source of the project file. + + for Library_Ali_Dir use "ali"; + -- for Library_Kind use "static"; + for Library_Kind use "dynamic"; + + package Linker is + for Linker_Options use ("-L/usr/lib", "-lpq"); + For Switches ("src/backlit-thin.ads") use ("-lpq"); + end Linker; + + package Compiler is + for Default_Switches ("ada") use + ("-O", "-gnatf", "-gnato", "-fstack-check", + "-gnatE", "-gnat05", "-gnata"); + end Compiler; + +end Backlit; diff --git a/demo/Makefile b/demo/Makefile new file mode 100644 index 0000000..d3c77b1 --- /dev/null +++ b/demo/Makefile @@ -0,0 +1,21 @@ +CC = gcc +GNATMAKE = gnatmake +RM = rm -f +MKDIR = mkdir -p + +default: build + +clean: + $(RM) -r ali + $(RM) -r lib + $(RM) -r obj + $(RM) -r build + +rep: + $(MKDIR) ali lib obj build + +build: rep + $(GNATMAKE) -P demo.grp + +check: rep + $(GNATMAKE) -gnatv -P demo.grp diff --git a/demo/demo.grp b/demo/demo.grp new file mode 100644 index 0000000..896294b --- /dev/null +++ b/demo/demo.grp @@ -0,0 +1,52 @@ +with "../backlit"; + +project Demo is + + type Mode_Type is + ("Production", "Debug"); + Mode : Mode_Type := external ("BUILD", "Debug"); + + package Compiler is + + case Mode is + + when "Debug" => +-- for Default_Switches ("ada") use ("-g", "-gnato", "-fstack-check", "-gnatVa", "-O3", "-gnat05", "-gnata"); + for Default_Switches ("ada") use ("-g", "-gnat05"); + + when "Production" => + for Default_Switches ("ada") use ("-O2"); + end case; + end Compiler; + + case Mode is + + when "Debug" => + for Source_Dirs use (".//**"); + for Object_Dir use "obj"; + for Exec_Dir use "build"; + for Main use ("simple_demo.adb"); + for Library_Dir use "lib"; + for Library_Ali_Dir use "ali"; +-- for Library_Kind use "dynamic"; + + when "Production" => + + end case; + + package Linker is + + case Mode is + + when "Debug" => + for Default_Switches ("ada") use (""); + + when "Production" => + + end case; + + For Switches ("simple_demo.adb") use ("-lpq"); + end Linker; + +end Demo; + diff --git a/demo/simple_demo.adb b/demo/simple_demo.adb new file mode 100644 index 0000000..f1bd380 --- /dev/null +++ b/demo/simple_demo.adb @@ -0,0 +1,203 @@ +with Ada.Text_IO; use Ada.Text_IO; +with Backlit.Client; use Backlit.Client; +with Backlit.client.statment; use Backlit.client.statment; + +procedure Simple_Demo is + + use Backlit; + + C : Connection_Object_Type; + --S : Backlit.client.Statment.Statment_Object_Type; + + procedure Create_Film_Table + (C :Connection_Object_Type) + is + S : Backlit.client.Statment.Statment_Object_Type; + begin + declare + S : Backlit.client.Statment.Statment_Object_Type; + begin + -- the command can be split in more than one line, in fact + -- the command will be executed as a single command. + -- check the documentation for more info. + S.Append_Command ("DROP TABLE films;"); + S.Exec (C); + exception + when Backlit.Error => + Put_Line (Backlit.client.Statment.Error_Message (S)); + end; + S.Append_Command ("CREATE TABLE films ("); + S.Append_Command (" code char(5) CONSTRAINT firstkey PRIMARY KEY,"); + S.Append_Command (" title varchar(40) NOT NULL,"); + S.Append_Command (" did integer NOT NULL,"); + S.Append_Command (" date_prod date,"); + S.Append_Command (" kind varchar(10),"); + S.Append_Command (" len interval hour to minute);"); + S.Exec (C); + Put ("Create_Film_Table :"); + if S.Status = COMMAND_OK then + Put_Line ("Ok"); + else + Put_Line ("Failed"); + end if; + exception + when Backlit.Error => + Put_Line (Backlit.client.Statment.Error_Message (S)); + end Create_Film_Table; + + procedure Insert_Value_1 (C :Connection_Object_Type) + is + S : Backlit.client.Statment.Statment_Object_Type; + begin + S.Append_Command ("INSERT INTO films"); + S.Append_Command ("(code, title, did,date_prod, kind, len)"); + S.Append_Command ("VALUES (1, 'test1', 1, '12-24-2008', 'test', '1h35m');"); + S.Exec (C); + exception + when Backlit.Error => + Put_Line (Backlit.client.Statment.Error_Message (S)); + end Insert_Value_1; + + procedure Prepare_1 (C :Connection_Object_Type) + is + S : Backlit.client.Statment.Statment_Object_Type; + begin + Put_Line ("prepare_procedure :"); + S.Append_Command ("INSERT INTO films"); + S.Append_Command ("(code, title, did,date_prod, kind, len)"); + S.Append_Command ("VALUES ($1, $2, $3, $4, $5, $6);"); + S.Prepare (C, "films_insert", 6); + exception + when Backlit.Error => + Put_Line (Backlit.client.Statment.Error_Message (S)); + end Prepare_1; + + procedure Insert_Prepared_1 + (C : Connection_Object_Type) + is + S : Backlit.client.Statment.Statment_Object_Type; + Count : Natural := 0; + begin + for I in 1 .. 9 loop + Count := Count + 1; + Put_Line ("=> code :" & Count'Img); + S.Bind_Parameter (6, "2h45m"); + S.Bind_Parameter (4, "01-30-2007"); + S.Bind_Parameter (2, "test" & Count'Img); + S.Bind_Parameter (3, Count'img); + S.Bind_Parameter (5, "test" & Count'Img); + S.Bind_Parameter (1, Count'Img); + -- The bind parameter can be put in any order + -- thanks to Ada.Containers.Indefinite_Ordered_Maps. + S.Exec (C,"films_insert"); + -- we insert an error here : + if Count = 8 then + Put_Line ("=> We insert an error here : duplicate key"); + Count := 7; + end if; + end loop; + exception + when Backlit.Error => + Put_Line (Backlit.client.Statment.Error_Message (S)); + end Insert_Prepared_1; + + procedure Insert_Value_2 (C :Connection_Object_Type) + is + S : Backlit.client.Statment.Statment_Object_Type; + Code : Natural := 20; + begin + Put_Line ("=> We insert directly some value with code 20 named test 20"); + S.Append_Command ("INSERT INTO films"); + S.Append_Command ("(code, title, did,date_prod, kind, len)"); + S.Append_Command ("VALUES ($1, $2, $3, $4, $5, $6);"); + S.Bind_Parameter (6, "2h45m"); + S.Bind_Parameter (4, "01-30-2007"); + S.Bind_Parameter (2, "test 20"); + S.Bind_Parameter (3, "3"); + S.Bind_Parameter (5, "test 20"); + S.Bind_Parameter (1, Code'Img); + -- The bind parameter can be put in any order + -- thanks to Ada.Containers.Indefinite_Ordered_Maps. + S.Exec (C); + exception + when Backlit.Error => + Put_Line (Backlit.client.Statment.Error_Message (S)); + end Insert_Value_2; + + procedure select_1 (C :Connection_Object_Type) + is + S : Backlit.client.Statment.Statment_Object_Type; + NT : Tuples_Type; + NF : Fields_Type; + begin + S.Append_Command ("SELECT code, title FROM films"); + S.Append_Command ("WHERE did=$1 OR date_prod > $2;"); + S.Bind_Parameter (1, "1"); + S.Bind_Parameter (2, "01-30-2000"); + S.Exec (C); + if S.Status = TUPLES_OK then + NT := S.N_Tuples; + Put_Line ("number of tuples :" & NT'Img); + NF := S.N_Fields; + Put_Line ("number of fields :"& NF'Img); + end if; + for I in 0 .. NT - 1 loop + Put ('|'); + for J in 0 .. NF - 1 loop + Put (S.Get_Value (I, J)); + Put ('|'); + if J = NF - 1 then + New_Line; + end if; + end loop; + end loop; + + exception + when Backlit.Error => + Put_Line (Backlit.client.Statment.Error_Message (S)); + end Select_1; + + +begin + --------------------------- + -- Database Connection -- + --------------------------- + ---- there is two way to set the connection + ---- but you can't use both on the same connection. + + -- C.Set_Host_Name ("localhost"); + -- C.Set_Host_Address ("127.0.0.1"); + -- C.Set_User_Name ("postgres"); + -- C.Set_db_Name ("template1"); + -- C.Set_User_Password ("secret"); + -- C.Set_Port ("5432"); + ---- and then make a server connection + -- C.Connect; + + -- The other way is to pass the connection parameter + -- as a string at the connection time + C.Connect ("host=localhost user=postgres dbname=template1"); + + ------------------------- + -- command execution -- + ------------------------- + if Is_Connected (C) then + Put_Line ("Connected!"); + end if; + -- you may create your own connection procedure + -- giving the user different try for the password + -- for example. + -- check the Needs_Password and Used_Password functions. + + Create_Film_Table (C); + -- Insert_Value_1 (C); + Prepare_1 (C); + Insert_Prepared_1 (C); + Insert_Value_2 (C); + Select_1 (C); + if Is_Connected (C) then + Put_Line ("Not Connected!"); + end if; + New_Line; + +end Simple_Demo; diff --git a/gpl-3.0.txt b/gpl-3.0.txt new file mode 100644 index 0000000..94a9ed0 --- /dev/null +++ b/gpl-3.0.txt @@ -0,0 +1,674 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + Copyright (C) + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. diff --git a/src/backlit-client-statment.adb b/src/backlit-client-statment.adb new file mode 100644 index 0000000..4886dc6 --- /dev/null +++ b/src/backlit-client-statment.adb @@ -0,0 +1,420 @@ +------------------------------------------------------------------------------ +-- -- +-- Copyright 2008, Ali Bendriss -- +-- -- +-- This file is part of Backlit. -- +-- -- +-- Backlit is free software: you can redistribute it and/or modify it under -- +-- the terms of the GNU Lesser General Public License as published by -- +-- the Free Software Foundation, either version 3 of the License, or -- +-- (at your option) any later version. -- +-- -- +-- Backlit is distributed in the hope that it will be useful, -- +-- but WITHOUT ANY WARRANTY; without even the implied warranty of -- +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- +-- GNU Lesser General Public License for more details. -- +-- -- +-- You should have received a copy of the GNU Lesser General Public License -- +-- along with Backlit. If not, see . -- +-- -- +------------------------------------------------------------------------------ + +with Interfaces.C.Strings; +with Ada.Exceptions; use Ada.Exceptions; +-- with Ada.Text_IO; use Ada.Text_IO; + +package body Backlit.Client.Statment is + + procedure To_C_Binded_Parameter_Value + (S : Statment_Object_Type; + O : out Pg_ParamValues) is + use Interfaces.C; + use type Ada.Containers.Count_Type; + + Map_Length : Positive := Natural (Stm_Map.Length (S.Parameter)); + Index : size_t; + begin + if Stm_Map.Last_Key (S.Parameter) /= S.Param_Length then + Raise_Exception (Error'Identity, "wrong bind key parameter"); + end if; + for I in 1 .. Map_Length loop + Index := size_t (I - 1); + O (Index) := Strings.New_Char_Array + (To_C (Stm_Map.Element (S.Parameter, I))); + end loop; + end To_C_Binded_Parameter_Value; + + function Error_Message (S : Statment_Object_Type) return String + is + begin + return Interfaces.C.Strings.Value + (Thin.PQRESULTERRORMESSAGE (S.Pg_Result)); + exception + when others => + return "unknow error."; + end Error_Message; + + procedure Append_Command + (S : in out Statment_Object_Type; + Q : String) + is + use Ada.Strings.Unbounded; + begin + S.Command := S.Command & Q & " "; + end Append_Command; + + procedure Bind_Parameter + (S : in out Statment_Object_Type; + Key : Positive; + Value : String) + is + use type Interfaces.C.int; + begin + Stm_Map.Insert (S.Parameter, Key, Value); + S.Param_Length := S.Param_Length + 1; + end Bind_Parameter; + + procedure Exec + (S : in out Statment_Object_Type; + C : Connection_Object_Type) + is + use Interfaces.C; + use type Interfaces.C.Strings.chars_ptr; + use type Thin.ExecStatusType; + use type Thin.A_PGRESULT_T; + Command : Strings.chars_ptr; + begin + Command := Strings.New_Char_Array + (To_C (Ada.Strings.Unbounded.To_String (S.Command))); + if Stm_Map.Is_Empty (S.Parameter) then + -- exec without parameters + S.Pg_Result := Thin.PQEXEC (C.Real, Command); + else + -- exec with parameters + declare + Pg_Param : Pg_ParamValues (0 .. size_t (S.Param_Length - 1)) := + (others => Interfaces.C.Strings.Null_Ptr); + begin + To_C_Binded_Parameter_Value (S, Pg_Param); + S.Pg_Result := Thin.PQEXECPARAMS + (C.Real, Command, int (S.Param_Length), + null, Pg_Param (0)'Access, null, null, 0); + for I in Pg_Param'Range loop + Interfaces.C.Strings.Free (Pg_Param (I)); + end loop; + end; + end if; + + if Command /= Strings.Null_Ptr then + Interfaces.C.Strings.Free (Command); + end if; + + Stm_Map.Clear (S.Parameter); + S.Param_Length := 0; + + if S.Pg_Result = null then + Raise_Exception (Error'Identity, Error_Message (C)); + -- S.Pg_Result so we use the last Error message available + -- in the connection + end if; + if Thin.PQRESULTSTATUS (S.Pg_Result) /= Thin.PGRES_COMMAND_OK and then + Thin.PQRESULTSTATUS (S.Pg_Result) /= Thin.PGRES_TUPLES_OK then + -- FIXME test that rules with command returning data + -- and command returning no data. + Raise_Exception (Error'Identity, Error_Message (S)); + end if; + -- if Thin.PQRESULTERRORFIELD (S.Pg_Result, 0) /= + -- Strings.Null_Ptr then + -- Raise_Exception (Error'Identity, Error_Message (S)); + -- end if; + end Exec; + + procedure Initialize (S : in out Statment_Object_Type) + is + begin + S.Command := Ada.Strings.Unbounded.Null_Unbounded_String; + Stm_Map.Clear (S.Parameter); + S.Param_Length := 0; + end Initialize; + + procedure Finalize (S : in out Statment_Object_Type) + is + begin + Thin.PQCLEAR (S.Pg_Result); + Stm_Map.Clear (S.Parameter); + S.Param_Length := 0; + end Finalize; + + + procedure Prepare + (S : in out Statment_Object_Type; + C : Connection_Object_Type; + Prepared_Stm_Name : String := ""; + Number_Of_Parameter : Natural := 0) + is + use Interfaces.C; + use type Interfaces.C.Strings.chars_ptr; + use type Thin.ExecStatusType; + use type Thin.A_PGRESULT_T; + Command : Strings.chars_ptr; + Stm_Name : Strings.chars_ptr; + NParams : constant int := int (Number_Of_Parameter); + begin + Command := Strings.New_Char_Array + (To_C (Ada.Strings.Unbounded.To_String (S.Command))); + Stm_Name := Strings.New_Char_Array + (To_C (Prepared_Stm_Name)); + + S.Pg_Result := Thin.PQPREPARE (C.Real, Stm_Name, Command, + NParams, null); + + if Command /= Strings.Null_Ptr then + Interfaces.C.Strings.Free (Command); + end if; + if Stm_Name /= Strings.Null_Ptr then + Interfaces.C.Strings.Free (Stm_Name); + end if; + + if S.Pg_Result = null then + Raise_Exception (Error'Identity, Error_Message (C)); + -- S.Pg_Result so we use the last Error message available + -- in the connection + end if; + if Thin.PQRESULTSTATUS (S.Pg_Result) /= Thin.PGRES_COMMAND_OK then + Raise_Exception (Error'Identity, Error_Message (S)); + end if; + end Prepare; + + + procedure Exec + (S : in out Statment_Object_Type; + C : Connection_Object_Type; + Prepared_Stm_Name : String) + is + use Interfaces.C; + use type Interfaces.C.Strings.chars_ptr; + use type Thin.ExecStatusType; + use type Thin.A_PGRESULT_T; + Stm_Name : Strings.chars_ptr; + Param_Last : Natural := S.Param_Length; + begin + Stm_Name := Strings.New_Char_Array + (To_C (Prepared_Stm_Name)); + if Param_Last > 0 then + Param_Last := Param_Last - 1; + end if; + declare + Pg_Param : Pg_ParamValues (0 .. size_t (Param_Last)) := + (others => Interfaces.C.Strings.Null_Ptr); + begin + if S.Param_Length > 0 then + To_C_Binded_Parameter_Value (S, Pg_Param); + end if; + S.Pg_Result := Thin.PQEXECPREPARED + (C.Real, Stm_Name, int (S.Param_Length), + Pg_Param (0)'Access, null, null, 0); + for I in Pg_Param'Range loop + Interfaces.C.Strings.Free (Pg_Param (I)); + end loop; + end; + Stm_Map.Clear (S.Parameter); + S.Param_Length := 0; + if Stm_Name /= Strings.Null_Ptr then + Interfaces.C.Strings.Free (Stm_Name); + end if; + if S.Pg_Result = null then + Raise_Exception (Error'Identity, Error_Message (C)); + -- S.Pg_Result so we use the last Error message available + -- in the connection + end if; + if Thin.PQRESULTSTATUS (S.Pg_Result) /= Thin.PGRES_COMMAND_OK then + Raise_Exception (Error'Identity, Error_Message (S)); + end if; + end Exec; + + function Status (S : Statment_Object_Type) return Exec_Status_Type + is + Result : Thin.ExecStatusType := Thin.PQRESULTSTATUS (S.Pg_Result); + begin + return Exec_Status_Type'Val (Thin.ExecStatusType'Pos (Result)); + end Status; + + function N_Tuples (S : Statment_Object_Type) return Tuples_Type + is + Result : Tuples_Type := + Tuples_Type (Thin.PQNTUPLES (S.Pg_Result)); + begin + return Result; + end N_Tuples; + + function N_Fields (S : Statment_Object_Type) return Fields_Type + is + Result : Fields_Type := + Fields_Type (Thin.PQNFIELDS (S.Pg_Result)); + begin + return Result; + end N_Fields; + + function F_Name + (S : Statment_Object_Type; + Column_Number : Fields_Type) + return String + is + use Interfaces.C; + Result : String := Interfaces.C.Strings.Value + (Thin.PQFNAME (S.Pg_Result, int (Column_Number))); + begin + return Result; + end F_Name; + + function F_Number + (S : Statment_Object_Type; + Column_Name : String) + return Fields_Type + is + use Interfaces.C; + use type Interfaces.C.Strings.chars_ptr; + C_Column_Name : Strings.chars_ptr := + Strings.New_Char_Array (To_C (Column_Name)); + Result : Fields_Type := + Fields_Type (Thin.PQFNUMBER (S.Pg_Result, C_Column_Name)); + begin + if C_Column_Name /= Strings.Null_Ptr then + Interfaces.C.Strings.Free (C_Column_Name); + end if; + return Result; + end F_Number; + + function F_Table + (S : Statment_Object_Type; + Column_Number : Fields_Type) return Oid + is + use Interfaces.C; + Result : Oid := + Oid (Thin.PQFTABLE (S.Pg_Result, int (Column_Number))); + begin + return Result; + end F_Table; + + function F_Table_Col + (S : Statment_Object_Type; + Column_Number : Fields_Type) return Fields_Type + is + use Interfaces.C; + Result : Fields_Type := + Fields_Type (Thin.PQFTABLECOL (S.Pg_Result, int (Column_Number))); + begin + return Result; + end F_Table_Col; + + function F_Format + (S : Statment_Object_Type; + Column_Number : Fields_Type) return Format_Code_Type + is + use Interfaces.C; + Result : Format_Code_Type := + Format_Code_Type (Thin.PQFFORMAT (S.Pg_Result, int (Column_Number))); + begin + return Result; + end F_Format; + + function F_Type + (S : Statment_Object_Type; + Column_Number : Fields_Type) return Oid + is + use Interfaces.C; + Result : Oid := + Oid (Thin.PQFTYPE (S.Pg_Result, int (Column_Number))); + begin + return Result; + end F_Type; + + function F_Mod + (S : Statment_Object_Type; + Column_Number : Fields_Type) return Modifier_Type + is + use Interfaces.C; + Result : Modifier_Type := + Modifier_Type (Thin.PQFMOD (S.Pg_Result, int (Column_Number))); + begin + return Result; + end F_Mod; + + function F_Size + (S : Statment_Object_Type; + Column_Number : Fields_Type) return Size_Type + is + use Interfaces.C; + Result : Size_Type := + Size_Type (Thin.PQFSIZE (S.Pg_Result, int (Column_Number))); + begin + return Result; + end F_Size; + + function Get_Value + (S : Statment_Object_Type; + Row_Number : Tuples_Type; + Column_Number : Fields_Type) return String + is + use Interfaces.C; + use type Interfaces.C.Strings.chars_ptr; + C_Result : Strings.chars_ptr := + Thin.PQGETVALUE (S.Pg_Result, + int (Row_Number), + int (Column_Number)); + Result : String := Strings.Value (C_Result); + begin + -- The caller should not free the result directly. + -- It will be freed when the associated PGresult handle + -- is passed to PQclear. + return Result; + end Get_Value; + + function Get_Is_Null + (S : Statment_Object_Type; + Row_Number : Tuples_Type; + Column_Number : Fields_Type) return Boolean + is + use Interfaces.C; + C_Result : int := Thin.PQGETISNULL (S.Pg_Result, + int (Row_Number), + int (Column_Number)); + begin + return C_Result = Thin.C_True; + end Get_Is_Null; + + function Getlength + (S : Statment_Object_Type; + Row_Number : Tuples_Type; + Column_Number : Fields_Type) return Length_Type + is + use Interfaces.C; + Result : Length_Type := + Length_Type (Thin.PQGETLENGTH (S.Pg_Result, + int (Row_Number), + int (Column_Number))); + begin + return Result; + end Getlength; + + function N_Params (S : Statment_Object_Type) return Param_Number_Type + is + use Interfaces.C; + Result : Param_Number_Type := + Param_Number_Type (Thin.PQNPARAMS (S.Pg_Result)); + begin + return Result; + end N_Params; + + function Param_Type + (S : Statment_Object_Type; + Param_Number : Param_Number_Type) return Oid + is + use Interfaces.C; + Result : Oid := + Oid (Thin.PQPARAMTYPE (S.Pg_Result, int (Param_Number))); + begin + return Result; + end Param_Type; + +end Backlit.Client.Statment; diff --git a/src/backlit-client-statment.ads b/src/backlit-client-statment.ads new file mode 100644 index 0000000..c527cf8 --- /dev/null +++ b/src/backlit-client-statment.ads @@ -0,0 +1,307 @@ +------------------------------------------------------------------------------ +-- -- +-- Copyright 2008, Ali Bendriss -- +-- -- +-- This file is part of Backlit. -- +-- -- +-- Backlit is free software: you can redistribute it and/or modify it under -- +-- the terms of the GNU Lesser General Public License as published by -- +-- the Free Software Foundation, either version 3 of the License, or -- +-- (at your option) any later version. -- +-- -- +-- Backlit is distributed in the hope that it will be useful, -- +-- but WITHOUT ANY WARRANTY; without even the implied warranty of -- +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- +-- GNU Lesser General Public License for more details. -- +-- -- +-- You should have received a copy of the GNU Lesser General Public License -- +-- along with Backlit. If not, see . -- +-- -- +------------------------------------------------------------------------------ + +with Ada.Strings.Unbounded; +with Ada.Containers.Indefinite_Ordered_Maps; +private with Interfaces.C; +private with Interfaces.C.Strings; + +package Backlit.Client.Statment is + + ------------------------- + -- Command Execution -- + ------------------------- + + type Statment_Object_Type is new + Ada.Finalization.Limited_Controlled with private; + + procedure Append_Command + (S : in out Statment_Object_Type; + Q : String); + -- The SQL command string to be executed. + -- If parameters are used, + -- they are referred to in the command string as $1, $2, etc. + -- And the coresponding Keys in the Bind_Parameter procedure + -- are referred as 1, 2, etc + + procedure Bind_Parameter + (S : in out Statment_Object_Type; + Key : Positive; + Value : String); + -- If paramaters a set then exec will run Thin.PQexecParams + -- rather than Thin.Exec. The primary advantage of PQexecParams over PQexec + -- is that parameter values can be separated from the command string, + -- thus avoiding the need for tedious and error-prone quoting and escaping. + -- + -- Unlike PQexec, PQexecParams allows at most one SQL command in + -- the given string. (There can be semicolons in it, but + -- not more than one nonempty command.) This is a limitation + -- of the underlying protocol, but has some usefulness as an extra defense + -- against SQL-injection attacks. + + procedure Exec + (S : in out Statment_Object_Type; + C : Connection_Object_Type); + -- Submits a command to the server and waits for the result, + -- with the ability to pass parameters separately + -- from the SQL command text by using the Bind_Parameter procedure + + procedure Prepare + (S : in out Statment_Object_Type; + C : Connection_Object_Type; + Prepared_Stm_Name : String := ""; + Number_Of_Parameter : Natural := 0); + -- Creates a prepared statement named Prepared_Stm_Name + -- from the query string supplied by the Append_Command procedure, + -- which must contain a single SQL command. Prepared_Stm_Name can be "" to + -- create an unnamed statement, in which case any pre-existing unnamed + -- statement is automatically replaced; otherwise it is an error if the + -- statement name is already defined in the current session. + -- If any parameters are used, they are referred to in the query + -- as $1, $2, etc. Number_Of_Parameter is their number. + + procedure Exec + (S : in out Statment_Object_Type; + C : Connection_Object_Type; + Prepared_Stm_Name : String); + -- Same as the Exec procedure but take a prepared statment name + -- as parameter to run a prepared statment using Prepare. + + function Error_Message (S : Statment_Object_Type) return String; + -- Returns the error message associated with the command, + -- or an empty string if there was no error. + + + type Exec_Status_Type is + (EMPTY_QUERY, + -- The string sent to the server was empty. + COMMAND_OK, + -- Successful completion of a command returning no data. + TUPLES_OK, + -- Successful completion of a command returning data + -- (such as a SELECT or SHOW). + COPY_OUT, + -- Copy Out (from server) data transfer started. + COPY_IN, + -- Copy In (to server) data transfer started. + BAD_RESPONSE, + -- The server's response was not understood. + NONFATAL_ERROR, + -- A nonfatal error (a notice or warning) occurred. + FATAL_ERROR + -- A fatal error occurred. + ); + + function Status (S : Statment_Object_Type) return Exec_Status_Type; + -- If the result status is PGRES_TUPLES_OK, then the functions described + -- below can be used to retrieve the rows returned by the query. + -- Note that a SELECT command that happens to retrieve zero rows + -- still shows PGRES_TUPLES_OK. PGRES_COMMAND_OK is for commands that + -- can never return rows (INSERT, UPDATE, etc.). + -- A response of PGRES_EMPTY_QUERY might indicate a bug + -- in the client software. A result of status PGRES_NONFATAL_ERROR + -- will never be returned directly by PQexec or other query execution + -- functions; results of this kind are instead passed to the + -- notice processor + + ------------------------------------------- + -- Retrieving Query Result Information -- + ------------------------------------------- + + subtype Oid is Thin.Oid range Thin.Oid'Range; + InvalidOid : constant Oid := 0; + + type Tuples_Type is new Integer; + function N_Tuples (S : Statment_Object_Type) return Tuples_Type; + -- Returns the number of rows (tuples) in the query result. + -- Because it returns an integer result, + -- large result sets might overflow the return value on 32-bit + -- operating systems. + -- FIXME change it for Long_integer for 64 Bit os ??? (in thin as well) + + type Fields_Type is new Integer; + function N_Fields (S : Statment_Object_Type) return Fields_Type; + -- Returns the number of columns (fields) in each row of the query result. + + function F_Name + (S : Statment_Object_Type; + Column_Number : Fields_Type) + return String; + -- Returns the column name associated with the given column number. + -- Column numbers start at 0. + + function F_Number + (S : Statment_Object_Type; + Column_Name : String) + return Fields_Type; + -- Returns the column number associated with the given column name. + -- -1 is returned if the given name does not match any column. + -- The given name is treated like an identifier in an SQL command, + -- that is, it is downcased unless double-quoted. + + function F_Table + (S : Statment_Object_Type; + Column_Number : Fields_Type) return Oid; + -- Returns the OID of the table from which the given column was fetched. + -- Column numbers start at 0. + -- InvalidOid is returned if the column number is out of range, + -- or if the specified column is not a simple reference to a table column, + -- or when using pre-3.0 protocol. You can query the system table pg_class + -- to determine exactly which table is referenced. + + function F_Table_Col + (S : Statment_Object_Type; + Column_Number : Fields_Type) return Fields_Type; + -- Returns the column number (within its table) of the column making up the + -- specified query result column. Query-result column numbers start at 0, + -- but table columns have nonzero numbers. + -- Zero is returned if the column number is out of range, + -- or if the specified column is not a simple reference to a table column, + -- or when using pre-3.0 protocol. + + type Format_Code_Type is new Integer; + function F_Format + (S : Statment_Object_Type; + Column_Number : Fields_Type) return Format_Code_Type; + -- Returns the format code indicating the format of the given column. + -- Column numbers start at 0. Format code zero indicates textual data + -- representation, while format code one indicates binary representation. + -- (Other codes are reserved for future definition.) + + function F_Type + (S : Statment_Object_Type; + Column_Number : Fields_Type) return Oid; + -- Returns the data type associated with the given column number. + -- The value returned is the internal OID number of the type. + -- Column numbers start at 0. You can query the system table pg_type to + -- obtain the names and properties of the various data types. + -- The OIDs of the built-in data types are defined in the file + -- src/include/catalog/pg_type.h in the source tree. + + type Modifier_Type is new Integer; + function F_Mod + (S : Statment_Object_Type; + Column_Number : Fields_Type) return Modifier_Type; + -- Returns the type modifier of the column associated with the + -- given column number. Column numbers start at 0. The interpretation + -- of modifier values is type-specific; + -- they typically indicate precision or size limits. + -- The value -1 is used to indicate "no information available". + -- Most data types do not use modifiers, + -- in which case the value is always -1. + + type Size_Type is new Integer; + function F_Size + (S : Statment_Object_Type; + Column_Number : Fields_Type) return Size_Type; + + -- Returns the size in bytes of the column associated with the given + -- column number. Column numbers start at 0. Fsize returns the space + -- allocated for this column in a database row, in other words the size + -- of the server's internal representation of the data type. + -- (Accordingly, it is not really very useful to clients.) + -- A negative value indicates the data type is variable-length. + + function Get_Value + (S : Statment_Object_Type; + Row_Number : Tuples_Type; + Column_Number : Fields_Type) return String; + -- Returns a single field value of one row of a PGresult. + -- Row and column numbers start at 0. + + function Get_Is_Null + (S : Statment_Object_Type; + Row_Number : Tuples_Type; + Column_Number : Fields_Type) return Boolean; + -- Tests a field for a null value. Row and column numbers start at 0. + + type Length_Type is new Integer; + function Getlength + (S : Statment_Object_Type; + Row_Number : Tuples_Type; + Column_Number : Fields_Type) return Length_Type; + -- Returns the actual length of a field value in bytes. + -- Row and column numbers start at 0. + + type Param_Number_Type is new Integer range 0 .. Integer'Last; + function N_Params (S : Statment_Object_Type) return Param_Number_Type; + -- Returns the number of parameters of a prepared statement. + -- This function is only useful when inspecting the result of + -- PQdescribePrepared. For other types of queries it will return zero. + + function Param_Type + (S : Statment_Object_Type; + Param_Number : Param_Number_Type) return Oid; + -- Returns the data type of the indicated statement parameter. + -- Parameter numbers start at 0. + -- This function is only useful when inspecting the result of + -- PQdescribePrepared. For other types of queries it will return zero. + + + + +private + + package Stm_Map is new Ada.Containers.Indefinite_Ordered_Maps + (Key_Type => Positive, + Element_Type => String, + "<" => "<", + "=" => "="); + + type Statment_Object_Type is new + Ada.Finalization.Limited_Controlled with + record + Pg_Result : Thin.A_PGRESULT_T; + Command : Ada.Strings.Unbounded.Unbounded_String; + Parameter : Stm_Map.Map; + Param_Length : Natural; + end record; + + procedure Initialize (S : in out Statment_Object_Type); + + procedure Finalize (S : in out Statment_Object_Type); + + type Pg_ParamTypes is array (Interfaces.C.size_t range <>) + of aliased Thin.Oid; + pragma Convention (C, Pg_ParamTypes); + + type Pg_ParamValues is array (Interfaces.C.size_t range <>) + of aliased Interfaces.C.Strings.chars_ptr; + pragma Convention (C, Pg_ParamValues); + + type ParamLengths is array (Interfaces.C.size_t range <>) + of aliased Interfaces.C.int; + pragma Convention (C, ParamLengths); + + type ParamFormats is array (Interfaces.C.size_t range <>) + of aliased Interfaces.C.int; + pragma Convention (C, ParamFormats); + + type Pg_Parameter_Type is record + ParamTypes : Thin.Oid := Thin.InvalidOid; + ParamValues : Interfaces.C.Strings.chars_ptr; + ParamLengths : Interfaces.C.int; + ParamFormats : Interfaces.C.int := 0; + end record; + -- only the Pg_ParamValues will be used for now as we are processing + -- text-format parameters. + +end Backlit.Client.Statment; diff --git a/src/backlit-client.adb b/src/backlit-client.adb new file mode 100644 index 0000000..05d8cd4 --- /dev/null +++ b/src/backlit-client.adb @@ -0,0 +1,336 @@ +------------------------------------------------------------------------------ +-- -- +-- Copyright 2008, Ali Bendriss -- +-- -- +-- This file is part of Backlit. -- +-- -- +-- Backlit is free software: you can redistribute it and/or modify it under -- +-- the terms of the GNU Lesser General Public License as published by -- +-- the Free Software Foundation, either version 3 of the License, or -- +-- (at your option) any later version. -- +-- -- +-- Backlit is distributed in the hope that it will be useful, -- +-- but WITHOUT ANY WARRANTY; without even the implied warranty of -- +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- +-- GNU Lesser General Public License for more details. -- +-- -- +-- You should have received a copy of the GNU Lesser General Public License -- +-- along with Backlit. If not, see . -- +-- -- +------------------------------------------------------------------------------ + +with Ada.Exceptions; +with Interfaces.C.Strings; +with Ada.Strings.Unbounded; +-- with Ada.Text_Io; use Ada.Text_IO; +with Ada.Characters.Handling; + +package body Backlit.Client is + + use Connection_Info_Map; + use Backlit.Thin; + use Ada.Exceptions; + + function Error_Message (C : in Connection_Object_Type) return String + is + begin + return Interfaces.C.Strings.Value (PQERRORMESSAGE (C.Real)); + exception + when others => + return "unknow error."; + end Error_Message; + + procedure Connection_Map_To_C + (C : in out Connection_Object_Type; + I : out Interfaces.C.Strings.chars_ptr) + is + use Ada.Strings.Unbounded; + use Interfaces.C; + use Interfaces.C.Strings; + TMP_US : Unbounded_String; + procedure Append_Info (C : Connection_Info_Map.Cursor) is + begin + Ada.Strings.Unbounded.Append + (TMP_US, Connection_Info_Map.Element (C) & " "); + -- Put_Line (Ada.Strings.Unbounded.To_String (TMP_US)); + end Append_Info; + begin + Connection_Info_Map.Iterate (C.Map, Append_Info'Access); + Connection_Info_Map.Clear (C.Map); + I := Interfaces.C.Strings.New_Char_Array + (To_C (Ada.Strings.Unbounded.To_String (TMP_US))); + end Connection_Map_To_C; + + procedure Frozen_Check (C : in out Connection_Object_Type) + is + use Ada.Exceptions; + begin + if C.Frozen then + Raise_Exception + (Error'Identity, + "connection already done, parameters can't be changed"); + end if; + end Frozen_Check; + -- libpq doesn't permit any change in the connection_info after the + -- connection. We make it explicite by raising an exception. + + procedure Set_Host_Name + (C : in out Connection_Object_Type; Value : String) + is + begin + Frozen_Check (C); + C.Map.Insert ("host", "host=" & Value); + end Set_Host_Name; + + procedure Set_Host_Address + (C : in out Connection_Object_Type; Value : String) + is + begin + Frozen_Check (C); + C.Map.Insert ("hostaddr", "hostaddr=" & Value); + end Set_Host_Address; + + procedure Set_Port + (C : in out Connection_Object_Type; Value : String) + is + begin + Frozen_Check (C); + C.Map.Insert ("port", "port=" & Value); + end Set_Port; + + procedure Set_Db_Name + (C : in out Connection_Object_Type; Value : String) + is + begin + Frozen_Check (C); + C.Map.Insert ("dbname", "dbname=" & Value); + end Set_Db_Name; + + procedure Set_User_Name + (C : in out Connection_Object_Type; Value : String) + is + begin + Frozen_Check (C); + C.Map.Insert ("user", "user=" & Value); + end Set_User_Name; + + procedure Set_User_Password + (C : in out Connection_Object_Type; Value : String) + is + begin + Frozen_Check (C); + C.Map.Insert ("password", "password=" & Value); + end Set_User_Password; + + procedure Set_Timeout + (C : in out Connection_Object_Type; Value : Natural) + is + begin + Frozen_Check (C); + C.Map.Insert ("connect_timeout", "connect_timeout=" & Value'Img); + end Set_Timeout; + + procedure Set_Options + (C : in out Connection_Object_Type; Value : String) + is + begin + Frozen_Check (C); + C.Map.Insert ("options", "options=" & Value); + end Set_Options; + + procedure Set_SSL + (C : in out Connection_Object_Type; Value : SSL_Mode_Type) + is + function PQ_Value (SSL : SSL_Mode_Type) return String + is + begin + case SSL is + when Disable => return "disable"; + when Allow => return "allow"; + when Prefer => return "prefer"; + when Require => return "require"; + end case; + end PQ_Value; + begin + Frozen_Check (C); + C.Map.Insert ("sslmode", "sslmode=" & PQ_Value (Value)); + end Set_SSL; + + procedure Set_Krbsrvname + (C : in out Connection_Object_Type; Value : String) + is + begin + Frozen_Check (C); + C.Map.Insert ("krbsrvname", "options=" & Value); + end Set_Krbsrvname; + + procedure Set_Gssapi + (C : in out Connection_Object_Type) + is + begin + Frozen_Check (C); + C.Map.Insert ("gsslib", "gsslib=gssapi"); + end Set_Gssapi; + + procedure Set_Service_Name + (C : in out Connection_Object_Type; Value : String) + is + begin + Frozen_Check (C); + C.Map.Insert ("service", "service=" & Value); + end Set_Service_Name; + + procedure Connect + (C : in out Connection_Object_Type) + is + CI : Interfaces.C.Strings.chars_ptr; + use Interfaces.C.Strings; + begin + if Is_Connected (C) then + return; + end if; + Connection_Map_To_C (C, CI); + C.Real := Backlit.Thin.PQCONNECTDB (CI); + if CI /= Null_Ptr then + Interfaces.C.Strings.Free (CI); + end if; + if PQSTATUS (C.Real) /= CONNECTION_OK then + Raise_Exception (Error'Identity, Error_Message (C)); + end if; + C.Frozen := True; + end Connect; + + procedure Connect + (C : in out Connection_Object_Type; + C_Info : String) + is + CI : Interfaces.C.Strings.chars_ptr; + use Interfaces.C.Strings; + use Interfaces.C.Strings; + begin + if Is_Connected (C) then + return; + end if; + if not Connection_Info_Map.Is_Empty (C.Map) then + Raise_Exception + (Error'Identity, + "Only one connection methode required"); + end if; + CI := New_Char_Array (Interfaces.C.To_C (C_Info)); + C.Real := Backlit.Thin.PQCONNECTDB (CI); + if CI /= Null_Ptr then + Interfaces.C.Strings.Free (CI); + end if; + if PQSTATUS (C.Real) /= CONNECTION_OK then + Raise_Exception (Error'Identity, Error_Message (C)); + end if; + C.Frozen := True; + end Connect; + + procedure Reset + (C : in out Connection_Object_Type) + is + begin + PQRESET (C.Real); + if PQSTATUS (C.Real) /= CONNECTION_OK then + Raise_Exception (Error'Identity, Error_Message (C)); + end if; + end Reset; + + procedure Connect_Non_Blocking + (C : in out Connection_Object_Type) + is + begin + null; + end Connect_Non_Blocking; + + procedure Reset_Non_Blocking + (C : in out Connection_Object_Type) + is + begin + null; + end Reset_Non_Blocking; + + function Get + (C : Connection_Object_Type; + Q : Connection_Key_Type) return String + is + begin + case Q is + when DB_Name => + return Interfaces.C.Strings.Value (PQDB (C.Real)); + when DB_User => + return Interfaces.C.Strings.Value (PQUSER (C.Real)); + when DB_Pass => + return Interfaces.C.Strings.Value (PQPASS (C.Real)); + when DB_Host => + return Interfaces.C.Strings.Value (PQHOST (C.Real)); + when DB_Port => + return Interfaces.C.Strings.Value (PQPORT (C.Real)); + when DB_Options => + return Interfaces.C.Strings.Value (PQOPTIONS (C.Real)); + end case; + end Get; + + procedure Initalize (C : in out Connection_Object_Type) + is + begin + C.Frozen := False; + end Initalize; + + procedure Finalize (C : in out Connection_Object_Type) + is + begin + PQFINISH (C.Real); + -- FIXME + -- There is no way to check the success yet: + -- libpq doesn't set conn to NULL after a PQFINISH call. + end Finalize; + + function Current_Server_Setting + (C : Connection_Object_Type; + Key : String; + To_Lower : Boolean := True) return String + is + Param : Interfaces.C.Strings.chars_ptr; + Real_Key : String := Key; + begin + if To_Lower = True then + Real_Key := Ada.Characters.Handling.To_Lower (Key); + end if; + Param := Interfaces.C.Strings.New_Char_Array + (Interfaces.C.To_C (Real_Key)); + declare + Result : String := Interfaces.C.Strings.Value + (PQPARAMETERSTATUS (C.Real, Param)); + begin + Interfaces.C.Strings.Free (Param); + return Result; + end; + exception + when others => return ""; + end Current_Server_Setting; + + function Needs_Password + (C : Connection_Object_Type) return Boolean + is + use type Interfaces.C.int; + begin + return PQCONNECTIONNEEDSPASSWORD (C.Real) = C_True; + end Needs_Password; + + function Used_Password + (C : Connection_Object_Type) return Boolean + is + use type Interfaces.C.int; + begin + return PQCONNECTIONUSEDPASSWORD (C.Real) = C_True; + end Used_Password; + + function Is_Connected (C : Connection_Object_Type) return Boolean + is + begin + return PQSTATUS (C.Real) = CONNECTION_OK; + end Is_Connected; + +end Backlit.Client; diff --git a/src/backlit-client.ads b/src/backlit-client.ads new file mode 100644 index 0000000..d17b99b --- /dev/null +++ b/src/backlit-client.ads @@ -0,0 +1,225 @@ +------------------------------------------------------------------------------ +-- -- +-- Copyright 2008, Ali Bendriss -- +-- -- +-- This file is part of Backlit. -- +-- -- +-- Backlit is free software: you can redistribute it and/or modify it under -- +-- the terms of the GNU Lesser General Public License as published by -- +-- the Free Software Foundation, either version 3 of the License, or -- +-- (at your option) any later version. -- +-- -- +-- Backlit is distributed in the hope that it will be useful, -- +-- but WITHOUT ANY WARRANTY; without even the implied warranty of -- +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- +-- GNU Lesser General Public License for more details. -- +-- -- +-- You should have received a copy of the GNU Lesser General Public License -- +-- along with Backlit. If not, see . -- +-- -- +------------------------------------------------------------------------------ + +with Ada.Finalization; +private with Ada.Containers.Indefinite_Hashed_Maps; +private with Ada.Strings.Hash; +with Backlit.Thin; + +package Backlit.Client is + + type Connection_Object_Type is new + Ada.Finalization.Limited_Controlled with private; + + -------------------------- + -- Connection Control -- + -------------------------- + + procedure Set_Host_Name + (C : in out Connection_Object_Type; Value : String); + -- Name of Host To Connect To. + -- If this Begins with a slash, it specifies Unix-Domain Communication + -- rather than TCP/IP communication. The Value is the Name of the Directory + -- in which the socket file is stored. + -- The default behavior when host is not specified is to connect to + -- A Unix-Domain Socket in /tmp (or whatever socket directory was specified + -- when PostgreSQL was built). + -- On machines without Unix-Domain Sockets, + -- the default is to connect to localhost. + + procedure Set_Host_Address + (C : in out Connection_Object_Type; Value : String); + -- Numeric IP address of host to connect to. + -- This should be in the standard IPv4 address format, e.g., 172.28.40.9. + -- if your machine supports IPv6, you can also use those addresses. + -- TCP/IP communication is always used when a nonempty string + -- is specified for this parameter. + + procedure Set_Port + (C : in out Connection_Object_Type; + Value : String); + -- Port number to connect to at the server host, + -- or socket file name extension for Unix-Domain Connections. + + procedure Set_Db_Name + (C : in out Connection_Object_Type; Value : String); + -- The database name. Defaults to be the same as the user name. + + procedure Set_User_Name + (C : in out Connection_Object_Type; Value : String); + -- PostgreSQL user name to connect as. + -- Defaults to be the same as the operating system name of the user + -- running the application. + + procedure Set_User_Password + (C : in out Connection_Object_Type; Value : String); + -- Password to be used if the server demands password authentication. + + procedure Set_Timeout + (C : in out Connection_Object_Type; Value : Natural); + -- Maximum wait for connection, in seconds (write as a Decimal). + -- Zero or not specified means wait indefinitely. + -- It is not recommended to use a timeout of less than 2 seconds. + + procedure Set_Options + (C : in out Connection_Object_Type; Value : String); + -- Command-line options to be sent to the server. + + type SSL_Mode_Type is (Disable, Allow, Prefer, Require); + procedure Set_SSL + (C : in out Connection_Object_Type; Value : SSL_Mode_Type); + -- This option determines whether or + -- with what priority an SSL Connection will be Negotiated + -- with the server. There are four modes: + -- * Disable will attempt only an unencrypted SSL Connection; + -- * Allow will negotiate, trying first a non-SSL connection, + -- then if that fails, trying an SSL connection; + -- * Prefer (the default) will negotiate, trying first an SSL connection, + -- then if that fails, trying a regular non-SSL connection; + -- * Require will try only an SSL connection. + -- if PostgreSQL is compiled without SSL support, + -- using option Require will cause an error, + -- while options Allow and Prefer will be accepted but + -- will not in fact attempt an SSL connection. + + procedure Set_Krbsrvname + (C : in out Connection_Object_Type; Value : String); + -- Kerberos service name to use when authenticating with + -- Kerberos 5 or GSSAPI. + -- This must match the service name specified in the server + -- configuration for Kerberos authentication to Succeed. + + procedure Set_Gssapi + (C : in out Connection_Object_Type); + -- Only Used On Windows. + -- Set_Gssapi force the use the GSSAPI library for Authentication + -- instead of the default SSPI. + + procedure Set_Service_Name + (C : in out Connection_Object_Type; Value : String); + -- Service name to use for additional parameters. + -- It specifies a service name in pg_service.conf that holds additional + -- connection parameters. This allows applications to Specify only a + -- service name so connection parameters can be centrally maintained. + + procedure Connect + (C : in out Connection_Object_Type); + -- Makes a new connection to the database server. + -- return if already connected. + + procedure Connect + (C : in out Connection_Object_Type; C_Info : String); + -- Makes a new connection to the database server. + -- Take the connection info from a string like + -- "host=localhost user=postgres dbname=template1 ..." + -- rather than using the procedure Set_Host_Name or Set_Host_Address. + -- You can't mix the two ways on the same connection. + -- return if already connected. + + procedure Reset + (C : in out Connection_Object_Type); + -- This procedure will close the connection to the server and + -- attempt to reestablish a new connection to the same server, + -- using all the same parameters previously used. + -- This might be useful for error recovery if a working connection is lost. + + + procedure Connect_Non_Blocking + (C : in out Connection_Object_Type); + -- Make a connection to the database server in a nonblocking manner. + + procedure Reset_Non_Blocking + (C : in out Connection_Object_Type); + -- This procedure will close the connection to the server and + -- attempt to reestablish a new connection to the same server, + -- using all the same parameters previously used. + -- This can be useful for error recovery if a working connection is lost. + -- It differ from reset (above) in that it act in a nonblocking manner. + + + ------------------------- + -- Connection Status -- + ------------------------- + type Connection_Key_Type is + (DB_Name, DB_User, DB_Pass, DB_Host, DB_Port, DB_Options); + + function Get + (C : Connection_Object_Type; + Q : Connection_Key_Type) return String; + -- The following functions return parameter values established at + -- connection. These values are fixed for the life of the PGconn object. + + function Error_Message (C : in Connection_Object_Type) return String; + -- Returns the error message most recently generated by + -- an operation on the connection. + + function Current_Server_Setting + (C : Connection_Object_Type; + Key : String; + To_Lower : Boolean := True) return String; + -- Certain parameter values are reported by the server automatically + -- at connection startup or whenever their values change. + -- this function can be used to interrogate these settings. + -- It returns the current value of a parameter if known, + -- or an empty string if the parameter is not known. + -- key looks like : server_version, server_encoding... + -- check the doc for Parameters reported as of the current release. + + function Needs_Password + (C : Connection_Object_Type) return Boolean; + -- Returns true if the connection authentication method + -- required a password, but none was available. + -- This function can be applied after a failed connection attempt + -- to decide whether to prompt the user for a password. + + function Used_Password + (C : Connection_Object_Type) return Boolean; + -- This function detects whether a password supplied to the connection + -- function was actually used. Passwords obtained from other sources + -- (such as the .pgpass file) are not considered caller-supplied. + + function Is_Connected + (C : Connection_Object_Type) return Boolean; + -- return True is the connection status is OK. + + +private + + package Connection_Info_Map is + new Ada.Containers.Indefinite_Hashed_Maps + (String, + String, + Ada.Strings.Hash, + "="); + + type Connection_Object_Type is new + Ada.Finalization.Limited_Controlled with + record + Real : Backlit.Thin.A_PGCONN_T; + Map : Connection_Info_Map.Map; + Frozen : Boolean; + end record; + + procedure Initalize (C : in out Connection_Object_Type); + + procedure Finalize (C : in out Connection_Object_Type); + +end Backlit.Client; diff --git a/src/backlit-thin.ads b/src/backlit-thin.ads new file mode 100644 index 0000000..dcab5bb --- /dev/null +++ b/src/backlit-thin.ads @@ -0,0 +1,1455 @@ +------------------------------------------------------------------------------ +-- -- +-- Copyright 2008, Ali Bendriss -- +-- -- +-- This file is part of Backlit. -- +-- -- +-- Backlit is free software: you can redistribute it and/or modify it under -- +-- the terms of the GNU Lesser General Public License as published by -- +-- the Free Software Foundation, either version 3 of the License, or -- +-- (at your option) any later version. -- +-- -- +-- Backlit is distributed in the hope that it will be useful, -- +-- but WITHOUT ANY WARRANTY; without even the implied warranty of -- +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- +-- GNU Lesser General Public License for more details. -- +-- -- +-- You should have received a copy of the GNU Lesser General Public License -- +-- along with Backlit. If not, see . -- +-- -- +------------------------------------------------------------------------------ + +with System; +with Interfaces.C; +-- with Interfaces.C.Extensions; +with Interfaces.C.Strings; +with Interfaces.C_Streams; + +package Backlit.Thin is + + pragma Preelaborate; + + C_True : constant Interfaces.C.int := 1; + C_False : constant Interfaces.C.int := 0; + + type ConnStatusType is + (CONNECTION_OK, -- libpq-fe.h:40 + CONNECTION_BAD, -- libpq-fe.h:41 + CONNECTION_STARTED, -- libpq-fe.h:48 + CONNECTION_MADE, -- libpq-fe.h:49 + CONNECTION_AWAITING_RESPONSE, -- libpq-fe.h:50 + CONNECTION_AUTH_OK, -- libpq-fe.h:52 + CONNECTION_SETENV, -- libpq-fe.h:54 + CONNECTION_SSL_STARTUP, -- libpq-fe.h:55 + CONNECTION_NEEDED -- libpq-fe.h:57 + ); + for ConnStatusType'Size use 32; + pragma Convention (C, ConnStatusType); + + type PostgresPollingStatusType is + (PGRES_POLLING_FAILED, -- libpq-fe.h:61 + PGRES_POLLING_READING, -- libpq-fe.h:62 + PGRES_POLLING_WRITING, -- libpq-fe.h:63 + PGRES_POLLING_OK, -- libpq-fe.h:64 + PGRES_POLLING_ACTIVE + ); + for PostgresPollingStatusType'Size use 32; + pragma Convention (C, PostgresPollingStatusType); + + type ExecStatusType is + (PGRES_EMPTY_QUERY, -- libpq-fe.h:71 + PGRES_COMMAND_OK, -- libpq-fe.h:72 + PGRES_TUPLES_OK, -- libpq-fe.h:75 + PGRES_COPY_OUT, -- libpq-fe.h:78 + PGRES_COPY_IN, -- libpq-fe.h:79 + PGRES_BAD_RESPONSE, -- libpq-fe.h:80 + PGRES_NONFATAL_ERROR, -- libpq-fe.h:82 + PGRES_FATAL_ERROR -- libpq-fe.h:84 + ); + for ExecStatusType'Size use 32; + pragma Convention (C, ExecStatusType); + + type PGTRANSACTIONSTATUSTYPE is + (PQTRANS_IDLE, -- libpq-fe.h:88 + PQTRANS_ACTIVE, -- libpq-fe.h:89 + PQTRANS_INTRANS, -- libpq-fe.h:90 + PQTRANS_INERROR, -- libpq-fe.h:91 + PQTRANS_UNKNOWN -- libpq-fe.h:93 + ); + for PGTRANSACTIONSTATUSTYPE'Size use 32; + pragma Convention (C, PGTRANSACTIONSTATUSTYPE); + + type PGVERBOSITY is + (PQERRORS_TERSE, -- libpq-fe.h:97 + PQERRORS_DEFAULT, -- libpq-fe.h:98 + PQERRORS_VERBOSE -- libpq-fe.h:100 + ); + for PGVERBOSITY'Size use 32; + pragma Convention (C, PGVERBOSITY); + + type Oid is new Interfaces.C.unsigned; -- postgres_ext.h:29 + -- Object ID is a fundamental type in Postgres. + InvalidOid : constant Oid := 0; -- postgres_ext.h:34 + + -- type PGCONN_T is new Interfaces.C.Extensions.opaque_structure_def; + type PGCONN_T is new System.Address; + -- libpq-fe.h:105 + + type A_PGCONN_T is access all PGCONN_T; + -- libpq-fe.h:204 + -- pragma Convention (C, A_PGCONN_T); + + -- type PGRESULT_T is new Interfaces.C.Extensions.opaque_structure_def; + type PGRESULT_T is new System.Address; + -- libpq-fe.h:112 + + type A_PGRESULT_T is access all PGRESULT_T; + -- libpq-fe.h:136 + + -- type PGCANCEL_T is new Interfaces.C.Extensions.opaque_structure_def; + type PGCANCEL_T is new System.Address; + -- libpq-fe.h:118 + + type A_PGCANCEL_T is access all PGCANCEL_T; + -- libpq-fe.h:238 + -- pragma Convention (C, A_PGCANCEL_T); + + type PGNOTIFY_T; + type A_PGNOTIFY_T is access all PGNOTIFY_T; -- libpq-fe.h:132 + -- pragma Convention (C, A_PGNOTIFY_T); + + type PGNOTIFY_T is + record + relname : Interfaces.C.Strings.chars_ptr; -- libpq-fe.h:128 + be_pid : Interfaces.C.int; -- libpq-fe.h:129 + extra : Interfaces.C.Strings.chars_ptr; -- libpq-fe.h:130 + next : A_PGNOTIFY_T; -- libpq-fe.h:132 + end record; + pragma Convention (C, PGNOTIFY_T); + + type PQNOTICERECEIVER_T is access procedure + (arg : System.Address; + res : A_PGRESULT_T); -- libpq-fe.h:136 + pragma Convention (C, PQNOTICERECEIVER_T); + + type PQNOTICEPROCESSOR_T is access procedure + (arg : System.Address; + message : Interfaces.C.Strings.chars_ptr); -- libpq-fe.h:137 + pragma Convention (C, PQNOTICEPROCESSOR_T); + + type pqbool is new Interfaces.C.signed_char range 0 .. 1; -- libpq-fe.h:140 + for pqbool'Size use Interfaces.C.signed_char'Size; + + type PQPRINTOPT_T is -- libpq-fe.h:142 + record + header : pqbool; -- libpq-fe.h:144 + align : pqbool; -- libpq-fe.h:145 + standard : pqbool; -- libpq-fe.h:146 + html3 : pqbool; -- libpq-fe.h:147 + expanded : pqbool; -- libpq-fe.h:148 + pager : pqbool; -- libpq-fe.h:149 + fieldSep : Interfaces.C.Strings.chars_ptr; -- libpq-fe.h:150 + tableOpt : Interfaces.C.Strings.chars_ptr; -- libpq-fe.h:151 + caption : Interfaces.C.Strings.chars_ptr; -- libpq-fe.h:152 + fieldName : access Interfaces.C.Strings.chars_ptr; -- libpq-fe.h:153 + end record; + pragma Convention (C, PQPRINTOPT_T); + + type A_PQPRINTOPT_T is access constant PQPRINTOPT_T; -- libpq-fe.h:463 + pragma Convention (C, A_PQPRINTOPT_T); + + type PQCONNINFOOPTION_T is -- libpq-fe.h:165 + record + keyword : Interfaces.C.Strings.chars_ptr; -- libpq-fe.h:167 + envvar : Interfaces.C.Strings.chars_ptr; -- libpq-fe.h:168 + compiled : Interfaces.C.Strings.chars_ptr; -- libpq-fe.h:169 + val : Interfaces.C.Strings.chars_ptr; -- libpq-fe.h:170 + label : Interfaces.C.Strings.chars_ptr; -- libpq-fe.h:171 + dispchar : Interfaces.C.Strings.chars_ptr; -- libpq-fe.h:172 + dispsize : Interfaces.C.int; -- libpq-fe.h:177 + end record; + pragma Convention (C, PQCONNINFOOPTION_T); + + type A_PQCONNINFOOPTION_T is access all PQCONNINFOOPTION_T; + -- libpq-fe.h:221 + pragma Convention (C, A_PQCONNINFOOPTION_T); + + type union_anonymous5_t_kind is -- libpq-fe.h:192 + (ptr_kind, integer_kind); + + type union_anonymous5_t -- libpq-fe.h:192 + (Which : union_anonymous5_t_kind := ptr_kind) + is + record + case Which is + when ptr_kind => + ptr : access Interfaces.C.int; -- libpq-fe.h:190 + when integer_kind => + integer : Interfaces.C.int; -- libpq-fe.h:191 + end case; + end record; + + pragma Convention (C, union_anonymous5_t); + pragma Unchecked_Union (union_anonymous5_t); + + type PQARGBLOCK_T is record + len : Interfaces.C.int; -- libpq-fe.h:186 + isint : Interfaces.C.int; -- libpq-fe.h:187 + u : union_anonymous5_t; -- libpq-fe.h:192 + end record; + pragma Convention (C, PQARGBLOCK_T); + + type A_PQARGBLOCK_T is access constant PQARGBLOCK_T; -- libpq-fe.h:386 + + type pgthreadlock_t is access procedure + (acquire : Interfaces.C.int); -- libpq-fe.h:300 + pragma Convention (C, pgthreadlock_t); + + --------------------------------------------------- + -- make a new client connection to the backend -- + --------------------------------------------------- + + -- Asynchronous (non-blocking) + + function PQCONNECTSTART + (conninfo : Interfaces.C.Strings.chars_ptr) + return A_PGCONN_T; + -- libpq-fe.h:204 + + function PQCONNECTPOLL + (conn : A_PGCONN_T) + return PostgresPollingStatusType; + -- libpq-fe.h:205 + + -- Synchronous (blocking) + + function PQCONNECTDB + (conninfo : Interfaces.C.Strings.chars_ptr) + return A_PGCONN_T; + -- libpq-fe.h:208 + + function PQSETDBLOGIN + (pghost : Interfaces.C.Strings.chars_ptr; + pgport : Interfaces.C.Strings.chars_ptr; + pgoptions : Interfaces.C.Strings.chars_ptr; + pgtty : Interfaces.C.Strings.chars_ptr; + dbName : Interfaces.C.Strings.chars_ptr; + login : Interfaces.C.Strings.chars_ptr; + pwd : Interfaces.C.Strings.chars_ptr) + return A_PGCONN_T; + -- libpq-fe.h:209 + + + procedure PQFINISH + (conn : A_PGCONN_T); + -- libpq-fe.h:218 + -- close the current connection and + -- free the PGconn data structure + + function PQCONNDEFAULTS + return A_PQCONNINFOOPTION_T; + -- libpq-fe.h:221 + -- get info about connection options known to PQconnectdb + + procedure PQCONNINFOFREE + (connOptions : A_PQCONNINFOOPTION_T); + -- libpq-fe.h:224 + -- free the data structure returned by PQconndefaults() + + ----------------------------------------------------- + -- close the current connection and -- + -- restablish a new one with the same parameters -- + ----------------------------------------------------- + + -- Asynchronous (non-blocking) + + function PQRESETSTART + (conn : A_PGCONN_T) + return Interfaces.C.int; + -- libpq-fe.h:231 + + function PQRESETPOLL + (conn : A_PGCONN_T) + return PostgresPollingStatusType; + -- libpq-fe.h:232 + + -- Synchronous (blocking) + + procedure PQRESET + (conn : A_PGCONN_T); + -- libpq-fe.h:235 + + + function PQGETCANCEL + (conn : A_PGCONN_T) + return A_PGCANCEL_T; + -- libpq-fe.h:238 + -- request a cancel structure + + procedure PQFREECANCEL + (cancel : A_PGCANCEL_T); + -- libpq-fe.h:241 + -- free a cancel structure + + function PQCANCEL + (cancel : A_PGCANCEL_T; + errbuf : Interfaces.C.Strings.chars_ptr; + errbufsize : Interfaces.C.int) + return Interfaces.C.int; + -- libpq-fe.h:244 + -- issue a cancel request + + function PQREQUESTCANCEL + (conn : A_PGCONN_T) + return Interfaces.C.int; + -- libpq-fe.h:247 + -- backwards compatible version of PQcancel; + -- not thread-safe + + --------------------------------------------- + -- Accessor functions for PGconn objects -- + --------------------------------------------- + function PQDB + (conn : A_PGCONN_T) + return Interfaces.C.Strings.chars_ptr; + -- libpq-fe.h:250 + + function PQUSER + (conn : A_PGCONN_T) + return Interfaces.C.Strings.chars_ptr; + -- libpq-fe.h:251 + + function PQPASS + (conn : A_PGCONN_T) + return Interfaces.C.Strings.chars_ptr; + -- libpq-fe.h:252 + + function PQHOST + (conn : A_PGCONN_T) + return Interfaces.C.Strings.chars_ptr; + -- libpq-fe.h:253 + + function PQPORT + (conn : A_PGCONN_T) + return Interfaces.C.Strings.chars_ptr; + -- libpq-fe.h:254 + + function PQTTY + (conn : A_PGCONN_T) + return Interfaces.C.Strings.chars_ptr; + -- libpq-fe.h:255 + + function PQOPTIONS + (conn : A_PGCONN_T) + return Interfaces.C.Strings.chars_ptr; + -- libpq-fe.h:256 + + function PQSTATUS + (conn : A_PGCONN_T) + return ConnStatusType; + -- libpq-fe.h:257 + + function PQTRANSACTIONSTATUS + (conn : A_PGCONN_T) + return PGTRANSACTIONSTATUSTYPE; + -- libpq-fe.h:258 + + function PQPARAMETERSTATUS + (conn : A_PGCONN_T; + paramName : Interfaces.C.Strings.chars_ptr) + return Interfaces.C.Strings.chars_ptr; + -- libpq-fe.h:259 + + function PQPROTOCOLVERSION + (conn : A_PGCONN_T) + return Interfaces.C.int; + -- libpq-fe.h:261 + + function PQSERVERVERSION + (conn : A_PGCONN_T) + return Interfaces.C.int; + -- libpq-fe.h:262 + + function PQERRORMESSAGE + (conn : A_PGCONN_T) + return Interfaces.C.Strings.chars_ptr; + -- libpq-fe.h:263 + + function PQSOCKET + (conn : A_PGCONN_T) + return Interfaces.C.int; + -- libpq-fe.h:264 + + function PQBACKENDPID + (conn : A_PGCONN_T) + return Interfaces.C.int; + -- libpq-fe.h:265 + + function PQCONNECTIONNEEDSPASSWORD + (conn : A_PGCONN_T) + return Interfaces.C.int; + -- libpq-fe.h:266 + + function PQCONNECTIONUSEDPASSWORD + (conn : A_PGCONN_T) + return Interfaces.C.int; + -- libpq-fe.h:267 + + function PQCLIENTENCODING + (conn : A_PGCONN_T) + return Interfaces.C.int; + -- libpq-fe.h:268 + + function PQSETCLIENTENCODING + (conn : A_PGCONN_T; + encoding : Interfaces.C.Strings.chars_ptr) + return Interfaces.C.int; + -- libpq-fe.h:269 + + function PQGETSSL + (conn : A_PGCONN_T) + return System.Address; + -- libpq-fe.h:273 + -- Get the OpenSSL structure associated with a connection. + -- Returns NULL for unencrypted connections or + -- if any other TLS library is in use. + + procedure PQINITSSL + (do_init : Interfaces.C.int); + -- libpq-fe.h:276 + -- Tell libpq whether it needs to initialize OpenSSL + + function PQSETERRORVERBOSITY + (conn : A_PGCONN_T; + verbosity : PGVERBOSITY) + return PGVERBOSITY; + -- libpq-fe.h:279 + -- Set verbosity for PQerrorMessage and PQresultErrorMessage + + procedure PQTRACE + (conn : A_PGCONN_T; + debug_port : Interfaces.C_Streams.FILEs); + -- libpq-fe.h:282 + -- Enable tracing + + procedure PQUNTRACE + (conn : A_PGCONN_T); + -- libpq-fe.h:283 + -- Disable tracing + + function PQSETNOTICERECEIVER + (conn : A_PGCONN_T; + proc : PQNOTICERECEIVER_T; + arg : System.Address) + return PQNOTICERECEIVER_T; + -- libpq-fe.h:286 + -- Override default notice handling routines + + function PQSETNOTICEPROCESSOR + (conn : A_PGCONN_T; + proc : PQNOTICEPROCESSOR_T; + arg : System.Address) + return PQNOTICEPROCESSOR_T; + -- libpq-fe.h:289 + -- Override default notice handling routines + + function PQREGISTERTHREADLOCK + (newhandler : pgthreadlock_t) + return pgthreadlock_t; + -- libpq-fe.h:302 + -- Used to set callback that prevents concurrent access to + -- non-thread safe functions that libpq needs. + -- The default implementation uses a libpq internal mutex. + -- Only required for multithreaded apps that use kerberos + -- both within their app and for postgresql connections. + + -------------------------------- + -- Simple synchronous query -- + -------------------------------- + + function PQEXEC + (conn : A_PGCONN_T; + query : Interfaces.C.Strings.chars_ptr) + return A_PGRESULT_T; + -- libpq-fe.h:307 + + function PQEXECPARAMS + (conn : A_PGCONN_T; + command : Interfaces.C.Strings.chars_ptr; + nParams : Interfaces.C.int; + paramTypes : access Oid; + paramValues : access Interfaces.C.Strings.chars_ptr; + paramLengths : access Interfaces.C.int; + paramFormats : access Interfaces.C.int; + resultFormat : Interfaces.C.int) + return A_PGRESULT_T; + -- libpq-fe.h:308 + + function PQPREPARE + (conn : A_PGCONN_T; + stmtName : Interfaces.C.Strings.chars_ptr; + query : Interfaces.C.Strings.chars_ptr; + nParams : Interfaces.C.int; + paramTypes : access Oid) + return A_PGRESULT_T; + -- libpq-fe.h:316 + + function PQEXECPREPARED + (conn : A_PGCONN_T; + stmtName : Interfaces.C.Strings.chars_ptr; + nParams : Interfaces.C.int; + paramValues : access Interfaces.C.Strings.chars_ptr; + paramLengths : access Interfaces.C.int; + paramFormats : access Interfaces.C.int; + resultFormat : Interfaces.C.int) + return A_PGRESULT_T; + -- libpq-fe.h:319 + + ---------------------------------------- + -- Interface for multiple-result or -- + -- asynchronous queries -- + ---------------------------------------- + + function PQSENDQUERY + (conn : A_PGCONN_T; + query : Interfaces.C.Strings.chars_ptr) + return Interfaces.C.int; + -- libpq-fe.h:328 + + function PQSENDQUERYPARAMS + (conn : A_PGCONN_T; + command : Interfaces.C.Strings.chars_ptr; + nParams : Interfaces.C.int; + paramTypes : access Oid; + paramValues : access Interfaces.C.Strings.chars_ptr; + paramLengths : access Interfaces.C.int; + paramFormats : access Interfaces.C.int; + resultFormat : Interfaces.C.int) + return Interfaces.C.int; + -- libpq-fe.h:329 + + function PQSENDPREPARE + (conn : A_PGCONN_T; + stmtName : Interfaces.C.Strings.chars_ptr; + query : Interfaces.C.Strings.chars_ptr; + nParams : Interfaces.C.int; + paramTypes : access Oid) + return Interfaces.C.int; + -- libpq-fe.h:337 + + function PQSENDQUERYPREPARED + (conn : A_PGCONN_T; + stmtName : Interfaces.C.Strings.chars_ptr; + nParams : Interfaces.C.int; + paramValues : access Interfaces.C.Strings.chars_ptr; + paramLengths : access Interfaces.C.int; + paramFormats : access Interfaces.C.int; + resultFormat : Interfaces.C.int) + return Interfaces.C.int; + -- libpq-fe.h:340 + + function PQGETRESULT + (conn : A_PGCONN_T) + return A_PGRESULT_T; + -- libpq-fe.h:347 + + --------------------------------------------------- + -- Routines for managing an asynchronous query -- + --------------------------------------------------- + + function PQISBUSY + (conn : A_PGCONN_T) + return Interfaces.C.int; + -- libpq-fe.h:350 + + function PQCONSUMEINPUT + (conn : A_PGCONN_T) + return Interfaces.C.int; + -- libpq-fe.h:351 + + + function PQNOTIFIES + (conn : A_PGCONN_T) + return A_PGNOTIFY_T; + -- libpq-fe.h:354 + -- LISTEN/NOTIFY support + + -------------------------------- + -- Routines for copy in/out -- + -------------------------------- + function PQPUTCOPYDATA + (conn : A_PGCONN_T; + buffer : Interfaces.C.Strings.chars_ptr; + nbytes : Interfaces.C.int) + return Interfaces.C.int; + -- libpq-fe.h:357 + + function PQPUTCOPYEND + (conn : A_PGCONN_T; + errormsg : Interfaces.C.Strings.chars_ptr) + return Interfaces.C.int; + -- libpq-fe.h:358 + + function PQGETCOPYDATA + (conn : A_PGCONN_T; + buffer : access Interfaces.C.Strings.chars_ptr; + async : Interfaces.C.int) + return Interfaces.C.int; + -- libpq-fe.h:359 + + ------------------------------------------- + -- Deprecated routines for copy in/out -- + ------------------------------------------- + function PQGETLINE + (conn : A_PGCONN_T; + string : Interfaces.C.Strings.chars_ptr; + length : Interfaces.C.int) + return Interfaces.C.int; + -- libpq-fe.h:362 + + function PQPUTLINE + (conn : A_PGCONN_T; + string : Interfaces.C.Strings.chars_ptr) + return Interfaces.C.int; + -- libpq-fe.h:363 + + function PQGETLINEASYNC + (conn : A_PGCONN_T; + buffer : Interfaces.C.Strings.chars_ptr; + bufsize : Interfaces.C.int) + return Interfaces.C.int; + -- libpq-fe.h:364 + + function PQPUTNBYTES + (conn : A_PGCONN_T; + buffer : Interfaces.C.Strings.chars_ptr; + nbytes : Interfaces.C.int) + return Interfaces.C.int; + -- libpq-fe.h:365 + + function PQENDCOPY + (conn : A_PGCONN_T) + return Interfaces.C.int; + -- libpq-fe.h:366 + + ---------------------------------------------------------- + -- Set blocking/nonblocking connection to the backend -- + ---------------------------------------------------------- + + function PQSETNONBLOCKING + (conn : A_PGCONN_T; + arg : Interfaces.C.int) + return Interfaces.C.int; + -- libpq-fe.h:369 + + function PQISNONBLOCKING + (conn : A_PGCONN_T) + return Interfaces.C.int; + -- libpq-fe.h:370 + + + function PQISTHREADSAFE + return Interfaces.C.int; + -- libpq-fe.h:371 + + function PQFLUSH + (conn : A_PGCONN_T) + return Interfaces.C.int; + -- libpq-fe.h:374 + -- Force the write buffer to be written (or at least try) + + function PQFN + (conn : A_PGCONN_T; + fnid : Interfaces.C.int; + result_buf : access Interfaces.C.int; + result_len : access Interfaces.C.int; + result_is_int : Interfaces.C.int; + args : A_PQARGBLOCK_T; + nargs : Interfaces.C.int) + return A_PGRESULT_T; + -- libpq-fe.h:380 + -- "Fast path" interface --- not really recommended for application use + + + ----------------------------------------------- + -- Accessor functions for PGresult objects -- + ----------------------------------------------- + + function PQRESULTSTATUS + (res : A_PGRESULT_T) + return ExecStatusType; + -- libpq-fe.h:389 + + function PQRESSTATUS + (status : ExecStatusType) + return Interfaces.C.Strings.chars_ptr; + -- libpq-fe.h:390 + + function PQRESULTERRORMESSAGE + (res : A_PGRESULT_T) + return Interfaces.C.Strings.chars_ptr; + -- libpq-fe.h:391 + + function PQRESULTERRORFIELD + (res : A_PGRESULT_T; + fieldcode : Interfaces.C.int) + return Interfaces.C.Strings.chars_ptr; + -- libpq-fe.h:392 + + function PQNTUPLES + (res : A_PGRESULT_T) + return Interfaces.C.int; + -- libpq-fe.h:393 + + function PQNFIELDS + (res : A_PGRESULT_T) + return Interfaces.C.int; + -- libpq-fe.h:394 + + function PQBINARYTUPLES + (res : A_PGRESULT_T) + return Interfaces.C.int; + -- libpq-fe.h:395 + + function PQFNAME + (res : A_PGRESULT_T; + field_num : Interfaces.C.int) + return Interfaces.C.Strings.chars_ptr; + -- libpq-fe.h:396 + + function PQFNUMBER + (res : A_PGRESULT_T; + field_name : Interfaces.C.Strings.chars_ptr) + return Interfaces.C.int; + -- libpq-fe.h:397 + + function PQFTABLE + (res : A_PGRESULT_T; + field_num : Interfaces.C.int) + return Oid; + -- libpq-fe.h:398 + + function PQFTABLECOL + (res : A_PGRESULT_T; + field_num : Interfaces.C.int) + return Interfaces.C.int; + -- libpq-fe.h:399 + + function PQFFORMAT + (res : A_PGRESULT_T; + field_num : Interfaces.C.int) + return Interfaces.C.int; + -- libpq-fe.h:400 + + function PQFTYPE + (res : A_PGRESULT_T; + field_num : Interfaces.C.int) + return Oid; + -- libpq-fe.h:401 + + function PQFSIZE + (res : A_PGRESULT_T; + field_num : Interfaces.C.int) + return Interfaces.C.int; + -- libpq-fe.h:402 + + function PQFMOD + (res : A_PGRESULT_T; + field_num : Interfaces.C.int) + return Interfaces.C.int; + -- libpq-fe.h:403 + + function PQCMDSTATUS + (res : A_PGRESULT_T) + return Interfaces.C.Strings.chars_ptr; + -- libpq-fe.h:404 + + function PQOIDSTATUS + (res : A_PGRESULT_T) + return Interfaces.C.Strings.chars_ptr; + -- libpq-fe.h:405 + + function PQOIDVALUE + (res : A_PGRESULT_T) + return Oid; + -- libpq-fe.h:406 + + function PQCMDTUPLES + (res : A_PGRESULT_T) + return Interfaces.C.Strings.chars_ptr; + -- libpq-fe.h:407 + + function PQGETVALUE + (res : A_PGRESULT_T; + tup_num : Interfaces.C.int; + field_num : Interfaces.C.int) + return Interfaces.C.Strings.chars_ptr; + -- libpq-fe.h:408 + + function PQGETLENGTH + (res : A_PGRESULT_T; + tup_num : Interfaces.C.int; + field_num : Interfaces.C.int) + return Interfaces.C.int; + -- libpq-fe.h:409 + + function PQGETISNULL + (res : A_PGRESULT_T; + tup_num : Interfaces.C.int; + field_num : Interfaces.C.int) + return Interfaces.C.int; + -- libpq-fe.h:410 + + function PQNPARAMS + (res : A_PGRESULT_T) + return Interfaces.C.int; + -- libpq-fe.h:411 + + function PQPARAMTYPE + (res : A_PGRESULT_T; + param_num : Interfaces.C.int) + return Oid; + -- libpq-fe.h:412 + + + ------------------------------------------------ + -- Describe prepared statements and portals -- + ------------------------------------------------ + + function PQDESCRIBEPREPARED + (conn : A_PGCONN_T; + stmt : Interfaces.C.Strings.chars_ptr) + return A_PGRESULT_T; + -- libpq-fe.h:415 + + function PQDESCRIBEPORTAL + (conn : A_PGCONN_T; + portal : Interfaces.C.Strings.chars_ptr) + return A_PGRESULT_T; + -- libpq-fe.h:416 + + function PQSENDDESCRIBEPREPARED + (conn : A_PGCONN_T; + stmt : Interfaces.C.Strings.chars_ptr) + return Interfaces.C.int; + -- libpq-fe.h:417 + + function PQSENDDESCRIBEPORTAL + (conn : A_PGCONN_T; + portal : Interfaces.C.Strings.chars_ptr) + return Interfaces.C.int; + -- libpq-fe.h:418 + + + procedure PQCLEAR + (res : A_PGRESULT_T); + -- libpq-fe.h:421 + -- Delete a PGresult + + procedure PQFREEMEM + (ptr : System.Address); + -- libpq-fe.h:424 + -- For freeing other alloc'd results, such as PGnotify structs + + function PQMAKEEMPTYPGRESULT + (conn : A_PGCONN_T; + status : ExecStatusType) + return A_PGRESULT_T; + -- libpq-fe.h:438 + -- Make an empty PGresult with given status (some apps find this useful). + -- If conn is not NULL and status indicates an error, + -- conn's errorMessage is copied. + + ---------------------------------------------------- + -- Quoting strings before inclusion in queries. -- + ---------------------------------------------------- + + function PQESCAPESTRINGCONN + (conn : A_PGCONN_T; + to : Interfaces.C.Strings.chars_ptr; + from : Interfaces.C.Strings.chars_ptr; + length : Interfaces.C.size_t; + error : access Interfaces.C.int) + return Interfaces.C.size_t; + -- libpq-fe.h:442 + + function PQESCAPEBYTEACONN + (conn : A_PGCONN_T; + from : access Interfaces.C.unsigned_char; + from_length : Interfaces.C.size_t; + to_length : access Interfaces.C.size_t) + return access Interfaces.C.unsigned_char; + -- libpq-fe.h:445 + -- + + function PQUNESCAPEBYTEA + (strtext : access Interfaces.C.unsigned_char; + retbuflen : access Interfaces.C.size_t) + return access Interfaces.C.unsigned_char; + -- libpq-fe.h:448 + + ----------------------------------- + -- These forms are deprecated! -- + ----------------------------------- + + function PQESCAPESTRING + (to : Interfaces.C.Strings.chars_ptr; + from : Interfaces.C.Strings.chars_ptr; + length : Interfaces.C.size_t) + return Interfaces.C.size_t; + -- libpq-fe.h:452 + + function PQESCAPEBYTEA + (from : access Interfaces.C.unsigned_char; + from_length : Interfaces.C.size_t; + to_length : access Interfaces.C.size_t) + return access Interfaces.C.unsigned_char; + -- libpq-fe.h:453 + + -- + -- + + ------------------------- + -- printing routines -- + ------------------------- + + procedure PQPRINT + (fout : Interfaces.C_Streams.FILEs; + res : in A_PGRESULT_T; + ps : in A_PQPRINTOPT_T); + -- libpq-fe.h:461 + + ------------------------------------ + -- really old printing routines -- + ------------------------------------ + + procedure PQDISPLAYTUPLES + (res : A_PGRESULT_T; + fp : Interfaces.C_Streams.FILEs; + fillAlign : Interfaces.C.int; + fieldSep : Interfaces.C.Strings.chars_ptr; + printHeader : Interfaces.C.int; + quiet : Interfaces.C.int); + -- libpq-fe.h:469 + + procedure PQPRINTTUPLES + (res : A_PGRESULT_T; + fout : Interfaces.C_Streams.FILEs; + printAttName : Interfaces.C.int; + terseOutput : Interfaces.C.int; + width : Interfaces.C.int); + -- libpq-fe.h:477 + + ------------------------------------ + -- Large-object access routines -- + ------------------------------------ + + function lo_Open + (conn : A_PGCONN_T; + lobjId : Oid; + mode : Interfaces.C.int) + return Interfaces.C.int; + -- libpq-fe.h:487 + + function lo_Close + (conn : A_PGCONN_T; + fd : Interfaces.C.int) + return Interfaces.C.int; + -- libpq-fe.h:488 + + function lo_Read + (conn : A_PGCONN_T; + fd : Interfaces.C.int; + buf : Interfaces.C.Strings.chars_ptr; + len : Interfaces.C.size_t) + return Interfaces.C.int; + -- libpq-fe.h:489 + + function lo_Write + (conn : A_PGCONN_T; + fd : Interfaces.C.int; + buf : Interfaces.C.Strings.chars_ptr; + len : Interfaces.C.size_t) + return Interfaces.C.int; + -- libpq-fe.h:490 + + function lo_Lseek + (conn : A_PGCONN_T; + fd : Interfaces.C.int; + offset : Interfaces.C.int; + whence : Interfaces.C.int) + return Interfaces.C.int; + -- libpq-fe.h:491 + + function lo_Creat + (conn : A_PGCONN_T; + mode : Interfaces.C.int) + return Oid; + -- libpq-fe.h:492 + + function lo_Create + (conn : A_PGCONN_T; + lobjId : Oid) + return Oid; + -- libpq-fe.h:493 + + function lo_Tell + (conn : A_PGCONN_T; + fd : Interfaces.C.int) + return Interfaces.C.int; + -- libpq-fe.h:494 + + function lo_Truncate + (conn : A_PGCONN_T; + fd : Interfaces.C.int; + len : Interfaces.C.size_t) + return Interfaces.C.int; + -- libpq-fe.h:495 + + function lo_Unlink + (conn : A_PGCONN_T; + lobjId : Oid) + return Interfaces.C.int; + -- libpq-fe.h:496 + + function lo_Import + (conn : A_PGCONN_T; + filename : Interfaces.C.Strings.chars_ptr) + return Oid; + -- libpq-fe.h:497 + + function lo_Export + (conn : A_PGCONN_T; + lobjId : Oid; + filename : Interfaces.C.Strings.chars_ptr) + return Interfaces.C.int; + -- libpq-fe.h:498 + + -------------------- + -- in fe-misc.c -- + -------------------- + + function PQMBLEN + (s : Interfaces.C.Strings.chars_ptr; + encoding : Interfaces.C.int) + return Interfaces.C.int; + -- libpq-fe.h:503 + -- Determine length of multibyte encoded char at *s + + function PQDSPLEN + (s : Interfaces.C.Strings.chars_ptr; + encoding : Interfaces.C.int) + return Interfaces.C.int; + -- libpq-fe.h:506 + -- Determine display length of multibyte encoded char at *s + + function PQENV2ENCODING + return Interfaces.C.int; + -- libpq-fe.h:509 + -- Get encoding id from environment variable PGCLIENTENCODING + + function PQENCRYPTPASSWORD + (passwd : Interfaces.C.Strings.chars_ptr; + user : Interfaces.C.Strings.chars_ptr) + return Interfaces.C.Strings.chars_ptr; + -- libpq-fe.h:513 + + -------------------- + -- in fe-auth.c -- + -------------------- + + function pg_char_to_encoding + (name : Interfaces.C.Strings.chars_ptr) + return Interfaces.C.int; + -- libpq-fe.h:517 + + --------------------- + -- in encnames.c -- + --------------------- + + function pg_encoding_to_char + (encoding : Interfaces.C.int) + return Interfaces.C.Strings.chars_ptr; + -- libpq-fe.h:518 + + function pg_valid_server_encoding_id + (encoding : Interfaces.C.int) + return Interfaces.C.int; + -- libpq-fe.h:519 + +private + + pragma Import (C, PQCONNECTSTART, "PQconnectStart"); + -- libpq-fe.h:204 + + pragma Import (C, PQCONNECTPOLL, "PQconnectPoll"); + -- libpq-fe.h:205 + + pragma Import (C, PQCONNECTDB, "PQconnectdb"); + -- libpq-fe.h:208 + + pragma Import (C, PQSETDBLOGIN, "PQsetdbLogin"); + -- libpq-fe.h:209 + + pragma Import (C, PQFINISH, "PQfinish"); + -- libpq-fe.h:218 + + pragma Import (C, PQCONNDEFAULTS, "PQconndefaults"); + -- libpq-fe.h:221 + + pragma Import (C, PQCONNINFOFREE, "PQconninfoFree"); + -- libpq-fe.h:224 + + pragma Import (C, PQRESETSTART, "PQresetStart"); + -- libpq-fe.h:231 + + pragma Import (C, PQRESETPOLL, "PQresetPoll"); + -- libpq-fe.h:232 + + pragma Import (C, PQRESET, "PQreset"); + -- libpq-fe.h:235 + + pragma Import (C, PQGETCANCEL, "PQgetCancel"); + -- libpq-fe.h:238 + + pragma Import (C, PQFREECANCEL, "PQfreeCancel"); + -- libpq-fe.h:241 + + pragma Import (C, PQCANCEL, "PQcancel"); + -- libpq-fe.h:244 + + pragma Import (C, PQREQUESTCANCEL, "PQrequestCancel"); + -- libpq-fe.h:247 + + pragma Import (C, PQDB, "PQdb"); + -- libpq-fe.h:250 + + pragma Import (C, PQUSER, "PQuser"); + -- libpq-fe.h:251 + + pragma Import (C, PQPASS, "PQpass"); + -- libpq-fe.h:252 + + pragma Import (C, PQHOST, "PQhost"); + -- libpq-fe.h:253 + + pragma Import (C, PQPORT, "PQport"); + -- libpq-fe.h:254 + + pragma Import (C, PQTTY, "PQtty"); + -- libpq-fe.h:255 + + pragma Import (C, PQOPTIONS, "PQoptions"); + -- libpq-fe.h:256 + + pragma Import (C, PQSTATUS, "PQstatus"); + -- libpq-fe.h:257 + + pragma Import (C, PQTRANSACTIONSTATUS, "PQtransactionStatus"); + -- libpq-fe.h:258 + + pragma Import (C, PQPARAMETERSTATUS, "PQparameterStatus"); + -- libpq-fe.h:259 + + pragma Import (C, PQPROTOCOLVERSION, "PQprotocolVersion"); + -- libpq-fe.h:261 + + pragma Import (C, PQSERVERVERSION, "PQserverVersion"); + -- libpq-fe.h:262 + + pragma Import (C, PQERRORMESSAGE, "PQerrorMessage"); + -- libpq-fe.h:263 + + pragma Import (C, PQSOCKET, "PQsocket"); + -- libpq-fe.h:264 + + pragma Import (C, PQBACKENDPID, "PQbackendPID"); + -- libpq-fe.h:265 + + pragma Import (C, PQCONNECTIONNEEDSPASSWORD, "PQconnectionNeedsPassword"); + -- libpq-fe.h:266 + + pragma Import (C, PQCONNECTIONUSEDPASSWORD, "PQconnectionUsedPassword"); + -- libpq-fe.h:267 + + pragma Import (C, PQCLIENTENCODING, "PQclientEncoding"); + -- libpq-fe.h:268 + + pragma Import (C, PQSETCLIENTENCODING, "PQsetClientEncoding"); + -- libpq-fe.h:269 + + pragma Import (C, PQGETSSL, "PQgetssl"); + -- libpq-fe.h:273 + + pragma Import (C, PQINITSSL, "PQinitSSL"); + -- libpq-fe.h:276 + + pragma Import (C, PQSETERRORVERBOSITY, "PQsetErrorVerbosity"); + -- libpq-fe.h:279 + + pragma Import (C, PQTRACE, "PQtrace"); + -- libpq-fe.h:282 + + pragma Import (C, PQUNTRACE, "PQuntrace"); + -- libpq-fe.h:283 + + pragma Import (C, PQSETNOTICERECEIVER, "PQsetNoticeReceiver"); + -- libpq-fe.h:286 + + pragma Import (C, PQSETNOTICEPROCESSOR, "PQsetNoticeProcessor"); + -- libpq-fe.h:289 + + pragma Import (C, PQREGISTERTHREADLOCK, "PQregisterThreadLock"); + -- libpq-fe.h:302 + + pragma Import (C, PQEXEC, "PQexec"); + -- libpq-fe.h:307 + + pragma Import (C, PQEXECPARAMS, "PQexecParams"); + -- libpq-fe.h:308 + + pragma Import (C, PQPREPARE, "PQprepare"); + -- libpq-fe.h:316 + + pragma Import (C, PQEXECPREPARED, "PQexecPrepared"); + -- libpq-fe.h:319 + + pragma Import (C, PQSENDQUERY, "PQsendQuery"); + -- libpq-fe.h:328 + + pragma Import (C, PQSENDQUERYPARAMS, "PQsendQueryParams"); + -- libpq-fe.h:329 + + pragma Import (C, PQSENDPREPARE, "PQsendPrepare"); + -- libpq-fe.h:337 + + pragma Import (C, PQSENDQUERYPREPARED, "PQsendQueryPrepared"); + -- libpq-fe.h:340 + + pragma Import (C, PQGETRESULT, "PQgetResult"); + -- libpq-fe.h:347 + + pragma Import (C, PQISBUSY, "PQisBusy"); + -- libpq-fe.h:350 + + pragma Import (C, PQCONSUMEINPUT, "PQconsumeInput"); + -- libpq-fe.h:351 + + pragma Import (C, PQNOTIFIES, "PQnotifies"); + -- libpq-fe.h:354 + + pragma Import (C, PQPUTCOPYDATA, "PQputCopyData"); + -- libpq-fe.h:357 + + pragma Import (C, PQPUTCOPYEND, "PQputCopyEnd"); + -- libpq-fe.h:358 + + pragma Import (C, PQGETCOPYDATA, "PQgetCopyData"); + -- libpq-fe.h:359 + + pragma Import (C, PQGETLINE, "PQgetline"); + -- libpq-fe.h:362 + + pragma Import (C, PQPUTLINE, "PQputline"); + -- libpq-fe.h:363 + + pragma Import (C, PQGETLINEASYNC, "PQgetlineAsync"); + -- libpq-fe.h:364 + + pragma Import (C, PQPUTNBYTES, "PQputnbytes"); + -- libpq-fe.h:365 + + pragma Import (C, PQENDCOPY, "PQendcopy"); + -- libpq-fe.h:366 + + pragma Import (C, PQSETNONBLOCKING, "PQsetnonblocking"); + -- libpq-fe.h:369 + + pragma Import (C, PQISNONBLOCKING, "PQisnonblocking"); + -- libpq-fe.h:370 + + pragma Import (C, PQISTHREADSAFE, "PQisthreadsafe"); + -- libpq-fe.h:371 + + pragma Import (C, PQFLUSH, "PQflush"); + -- libpq-fe.h:374 + + pragma Import (C, PQFN, "PQfn"); + -- libpq-fe.h:380 + + pragma Import (C, PQRESULTSTATUS, "PQresultStatus"); + -- libpq-fe.h:389 + + pragma Import (C, PQRESSTATUS, "PQresStatus"); + -- libpq-fe.h:390 + + pragma Import (C, PQRESULTERRORMESSAGE, "PQresultErrorMessage"); + -- libpq-fe.h:391 + + pragma Import (C, PQRESULTERRORFIELD, "PQresultErrorField"); + -- libpq-fe.h:392 + + pragma Import (C, PQNTUPLES, "PQntuples"); + -- libpq-fe.h:393 + + pragma Import (C, PQNFIELDS, "PQnfields"); + -- libpq-fe.h:394 + + pragma Import (C, PQBINARYTUPLES, "PQbinaryTuples"); + -- libpq-fe.h:395 + + pragma Import (C, PQFNAME, "PQfname"); + -- libpq-fe.h:396 + + pragma Import (C, PQFNUMBER, "PQfnumber"); + -- libpq-fe.h:397 + + pragma Import (C, PQFTABLE, "PQftable"); + -- libpq-fe.h:398 + + pragma Import (C, PQFTABLECOL, "PQftablecol"); + -- libpq-fe.h:399 + + pragma Import (C, PQFFORMAT, "PQfformat"); + -- libpq-fe.h:400 + + pragma Import (C, PQFTYPE, "PQftype"); + -- libpq-fe.h:401 + + pragma Import (C, PQFSIZE, "PQfsize"); + -- libpq-fe.h:402 + + pragma Import (C, PQFMOD, "PQfmod"); + -- libpq-fe.h:403 + + pragma Import (C, PQCMDSTATUS, "PQcmdStatus"); + -- libpq-fe.h:404 + + pragma Import (C, PQOIDSTATUS, "PQoidStatus"); + -- libpq-fe.h:405 + + pragma Import (C, PQOIDVALUE, "PQoidValue"); + -- libpq-fe.h:406 + + pragma Import (C, PQCMDTUPLES, "PQcmdTuples"); + -- libpq-fe.h:407 + + pragma Import (C, PQGETVALUE, "PQgetvalue"); + -- libpq-fe.h:408 + + pragma Import (C, PQGETLENGTH, "PQgetlength"); + -- libpq-fe.h:409 + + pragma Import (C, PQGETISNULL, "PQgetisnull"); + -- libpq-fe.h:410 + + pragma Import (C, PQNPARAMS, "PQnparams"); + -- libpq-fe.h:411 + + pragma Import (C, PQPARAMTYPE, "PQparamtype"); + -- libpq-fe.h:412 + + pragma Import (C, PQDESCRIBEPREPARED, "PQdescribePrepared"); + -- libpq-fe.h:415 + + pragma Import (C, PQDESCRIBEPORTAL, "PQdescribePortal"); + -- libpq-fe.h:416 + + pragma Import (C, PQSENDDESCRIBEPREPARED, "PQsendDescribePrepared"); + -- libpq-fe.h:417 + + pragma Import (C, PQSENDDESCRIBEPORTAL, "PQsendDescribePortal"); + -- libpq-fe.h:418 + + pragma Import (C, PQCLEAR, "PQclear"); + -- libpq-fe.h:421 + + pragma Import (C, PQFREEMEM, "PQfreemem"); + -- libpq-fe.h:424 + + pragma Import (C, PQMAKEEMPTYPGRESULT, "PQmakeEmptyPGresult"); + -- libpq-fe.h:438 + + pragma Import (C, PQESCAPESTRINGCONN, "PQescapeStringConn"); + -- libpq-fe.h:442 + + pragma Import (C, PQESCAPEBYTEACONN, "PQescapeByteaConn"); + -- libpq-fe.h:445 + + pragma Import (C, PQUNESCAPEBYTEA, "PQunescapeBytea"); + -- libpq-fe.h:448 + + pragma Import (C, PQESCAPESTRING, "PQescapeString"); + -- libpq-fe.h:452 + + pragma Import (C, PQESCAPEBYTEA, "PQescapeBytea"); + -- libpq-fe.h:453 + + pragma Import (C, PQPRINT, "PQprint"); + -- libpq-fe.h:461 + + pragma Import (C, PQDISPLAYTUPLES, "PQdisplayTuples"); + -- libpq-fe.h:469 + + pragma Import (C, PQPRINTTUPLES, "PQprintTuples"); + -- libpq-fe.h:477 + + pragma Import (C, lo_Open, "lo_open"); + -- libpq-fe.h:487 + + pragma Import (C, lo_Close, "lo_close"); + -- libpq-fe.h:488 + + pragma Import (C, lo_Read, "lo_read"); + -- libpq-fe.h:489 + + pragma Import (C, lo_Write, "lo_write"); + -- libpq-fe.h:490 + + pragma Import (C, lo_Lseek, "lo_lseek"); + -- libpq-fe.h:491 + + pragma Import (C, lo_Creat, "lo_creat"); + -- libpq-fe.h:492 + + pragma Import (C, lo_Create, "lo_create"); + -- libpq-fe.h:493 + + pragma Import (C, lo_Tell, "lo_tell"); + -- libpq-fe.h:494 + + pragma Import (C, lo_Truncate, "lo_truncate"); + -- libpq-fe.h:495 + + pragma Import (C, lo_Unlink, "lo_unlink"); + -- libpq-fe.h:496 + + pragma Import (C, lo_Import, "lo_import"); + -- libpq-fe.h:497 + + pragma Import (C, lo_Export, "lo_export"); + -- libpq-fe.h:498 + + pragma Import (C, PQMBLEN, "PQmblen"); + -- libpq-fe.h:503 + + pragma Import (C, PQDSPLEN, "PQdsplen"); + -- libpq-fe.h:506 + + pragma Import (C, PQENV2ENCODING, "PQenv2encoding"); + -- libpq-fe.h:509 + + pragma Import (C, PQENCRYPTPASSWORD, "PQencryptPassword"); + -- libpq-fe.h:513 + + pragma Import (C, pg_char_to_encoding, "pg_char_to_encoding"); + -- libpq-fe.h:517 + + pragma Import (C, pg_encoding_to_char, "pg_encoding_to_char"); + -- libpq-fe.h:518 + + pragma Import (C, pg_valid_server_encoding_id, + "pg_valid_server_encoding_id"); + -- libpq-fe.h:519 + +end Backlit.Thin; diff --git a/src/backlit.ads b/src/backlit.ads new file mode 100644 index 0000000..a4b18ee --- /dev/null +++ b/src/backlit.ads @@ -0,0 +1,28 @@ +------------------------------------------------------------------------------ +-- -- +-- Copyright 2008, Ali Bendriss -- +-- -- +-- This file is part of Backlit. -- +-- -- +-- Backlit is free software: you can redistribute it and/or modify it under -- +-- the terms of the GNU Lesser General Public License as published by -- +-- the Free Software Foundation, either version 3 of the License, or -- +-- (at your option) any later version. -- +-- -- +-- Backlit is distributed in the hope that it will be useful, -- +-- but WITHOUT ANY WARRANTY; without even the implied warranty of -- +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- +-- GNU Lesser General Public License for more details. -- +-- -- +-- You should have received a copy of the GNU Lesser General Public License -- +-- along with Backlit. If not, see . -- +-- -- +------------------------------------------------------------------------------ + +package Backlit is + + pragma Pure; + + Error : exception; + +end Backlit; -- 2.11.4.GIT