⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sdpgsql.pas

📁 SQLDirect Component Library is a light-weight Borland Database Engine replacement for Borland Delphi
💻 PAS
📖 第 1 页 / 共 5 页
字号:

{*******************************************************}
{							}
{       Delphi SQLDirect Component Library		}
{	PostgreSQL Interface Unit			}
{       PostgreSQL API ver.7.1 (Date: 22.03.2001)	}
{       		                                }
{       Copyright (c) 1997,2005 by Yuri Sheino		}
{                                                       }
{*******************************************************}
{$I SqlDir.inc}
unit SDPgSQL {$IFDEF SD_CLR} platform {$ENDIF};

interface

uses
  Windows, SysUtils, Classes, Db, Registry, SyncObjs,
{$IFDEF SD_CLR}
  System.Runtime.InteropServices,
{$ENDIF}
  SDConsts, SDCommon;


{*******************************************************************************
*	pg_type.h - The OIDs of the built-in datatypes are defined in          *
*			system table pg_type and                               *
* 			src/include/catalog/pg_type.h in the source tree.      *
*******************************************************************************}

const
  BOOLOID    	= 16;
  BYTEAOID   	= 17;
  CHAROID    	= 18;
  NAMEOID    	= 19;
  INT8OID    	= 20;
  INT2OID    	= 21;
  INT2VECTOROID	= 22;
  INT4OID    	= 23;
  REGPROCOID 	= 24;
  TEXTOID    	= 25;
  OIDOID     	= 26;
  TIDOID     	= 27;
  XIDOID 	= 28;
  CIDOID 	= 29;
  OIDVECTOROID	= 30;
  POINTOID   	= 600;
  LSEGOID    	= 601;
  PATHOID    	= 602;
  BOXOID     	= 603;
  POLYGONOID 	= 604;
  LINEOID    	= 628;
  FLOAT4OID	= 700;
  FLOAT8OID	= 701;
  ABSTIMEOID	= 702;
  RELTIMEOID	= 703;
  TINTERVALOID	= 704;
  UNKNOWNOID  	= 705;
  CIRCLEOID   	= 718;
  CASHOID 	= 790;
  INETOID 	= 869;
  CIDROID 	= 650;
  ACLITEMSIZE	= 8;
  BPCHAROID  	= 1042;
  VARCHAROID 	= 1043;
  DATEOID    	= 1082;
  TIMEOID    	= 1083;
  TIMESTAMPOID	= 1184;
  INTERVALOID 	= 1186;
  TIMETZOID   	= 1266;
  ZPBITOID    	= 1560;
  VARBITOID   	= 1562;
  NUMERICOID  	= 1700;
	// for PostgreSQL v.7.2
  TIMESTAMPOID_v72= 1114;

{*******************************************************************************
*	postgres_ext.h - This file is only for fundamental Postgres declarations *
*******************************************************************************}

{*
 * Object ID is a fundamental type in Postgres.
 *}
type
  Oid	= Cardinal;	// object id

const
  InvalidOid	= 0;

{*
 * NAMEDATALEN is the max length for system identifiers (e.g. table names,
 * attribute names, function names, etc.)
 *
 * NOTE that databases with different NAMEDATALEN's cannot interoperate!
 *}
  NAMEDATALEN 	= 32;

{*******************************************************************************
*	libpq-fe.h - Common definition used by frontend postgres applications  ********************************************************************************}

