GNAT CE 2019内如何查询PostgreSQL?

问题描述 投票:1回答:1

我正试图使用GNAT CE 2019查询PostgreSQL数据库。我的数据库中有两个表,汽车和人。

mydb1-# \dt
         List of relations
 Schema |  Name  | Type  |  Owner   
--------+--------+-------+----------
 public | car    | table | postgres
 public | person | table | postgres
(2 rows)

我想执行一个简单的Select语句,当我在终端使用psql执行时,返回的是这个。

mydb1=# SELECT * FROM Person;

              person_uid              | first_name | last_name  | gender |            email             | date_of_birth | country_of_birth |               car_uid                
--------------------------------------+------------+------------+--------+------------------------------+---------------+------------------+--------------------------------------
 75f5e55d-12b2-463e-93ff-1c921e44c3e1 | Audrie     | Vasyukov   | Female | [email protected] | 1988-11-24    | Guatemala        | 
 9e3f7f90-6e9a-4f2d-ae4e-c852d819ed33 | Nefen      | Philippard | Male   | [email protected]  | 2006-11-08    | Russia           | 
 ffad6113-2321-47c3-8e1d-b8bbe1f7ffa1 | Leonore    | Garthland  | Female | [email protected]        | 1991-03-23    | Canada           | 
 268c1977-a5cc-4794-9cdd-e0e4af7890b9 | Yank       | Turfitt    | Male   | [email protected]         | 1990-02-07    | China            | 
 3c815fa3-74b9-493a-9466-f32010806b16 | Benn       | Pawley     | Male   | [email protected]      | 2006-10-28    | Russia           | 
 690fc9e9-309e-4d70-8dab-167653b99763 | Tod        | Easen      | Male   | [email protected]             | 1990-08-24    | China            | 5fa7490e-ba42-4a96-b806-097bbb16e30e

然而,我想在GNAT CE 2019中执行这个操作。这是我的main.adb文件目前的样子。

with GNATCOLL.SQL.Postgres;  use GNATCOLL.SQL.Postgres;
with GNATCOLL.SQL.Exec;      use GNATCOLL.SQL.Exec;
with GNATCOLL.VFS;           use GNATCOLL.VFS;
with GNATCOLL.SQL.Inspect;   use GNATCOLL.SQL.Inspect;
with GNATCOLL.SQL;           use GNATCOLL.SQL;



procedure Main is


   -- Datebase Description
   --
   DB_Descr : GNATCOLL.SQL.Exec.Database_Description;

   -- Database Connection
   --
   DB : GNATCOLL.SQL.Exec.Database_Connection;


   -- Used to Query the data
   --
   Q : SQL_Query;


begin


   -- Database Description
   --
   DB_Descr := GNATCOLL.SQL.Postgres.Setup ("mydb1", "parallels", "localhost", "MyPassword", 5432);

   -- Database Connection
   --
   DB := DB_Descr.Build_Connection;



   -- Query the data
   --

   Q := SQL_Select
      (Fields => Person.first_name,
       From   => Person);




  Free (DB);  --  for all connections you have opened
  Free (DB_Descr);

   end Main;

当我试图连接数据库时 进程成功终止了。

我不确定应该使用Select语句的语法。Name SELECT * FROM Person; 从GNAT CE 2019内的声明,这将是非常感激。

谢谢你,劳埃德

新增130520

parallels@localhost gnatcoll_db2ada]$ ls
dborm.py                  gnatcoll-db2ada-main-generate.adb
dbschema.txt              gnatcoll_postgres2ada.adb
gnatcoll_all2ada.adb      gnatcoll_postgres2ada.gpr
gnatcoll_all2ada.gpr      gnatcoll_sqlite2ada.adb
gnatcoll_db2ada.adb       gnatcoll_sqlite2ada.gpr
gnatcoll-db2ada.ads       Makefile
gnatcoll_db2ada.gpr       makefile.setup
[parallels@localhost gnatcoll_db2ada]$ gnatcoll_postgres2ada -dbmodel dschema.txt/home/parallels/Desktop/dschema.txt
bash: gnatcoll_postgres2ada: command not found...
[parallels@localhost gnatcoll_db2ada]$ 

新增150520

prbuild -d -P/home/parallels/Documents/Ada Projects/TEST/default.gpr -XGNATCOLL_OS=unix -XBUILD=PROD -XGNATCOLL_HASPQPREPARE=yes -XGPR_BUILD=static -XLIBRARY_TYPE=static -XXMLADA_BUILD=static -XGNATCOLL_CORE_BUILD=static -XGNATCOLL_BUILD=static /home/parallels/Documents/Ada Projects/TEST/src/main.adb
Compile
   [Ada]          main.adb
Bind
   [gprbind]      main.bexch
   [Ada]          main.ali
Link
   [link]         main.adb
