Главная страница
Top.Mail.Ru    Яндекс.Метрика
Текущий архив: 2005.06.29;
Скачать: CL | DM;

Вниз

Подскажите как работать с libpq.dll для 8.0?   Найти похожие ветки 

 
chili   (2005-06-01 14:47) [0]

Подскажите как работать с libpq.dll для 8.0?

делаю так:
type
   PPGConn = ^PGConn;
   PGConn = record
       host : string;
       hostaddr : string;
       port : string;
       dbname : string;
       user : string;
       password : string;
       connect_timeout : string;
       options : string;
       tty : string;
       sslmode : string;
       requiressl : string;
       service : string;
   end;

function PQconnectdb(conninfo: PChar): PPGConn; stdcall; external "libpq.dll"


 
chili   (2005-06-01 15:16) [1]

help,help ну очень нужно


 
Плохиш ©   (2005-06-01 15:28) [2]

Используя dbExpress


 
pasha_golub ©   (2005-06-01 17:52) [3]

function PQconnectdb ..; cdecl;


 
pasha_golub ©   (2005-06-01 17:57) [4]

PPGConn = pointer;
И вообще, абсолютно все не то...

Что именно нужно?


 
pasha_golub ©   (2005-06-01 18:00) [5]

PGconn encapsulates a connection to the backend.            
The contents of this struct are not supposed to be known to  
applications.


 
chili   (2005-06-02 10:45) [6]

> pasha_golub
//Что именно нужно?

Ну если можно тогда примерчик как работать с Libpq.dll


 
pasha_golub ©   (2005-06-02 12:09) [7]

Знач так. На форме лежит два Мемо. Один для данных, другой волучает извещения от сервера. Это стандартный пример из хелпа серверного, переведенный на Делфи.

Типы:
PGConn = pointer;
PgResult = pointer;

Фунции объявляются так:

TPQconnectdb     = function(ConnInfo: PChar): PPGconn; cdecl;
var PQConnectdb: TPQconnectdb;
Соответственно подгрузка через LoadLibrary.

 TPQstatus        = function(Handle: PPGconn): ConnStatusType; cdecl;
 TPQsetNoticeProcessor = function(Handle: PPGconn; Proc: PQnoticeProcessor; Arg: Pointer):pointer; cdecl;
 TPQexec          = function(Handle: PPGconn; Query: PChar): PPGresult; cdecl;
 TPQresultStatus  = function(Result: PPGresult): ExecStatusType; cdecl;
 TPQclear         = procedure(Result: PPGresult); cdecl;
 TPQfinish        = procedure(Handle: PPGconn); cdecl;
 TPQerrorMessage  = function(Handle: PPGconn): PChar; cdecl;
 TPQntuples       = function(Result: PPGresult): Integer; cdecl;
 TPQgetvalue      = function(Result: PPGresult; tup_num, field_num: Integer): PChar; cdecl;

Константы (выделены заглавными буквами) надо глядель в коде сервера, а именно в файле http://developer.postgresql.org/cvsweb.cgi/pgsql/src/interfaces/libpq/libpq-fe.h?rev=1.116;content-type=text%2Fplain

Желаю удачи. Но есть у меня сомнения в целесообразности такого низкого доступа к серверу в твоем случае.


unit Unit1;

interface

uses
 Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
 Dialogs, PSQLTypes, StdCtrls;

type
 TForm1 = class(TForm)
   Button1: TButton;
   Memo1: TMemo;
   Memo2: TMemo;
   procedure Button1Click(Sender: TObject);
 private
   { Private declarations }
 public
   { Public declarations }
 end;

var
 Form1: TForm1;

implementation

{$R *.dfm}

procedure NoticeProcessor(arg: pointer; Msg: PChar); cdecl;
begin
Form1.Memo2.Lines.Append(Msg);
end;

procedure Main;
(*
static void
exit_nicely(PGconn *conn)
{
       PQfinish(conn);
       exit(1);
} *)

