仓酷云

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 955|回复: 7
打印 上一主题 下一主题

[学习教程] MSSQL网站制作之ODBC API经常使用函数解释

[复制链接]
小妖女 该用户已被删除
跳转到指定楼层
楼主
发表于 2015-1-16 22:34:45 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
MySQL是一个开放源码的小型关联式数据库管理系统,开发者为瑞典MySQLAB公司。目前MySQL被广泛地应用在Internet上的中小型网站中。odbc|函数
ODBCAPI经常使用函数解释
记得kony已经在我的这个坛子上转过一个帖子,注释利用ODBC数据源来毗连数据库举行数据库操纵速率慢的缘故原由,同时谁人帖子也提出了进步ODBC数据源毗连数据库举行数据库操纵速率的两个举措,一个是使用VisiualBasic中的RDO组件,一个就是间接挪用odbcapi函数举行相干数据库操纵,应对应过这里的弟弟mm们写点关于ODBCAPI函数方面的东东,以是只能赶鸭子上架了;
以下为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毗连句柄。
-:)下面总算将列出的几个ODBCAPI函数形貌完,等偶然间分离详细例子来讲明怎样使用ODBCAPI函数会见数据库了-:)
例程:
界说实例变量:
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)

php本地模拟的prepare底层就是mysql_real_escape_string,所以必须得用mysql_set_character_set去设置mysql->charset,否则就存在字符集问题。
柔情似水 该用户已被删除
沙发
发表于 2015-1-28 09:01:53 | 只看该作者
我是一个ERP初学者,对于前台运用基本熟悉,但对于后台SQLServer的运用一点也不懂,特想学习下相关资料。至少懂得一些基本的运用。希望各位能给于建议,小弟再谢过!
第二个灵魂 该用户已被删除
板凳
发表于 2015-2-5 14:36:37 | 只看该作者
对一张百万级别的表建游标,同时又没有什么过滤条件,取得游标效率是如果直接SQL查询百万条数据;如果再对每条记录做处理,耗时将更长。
灵魂腐蚀 该用户已被删除
地板
发表于 2015-2-12 07:02:26 | 只看该作者
只能告诉你,学好数据库语言和原理,多见识几种数据库软件,比一棵树上吊死要好。
小魔女 该用户已被删除
5#
发表于 2015-3-2 23:59:34 | 只看该作者
两个月啃那本sqlserver2005技术内部-存储引擎,花了几个月啃四本书
谁可相欹 该用户已被删除
6#
发表于 2015-3-11 07:44:24 | 只看该作者
多加的系统视图和实时系统信息这些东西对DBA挑优非常有帮助,但是感觉粒度还是不太细。
不帅 该用户已被删除
7#
发表于 2015-3-17 23:10:33 | 只看该作者
groupby子句可以将查询结果分组,并返回行的汇总信息Oracle按照groupby子句中指定的表达式的值分组查询结果。
再现理想 该用户已被删除
8#
发表于 2015-3-25 07:29:35 | 只看该作者
另一个是把SQL语句写到服务器端,就是所谓的SP(存储过程);
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|仓酷云 鄂ICP备14007578号-2

GMT+8, 2024-5-17 23:39

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表