odbcapi30.c

来自「postgresql-odbc,跨平台应用」· C语言 代码 · 共 662 行 · 第 1/2 页

C
662
字号
/*------- * Module:			odbcapi30.c * * Description:		This module contains routines related to ODBC 3.0 *			most of their implementations are temporary *			and must be rewritten properly. *			2001/07/23	inoue * * Classes:			n/a * * API functions:	SQLAllocHandle, SQLBindParam, SQLCloseCursor,			SQLColAttribute, SQLCopyDesc, SQLEndTran,			SQLFetchScroll, SQLFreeHandle, SQLGetDescField,			SQLGetDescRec, SQLGetDiagField, SQLGetDiagRec,			SQLGetEnvAttr, SQLGetConnectAttr, SQLGetStmtAttr,			SQLSetConnectAttr, SQLSetDescField, SQLSetDescRec,			SQLSetEnvAttr, SQLSetStmtAttr, SQLBulkOperations *------- */#include "psqlodbc.h"#include "misc.h"#if (ODBCVER >= 0x0300)#include <stdio.h>#include <string.h>#include "environ.h"#include "connection.h"#include "statement.h"#include "pgapifunc.h"/*	SQLAllocConnect/SQLAllocEnv/SQLAllocStmt -> SQLAllocHandle */RETCODE		SQL_APISQLAllocHandle(SQLSMALLINT HandleType,			   SQLHANDLE InputHandle, SQLHANDLE * OutputHandle){	CSTR	func = "SQLAllocHandle";	RETCODE		ret;	ConnectionClass	*conn;	mylog("[[%s]]", func);	switch (HandleType)	{		case SQL_HANDLE_ENV:			ret = PGAPI_AllocEnv(OutputHandle);			break;		case SQL_HANDLE_DBC:			ENTER_ENV_CS((EnvironmentClass *) InputHandle);			ret = PGAPI_AllocConnect(InputHandle, OutputHandle);			LEAVE_ENV_CS((EnvironmentClass *) InputHandle);			break;		case SQL_HANDLE_STMT:			ENTER_CONN_CS((ConnectionClass *) InputHandle);			ret = PGAPI_AllocStmt(InputHandle, OutputHandle);			LEAVE_CONN_CS((ConnectionClass *) InputHandle);			break;		case SQL_HANDLE_DESC:			conn = (ConnectionClass *) InputHandle;			ENTER_CONN_CS(conn);			ret = PGAPI_AllocDesc(InputHandle, OutputHandle);			LEAVE_CONN_CS(conn);inolog("OutputHandle=%p\n", *OutputHandle);			break;		default:			ret = SQL_ERROR;			break;	}	return ret;}/*	SQLBindParameter/SQLSetParam -> SQLBindParam */RETCODE		SQL_APISQLBindParam(HSTMT StatementHandle,			 SQLUSMALLINT ParameterNumber, SQLSMALLINT ValueType,			 SQLSMALLINT ParameterType, SQLULEN LengthPrecision,			 SQLSMALLINT ParameterScale, PTR ParameterValue,			 SQLLEN *StrLen_or_Ind){	CSTR	func = "SQLBindParam";	RETCODE			ret;	StatementClass	*stmt = (StatementClass *) StatementHandle;	int			BufferLength = 512;		/* Is it OK ? */	mylog("[[%s]]", func);	ENTER_STMT_CS(stmt);	SC_clear_error(stmt);	StartRollbackState(stmt);	ret = PGAPI_BindParameter(StatementHandle, ParameterNumber, SQL_PARAM_INPUT, ValueType, ParameterType, LengthPrecision, ParameterScale, ParameterValue, BufferLength, StrLen_or_Ind);	ret = DiscardStatementSvp(stmt,ret, FALSE);	LEAVE_STMT_CS(stmt);	return ret;}/*	New function */RETCODE		SQL_APISQLCloseCursor(HSTMT StatementHandle){	CSTR	func = "SQLCloseCursor";	StatementClass	*stmt = (StatementClass *) StatementHandle;	RETCODE	ret;	mylog("[[%s]]", func);	ENTER_STMT_CS(stmt);	SC_clear_error(stmt);	StartRollbackState(stmt);	ret = PGAPI_FreeStmt(StatementHandle, SQL_CLOSE);	ret = DiscardStatementSvp(stmt,ret, FALSE);	LEAVE_STMT_CS(stmt);	return ret;}/*	SQLColAttributes -> SQLColAttribute */SQLRETURN	SQL_APISQLColAttribute(SQLHSTMT StatementHandle,			SQLUSMALLINT ColumnNumber,			SQLUSMALLINT FieldIdentifier,			SQLPOINTER CharacterAttribute,			SQLSMALLINT BufferLength,			SQLSMALLINT *StringLength,#if defined(_WIN64)			SQLLEN *NumericAttribute#elif defined(WITH_UNIXODBC) || defined(WIN32)			SQLPOINTER NumericAttribute#else			SQLLEN *NumericAttribute#endif			){	CSTR	func = "SQLColAttribute";	RETCODE	ret;	StatementClass	*stmt = (StatementClass *) StatementHandle;	mylog("[[%s]]", func);	ENTER_STMT_CS(stmt);	SC_clear_error(stmt);	StartRollbackState(stmt);	ret = PGAPI_ColAttributes(StatementHandle, ColumnNumber,					   FieldIdentifier, CharacterAttribute, BufferLength,							   StringLength, NumericAttribute);	ret = DiscardStatementSvp(stmt,ret, FALSE);	LEAVE_STMT_CS(stmt);	return ret;}/*	new function */RETCODE		SQL_APISQLCopyDesc(SQLHDESC SourceDescHandle,			SQLHDESC TargetDescHandle){	CSTR	func = "SQLCopyDesc";	RETCODE	ret;	mylog("[[%s]]\n", func);	ret = PGAPI_CopyDesc(SourceDescHandle, TargetDescHandle);	return ret;}/*	SQLTransact -> SQLEndTran */RETCODE		SQL_APISQLEndTran(SQLSMALLINT HandleType, SQLHANDLE Handle,		   SQLSMALLINT CompletionType){	CSTR	func = "SQLEndTran";	RETCODE	ret;	mylog("[[%s]]", func);	switch (HandleType)	{		case SQL_HANDLE_ENV:			ENTER_ENV_CS((EnvironmentClass *) Handle);			ret = PGAPI_Transact(Handle, SQL_NULL_HDBC, CompletionType);			LEAVE_ENV_CS((EnvironmentClass *) Handle);			break;		case SQL_HANDLE_DBC:			ENTER_CONN_CS((ConnectionClass *) Handle);			CC_clear_error((ConnectionClass *) Handle);			ret = PGAPI_Transact(SQL_NULL_HENV, Handle, CompletionType);			LEAVE_CONN_CS((ConnectionClass *) Handle);			break;		default:			ret = SQL_ERROR;			break;	}	return ret;}/*	SQLExtendedFetch -> SQLFetchScroll */RETCODE		SQL_APISQLFetchScroll(HSTMT StatementHandle,			   SQLSMALLINT FetchOrientation, SQLLEN FetchOffset){	CSTR func = "SQLFetchScroll";	StatementClass *stmt = (StatementClass *) StatementHandle;	RETCODE		ret = SQL_SUCCESS;	IRDFields	*irdopts = SC_get_IRDF(stmt);	SQLUSMALLINT *rowStatusArray = irdopts->rowStatusArray;	SQLLEN *pcRow = irdopts->rowsFetched, bkmarkoff = 0;	mylog("[[%s]] %d,%d\n", func, FetchOrientation, FetchOffset);	ENTER_STMT_CS(stmt);	SC_clear_error(stmt);	StartRollbackState(stmt);	if (FetchOrientation == SQL_FETCH_BOOKMARK)	{		if (stmt->options.bookmark_ptr)		{			bkmarkoff = FetchOffset;			FetchOffset = *((Int4 *) stmt->options.bookmark_ptr);mylog("bookmark=%u FetchOffset = %d\n", FetchOffset, bkmarkoff);		}		else		{			SC_set_error(stmt, STMT_SEQUENCE_ERROR, "Bookmark isn't specifed yet", func);			ret = SQL_ERROR;		}	}	if (SQL_SUCCESS == ret)	{		ARDFields	*opts = SC_get_ARDF(stmt);		ret = PGAPI_ExtendedFetch(StatementHandle, FetchOrientation, FetchOffset,				pcRow, rowStatusArray, bkmarkoff, opts->size_of_rowset);		stmt->transition_status = 6;	}	ret = DiscardStatementSvp(stmt,ret, FALSE);	LEAVE_STMT_CS(stmt);	if (ret != SQL_SUCCESS)		mylog("%s return = %d\n", func, ret);	return ret;}/*	SQLFree(Connect/Env/Stmt) -> SQLFreeHandle */RETCODE		SQL_APISQLFreeHandle(SQLSMALLINT HandleType, SQLHANDLE Handle){	CSTR	func = "SQLFreeHandle";	RETCODE		ret;	mylog("[[%s]]", func);	switch (HandleType)	{		case SQL_HANDLE_ENV:			ret = PGAPI_FreeEnv(Handle);			break;		case SQL_HANDLE_DBC:			ret = PGAPI_FreeConnect(Handle);			break;		case SQL_HANDLE_STMT:			ret = PGAPI_FreeStmt(Handle, SQL_DROP);			break;		case SQL_HANDLE_DESC:			ret = PGAPI_FreeDesc(Handle);			break;		default:			ret = SQL_ERROR;			break;	}	return ret;}/*	new function */RETCODE		SQL_APISQLGetDescField(SQLHDESC DescriptorHandle,				SQLSMALLINT RecNumber, SQLSMALLINT FieldIdentifier,				PTR Value, SQLINTEGER BufferLength,				SQLINTEGER *StringLength){	RETCODE	ret;	mylog("[[SQLGetDescField]]\n");	ret = PGAPI_GetDescField(DescriptorHandle, RecNumber, FieldIdentifier,			Value, BufferLength, StringLength);	return ret;}/*	new function */RETCODE		SQL_APISQLGetDescRec(SQLHDESC DescriptorHandle,			  SQLSMALLINT RecNumber, SQLCHAR *Name,			  SQLSMALLINT BufferLength, SQLSMALLINT *StringLength,			  SQLSMALLINT *Type, SQLSMALLINT *SubType,			  SQLLEN *Length, SQLSMALLINT *Precision,			  SQLSMALLINT *Scale, SQLSMALLINT *Nullable){	mylog("[[SQLGetDescRec]]\n");	mylog("Error not implemented\n");	return SQL_ERROR;}/*	new function */RETCODE		SQL_APISQLGetDiagField(SQLSMALLINT HandleType, SQLHANDLE Handle,				SQLSMALLINT RecNumber, SQLSMALLINT DiagIdentifier,				PTR DiagInfo, SQLSMALLINT BufferLength,				SQLSMALLINT *StringLength){	CSTR func = "SQLGetDiagField";	RETCODE	ret;	mylog("[[%s]] Handle=(%u,%p) Rec=%d Id=%d info=(%p,%d)\n", func, HandleType, Handle, RecNumber, DiagIdentifier, DiagInfo, BufferLength);	ret = PGAPI_GetDiagField(HandleType, Handle, RecNumber, DiagIdentifier,				DiagInfo, BufferLength, StringLength);	return ret;}/*	SQLError -> SQLDiagRec */RETCODE		SQL_APISQLGetDiagRec(SQLSMALLINT HandleType, SQLHANDLE Handle,			  SQLSMALLINT RecNumber, SQLCHAR *Sqlstate,			  SQLINTEGER *NativeError, SQLCHAR *MessageText,			  SQLSMALLINT BufferLength, SQLSMALLINT *TextLength){	RETCODE	ret;	mylog("[[SQLGetDiagRec]]\n");	ret = PGAPI_GetDiagRec(HandleType, Handle, RecNumber, Sqlstate,			NativeError, MessageText, BufferLength, TextLength);	return ret;}/*	new function */RETCODE		SQL_APISQLGetEnvAttr(HENV EnvironmentHandle,			  SQLINTEGER Attribute, PTR Value,			  SQLINTEGER BufferLength, SQLINTEGER *StringLength){	RETCODE	ret;	EnvironmentClass *env = (EnvironmentClass *) EnvironmentHandle;	mylog("[[SQLGetEnvAttr]] %d\n", Attribute);	ENTER_ENV_CS(env);

⌨️ 快捷键说明

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