/home/parallels/opt/GNAT/2019/bin/../libexec/gcc/x86_64-pc-linux-gnu/8.3.1/ld: cannot find -lpq
collect2: error: ld returned 1 exit status
gprbuild: link of main.adb failed
gprbuild: failed command was: /home/parallels/opt/GNAT/2019/bin/gcc main.o b__main.o /home/parallels/Documents/Ada Projects/TEST/obj/database_names.o /home/parallels/Documents/Ada Projects/TEST/obj/database.o /home/parallels/gnatcoll-db/postgres/lib/static/libgnatcoll_postgres.a /home/parallels/gnatcoll-db/sql/lib/static/libgnatcoll_sql.a /home/parallels/opt/GNAT/2019/lib/gnatcoll.static/libgnatcoll.a /home/parallels/opt/GNAT/2019/lib/gpr/static/gpr/libgpr.a /home/parallels/opt/GNAT/2019/lib/xmla
da/xmlada_schema.static/libxmlada_schema.a /home/parallels/opt/GNAT/2019/lib/xmlada/xmlada_dom.static/libxmlada_dom.a /home/parallels/opt/GNAT/2019/lib/xmlada/xmlada_sax.static/libxmlada_sax.a /home/parallels/opt/GNAT/2019/lib/xmlada/xmlada_input.static/libxmlada_input_sources.a /home/parallels/opt/GNAT/2019/lib/xmlada/xmlada_unicode.static/libxmlada_unicode.a -lpq -L/home/parallels/Documents/Ada Projects/TEST/obj/ -L/home/parallels/Documents/Ada Projects/TEST/obj/ -L/home/parallels/gnatcoll-db/p
ostgres/lib/static/ -L/home/parallels/opt/GNAT/2019/lib/gnatcoll.static/ -L/home/parallels/opt/GNAT/2019/lib/xmlada/xmlada_dom.static/ -L/home/parallels/opt/GNAT/2019/lib/xmlada/xmlada_sax.static/ -L/home/parallels/opt/GNAT/2019/lib/xmlada/xmlada_unicode.static/ -L/home/parallels/opt/GNAT/2019/lib/xmlada/xmlada_input.static/ -L/home/parallels/opt/GNAT/2019/lib/xmlada/xmlada_schema.static/ -L/home/parallels/opt/GNAT/2019/lib/gpr/static/gpr/ -L/home/parallels/gnatcoll-db/sql/lib/static/ -L/home/par
allels/opt/GNAT/2019/lib/gcc/x86_64-pc-linux-gnu/8.3.1/adalib/ -static-libgcc /home/parallels/opt/GNAT/2019/lib/gcc/x86_64-pc-linux-gnu/8.3.1/adalib/libgnarl.a /home/parallels/opt/GNAT/2019/lib/gcc/x86_64-pc-linux-gnu/8.3.1/adalib/libgnat.a -lrt -lpthread -ldl -Wl,-rpath-link,/home/parallels/opt/GNAT/2019/lib/gcc/x86_64-pc-linux-gnu/8.3.1//adalib -Wl,-z,origin,-rpath,$ORIGIN/:$ORIGIN/../../../..//gnatcoll-db/postgres/lib/static:$ORIGIN/../../../..//opt/GNAT/2019/lib/gnatcoll.static:$ORIGIN/../../
../..//opt/GNAT/2019/lib/xmlada/xmlada_dom.static:$ORIGIN/../../../..//opt/GNAT/2019/lib/xmlada/xmlada_sax.static:$ORIGIN/../../../..//opt/GNAT/2019/lib/xmlada/xmlada_unicode.static:$ORIGIN/../../../..//opt/GNAT/2019/lib/xmlada/xmlada_input.static:$ORIGIN/../../../..//opt/GNAT/2019/lib/xmlada/xmlada_schema.static:$ORIGIN/../../../..//opt/GNAT/2019/lib/gpr/static/gpr:$ORIGIN/../../../..//gnatcoll-db/sql/lib/static:$ORIGIN/../../../..//opt/GNAT/2019/lib/gcc/x86_64-pc-linux-gnu/8.3.1/adalib -o main
[2020-05-15 14:56:50] process exited with status 4, 100% (30/30), elapsed time: 02.34s

已添加170520

[SQL.ERROR] FATAL:  Ident authentication failed for user "postgres"
_SQL.ERROR_ FATAL:  Ident authentication failed for user "postgres"
_SQL.ERROR_  params="dbname='mydb1' user='postgres' host='localhost' sslmode=allow" ()
[SQL.ERROR] Failed to execute SELECT persons.person_uid, persons.first_name, persons.last_name, persons.gender, persons.email, persons.date_of_birth, persons.country_of_birth FROM persons  error=No connection to database
FAILED
[2020-05-17 19:30:04] process terminated successfully, elapsed time: 00.19s

新增290520

home/parallels/Documents/Ada Projects/Connect to a DB/obj/main
[SQL.ERROR] select failed: SELECT persons.person_uid, persons.first_name, persons.last_name, persons.gender, persons.email, persons.date_of_birth, persons.country_of_birth FROM persons PGRES_FATAL_ERROR ERROR:  relation "persons" does not exist
_SQL.ERROR_ LINE 1: ...persons.date_of_birth, persons.country_of_birth FROM persons
_SQL.ERROR_                                                                 ^
FAILED
[2020-05-29 22:40:11] process terminated successfully, elapsed time: 00.19s
postgres=# select * from persons;
              person_uid              | first_name | last_name  | gender |            email             | date_of_birth | country_of_birth 
--------------------------------------+------------+------------+--------+------------------------------+---------------+------------------
 afbf64be-e7d5-45a1-b8fb-1a9fd66e2765 | Audrie     | Vasyukov   | Female | [email protected] | 1988-11-24    | Guatemala
 ffda7264-1e54-428b-ae68-9ddb7b97702a | Nefen      | Philippard | Male   | [email protected]  | 2006-11-08    | Russia
 169d5fb9-8d40-451e-8b02-cd1c3639fbed | Leonore    | Garthland  | Female | [email protected]        | 1991-03-23    | Canada
 e34f4f21-524c-4134-81d6-7fd1fd9a7537 | Yank       | Turfitt    | Male   | [email protected]         | 1990-02-07    | China
 57336d0e-34f2-4166-a100-7b468e96a521 | Benn       | Pawley     | Male   | [email protected]      | 2006-10-28    | Russia
 b54a8411-3674-4432-b896-aaf35a10919b | Tod        | Easen      | Male   | [email protected]             | 1990-08-24    | China
(6 rows)
linux postgresql ada gnat-gps ada2012
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.