Главная страница
    Top.Mail.Ru    Яндекс.Метрика
Форум: "Основная";
Текущий архив: 2005.06.29;
Скачать: [xml.tar.bz2];

Вниз

Подскажите как работать с 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;
Скачать: [xml.tar.bz2];

Наверх




Память: 0.49 MB
Время: 0.075 c
4-1115175884
Alexandr_jr
2005-05-04 07:04
2005.06.29
CreateFileMapping&amp;MapViewOfFile


1-1117867566
seregka
2005-06-04 10:46
2005.06.29
как очистить буфер обмена


4-1115318045
bc0113
2005-05-05 22:34
2005.06.29
FreeLibrary


1-1117867534
Vf
2005-06-04 10:45
2005.06.29
массив


1-1118325601
lehich
2005-06-09 18:00
2005.06.29
фоновой рисунок на Form





Afrikaans Albanian Arabic Armenian Azerbaijani Basque Belarusian Bulgarian Catalan Chinese (Simplified) Chinese (Traditional) Croatian Czech Danish Dutch English Estonian Filipino Finnish French
Galician Georgian German Greek Haitian Creole Hebrew Hindi Hungarian Icelandic Indonesian Irish Italian Japanese Korean Latvian Lithuanian Macedonian Malay Maltese Norwegian
Persian Polish Portuguese Romanian Russian Serbian Slovak Slovenian Spanish Swahili Swedish Thai Turkish Ukrainian Urdu Vietnamese Welsh Yiddish Bengali Bosnian
Cebuano Esperanto Gujarati Hausa Hmong Igbo Javanese Kannada Khmer Lao Latin Maori Marathi Mongolian Nepali Punjabi Somali Tamil Telugu Yoruba
Zulu
Английский Французский Немецкий Итальянский Португальский Русский Испанский