(*int
main(int argc, char **argv)
{
       const char *conninfo;
       PGconn     *conn;
       PGresult   *res;
       int                     nFields;
       int                     i,
                               j;
*)
var
 conninfo: PChar;
 Conn: PGConn;
 Res: PGResult;
 i,j:integer;
 nFields: integer;
 s:string;
begin
 (*
               conninfo = "dbname = template1";
*)
 Conninfo := "host = ""localhost"" dbname = ""Test"" user = ""<user>"" password = ""<pass>""";
(*
       /* Make a connection to the database */
       conn = PQconnectdb(conninfo);
*)

 Conn := PQConnectdb(ConnInfo);
(*        /* Check to see that the backend connection was successfully made */
       if (PQstatus(conn) != CONNECTION_OK)
       {
               fprintf(stderr, "Connection to database failed: %s",
                       PQerrorMessage(conn));
               exit_nicely(conn);
       }

*)
 If PQStatus(Conn) <> CONNECTION_OK then
  begin
   ShowMessage("CAN""T START connection!");
   PQFinish(Conn);
   Exit;
  end;

 PQSetNoticeProcessor(Conn,NoticeProcessor,nil);
 (*
       /*
        * Our test case here involves using a cursor, for which we must be
        * inside a transaction block.  We could do the whole thing with a
        * single PQexec() of "select * from pg_database", but that"s too
        * trivial to make a good example.
        */

       /* Start a transaction block */
       res = PQexec(conn, "BEGIN");
       if (PQresultStatus(res) != PGRES_COMMAND_OK)
       {
               fprintf(stderr, "BEGIN command failed: %s", PQerrorMessage(conn));
               PQclear(res);
               exit_nicely(conn);
       }
        /*
        * Should PQclear PGresult whenever it is no longer needed to avoid
        * memory leaks
        */
       PQclear(res);

*)
  Res := PQExec(conn,"BEGIN");
  if PQResultStatus(res) <> PGRES_COMMAND_OK then
    begin
      ShowMessage("CAN""T START TRANSACTION");
      PQClear(res);
      PQFinish(Conn);
      Exit;
    end
  else
    PQClear(res);

  res := PQExec(conn,"ANALYZE VERBOSE <tablename>");
  if PQResultStatus(res) <> PGRES_TUPLES_OK then
    begin
      s := PQerrorMessage(conn);
      ShowMessage("CAN""T START EXECUTING: "+S);
      PQClear(res);
      PQFinish(Conn);
      Exit;
    end;

(*       /* first, print out the attribute names */
       nFields = PQnfields(res);
       for (i = 0; i < nFields; i++)
               printf("%-15s", PQfname(res, i));
       printf("\n\n");
*)
  nFields := PQnFields(res);
  for i:=0 to nFields-1 do
    Form1.Memo1.Lines.Append(PQfname(res,i));
  Form1.Memo1.Lines.Append("==============");
(*

       /* next, print out the rows */
       for (i = 0; i < PQntuples(res); i++)
       {
               for (j = 0; j < nFields; j++)
                       printf("%-15s", PQgetvalue(res, i, j));
               printf("\n");
       }
      PQclear(res);

*)
 for i:=0 to PQntuples(res)-1 do
 begin
  for j:=0 to nFields -1 do
   Form1.Memo1.Lines.Append(PQgetvalue(res,i,j));
  Form1.Memo1.Lines.Append("--------------");
 end;
 Form1.Memo1.Lines.Append("==============");
 pqclear(res);

 res := PQExec(conn,"END");
 PQClear(res);
(*
       /* close the connection to the database and cleanup */
       PQfinish(conn);

       return 0;
}   *)
 PQFinish(Conn);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
Main;
end;

end.


 
pasha_golub ©   (2005-06-02 12:14) [8]

Вообще-то, не полностью идентичный перевод. Это я уже сам игрался в последствии, но думаю ход мыслей ясен.


 
chili   (2005-06-02 12:47) [9]

Большое спасибо



Страницы: 1 вся ветка

Текущий архив: 2005.06.29;
Скачать: CL | DM;

Наверх




Память: 0.5 MB
Время: 0.044 c
14-1117565007
NightStranger
2005-05-31 22:43
2005.06.29
С чего все начинали


14-1117448242
Yegorchic
2005-05-30 14:17
2005.06.29
Сертификат "Лаборант-программист"


8-1109790766
seregka
2005-03-02 22:12
2005.06.29
Прозрачность изображения+наложение 2-х изображений


8-1109756936
X-Disa
2005-03-02 12:48
2005.06.29
Проблем с Preview и Undo


3-1115984454
tema
2005-05-13 15:40
2005.06.29
Поиск без locate