Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
F
freeswitch
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
张华
freeswitch
Commits
29daaa07
提交
29daaa07
authored
1月 10, 2011
作者:
Anthony Minessale
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
FS-2960
上级
3f1a7dc5
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
84 行增加
和
33 行删除
+84
-33
switch_odbc.h
src/include/switch_odbc.h
+3
-0
switch_odbc.c
src/switch_odbc.c
+81
-33
没有找到文件。
src/include/switch_odbc.h
浏览文件 @
29daaa07
...
...
@@ -34,6 +34,8 @@
#include <switch.h>
#define DEFAULT_ODBC_RETRIES 120
SWITCH_BEGIN_EXTERN_C
struct
switch_odbc_handle
;
typedef
void
*
switch_odbc_statement_handle_t
;
...
...
@@ -50,6 +52,7 @@ typedef enum {
}
switch_odbc_status_t
;
SWITCH_DECLARE
(
switch_odbc_handle_t
*
)
switch_odbc_handle_new
(
const
char
*
dsn
,
const
char
*
username
,
const
char
*
password
);
SWITCH_DECLARE
(
void
)
switch_odbc_set_num_retries
(
switch_odbc_handle_t
*
handle
,
int
num_retries
);
SWITCH_DECLARE
(
switch_odbc_status_t
)
switch_odbc_handle_disconnect
(
switch_odbc_handle_t
*
handle
);
SWITCH_DECLARE
(
switch_odbc_status_t
)
switch_odbc_handle_connect
(
switch_odbc_handle_t
*
handle
);
SWITCH_DECLARE
(
void
)
switch_odbc_handle_destroy
(
switch_odbc_handle_t
**
handlep
);
...
...
src/switch_odbc.c
浏览文件 @
29daaa07
...
...
@@ -57,6 +57,7 @@ struct switch_odbc_handle {
char
odbc_driver
[
256
];
BOOL
is_firebird
;
int
affected_rows
;
int
num_retries
;
};
#endif
...
...
@@ -90,6 +91,7 @@ SWITCH_DECLARE(switch_odbc_handle_t *) switch_odbc_handle_new(const char *dsn, c
new_handle
->
env
=
SQL_NULL_HANDLE
;
new_handle
->
state
=
SWITCH_ODBC_STATE_INIT
;
new_handle
->
affected_rows
=
0
;
new_handle
->
num_retries
=
DEFAULT_ODBC_RETRIES
;
return
new_handle
;
...
...
@@ -104,6 +106,15 @@ SWITCH_DECLARE(switch_odbc_handle_t *) switch_odbc_handle_new(const char *dsn, c
return
NULL
;
}
SWITCH_DECLARE
(
void
)
switch_odbc_set_num_retries
(
switch_odbc_handle_t
*
handle
,
int
num_retries
)
{
#ifdef SWITCH_HAVE_ODBC
if
(
handle
)
{
handle
->
num_retries
=
num_retries
;
}
#endif
}
SWITCH_DECLARE
(
switch_odbc_status_t
)
switch_odbc_handle_disconnect
(
switch_odbc_handle_t
*
handle
)
{
#ifdef SWITCH_HAVE_ODBC
...
...
@@ -133,6 +144,53 @@ SWITCH_DECLARE(switch_odbc_status_t) switch_odbc_handle_disconnect(switch_odbc_h
#ifdef SWITCH_HAVE_ODBC
static
switch_odbc_status_t
init_odbc_handles
(
switch_odbc_handle_t
*
handle
,
switch_bool_t
do_reinit
)
{
int
result
;
if
(
!
handle
)
{
return
SWITCH_ODBC_FAIL
;
}
/* if handle is already initialized, and we're supposed to reinit - free old handle first */
if
(
do_reinit
==
SWITCH_TRUE
&&
handle
->
env
!=
SQL_NULL_HANDLE
)
{
SQLFreeHandle
(
SQL_HANDLE_DBC
,
handle
->
con
);
SQLFreeHandle
(
SQL_HANDLE_ENV
,
handle
->
env
);
handle
->
env
=
SQL_NULL_HANDLE
;
}
if
(
handle
->
env
==
SQL_NULL_HANDLE
)
{
result
=
SQLAllocHandle
(
SQL_HANDLE_ENV
,
SQL_NULL_HANDLE
,
&
handle
->
env
);
if
((
result
!=
SQL_SUCCESS
)
&&
(
result
!=
SQL_SUCCESS_WITH_INFO
))
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_ERROR
,
"Error AllocHandle
\n
"
);
handle
->
env
=
SQL_NULL_HANDLE
;
/* Reset handle value, just in case */
return
SWITCH_ODBC_FAIL
;
}
result
=
SQLSetEnvAttr
(
handle
->
env
,
SQL_ATTR_ODBC_VERSION
,
(
void
*
)
SQL_OV_ODBC3
,
0
);
if
((
result
!=
SQL_SUCCESS
)
&&
(
result
!=
SQL_SUCCESS_WITH_INFO
))
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_ERROR
,
"Error SetEnv
\n
"
);
SQLFreeHandle
(
SQL_HANDLE_ENV
,
handle
->
env
);
handle
->
env
=
SQL_NULL_HANDLE
;
/* Reset handle value after it's freed */
return
SWITCH_ODBC_FAIL
;
}
result
=
SQLAllocHandle
(
SQL_HANDLE_DBC
,
handle
->
env
,
&
handle
->
con
);
if
((
result
!=
SQL_SUCCESS
)
&&
(
result
!=
SQL_SUCCESS_WITH_INFO
))
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_ERROR
,
"Error AllocHDB %d
\n
"
,
result
);
SQLFreeHandle
(
SQL_HANDLE_ENV
,
handle
->
env
);
handle
->
env
=
SQL_NULL_HANDLE
;
/* Reset handle value after it's freed */
return
SWITCH_ODBC_FAIL
;
}
SQLSetConnectAttr
(
handle
->
con
,
SQL_LOGIN_TIMEOUT
,
(
SQLPOINTER
*
)
10
,
0
);
}
return
SWITCH_ODBC_SUCCESS
;
}
static
int
db_is_up
(
switch_odbc_handle_t
*
handle
)
{
int
ret
=
0
;
...
...
@@ -143,12 +201,18 @@ static int db_is_up(switch_odbc_handle_t *handle)
switch_odbc_status_t
recon
=
0
;
char
*
err_str
=
NULL
;
SQLCHAR
sql
[
255
]
=
""
;
int
max_tries
=
120
;
int
max_tries
=
DEFAULT_ODBC_RETRIES
;
int
code
=
0
;
SQLRETURN
rc
;
SQLSMALLINT
nresultcols
;
if
(
handle
)
{
max_tries
=
handle
->
num_retries
;
if
(
max_tries
<
1
)
max_tries
=
DEFAULT_ODBC_RETRIES
;
}
top
:
if
(
!
handle
)
{
...
...
@@ -199,6 +263,13 @@ static int db_is_up(switch_odbc_handle_t *handle)
error
:
err_str
=
switch_odbc_handle_get_error
(
handle
,
stmt
);
/* Make sure to free the handle before we try to reconnect */
if
(
stmt
)
{
SQLFreeHandle
(
SQL_HANDLE_STMT
,
stmt
);
stmt
=
NULL
;
}
recon
=
switch_odbc_handle_connect
(
handle
);
max_tries
--
;
...
...
@@ -228,11 +299,6 @@ static int db_is_up(switch_odbc_handle_t *handle)
goto
done
;
}
if
(
stmt
)
{
SQLFreeHandle
(
SQL_HANDLE_STMT
,
stmt
);
stmt
=
NULL
;
}
switch_safe_free
(
err_str
);
switch_yield
(
1000000
);
goto
top
;
...
...
@@ -274,31 +340,8 @@ SWITCH_DECLARE(switch_odbc_status_t) switch_odbc_handle_connect(switch_odbc_hand
SQLSMALLINT
valueLength
=
0
;
int
i
=
0
;
if
(
handle
->
env
==
SQL_NULL_HANDLE
)
{
result
=
SQLAllocHandle
(
SQL_HANDLE_ENV
,
SQL_NULL_HANDLE
,
&
handle
->
env
);
init_odbc_handles
(
handle
,
SWITCH_FALSE
);
/* Init ODBC handles, if they are already initialized, don't do it again */
if
((
result
!=
SQL_SUCCESS
)
&&
(
result
!=
SQL_SUCCESS_WITH_INFO
))
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_ERROR
,
"Error AllocHandle
\n
"
);
return
SWITCH_ODBC_FAIL
;
}
result
=
SQLSetEnvAttr
(
handle
->
env
,
SQL_ATTR_ODBC_VERSION
,
(
void
*
)
SQL_OV_ODBC3
,
0
);
if
((
result
!=
SQL_SUCCESS
)
&&
(
result
!=
SQL_SUCCESS_WITH_INFO
))
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_ERROR
,
"Error SetEnv
\n
"
);
SQLFreeHandle
(
SQL_HANDLE_ENV
,
handle
->
env
);
return
SWITCH_ODBC_FAIL
;
}
result
=
SQLAllocHandle
(
SQL_HANDLE_DBC
,
handle
->
env
,
&
handle
->
con
);
if
((
result
!=
SQL_SUCCESS
)
&&
(
result
!=
SQL_SUCCESS_WITH_INFO
))
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_ERROR
,
"Error AllocHDB %d
\n
"
,
result
);
SQLFreeHandle
(
SQL_HANDLE_ENV
,
handle
->
env
);
return
SWITCH_ODBC_FAIL
;
}
SQLSetConnectAttr
(
handle
->
con
,
SQL_LOGIN_TIMEOUT
,
(
SQLPOINTER
*
)
10
,
0
);
}
if
(
handle
->
state
==
SWITCH_ODBC_STATE_CONNECTED
)
{
switch_odbc_handle_disconnect
(
handle
);
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_DEBUG1
,
"Re-connecting %s
\n
"
,
handle
->
dsn
);
...
...
@@ -325,7 +368,9 @@ SWITCH_DECLARE(switch_odbc_status_t) switch_odbc_handle_connect(switch_odbc_hand
SQLGetDiagRec
(
SQL_HANDLE_DBC
,
handle
->
con
,
1
,
stat
,
&
err
,
msg
,
100
,
&
mlen
);
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_ERROR
,
"Error SQLConnect=%d errno=%d %s
\n
"
,
result
,
(
int
)
err
,
msg
);
}
SQLFreeHandle
(
SQL_HANDLE_ENV
,
handle
->
env
);
/* Deallocate handles again, more chanses to succeed when reconnecting */
init_odbc_handles
(
handle
,
SWITCH_TRUE
);
/* Reinit ODBC handles */
return
SWITCH_ODBC_FAIL
;
}
...
...
@@ -554,6 +599,7 @@ SWITCH_DECLARE(switch_odbc_status_t) switch_odbc_handle_callback_exec_detailed(c
}
SQLFreeHandle
(
SQL_HANDLE_STMT
,
stmt
);
stmt
=
NULL
;
/* Make sure we don't try to free this handle again */
if
(
!
err_cnt
)
{
return
SWITCH_ODBC_SUCCESS
;
...
...
@@ -593,8 +639,10 @@ SWITCH_DECLARE(void) switch_odbc_handle_destroy(switch_odbc_handle_t **handlep)
if
(
handle
)
{
switch_odbc_handle_disconnect
(
handle
);
SQLFreeHandle
(
SQL_HANDLE_DBC
,
handle
->
con
);
SQLFreeHandle
(
SQL_HANDLE_ENV
,
handle
->
env
);
if
(
handle
->
env
!=
SQL_NULL_HANDLE
)
{
SQLFreeHandle
(
SQL_HANDLE_DBC
,
handle
->
con
);
SQLFreeHandle
(
SQL_HANDLE_ENV
,
handle
->
env
);
}
switch_safe_free
(
handle
->
dsn
);
switch_safe_free
(
handle
->
username
);
switch_safe_free
(
handle
->
password
);
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论