const
  {	Application-visible enum types	}
	// enum ConnStatusType
  CONNECTION_OK 	= 0;
  CONNECTION_BAD	= 1;
  // Non-blocking mode only below here
  CONNECTION_STARTED	= 2;		// Waiting for connection to be made
  CONNECTION_MADE 	= 3;		// Connection OK; waiting to send
  CONNECTION_AWAITING_RESPONSE	= 4;	// Waiting for a response from the postmaster
  CONNECTION_AUTH_OK	= 5;		// Received authentication; waiting for backend startup
  CONNECTION_SETENV	= 6;		// Negotiating environment

	// enum PostgresPollingStatusType
  PGRES_POLLING_FAILED	= 0;
  PGRES_POLLING_READING	= 1;		// These two indicate that one may
  PGRES_POLLING_WRITING	= 2;		// use select before polling again
  PGRES_POLLING_OK	= 3;
  PGRES_POLLING_ACTIVE	= 4;		// Can call poll function immediately

	// enum ExecStatusType
  PGRES_EMPTY_QUERY	= 0;
  PGRES_COMMAND_OK	= 1;		// a query command that doesn't return anything was executed properly by the backend
  PGRES_TUPLES_OK	= 2;		// a query command that returns tuples was executed properly by the backend, PGresult contains the result tuples
  PGRES_COPY_OUT	= 3;		// Copy Out data transfer in progress
  PGRES_COPY_IN		= 4;		// Copy In data transfer in progress
  PGRES_BAD_RESPONSE	= 5;		// an unexpected response was recv'd from the backend
  PGRES_NONFATAL_ERROR	= 6;
  PGRES_FATAL_ERROR	= 7;

type
  TVoid = TSDPtr;

{* PGconn encapsulates a connection to the backend.
 * The contents of this struct are not supposed to be known to applications.
 *}
  PPGconn = TVoid;

  TConnStatusType 		= Integer;	// enum
  TPostgresPollingStatusType	= Integer;	// enum
  TExecStatusType		= Integer;	// enum
  PSSL				= TVoid;
    
{* PGresult encapsulates the result of a query (or more precisely, of a single
 * SQL command --- a query string given to PQsendQuery can contain multiple
 * commands and thus return multiple PGresult objects).
 * The contents of this struct are not supposed to be known to applications.
 *}
  PPGresult = TVoid;

{* PGnotify represents the occurrence of a NOTIFY message.
 * Ideally this would be an opaque typedef, but it's so simple that it's
 * unlikely to change.
 * NOTE: in Postgres 6.4 and later, the be_pid is the notifying backend's,
 * whereas in earlier versions it was always your own backend's PID.
 *}
  TPGnotify	= record
    szRelName: array[0..NAMEDATALEN] of Char;	// name of relation containing data
    be_pid: Integer;				// process id of backend
  end;

{* PQnoticeProcessor is the function type for the notice-message callback.
 *}
  TPQnoticeProcessor	= procedure (arg: Pointer; szMessage: TSDCharPtr); cdecl;

	{ Print options for PQprint() }
  TPQBool	= Char;

  TPQprintOpt	= record
    header,				// print output field headings and row count
    align,				// fill align the fields
    standard,				// old brain dead format
    html3,				// output html tables
    expanded,				// expand tables
    pager:	TPQBool;		// use pager for output if needed
    fieldSep,				// field separator
    tableOpt,				// insert to HTML <table ...>
    caption:	TSDCharPtr;			// HTML <caption>
    fieldName:	array[0..0] of TSDCharPtr;	// null terminated array of repalcement field names
  end;


{* ----------------
 * Structure for the conninfo parameter definitions returned by PQconndefaults
 *
 * All fields except "val" point at static strings which must not be altered.
 * "val" is either NULL or a malloc'd current-value string.  PQconninfoFree()
 * will release both the val strings and the PQconninfoOption array itself.
 * ----------------
 *}
  TPQconninfoOption	= record
    szKeyword,		// The keyword of the option
    szEnvVar,		// Fallback environment variable name
    szCompiled,		// Fallback compiled in default value
    szVal,		// Option's current value, or NULL
    szLabel,		// Label for field in connect dialog
    szDispChar:	TSDCharPtr;	// Character to display for this field in a connect dialog.
    			// Values are: "" Display entered value as is "*" Password field - hide value "D"
                        // Debug option - don't show by default
    dispsize: Integer;	// Field size in characters for dialog
  end;
{$IFDEF SD_CLR}
  PPQconninfoOption	= TVoid;
  PPGnotify		= TVoid;
  PPQprintOpt		= TVoid;
{$ELSE}
  PPQconninfoOption	= ^TPQconninfoOption;
  PPGnotify		= ^TPGnotify;
  PPQprintOpt		= ^TPQprintOpt;
{$ENDIF}


