Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
A
asterisk
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Voice
asterisk
Commits
7e8833cc
Commit
7e8833cc
authored
6 years ago
by
Kevin Harwell
Committed by
Gerrit Code Review
6 years ago
Browse files
Options
Downloads
Plain Diff
Merge "res_config_odbc: Avoid deadlock when max_connections = 1" into 13
parents
cdcba0d1
c38c8db1
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
res/res_config_odbc.c
+21
-16
21 additions, 16 deletions
res/res_config_odbc.c
with
21 additions
and
16 deletions
res/res_config_odbc.c
+
21
−
16
View file @
7e8833cc
...
@@ -576,6 +576,7 @@ struct update2_prepare_struct {
...
@@ -576,6 +576,7 @@ struct update2_prepare_struct {
const
char
*
table
;
const
char
*
table
;
const
struct
ast_variable
*
lookup_fields
;
const
struct
ast_variable
*
lookup_fields
;
const
struct
ast_variable
*
update_fields
;
const
struct
ast_variable
*
update_fields
;
struct
odbc_cache_tables
*
tableptr
;
};
};
static
SQLHSTMT
update2_prepare
(
struct
odbc_obj
*
obj
,
void
*
data
)
static
SQLHSTMT
update2_prepare
(
struct
odbc_obj
*
obj
,
void
*
data
)
...
@@ -585,29 +586,21 @@ static SQLHSTMT update2_prepare(struct odbc_obj *obj, void *data)
...
@@ -585,29 +586,21 @@ static SQLHSTMT update2_prepare(struct odbc_obj *obj, void *data)
const
struct
ast_variable
*
field
;
const
struct
ast_variable
*
field
;
struct
ast_str
*
sql
=
ast_str_thread_get
(
&
sql_buf
,
SQL_BUF_SIZE
);
struct
ast_str
*
sql
=
ast_str_thread_get
(
&
sql_buf
,
SQL_BUF_SIZE
);
SQLHSTMT
stmt
;
SQLHSTMT
stmt
;
struct
odbc_cache_tables
*
tableptr
;
if
(
!
sql
)
{
if
(
!
sql
)
{
return
NULL
;
return
NULL
;
}
}
tableptr
=
ast_odbc_find_table
(
ups
->
database
,
ups
->
table
);
if
(
!
tableptr
)
{
ast_log
(
LOG_ERROR
,
"Could not retrieve metadata for table '%s@%s'. Update will fail!
\n
"
,
ups
->
table
,
ups
->
database
);
return
NULL
;
}
res
=
SQLAllocHandle
(
SQL_HANDLE_STMT
,
obj
->
con
,
&
stmt
);
res
=
SQLAllocHandle
(
SQL_HANDLE_STMT
,
obj
->
con
,
&
stmt
);
if
((
res
!=
SQL_SUCCESS
)
&&
(
res
!=
SQL_SUCCESS_WITH_INFO
))
{
if
((
res
!=
SQL_SUCCESS
)
&&
(
res
!=
SQL_SUCCESS_WITH_INFO
))
{
ast_log
(
LOG_WARNING
,
"SQL Alloc Handle failed!
\n
"
);
ast_log
(
LOG_WARNING
,
"SQL Alloc Handle failed!
\n
"
);
ast_odbc_release_table
(
tableptr
);
return
NULL
;
return
NULL
;
}
}
ast_str_set
(
&
sql
,
0
,
"UPDATE %s SET "
,
ups
->
table
);
ast_str_set
(
&
sql
,
0
,
"UPDATE %s SET "
,
ups
->
table
);
for
(
field
=
ups
->
update_fields
;
field
;
field
=
field
->
next
)
{
for
(
field
=
ups
->
update_fields
;
field
;
field
=
field
->
next
)
{
if
(
ast_odbc_find_column
(
tableptr
,
field
->
name
))
{
if
(
ast_odbc_find_column
(
ups
->
tableptr
,
field
->
name
))
{
ast_str_append
(
&
sql
,
0
,
"%s%s=? "
,
first
?
""
:
", "
,
field
->
name
);
ast_str_append
(
&
sql
,
0
,
"%s%s=? "
,
first
?
""
:
", "
,
field
->
name
);
SQLBindParameter
(
stmt
,
x
++
,
SQL_PARAM_INPUT
,
SQL_C_CHAR
,
SQL_CHAR
,
strlen
(
field
->
name
),
0
,
(
void
*
)
field
->
value
,
0
,
NULL
);
SQLBindParameter
(
stmt
,
x
++
,
SQL_PARAM_INPUT
,
SQL_C_CHAR
,
SQL_CHAR
,
strlen
(
field
->
name
),
0
,
(
void
*
)
field
->
value
,
0
,
NULL
);
first
=
0
;
first
=
0
;
...
@@ -620,9 +613,8 @@ static SQLHSTMT update2_prepare(struct odbc_obj *obj, void *data)
...
@@ -620,9 +613,8 @@ static SQLHSTMT update2_prepare(struct odbc_obj *obj, void *data)
first
=
1
;
first
=
1
;
for
(
field
=
ups
->
lookup_fields
;
field
;
field
=
field
->
next
)
{
for
(
field
=
ups
->
lookup_fields
;
field
;
field
=
field
->
next
)
{
if
(
!
ast_odbc_find_column
(
tableptr
,
field
->
name
))
{
if
(
!
ast_odbc_find_column
(
ups
->
tableptr
,
field
->
name
))
{
ast_log
(
LOG_ERROR
,
"One or more of the criteria columns '%s' on '%s@%s' for this update does not exist!
\n
"
,
field
->
name
,
ups
->
table
,
ups
->
database
);
ast_log
(
LOG_ERROR
,
"One or more of the criteria columns '%s' on '%s@%s' for this update does not exist!
\n
"
,
field
->
name
,
ups
->
table
,
ups
->
database
);
ast_odbc_release_table
(
tableptr
);
SQLFreeHandle
(
SQL_HANDLE_STMT
,
stmt
);
SQLFreeHandle
(
SQL_HANDLE_STMT
,
stmt
);
return
NULL
;
return
NULL
;
}
}
...
@@ -631,9 +623,6 @@ static SQLHSTMT update2_prepare(struct odbc_obj *obj, void *data)
...
@@ -631,9 +623,6 @@ static SQLHSTMT update2_prepare(struct odbc_obj *obj, void *data)
first
=
0
;
first
=
0
;
}
}
/* Done with the table metadata */
ast_odbc_release_table
(
tableptr
);
res
=
ast_odbc_prepare
(
obj
,
stmt
,
ast_str_buffer
(
sql
));
res
=
ast_odbc_prepare
(
obj
,
stmt
,
ast_str_buffer
(
sql
));
if
((
res
!=
SQL_SUCCESS
)
&&
(
res
!=
SQL_SUCCESS_WITH_INFO
))
{
if
((
res
!=
SQL_SUCCESS
)
&&
(
res
!=
SQL_SUCCESS_WITH_INFO
))
{
if
(
res
==
SQL_ERROR
)
{
if
(
res
==
SQL_ERROR
)
{
...
@@ -665,20 +654,36 @@ static int update2_odbc(const char *database, const char *table, const struct as
...
@@ -665,20 +654,36 @@ static int update2_odbc(const char *database, const char *table, const struct as
{
{
struct
odbc_obj
*
obj
;
struct
odbc_obj
*
obj
;
SQLHSTMT
stmt
;
SQLHSTMT
stmt
;
struct
update2_prepare_struct
ups
=
{
.
database
=
database
,
.
table
=
table
,
.
lookup_fields
=
lookup_fields
,
.
update_fields
=
update_fields
,
};
struct
update2_prepare_struct
ups
=
{
.
database
=
database
,
.
table
=
table
,
.
lookup_fields
=
lookup_fields
,
.
update_fields
=
update_fields
,
};
struct
ast_str
*
sql
;
struct
ast_str
*
sql
;
int
res
;
int
res
;
SQLLEN
rowcount
=
0
;
SQLLEN
rowcount
=
0
;
ups
.
tableptr
=
ast_odbc_find_table
(
database
,
table
);
if
(
!
ups
.
tableptr
)
{
ast_log
(
LOG_ERROR
,
"Could not retrieve metadata for table '%s@%s'. Update will fail!
\n
"
,
table
,
database
);
return
-
1
;
}
if
(
!
(
obj
=
ast_odbc_request_obj
(
database
,
0
)))
{
if
(
!
(
obj
=
ast_odbc_request_obj
(
database
,
0
)))
{
ast_odbc_release_table
(
ups
.
tableptr
);
return
-
1
;
return
-
1
;
}
}
if
(
!
(
stmt
=
ast_odbc_prepare_and_execute
(
obj
,
update2_prepare
,
&
ups
)))
{
if
(
!
(
stmt
=
ast_odbc_prepare_and_execute
(
obj
,
update2_prepare
,
&
ups
)))
{
ast_odbc_release_obj
(
obj
);
ast_odbc_release_obj
(
obj
);
ast_odbc_release_table
(
ups
.
tableptr
);
return
-
1
;
return
-
1
;
}
}
/* We don't need the table anymore */
ast_odbc_release_table
(
ups
.
tableptr
);
res
=
SQLRowCount
(
stmt
,
&
rowcount
);
res
=
SQLRowCount
(
stmt
,
&
rowcount
);
SQLFreeHandle
(
SQL_HANDLE_STMT
,
stmt
);
SQLFreeHandle
(
SQL_HANDLE_STMT
,
stmt
);
ast_odbc_release_obj
(
obj
);
ast_odbc_release_obj
(
obj
);
...
@@ -692,7 +697,7 @@ static int update2_odbc(const char *database, const char *table, const struct as
...
@@ -692,7 +697,7 @@ static int update2_odbc(const char *database, const char *table, const struct as
}
}
if
(
rowcount
>=
0
)
{
if
(
rowcount
>=
0
)
{
return
(
int
)
rowcount
;
return
(
int
)
rowcount
;
}
}
return
-
1
;
return
-
1
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment