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

📄 connection.h

📁 postgresql-odbc,跨平台应用
💻 H
📖 第 1 页 / 共 2 页
字号:
/* File:			connection.h * * Description:		See "connection.c" * * Comments:		See "notice.txt" for copyright and license information. * */#ifndef __CONNECTION_H__#define __CONNECTION_H__#include "psqlodbc.h"#include <stdlib.h>#include <string.h>#include "descriptor.h"#if defined (POSIX_MULTITHREAD_SUPPORT)#include <pthread.h>#endif#ifdef	__cplusplusextern "C" {#endiftypedef enum{	CONN_NOT_CONNECTED,	/* Connection has not been established */	CONN_CONNECTED,		/* Connection is up and has been established */	CONN_DOWN,		/* Connection is broken */	CONN_EXECUTING		/* the connection is currently executing a				 * statement */} CONN_Status;enum{	DISALLOW_UPDATABLE_CURSORS = 0,	/* No cursors are updatable */	ALLOW_STATIC_CURSORS = 1L, /* Static cursors are updatable */	ALLOW_KEYSET_DRIVEN_CURSORS = (1L << 1), /* Keyset-driven cursors are updatable */	ALLOW_DYNAMIC_CURSORS = (1L << 2), /* Dynamic cursors are updatable */	ALLOW_BULK_OPERATIONS = (1L << 3), /* Bulk operations available */	SENSE_SELF_OPERATIONS = (1L << 4), /* Sense self update/delete/add */};/*	These errors have general sql error state */#define CONNECTION_SERVER_NOT_REACHED				101#define CONNECTION_MSG_TOO_LONG					103#define CONNECTION_COULD_NOT_SEND				104#define CONNECTION_NO_SUCH_DATABASE				105#define CONNECTION_BACKEND_CRAZY				106#define CONNECTION_NO_RESPONSE					107#define CONNECTION_SERVER_REPORTED_ERROR			108#define CONNECTION_COULD_NOT_RECEIVE				109#define CONNECTION_SERVER_REPORTED_WARNING			110#define CONNECTION_NEED_PASSWORD				112#define CONNECTION_COMMUNICATION_ERROR				113#define CONN_TRUNCATED							(-2)#define CONN_OPTION_VALUE_CHANGED					(-1)/*	These errors correspond to specific SQL states */#define CONN_INIREAD_ERROR						201#define CONN_OPENDB_ERROR						202 #define CONN_STMT_ALLOC_ERROR						203#define CONN_IN_USE							204 #define CONN_UNSUPPORTED_OPTION						205/* Used by SetConnectoption to indicate unsupported options */#define CONN_INVALID_ARGUMENT_NO					206/* SetConnectOption: corresponds to ODBC--"S1009" */#define CONN_TRANSACT_IN_PROGRES					207#define CONN_NO_MEMORY_ERROR						208#define CONN_NOT_IMPLEMENTED_ERROR					209#define CONN_INVALID_AUTHENTICATION					210#define CONN_AUTH_TYPE_UNSUPPORTED					211#define CONN_UNABLE_TO_LOAD_DLL						212#define CONN_VALUE_OUT_OF_RANGE						214#define CONN_OPTION_NOT_FOR_THE_DRIVER					216#define CONN_EXEC_ERROR							217/* Conn_status defines */#define CONN_IN_AUTOCOMMIT		1L #define CONN_IN_TRANSACTION		(1L<<1)#define CONN_IN_MANUAL_TRANSACTION	(1L<<2)#define CONN_IN_ERROR_BEFORE_IDLE	(1L<<3)/* AutoCommit functions */#define CC_is_in_autocommit(x)		(x->transact_status & CONN_IN_AUTOCOMMIT)/* Transaction in/not functions */#define CC_set_in_trans(x)	(x->transact_status |= CONN_IN_TRANSACTION)#define CC_set_no_trans(x)	(x->transact_status &= ~(CONN_IN_TRANSACTION | CONN_IN_ERROR_BEFORE_IDLE))#define CC_is_in_trans(x)	(0 != (x->transact_status & CONN_IN_TRANSACTION))/* Manual transaction in/not functions */#define CC_set_in_manual_trans(x) (x->transact_status |= CONN_IN_MANUAL_TRANSACTION)#define CC_set_no_manual_trans(x) (x->transact_status &= ~CONN_IN_MANUAL_TRANSACTION)#define CC_is_in_manual_trans(x) (0 != (x->transact_status & CONN_IN_MANUAL_TRANSACTION))/* Error waiting for ROLLBACK */#define CC_set_in_error_trans(x) (x->transact_status |= CONN_IN_ERROR_BEFORE_IDLE)#define CC_set_no_error_trans(x) (x->transact_status &= ~CONN_IN_ERROR_BEFORE_IDLE)#define CC_is_in_error_trans(x) (x->transact_status & CONN_IN_ERROR_BEFORE_IDLE)#define CC_get_errornumber(x)	(x->__error_number)#define CC_get_errormsg(x)	(x->__error_message)#define CC_set_errornumber(x, n)	(x->__error_number = n)/* Unicode handling */#define	CONN_UNICODE_DRIVER	(1L)#define	CONN_ANSI_APP		(1L << 1)#define	CONN_DISALLOW_WCHAR	(1L << 2)#define	CC_set_in_unicode_driver(x)	(x->unicode |= CONN_UNICODE_DRIVER)#define	CC_set_in_ansi_app(x)	(x->unicode |= CONN_ANSI_APP)#define	CC_is_in_unicode_driver(x)	(0 != (x->unicode & CONN_UNICODE_DRIVER))#define	CC_is_in_ansi_app(x)	(0 != (x->unicode & CONN_ANSI_APP))#define	ALLOW_WCHAR(x)	(0 != (x->unicode & CONN_UNICODE_DRIVER) && 0 == (x->unicode & CONN_DISALLOW_WCHAR))#define CC_MALLOC_return_with_error(t, tp, s, x, m, ret) \do { \	if (t = malloc(s), NULL == t) \	{ \		CC_set_error(x, CONN_NO_MEMORY_ERROR, m, ""); \		return ret; \	} \} while (0)#define CC_REALLOC_return_with_error(t, tp, s, x, m, ret) \do { \	tp *tmp; \	if (tmp = (tp *) realloc(t, s), NULL == tmp) \	{ \		CC_set_error(x, CONN_NO_MEMORY_ERROR, m, ""); \		return ret; \	} \	t = tmp; \} while (0)/* For Multi-thread */#if defined(WIN_MULTITHREAD_SUPPORT)#define INIT_CONN_CS(x)		InitializeCriticalSection(&((x)->cs))#define INIT_CONNLOCK(x)	InitializeCriticalSection(&((x)->slock))#define ENTER_CONN_CS(x)	EnterCriticalSection(&((x)->cs))#define CONNLOCK_ACQUIRE(x)	EnterCriticalSection(&((x)->slock))#define TRY_ENTER_CONN_CS(x)	TryEnterCriticalSection(&((x)->cs))#define ENTER_INNER_CONN_CS(x, entered) \do { \	EnterCriticalSection(&((x)->cs)); \	entered++; \} while (0)#define LEAVE_CONN_CS(x)	LeaveCriticalSection(&((x)->cs))#define CONNLOCK_RELEASE(x)	LeaveCriticalSection(&((x)->slock))#define DELETE_CONN_CS(x)	DeleteCriticalSection(&((x)->cs))#define DELETE_CONNLOCK(x)	DeleteCriticalSection(&((x)->slock))#elif defined(POSIX_THREADMUTEX_SUPPORT)#define INIT_CONN_CS(x)		pthread_mutex_init(&((x)->cs), getMutexAttr())#define INIT_CONNLOCK(x)	pthread_mutex_init(&((x)->slock), getMutexAttr())#define ENTER_CONN_CS(x)	pthread_mutex_lock(&((x)->cs))#define CONNLOCK_ACQUIRE(x) 	pthread_mutex_lock(&((x)->slock))#define TRY_ENTER_CONN_CS(x)	(0 == pthread_mutex_trylock(&((x)->cs)))#define ENTER_INNER_CONN_CS(x, entered) \do { \	if (getMutexAttr()) \	{ \		if (pthread_mutex_lock(&((x)->cs)) == 0) \			entered++; \	} \} while (0)#define LEAVE_CONN_CS(x)	pthread_mutex_unlock(&((x)->cs))#define CONNLOCK_RELEASE(x) 	pthread_mutex_unlock(&((x)->slock))#define DELETE_CONN_CS(x)	pthread_mutex_destroy(&((x)->cs))#define DELETE_CONNLOCK(x)	pthread_mutex_destroy(&((x)->slock))#else#define INIT_CONN_CS(x)	#define INIT_CONNLOCK(x)	#define TRY_ENTER_CONN_CS(x)#define ENTER_CONN_CS(x)#define CONNLOCK_ACQUIRE(x)#define ENTER_INNER_CONN_CS(x, entered)#define LEAVE_CONN_CS(x)#define CONNLOCK_RELEASE(x)#define DELETE_CONN_CS(x)#define DELETE_CONNLOCK(x)#endif /* WIN_MULTITHREAD_SUPPORT */#define	LEAVE_INNER_CONN_CS(entered, conn) \do { \	if (entered > 0) \	{ \		LEAVE_CONN_CS(conn); \		entered--; \	} \} while (0)#define CLEANUP_FUNC_CONN_CS(entered, conn) \do { \	while (entered > 0) \	{ \		LEAVE_CONN_CS(conn); \		entered--; \	} \} while (0)/* Authentication types */#define AUTH_REQ_OK		0#define AUTH_REQ_KRB4		1#define AUTH_REQ_KRB5		2#define AUTH_REQ_PASSWORD	3#define AUTH_REQ_CRYPT		4#define AUTH_REQ_MD5		5#define AUTH_REQ_SCM_CREDS	6/*	Startup Packet sizes */#define SM_DATABASE		64#define SM_USER			32#define SM_OPTIONS		64#define SM_UNUSED		64#define SM_TTY			64/*	Old 6.2 protocol defines */#define NO_AUTHENTICATION	7#define PATH_SIZE		64#define ARGV_SIZE		64#define USRNAMEDATALEN		16typedef unsigned int ProtocolVersion;#define PG_PROTOCOL(major, minor)	(((major) << 16) | (minor))#define PG_PROTOCOL_LATEST	PG_PROTOCOL(3, 0) #define PG_PROTOCOL_74	PG_PROTOCOL(3, 0) #define PG_PROTOCOL_64	PG_PROTOCOL(2, 0) #define PG_PROTOCOL_63	PG_PROTOCOL(1, 0)#define PG_PROTOCOL_62	PG_PROTOCOL(0, 0)/*	This startup packet is to support latest Postgres protocol (6.4, 6.3) */typedef struct _StartupPacket{	ProtocolVersion protoVersion;	char		database[SM_DATABASE];	char		user[SM_USER];	char		options[SM_OPTIONS];	char		unused[SM_UNUSED];	char		tty[SM_TTY];} StartupPacket;/*	This startup packet is to support pre-Postgres 6.3 protocol */typedef struct _StartupPacket6_2{	unsigned int authtype;	char		database[PATH_SIZE];	char		user[USRNAMEDATALEN];	char		options[ARGV_SIZE];	char		execfile[ARGV_SIZE];	char		tty[PATH_SIZE];} StartupPacket6_2;/* Transferred from pqcomm.h:  */typedef ProtocolVersion MsgType;#define CANCEL_REQUEST_CODE PG_PROTOCOL(1234,5678)typedef struct CancelRequestPacket{	/* Note that each field is stored in network byte order! */	MsgType		cancelRequestCode;	/* code to identify a cancel request */	unsigned int	backendPID;	/* PID of client's backend */	unsigned int	cancelAuthCode; /* secret key to authorize cancel */} CancelRequestPacket;/*	Structure to hold all the connection attributes for a specific	connection (used for both registry and file, DSN and DRIVER)*/typedef struct{	char		dsn[MEDIUM_REGISTRY_LEN];	char		desc[MEDIUM_REGISTRY_LEN];	char		drivername[MEDIUM_REGISTRY_LEN];	char		server[MEDIUM_REGISTRY_LEN];

⌨️ 快捷键说明

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