以下为ODBCAPI的常用十四个函数,先列出在PowerBuilder中外部函数引用声明:
functionintegerSQLAllocEnv(reflongphenv)library"odbc32.dll"
functionintegerSQLFreeEnv(longhenv)library"odbc32.dll"
functionintegerSQLDataSources(longhenv,intfdirection,refstringszdsn,&
integercbdsnmax,refintegerpcbdsn,refstringszdescription,integercbdescriptionmax,refintegerpcbdescription)library"odbc32.dll"
functionintegerSQLAllocConnect(longhenv,reflonghdbc)library"odbc32.dll"
functionintegerSQLConnect(longhstmt,refstringszdsn,integerdsnlen,refstring
szuid,integeruidlen,refstringszpwd,integerpwdlen)library"odbc32.dll"
functionintegerSQLDisconnect(longhdbc)library"odbc32.dll"
functionintegerSQLAllocStmt(longhdbc,reflonghstmt)library"odbc32.dll"
functionintegerSQLTables(longhstmt,refstringsztablequalifier,integertablequalifierlen,refstringszowner,integerowerlen,refstringszname,integernamelen,
refstringsztype,integertypelen)library"odbc32.dll"
functionintegerSQLColumns(longhstmt,refstringsztablequalifier,integertablequalifierlen,refstringszowner,integerowerlen,refstringszname,integernamelen,
refstringsztype,integertypelen)library"odbc32.dll"
functionintegerSQLBindCol(longhstmt,integercolnum,integerdatatype,refstringname,longmaxlen,reflongactlen)library"odbc32.dll"
functionintegerSQLFetch(longhstmt)library"odbc32.dll"
functionintegerSQLError(longlenv,longhdbc,longhstmt,refstringsqlstate,reflongnativeerror,refstringerrormsg,integererrormsgmax,refintegererrormsglen)library"odbc32.dll"
functionintegerSQLFreeStmt(longhstmt,integerOptions)library"odbc32.dll"
1、functionintegerSQLAllocEnv(reflongphenv)library"odbc32.dll"
参数:reflongphenv引用传递的long类型参数,保存该函数返回的OBDC环境的句柄。
存放在phenv中的值成为以后OBDCAPI函数调用的唯一标识符。
返回值:integer成功时,返回0,失败返回值小于0。
函数功能:获取ODBC环境句柄。
2、functionintegerSQLAllocStmt(longhdbc,reflonghstmt)library"odbc32.dll"
参数:longhdbcODBC环境的句柄。
Reflonghstmt保存SQL语句句柄。
返回值:integer,成功时,返回0,失败返回值小于0。
函数功能:获取SQL语句句柄。
3、functionintegerSQLConnect(longhstmt,refstringszdsn,integerdsnlen,refstringszuid,integeruidlen,
refstringszpwd,integerpwdlen)library"odbc32.dll"
参数:longhstmt,调用SQLAllocStmt()函数获取的句柄。
Refstringszdsn,ODBC数据源名。
Integerdsnlen,ODBC数据源名的长度。
Refstringszuid,用户帐号。
Integeruidlen,用户帐号长度。
Refstringszpwd,用户口令。
Refintegerpwdlen,用户口令长度。
返回值:integer,成功时,返回值大于0,失败返回值小于0。
函数功能:连接ODBC数据源,并返回连接句柄。
4、functionintegerSQLDisconnect(longhdbc)library"odbc32.dll"
参数:longhdbc连接句柄。
返回值:integer,成功时,返回0,失败返回值小于0。
函数功能:断开连接ODBC数据源。
5、 functionintegerSQLTables(longhstmt,refstringsztablequalifier,integertablequalifierlen,refstringszowner,integerowerlen,refstringszname,integernamelen,refstringsztype,integertypelen)library"odbc32.dll"
参数:longhstmtSQL语句句柄
refstringsztablequalifier表的qualifier名。
integertablequalifierlen表的qualifier名的长度。
refstringszowner表的所有者名。
integerowerlen表的所有者名长度。
refstringszname表名。
integernamelen表名长度。
refstringsztype表的类型名。
integertypelen表的类型名长度。
返回值:integer,成功时,返回0,失败返回值小于0。
函数功能:获取表的信息。
6、 functionintegerSQLColumns(longhstmt,refstringsztablequalifier,integertablequalifierlen,refstringszowner,integerowerlen,refstringszname,integernamelen,refstringsztype,integertypelen)library"odbc32.dll"
参数:longhstmtSQL语句句柄
refstringsztablequalifier表的qualifier名。
integertablequalifierlen表的qualifier名的长度。
refstringszowner表的所有者名。
integerowerlen表的所有者名长度。
refstringszname表名。
integernamelen表名长度。
refstringsztype表的类型名。
integertypelen表的类型名长度。
返回值:integer,成功时,返回0,失败返回值小于0。
函数功能:获取指定表的列信息。
7、FunctionintegerSQLBindCol(longhstmt,integercolnum,integerdatatype,refstringname,longmaxlen,
reflongactlen)library"odbc32.dll"
参数:longhstmtSQL语句句柄
integercolnum1-5(是否有资格,拥有者名字、类型、注释)。
integerdatatype1-8,12,99。
refstringname程序字符串变量。
longmaxlen可变。
reflongactlen可变。
返回值:integer,成功时,返回0,失败返回值小于0。
函数功能:绑定结果集。
8、functionintegerSQLFetch(longhstmt)library"odbc32.dll"
参数:longhstmtSQL语句句柄
返回值:integer,成功时,返回0,失败返回值小于0。
函数功能:绑定结果集。
9、 functionintegerSQLError(longlenv,longhdbc,longhstmt,refstringsqlstate,reflongnativeerror,refstringerrormsg,integererrormsgmax,refintegererrormsglen)library"odbc32.dll"
参数:longlenvODBC环境句柄
longhdbc连接句柄
longhstmtsql语句句柄
refstringsqlstate用于接受包含sql错误标识的字符串
reflongnativeerror用于接受包含sql错误标识码
refstringerrormsg用于接受包含sql错误信息的字符串
integererrormsgmax函数返回的最多字符数
refintegererrormsglen函数返回的实际字符数
返回值:integer,成功时,返回0,失败返回值小于0。
函数功能:返回调用ODBCAPI函数错误。
10、functionintegerSQLFreeEnv(longhenv)library"odbc32.dll"
参数:longlenvODBC环境句柄
返回值:integer,成功时,返回0,失败返回值小于0。
函数功能:释放ODBC环境句柄。
11、functionintegerSQLFreeStmt(longhstmt,integerOptions)library"odbc32.dll"
参数:longhstmtSQL语句句柄。
integerOptions相关选项。
返回值:integer,成功时,返回0,失败返回值小于0。
函数功能:释放SQL语句句柄。
12、 functionintegerSQLDataSources(longhenv,intfdirection,refstringszdsn,integercbdsnmax,refintegerpcbdsn,refstringszdescription,integercbdescriptionmax,refintegerpcbdescription)library"odbc32.dll"
参数:longhenvODBC数据源环境句柄。
intfdirection方向标志1(下一个),2(第一个),3(最后一个),4(前一个)
refstringszdsn数据源名称
integercbdsnmax数据源名称的最大长度
refintegerpcbdsn数据源名称的实际长度
refstringszdescription数据源描述名称
integercbdescriptionmax数据源描述字符串的最大长度
refintegerpcbdescription数据源描述字符串的实际长度
返回值:integer,成功时,返回0,失败返回值小于0。
函数功能:释放SQL语句句柄。
13、functionintegerSQLAllocConnect(longhenv,reflonghdbc)library"odbc32.dll"
参数:longhenvODBC数据源环境句柄。
reflonghdbc保存ODBC连接句柄。
返回值:integer,成功时,返回0,失败返回值小于0。
函数功能:获取ODBC连接句柄。
例程:
定义实例变量:
protected:
longhenv//sql环境句柄
longhstmt//sql语句句柄
longhdbc//sql连接句柄
定义句柄外部函数引用:
functionintegerSQLAllocEnv(reflongphenv)library"odbc32.dll"
functionintegerSQLFreeEnv(longhenv)library"odbc32.dll"
functionintegerSQLDataSources(longhenv,intfdirection,refstringszdsn,&
integercbdsnmax,refintegerpcbdsn,refstringszdescription,integercbdescriptionmax,refintegerpcbdescription)library"odbc32.dll"
functionintegerSQLAllocConnect(longhenv,reflonghdbc)library"odbc32.dll"
functionintegerSQLConnect(longhstmt,refstringszdsn,integerdsnlen,refstring
szuid,integeruidlen,refstringszpwd,integerpwdlen)library"odbc32.dll"
functionintegerSQLDisconnect(longhdbc)library"odbc32.dll"
functionintegerSQLAllocStmt(longhdbc,reflonghstmt)library"odbc32.dll"
functionintegerSQLTables(longhstmt,refstringsztablequalifier,integertablequalifierlen,refstringszowner,integerowerlen,refstringszname,integernamelen,
refstringsztype,integertypelen)library"odbc32.dll"
functionintegerSQLColumns(longhstmt,refstringsztablequalifier,integertablequalifierlen,refstringszowner,integerowerlen,refstringszname,integernamelen,
refstringsztype,integertypelen)library"odbc32.dll"
functionintegerSQLBindCol(longhstmt,integercolnum,integerdatatype,refstringname,longmaxlen,reflongactlen)library"odbc32.dll"
functionintegerSQLFetch(longhstmt)library"odbc32.dll"
functionintegerSQLError(longlenv,longhdbc,longhstmt,refstringsqlstate,reflongnativeerror,refstringerrormsg,integererrormsgmax,refintegererrormsglen)library"odbc32.dll"
functionintegerSQLFreeStmt(longhstmt,integerOptions)library"odbc32.dll"
声明一个函数wf_sqlerror()
代码如下:
stringls_sqlstate,ls_errormsg
integerli_errormsgmax,li_ret
longnativeerror
ls_errormsg=space(255)
ls_sqlstate=space(255)
li_ret=sqlerror(henv,hdbc,hstmt,ls_sqlstate,li_nativeerror,ls_errormsg,255,li_errormsgmax)
messagebox("ODBC:"+ls_sqlstate,ls_errormsg)
return
窗口的open事件,写入如下代码:
stringls_dsn,ls_description
integerli_direction,li_dsnmax,li_dsn_len
integerli_descriptionmax,li_description_len,li_retval
ls_dsn=space(255)
li_dsnmax=len(li_dsn)
ls_description=space(255)
li_descriptionmax=len(ls_description)
ifsqlallocenv(henv)=-1then
wf_sqlerror()
else
li_driection=1
dowhilesqldatasources(henv,li_direction,ls_dsn,li_dsnmax,li_dsn_len,ls_description,li_descriptionmax,li_description_len)=0
lb_datasources.additem(ls_dsn0
loop
endif
窗口的close事件中写入如下代码:
sqldisconnect(hdbc)
sqlfreeenv(henv)
在cb_connect按钮的cliked事件中写入如下的代码:
integerli_ret
stringls_dsn,ls_uid,ls_pwd
stringls_qualifer,ls_owner,ls_name,ls_type,ls_table
longll_len
ls_dsn=lb_datasources.selecteditem()
ls_uid=sle_uid.text
ls_pwd=sle_pwd.text
li_ret=sqlallocconnect(henv,hdbc)
ifli_ret<0then
wf_sqlerror()
else
li_ret=sqlconnect(hdbc,ls_dsn,len(ls_dsn),ls_uid,len(ls_uid),ls_pwd,len(ls_pwd))
ifli_ret<0then
wf_sqlerror()
else
li_ret=sqlallocstmt(hdbc,hstmt)
ifli_ret<0then
wf_sqlerror()
else
ls_type="’TABLE’,’VIEW’"
ifcbx_systemtables.checkedthen
ls_type=ls_type+",’SYSTEMTABLE’"
endif
li_ret=SQLTABLES(hstmt,ls_qualifier,len(ls_qualifier),ls_owner,len(ls_owner),ls_name,len(ls_name),ls_type,len(ls_type))
ifli_ret<0then
wf_sqlerror()
else
ls_table=space(255)
ll_len=255
sqlbincol(hstmt,3,1,ls_table,ll_len,ll_en)
lb_tables.setredraw(false)
dowhilesqlfetch(hstmt)=0
lb_tables.additem(ls_table)
loop
lb_tables.setredraw(true)
li_ret=sqlfreestmt(hstmt,0)
endif
endif
endif
endif
this.enabled=false
this.default=false
cbx_systemtables.enabled=false
在lb_datasources的selectionchanged事件中写入如下代码:
sle_uid.text=""
sle_pwd.text=""
sqldisconnect(hdbc)
cbx_systemtables.enabled=true
cb_connect.enabled=true
lb_columns.reset()
lb_tables.reset()
sle_uid.setfocus()
cb_connect.default=true
在lb_tables的selectionchanged事件中写入如下代码:
integerli_ret,li_len
stringls_qualifier,ls_owner,ls_name,ls_column,ls_colname,ls_type
longll_maxlen
lb_columns.reset()
ls_qualifier=space(255)
ls_owner=space(255)
ls_column=space(255)
ls_colname=space(255)
ls_type=space(255)
ls_name=space(255)
ls_name=this.selecteditem()
li_ret=sqlcolumns(hstmt,ls_quanlifier,0,ls_owner,0,ls_name,len(ls_name),ls_column,0)
ifli_ret<0then
wf_sqlerror()
else
ls_colname=space(255)
ls_type=space(255)
ll_maxlen=255
sqlbindcol(hstmt,4,1,ls_colname,ll_maxlen,ll_maxlen)
sqlbindcol(hstmt,6,1,ls_type,ll_maxlen,ll_maxlen)
lb_columns.setredraw(false)
dowhilesqlfetch(hstmt)=0
lb_columns.additem(ls_colname+"~t"+ls_type)
loop
lb_columns.setredraw(true)
li_ret=sqlfreestmt(hstmt,0)
endif
在按钮cb_exit的clicked事件中写入以下代码:
close(parent)
在应用对象的open事件中写入以下代码:
open(w_odbc_data_sources)
functionintegerSQLAllocEnv(reflongphenv)library"odbc32.dll"
functionintegerSQLFreeEnv(longhenv)library"odbc32.dll"
functionintegerSQLDataSources(longhenv,intfdirection,refstringszdsn,&
integercbdsnmax,refintegerpcbdsn,refstringszdescription,integercbdescriptionmax,refintegerpcbdescription)library"odbc32.dll"
functionintegerSQLAllocConnect(longhenv,reflonghdbc)library"odbc32.dll"
functionintegerSQLConnect(longhstmt,refstringszdsn,integerdsnlen,refstring
szuid,integeruidlen,refstringszpwd,integerpwdlen)library"odbc32.dll"
functionintegerSQLDisconnect(longhdbc)library"odbc32.dll"
functionintegerSQLAllocStmt(longhdbc,reflonghstmt)library"odbc32.dll"
functionintegerSQLTables(longhstmt,refstringsztablequalifier,integertablequalifierlen,refstringszowner,integerowerlen,refstringszname,integernamelen,
refstringsztype,integertypelen)library"odbc32.dll"
functionintegerSQLColumns(longhstmt,refstringsztablequalifier,integertablequalifierlen,refstringszowner,integerowerlen,refstringszname,integernamelen,
refstringsztype,integertypelen)library"odbc32.dll"
functionintegerSQLBindCol(longhstmt,integercolnum,integerdatatype,refstringname,longmaxlen,reflongactlen)library"odbc32.dll"
functionintegerSQLFetch(longhstmt)library"odbc32.dll"
functionintegerSQLError(longlenv,longhdbc,longhstmt,refstringsqlstate,reflongnativeerror,refstringerrormsg,integererrormsgmax,refintegererrormsglen)library"odbc32.dll"
functionintegerSQLFreeStmt(longhstmt,integerOptions)library"odbc32.dll"
1、functionintegerSQLAllocEnv(reflongphenv)library"odbc32.dll"
参数:reflongphenv引用传递的long类型参数,保存该函数返回的OBDC环境的句柄。
存放在phenv中的值成为以后OBDCAPI函数调用的唯一标识符。
返回值:integer成功时,返回0,失败返回值小于0。
函数功能:获取ODBC环境句柄。
2、functionintegerSQLAllocStmt(longhdbc,reflonghstmt)library"odbc32.dll"
参数:longhdbcODBC环境的句柄。
Reflonghstmt保存SQL语句句柄。
返回值:integer,成功时,返回0,失败返回值小于0。
函数功能:获取SQL语句句柄。
3、functionintegerSQLConnect(longhstmt,refstringszdsn,integerdsnlen,refstringszuid,integeruidlen,
refstringszpwd,integerpwdlen)library"odbc32.dll"
参数:longhstmt,调用SQLAllocStmt()函数获取的句柄。
Refstringszdsn,ODBC数据源名。
Integerdsnlen,ODBC数据源名的长度。
Refstringszuid,用户帐号。
Integeruidlen,用户帐号长度。
Refstringszpwd,用户口令。
Refintegerpwdlen,用户口令长度。
返回值:integer,成功时,返回值大于0,失败返回值小于0。
函数功能:连接ODBC数据源,并返回连接句柄。
4、functionintegerSQLDisconnect(longhdbc)library"odbc32.dll"
参数:longhdbc连接句柄。
返回值:integer,成功时,返回0,失败返回值小于0。
函数功能:断开连接ODBC数据源。
5、 functionintegerSQLTables(longhstmt,refstringsztablequalifier,integertablequalifierlen,refstringszowner,integerowerlen,refstringszname,integernamelen,refstringsztype,integertypelen)library"odbc32.dll"
参数:longhstmtSQL语句句柄
refstringsztablequalifier表的qualifier名。
integertablequalifierlen表的qualifier名的长度。
refstringszowner表的所有者名。
integerowerlen表的所有者名长度。
refstringszname表名。
integernamelen表名长度。
refstringsztype表的类型名。
integertypelen表的类型名长度。
返回值:integer,成功时,返回0,失败返回值小于0。
函数功能:获取表的信息。
6、 functionintegerSQLColumns(longhstmt,refstringsztablequalifier,integertablequalifierlen,refstringszowner,integerowerlen,refstringszname,integernamelen,refstringsztype,integertypelen)library"odbc32.dll"
参数:longhstmtSQL语句句柄
refstringsztablequalifier表的qualifier名。
integertablequalifierlen表的qualifier名的长度。
refstringszowner表的所有者名。
integerowerlen表的所有者名长度。
refstringszname表名。
integernamelen表名长度。
refstringsztype表的类型名。
integertypelen表的类型名长度。
返回值:integer,成功时,返回0,失败返回值小于0。
函数功能:获取指定表的列信息。
7、FunctionintegerSQLBindCol(longhstmt,integercolnum,integerdatatype,refstringname,longmaxlen,
reflongactlen)library"odbc32.dll"
参数:longhstmtSQL语句句柄
integercolnum1-5(是否有资格,拥有者名字、类型、注释)。
integerdatatype1-8,12,99。
refstringname程序字符串变量。
longmaxlen可变。
reflongactlen可变。
返回值:integer,成功时,返回0,失败返回值小于0。
函数功能:绑定结果集。
8、functionintegerSQLFetch(longhstmt)library"odbc32.dll"
参数:longhstmtSQL语句句柄
返回值:integer,成功时,返回0,失败返回值小于0。
函数功能:绑定结果集。
9、 functionintegerSQLError(longlenv,longhdbc,longhstmt,refstringsqlstate,reflongnativeerror,refstringerrormsg,integererrormsgmax,refintegererrormsglen)library"odbc32.dll"
参数:longlenvODBC环境句柄
longhdbc连接句柄
longhstmtsql语句句柄
refstringsqlstate用于接受包含sql错误标识的字符串
reflongnativeerror用于接受包含sql错误标识码
refstringerrormsg用于接受包含sql错误信息的字符串
integererrormsgmax函数返回的最多字符数
refintegererrormsglen函数返回的实际字符数
返回值:integer,成功时,返回0,失败返回值小于0。
函数功能:返回调用ODBCAPI函数错误。
10、functionintegerSQLFreeEnv(longhenv)library"odbc32.dll"
参数:longlenvODBC环境句柄
返回值:integer,成功时,返回0,失败返回值小于0。
函数功能:释放ODBC环境句柄。
11、functionintegerSQLFreeStmt(longhstmt,integerOptions)library"odbc32.dll"
参数:longhstmtSQL语句句柄。
integerOptions相关选项。
返回值:integer,成功时,返回0,失败返回值小于0。
函数功能:释放SQL语句句柄。
12、 functionintegerSQLDataSources(longhenv,intfdirection,refstringszdsn,integercbdsnmax,refintegerpcbdsn,refstringszdescription,integercbdescriptionmax,refintegerpcbdescription)library"odbc32.dll"
参数:longhenvODBC数据源环境句柄。
intfdirection方向标志1(下一个),2(第一个),3(最后一个),4(前一个)
refstringszdsn数据源名称
integercbdsnmax数据源名称的最大长度
refintegerpcbdsn数据源名称的实际长度
refstringszdescription数据源描述名称
integercbdescriptionmax数据源描述字符串的最大长度
refintegerpcbdescription数据源描述字符串的实际长度
返回值:integer,成功时,返回0,失败返回值小于0。
函数功能:释放SQL语句句柄。
13、functionintegerSQLAllocConnect(longhenv,reflonghdbc)library"odbc32.dll"
参数:longhenvODBC数据源环境句柄。
reflonghdbc保存ODBC连接句柄。
返回值:integer,成功时,返回0,失败返回值小于0。
函数功能:获取ODBC连接句柄。
例程:
定义实例变量:
protected:
longhenv//sql环境句柄
longhstmt//sql语句句柄
longhdbc//sql连接句柄
定义句柄外部函数引用:
functionintegerSQLAllocEnv(reflongphenv)library"odbc32.dll"
functionintegerSQLFreeEnv(longhenv)library"odbc32.dll"
functionintegerSQLDataSources(longhenv,intfdirection,refstringszdsn,&
integercbdsnmax,refintegerpcbdsn,refstringszdescription,integercbdescriptionmax,refintegerpcbdescription)library"odbc32.dll"
functionintegerSQLAllocConnect(longhenv,reflonghdbc)library"odbc32.dll"
functionintegerSQLConnect(longhstmt,refstringszdsn,integerdsnlen,refstring
szuid,integeruidlen,refstringszpwd,integerpwdlen)library"odbc32.dll"
functionintegerSQLDisconnect(longhdbc)library"odbc32.dll"
functionintegerSQLAllocStmt(longhdbc,reflonghstmt)library"odbc32.dll"
functionintegerSQLTables(longhstmt,refstringsztablequalifier,integertablequalifierlen,refstringszowner,integerowerlen,refstringszname,integernamelen,
refstringsztype,integertypelen)library"odbc32.dll"
functionintegerSQLColumns(longhstmt,refstringsztablequalifier,integertablequalifierlen,refstringszowner,integerowerlen,refstringszname,integernamelen,
refstringsztype,integertypelen)library"odbc32.dll"
functionintegerSQLBindCol(longhstmt,integercolnum,integerdatatype,refstringname,longmaxlen,reflongactlen)library"odbc32.dll"
functionintegerSQLFetch(longhstmt)library"odbc32.dll"
functionintegerSQLError(longlenv,longhdbc,longhstmt,refstringsqlstate,reflongnativeerror,refstringerrormsg,integererrormsgmax,refintegererrormsglen)library"odbc32.dll"
functionintegerSQLFreeStmt(longhstmt,integerOptions)library"odbc32.dll"
声明一个函数wf_sqlerror()
代码如下:
stringls_sqlstate,ls_errormsg
integerli_errormsgmax,li_ret
longnativeerror
ls_errormsg=space(255)
ls_sqlstate=space(255)
li_ret=sqlerror(henv,hdbc,hstmt,ls_sqlstate,li_nativeerror,ls_errormsg,255,li_errormsgmax)
messagebox("ODBC:"+ls_sqlstate,ls_errormsg)
return
窗口的open事件,写入如下代码:
stringls_dsn,ls_description
integerli_direction,li_dsnmax,li_dsn_len
integerli_descriptionmax,li_description_len,li_retval
ls_dsn=space(255)
li_dsnmax=len(li_dsn)
ls_description=space(255)
li_descriptionmax=len(ls_description)
ifsqlallocenv(henv)=-1then
wf_sqlerror()
else
li_driection=1
dowhilesqldatasources(henv,li_direction,ls_dsn,li_dsnmax,li_dsn_len,ls_description,li_descriptionmax,li_description_len)=0
lb_datasources.additem(ls_dsn0
loop
endif
窗口的close事件中写入如下代码:
sqldisconnect(hdbc)
sqlfreeenv(henv)
在cb_connect按钮的cliked事件中写入如下的代码:
integerli_ret
stringls_dsn,ls_uid,ls_pwd
stringls_qualifer,ls_owner,ls_name,ls_type,ls_table
longll_len
ls_dsn=lb_datasources.selecteditem()
ls_uid=sle_uid.text
ls_pwd=sle_pwd.text
li_ret=sqlallocconnect(henv,hdbc)
ifli_ret<0then
wf_sqlerror()
else
li_ret=sqlconnect(hdbc,ls_dsn,len(ls_dsn),ls_uid,len(ls_uid),ls_pwd,len(ls_pwd))
ifli_ret<0then
wf_sqlerror()
else
li_ret=sqlallocstmt(hdbc,hstmt)
ifli_ret<0then
wf_sqlerror()
else
ls_type="’TABLE’,’VIEW’"
ifcbx_systemtables.checkedthen
ls_type=ls_type+",’SYSTEMTABLE’"
endif
li_ret=SQLTABLES(hstmt,ls_qualifier,len(ls_qualifier),ls_owner,len(ls_owner),ls_name,len(ls_name),ls_type,len(ls_type))
ifli_ret<0then
wf_sqlerror()
else
ls_table=space(255)
ll_len=255
sqlbincol(hstmt,3,1,ls_table,ll_len,ll_en)
lb_tables.setredraw(false)
dowhilesqlfetch(hstmt)=0
lb_tables.additem(ls_table)
loop
lb_tables.setredraw(true)
li_ret=sqlfreestmt(hstmt,0)
endif
endif
endif
endif
this.enabled=false
this.default=false
cbx_systemtables.enabled=false
在lb_datasources的selectionchanged事件中写入如下代码:
sle_uid.text=""
sle_pwd.text=""
sqldisconnect(hdbc)
cbx_systemtables.enabled=true
cb_connect.enabled=true
lb_columns.reset()
lb_tables.reset()
sle_uid.setfocus()
cb_connect.default=true
在lb_tables的selectionchanged事件中写入如下代码:
integerli_ret,li_len
stringls_qualifier,ls_owner,ls_name,ls_column,ls_colname,ls_type
longll_maxlen
lb_columns.reset()
ls_qualifier=space(255)
ls_owner=space(255)
ls_column=space(255)
ls_colname=space(255)
ls_type=space(255)
ls_name=space(255)
ls_name=this.selecteditem()
li_ret=sqlcolumns(hstmt,ls_quanlifier,0,ls_owner,0,ls_name,len(ls_name),ls_column,0)
ifli_ret<0then
wf_sqlerror()
else
ls_colname=space(255)
ls_type=space(255)
ll_maxlen=255
sqlbindcol(hstmt,4,1,ls_colname,ll_maxlen,ll_maxlen)
sqlbindcol(hstmt,6,1,ls_type,ll_maxlen,ll_maxlen)
lb_columns.setredraw(false)
dowhilesqlfetch(hstmt)=0
lb_columns.additem(ls_colname+"~t"+ls_type)
loop
lb_columns.setredraw(true)
li_ret=sqlfreestmt(hstmt,0)
endif
在按钮cb_exit的clicked事件中写入以下代码:
close(parent)
在应用对象的open事件中写入以下代码:
open(w_odbc_data_sources)