ODBC SQLSetConnectAttr
作者:互联网
{
SQLSetConnectAttr
函数定义:
用法类似于SQLSetEnvAttr,该函数是设置连接的各项属性用的
SQLRETURN SQLSetConnectAttr(
SQLHDBC ConnectionHandle,
SQLINTEGER Attribute,
SQLPOINTER ValuePtr,
SQLINTEGER StringLength);
参数详解:
ConnectionHandle :输入变量
连接的句柄
Attribute :输入变量 ValuePtr :输入变量
Attribute
ValuePtr contents
SQL_ATTR_ACCESS_MODE
(ODBC 1.0)
SQL_MODE_READ_ONLY 设置为只读连接,update类似的操作都是不能在他下属的stmt中执行的,只能支持查询语句。
SQL_MODE_READ_WRITE 默认值,可读可写
SQL_ATTR_ASYNC_ENABLE
(ODBC 3.0)
该连接下属的stmthandle所执行的语句可以异步处理
SQL_ASYNC_ENABLE_OFF = Off 默认值关闭异步处理
SQL_ASYNC_ENABLE_ON = On 开启异步处理
SQL_ATTR_AUTO_IPD
(ODBC 3.0)
不好意思说实话没搞懂这个是啥,如果有知道的大佬麻烦留言一下,我加上去帮助到更多的人
A read-only SQLUINTEGER value that specifies whether automatic population of the IPD after a call to SQLPrepare is supported:
SQL_TRUE = Automatic population of the IPD after a call to SQLPrepare is supported by the driver.
SQL_FALSE = Automatic population of the IPD after a call to SQLPrepare is not supported by the driver. Servers that do not support prepared statements will not be able to populate the IPD automatically.
If SQL_TRUE is returned for the SQL_ATTR_AUTO_IPD connection attribute, the statement attribute SQL_ATTR_ENABLE_AUTO_IPD can be set to turn automatic population of the IPD on or off. If SQL_ATTR_AUTO_IPD is SQL_FALSE, SQL_ATTR_ENABLE_AUTO_IPD cannot be set to SQL_TRUE. The default value of SQL_ATTR_ENABLE_AUTO_IPD is equal to the value of SQL_ATTR_AUTO_IPD.
This connection attribute can be returned by SQLGetConnectAttr but cannot be set by SQLSetConnectAttr.
SQL_ATTR_AUTOCOMMIT
(ODBC 1.0)
设置是否自动提交:
SQL_AUTOCOMMIT_OFF 关闭自动提交,可以手动commit或者rollback
SQL_AUTOCOMMIT_ON 自动提交开启,一但执行会自动commit
SQL_ATTR_CONNECTION_DEAD
(ODBC 3.5)
终止连接
SQL_CD_TRUE关闭连接
SQL_CD_FALSE保持连接
SQL_ATTR_CONNECTION_TIMEOUT
(ODBC 3.0)
除了查询与登录外的操作超时时长,单位为秒,整型。默认为0秒,意思不是执行sql语句立马超时而是不会超时,一直等待语句完成才向后执行
SQL_ATTR_CURRENT_CATALOG
(ODBC 2.0)
一个包含database名称的字符串指针。
SQL_ATTR_LOGIN_TIMEOUT
(ODBC 1.0)
设置登录超时时长,同SQL_ATTR_CONNECTION_TIMEOUT
SQL_ATTR_METADATA_ID
(ODBC 3.0)
设定连接CATALOG函数参数
SQL_TRUE设置启用标识符ID
If SQL_FALSE设置不启用标识符ID
SQL_ATTR_ODBC_CURSORS
(ODBC 2.0)
设置连接游标参数
SQL_CUR_USE_IF_NEEDED 当必要时采用游标
SQL_CUR_USE_ODBC 使用OBDC游标
SQL_CUR_USE_DRIVER使用驱动游标
SQL_ATTR_PACKET_SIZE
(ODBC 2.0)
设置连接包大小,格式为(void*)(整型数字)
SQL_ATTR_QUIET_MODE
(ODBC 2.0)
设置对话框,当窗口句柄为空的时候,设置为不显示对话框
SQL_ATTR_TRACE
(ODBC 1.0)
设置连接是否启用跟踪
SQL_OPT_TRACE_OFF 默认,不跟踪
SQL_OPT_TRACE_ON 跟踪会将跟踪记录写入root下的 SQL.LOG
SQL_ATTR_TRACEFILE
(ODBC 1.0)
设置跟踪文件路径,参数为一个 null-terminated 字符串。
SQL_ATTR_TRANSLATE_LIB
(ODBC 1.0)
设置连接转化字符集的动态库路径,参数为一个 null-terminated 字符串
SQL_ATTR_TRANSLATE_OPTION
(ODBC 1.0)
设置连接转化字符集的参数,详情见 Translation DLLs.
SQL_ATTR_TXN_ISOLATION
(ODBC 1.0)
设置连接事务隔离级别
详情见 Transaction Isolation Levels.
StringLength :输入变量
如果ValuePtr 为字符串,填入字符串长度或者 SQL_NTS.
如果是二进制缓存填入 SQL_LEN_BINARY_ATTR(length) 的结果If ValuePtr is a pointer to a 不是上述两个填入SQL_IS_POINTER.
如果是边长的数组根据情况填入SQL_IS_INTEGER 或者SQL_IS_UINTEGER
返回值:
返回值有四种:SQL_SUCCESS, SQL_SUCCESS_WITH_INFO, SQL_INVALID_HANDLE, or SQL_ERROR.
查看详细错误信息可调用SQLGetDiagRec 函数(之后章节讲解)。
用法:
1. 设定建立数据库连接超时(设定5秒超时,连接正常)
rs = SQLSetConnectAttr(hdbc,SQL_ATTR_LOGIN_TIMEOUT,(void*)5,0);
rs_c = SQLConnect(hdbc,(UCHAR*)szDSN,SQL_NTS,(UCHAR*)szUID ,SQL_NTS,(UCHAR*)szAuthStr,SQL_NTS);
2. 设定建立数据库连接(只读)
rs_c = SQLConnect(hdbc,(UCHAR*)szDSN,SQL_NTS,(UCHAR*)szUID ,SQL_NTS,(UCHAR*)szAuthStr,SQL_NTS);
rs = SQLSetConnectAttr(hdbc,SQL_ATTR_ACCESS_MODE,(void*)SQL_MODE_READ_ONLY,0);
3. 设定连接异步属性(关闭异步)
rs_c = SQLConnect(hdbc,(UCHAR*)szDSN,SQL_NTS,(UCHAR*)szUID ,SQL_NTS,(UCHAR*)szAuthStr,SQL_NTS);
rs = SQLSetConnectAttr(hdbc,SQL_ATTR_ASYNC_ENABLE,(void*)SQL_ASYNC_ENABLE_OFF,0);
4. 设定连接自动提交属性(自动提交)
rs_c = SQLConnect(hdbc,(UCHAR*)szDSN,SQL_NTS,(UCHAR*)szUID ,SQL_NTS,(UCHAR*)szAuthStr,SQL_NTS);
rs = SQLSetConnectAttr(hdbc,SQL_ATTR_AUTOCOMMIT,(void*)SQL_AUTOCOMMIT_ON,0);
5. 设定连接请求超时时间(设置 请求超时)
rs_c = SQLConnect(hdbc,(UCHAR*)szDSN,SQL_NTS,(UCHAR*)szUID ,SQL_NTS,(UCHAR*)szAuthStr,SQL_NTS);
rs = SQLSetConnectAttr(hdbc,SQL_ATTR_CONNECTION_TIMEOUT,(void*)3600,0);
6. 设定连接当前库(设置 当前库)
rs_c = SQLConnect(hdbc,(UCHAR*)szDSN,SQL_NTS,(UCHAR*)szUID ,SQL_NTS,(UCHAR*)szAuthStr,SQL_NTS);
rs = SQLSetConnectAttr(hdbc,SQL_ATTR_CURRENT_CATALOG,(void*)"SYSTEM",SQL_NTS);
7. 设定连接CATALOG函数参数(设置启用标识符)
rs_c = SQLConnect(hdbc,(UCHAR*)szDSN,SQL_NTS,(UCHAR*)szUID ,SQL_NTS,(UCHAR*)szAuthStr,SQL_NTS);
rs = SQLSetConnectAttr(hdbc,SQL_ATTR_METADATA_ID,(void*)SQL_FALSE,0);
8. 设定连接游标参数(设置启用游标据需要)
rs = SQLSetConnectAttr(hdbc,SQL_ATTR_ODBC_CURSORS,(void*)SQL_CUR_USE_IF_NEEDED,0);
rs_c = SQLConnect(hdbc,(UCHAR*)szDSN,SQL_NTS,(UCHAR*)szUID ,SQL_NTS,(UCHAR*)szAuthStr,SQL_NTS);
9. 设定连接游标参数(设置启用ODBC游标)
rs = SQLSetConnectAttr(hdbc,SQL_ATTR_ODBC_CURSORS,(void*)SQL_CUR_USE_ODBC,0);
rs_c = SQLConnect(hdbc,(UCHAR*)szDSN,SQL_NTS,(UCHAR*)szUID ,SQL_NTS,(UCHAR*)szAuthStr,SQL_NTS);
10. 设定连接游标参数(设置启用驱动游标)
rs = SQLSetConnectAttr(hdbc,SQL_ATTR_ODBC_CURSORS,(void*)SQL_CUR_USE_DRIVER,0);
rs_c = SQLConnect(hdbc,(UCHAR*)szDSN,SQL_NTS,(UCHAR*)szUID ,SQL_NTS,(UCHAR*)szAuthStr,SQL_NTS);
11. 设定连接包大小(设置包大小)
rs = SQLSetConnectAttr(hdbc,SQL_ATTR_PACKET_SIZE,(void*)2000,0);
rs_c = SQLConnect(hdbc,(UCHAR*)szDSN,SQL_NTS,(UCHAR*)szUID ,SQL_NTS,(UCHAR*)szAuthStr,SQL_NTS);
12. 设定连接对话框(设置空指针句柄)
rs_c = SQLConnect(hdbc,(UCHAR*)szDSN,SQL_NTS,(UCHAR*)szUID ,SQL_NTS,(UCHAR*)szAuthStr,SQL_NTS);
rs = SQLSetConnectAttr(hdbc,SQL_ATTR_QUIET_MODE,(void*)NULL,0);
13. 设定连接包对话框(设置句柄)
rs_c = SQLConnect(hdbc,(UCHAR*)szDSN,SQL_NTS,(UCHAR*)szUID ,SQL_NTS,(UCHAR*)szAuthStr,SQL_NTS);
rs = SQLSetConnectAttr(hdbc,SQL_ATTR_QUIET_MODE,(void*)ht,0);
14. 设定连接不启用跟踪(设置不启用)
rs_c = SQLConnect(hdbc,(UCHAR*)szDSN,SQL_NTS,(UCHAR*)szUID ,SQL_NTS,(UCHAR*)szAuthStr,SQL_NTS);
rs = SQLSetConnectAttr(hdbc,SQL_ATTR_TRACE,(void*)SQL_OPT_TRACE_OFF,0);
15. 设定连接启用跟踪(设置启用)
rs_c = SQLConnect(hdbc,(UCHAR*)szDSN,SQL_NTS,(UCHAR*)szUID ,SQL_NTS,(UCHAR*)szAuthStr,SQL_NTS);
rs = SQLSetConnectAttr(hdbc,SQL_ATTR_TRACE,(void*)SQL_OPT_TRACE_ON,0);
16. 设定连接跟踪路径(设置路径)
rs_c = SQLConnect(hdbc,(UCHAR*)szDSN,SQL_NTS,(UCHAR*)szUID ,SQL_NTS,(UCHAR*)szAuthStr,SQL_NTS);
rs = SQLSetConnectAttr(hdbc,SQL_ATTR_TRACEFILE,(void*)"PATH",SQL_NTS);
17. 设置连接转化字符集的动态库路径
rs_c = SQLConnect(hdbc,(UCHAR*)szDSN,SQL_NTS,(UCHAR*)szUID ,SQL_NTS,(UCHAR*)szAuthStr,SQL_NTS);
rs = SQLSetConnectAttr(hdbc,SQL_ATTR_TRANSLATE_LIB,(void*)"PATH_DLL_NAME",SQL_NTS);
18. 设置连接转化字符集的参数
rs_c = SQLConnect(hdbc,(UCHAR*)szDSN,SQL_NTS,(UCHAR*)szUID ,SQL_NTS,(UCHAR*)szAuthStr,SQL_NTS);
rs = SQLSetConnectAttr(hdbc,SQL_ATTR_TRANSLATE_OPTION,(void*)1,0);
19. 设置连接事务隔离级别(读未提交)
rs_c = SQLConnect(hdbc,(UCHAR*)szDSN,SQL_NTS,(UCHAR*)szUID ,SQL_NTS,(UCHAR*)szAuthStr,SQL_NTS);
rs = SQLSetConnectAttr(hdbc,SQL_ATTR_TXN_ISOLATION,(void*)1,0);
20. 设置连接事务隔离级别(读已提交)
rs_c = SQLConnect(hdbc,(UCHAR*)szDSN,SQL_NTS,(UCHAR*)szUID ,SQL_NTS,(UCHAR*)szAuthStr,SQL_NTS);
rs = SQLSetConnectAttr(hdbc,SQL_ATTR_TXN_ISOLATION,(void*)2,0);
21. 设置连接事务隔离级别(可重复读)
rs_c = SQLConnect(hdbc,(UCHAR*)szDSN,SQL_NTS,(UCHAR*)szUID ,SQL_NTS,(UCHAR*)szAuthStr,SQL_NTS);
rs = SQLSetConnectAttr(hdbc,SQL_ATTR_TXN_ISOLATION,(void*)4,0);
22. 设置连接事务隔离级别(串行化)
rs_c = SQLConnect(hdbc,(UCHAR*)szDSN,SQL_NTS,(UCHAR*)szUID ,SQL_NTS,(UCHAR*)szAuthStr,SQL_NTS);
rs = SQLSetConnectAttr(hdbc,SQL_ATTR_TXN_ISOLATION,(void*)8,0);
————————————————
版权声明:本文为CSDN博主「tanshoudong0049」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/tanshoudong0049/article/details/74562827
}
标签:ATTR,rs,UCHAR,NTS,ODBC,SQLSetConnectAttr,SQL,hdbc 来源: https://www.cnblogs.com/YZFHKMS-X/p/14789491.html