以下为ODBC API的常用十四个函数,先列出在PowerBuilder中外部函数引用声明:
| function integer SQLAllocEnv(ref long phenv) library "odbc32.dll" function integer SQLFreeEnv(long henv) library "odbc32.dll" function integer SQLDataSources(long henv,int fdirection,ref string szdsn,& integer cbdsnmax,ref integer pcbdsn,ref string szdescription,integer cbdescriptionmax,ref integer pcbdescription)library "odbc32.dll" function integer SQLAllocConnect(long henv,ref long hdbc)library "odbc32.dll" function integer SQLConnect (long hstmt,ref string szdsn,integer dsnlen,ref string szuid,integer uidlen,ref string szpwd,integer pwdlen) library "odbc32.dll" function integer SQLDisconnect (long hdbc) library "odbc32.dll" function integer SQLAllocStmt(long hdbc,ref long hstmt)library "odbc32.dll" function integer SQLTables(long hstmt,ref string sztablequalifier,integer tablequalifierlen,ref string szowner,integer owerlen,ref string szname,integer namelen, ref string sztype,integer typelen)library "odbc32.dll" function integer SQLColumns(long hstmt,ref string sztablequalifier,integer tablequalifierlen,ref string szowner,integer owerlen,ref string szname,integer namelen, ref string sztype,integer typelen)library "odbc32.dll" function integer SQLBindCol(long hstmt,integer colnum,integer datatype,ref string name,long maxlen,ref long actlen) library "odbc32.dll" function integer SQLFetch(long hstmt)library "odbc32.dll" function integer SQLError(long lenv,long hdbc,long hstmt,ref string sqlstate,ref long nativeerror,ref string errormsg,integer errormsgmax,ref integer errormsglen)library "odbc32.dll" function integer SQLFreeStmt(long hstmt,integer Options)library "odbc32.dll" |
1、function integer SQLAllocEnv(ref long phenv) library "odbc32.dll"
参数:ref long phenv 引用传递的long类型参数,保存该函数返回的OBDC环境的句柄。
存放在phenv中的值成为以后OBDC API函数调用的唯一标识符。
返回值:integer 成功时,返回0,失败返回值小于0。
函数功能:获取ODBC环境句柄。
2、function integer SQLAllocStmt(long hdbc,ref long hstmt)library "odbc32.dll"
参数:long hdbc ODBC环境的句柄。
Ref long hstmt 保存SQL语句句柄。
返回值:integer ,成功时,返回0,失败返回值小于0。
函数功能:获取SQL语句句柄。
3、function integer SQLConnect (long hstmt,ref string szdsn,integer dsnlen,ref string szuid,integer uidlen,
ref string szpwd,integer pwdlen) library "odbc32.dll"
参数:long hstmt ,调用SQLAllocStmt()函数获取的句柄。