{* ----------------
 * PQArgBlock -- structure for PQfn() arguments
 * ----------------
 *}
  TPQArgBlock	= record
    len,
    isint:	Integer;
    IntOrPtr:	Integer;	// union {int *ptr; int	integer;} u;
  end;


{* ----------------
 * Exported functions of libpq
 * ----------------
 *}
 {$IFNDEF SD_CLR}
var
	// make a new client connection to the backend
  // Asynchronous (non-blocking)
  PQconnectStart: 	function(szConnInfo: TSDCharPtr): PPGconn; cdecl;
  PQconnectPoll:	function(conn: PPGconn): TPostgresPollingStatusType; cdecl;

  // Synchronous (blocking)
  PQconnectdb: 		function(szConnInfo: TSDCharPtr): PPGconn; cdecl;
  PQsetdbLogin:		function(pghost, pgport, pgoptions, pgtty, dbName, login, pwd: TSDCharPtr): PPGconn; cdecl;

  // close the current connection and free the PGconn data structure
   PQfinish:		procedure(conn: PPGconn); cdecl;

  // get info about connection options known to PQconnectdb
  PQconndefaults:	function: PPQconninfoOption; cdecl;

  // free the data structure returned by PQconndefaults()
  PQconninfoFree:	procedure(connOptions: PPQconninfoOption); cdecl;

  	// close the current connection and restablish a new one with the same parameters

  // Asynchronous (non-blocking)
  PQresetStart:	function(conn: PPGconn): Integer; cdecl;
  PQresetPoll:	function(conn: PPGconn): TPostgresPollingStatusType; cdecl;
  // Synchronous (blocking)
  PQreset:	procedure(conn: PPGconn); cdecl;

  // issue a cancel request
  PQrequestCancel:	function(conn: PPGconn): Integer; cdecl;

	// Accessor functions for PGconn objects
  PQdb:		function(const conn: PPGconn): TSDCharPtr; cdecl;
  PQuser:	function(const conn: PPGconn): TSDCharPtr; cdecl;
  PQpass:	function(const conn: PPGconn): TSDCharPtr; cdecl;
  PQhost:	function(const conn: PPGconn): TSDCharPtr; cdecl;
  PQport:	function(const conn: PPGconn): TSDCharPtr; cdecl;
  PQtty:	function(const conn: PPGconn): TSDCharPtr; cdecl;
  PQoptions:	function(const conn: PPGconn): TSDCharPtr; cdecl;
  PQstatus:	function(const conn: PPGconn): TConnStatusType; cdecl;
  PQerrorMessage:function(const conn: PPGconn): TSDCharPtr; cdecl;
  PQsocket:	function(const conn: PPGconn): Integer; cdecl;
  PQbackendPID:	function(const conn: PPGconn): Integer; cdecl;
  PQclientEncoding:
  		function(const conn: PPGconn): Integer; cdecl;
  PQsetClientEncoding:
  		function(conn: PPGconn; const encoding: TSDCharPtr): Integer; cdecl;

  // Get the SSL structure associated with a connection
  PQgetssl:	function(conn: PPGconn): PSSL; cdecl;


  // Enable/disable tracing
  PQtrace:	procedure(conn: PPGconn; debug_port: Pointer); cdecl;
  PQuntrace:	procedure(conn: PPGconn); cdecl;

  // Override default notice processor
  PQsetNoticeProcessor:
  		function(conn: PPGconn; proc: TPQnoticeProcessor; arg: Pointer): TPQnoticeProcessor;


  // Simple synchronous query
  PQexec:	function(conn: PPGconn; const query: TSDCharPtr): PPGresult; cdecl;
  PQnotifies:	function(conn: PPGconn): PPGnotify; cdecl;

  // Interface for multiple-result or asynchronous queries
  PQsendQuery:	function(conn: PPGconn; const query: TSDCharPtr): Integer; cdecl;
  PQgetResult:	function(conn: PPGconn): PPGresult; cdecl;

  // Routines for managing an asychronous query
  PQisBusy: 	function(conn: PPGconn): Integer; cdecl;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -