[Asterisk-code-review] odbc: acf_odbc_read() and cli_odbc_read() unicode support (...asterisk[master])
Boris P. Korzun
asteriskteam at digium.com
Wed Aug 28 05:23:29 CDT 2019
Boris P. Korzun has uploaded this change for review. ( https://gerrit.asterisk.org/c/asterisk/+/12812
Change subject: odbc: acf_odbc_read() and cli_odbc_read() unicode support
......................................................................
odbc: acf_odbc_read() and cli_odbc_read() unicode support
Added ast_odbc_ast_str_SQLGetData() considers column type for correct
allocating the buffer.
ASTERISK-28497 #close
Change-Id: I50e86c8a277996f13d4a4b9b318ece0d60b279bf
---
M funcs/func_odbc.c
1 file changed, 13 insertions(+), 3 deletions(-)
git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/12/12812/1
diff --git a/funcs/func_odbc.c b/funcs/func_odbc.c
index 126a339..b6b5281 100644
--- a/funcs/func_odbc.c
+++ b/funcs/func_odbc.c
@@ -921,13 +921,18 @@
if (y == 0) {
char colname[256];
SQLULEN maxcol = 0;
+ SQLSMALLINT coltype;
- res = SQLDescribeCol(stmt, x + 1, (unsigned char *)colname, sizeof(colname), &collength, NULL, &maxcol, NULL, NULL);
+ res = SQLDescribeCol(stmt, x + 1, (unsigned char *)colname, sizeof(colname), &collength, &coltype, &maxcol, NULL, NULL);
ast_debug(3, "Got collength of %d and maxcol of %d for column '%s' (offset %d)\n", (int)collength, (int)maxcol, colname, x);
if (((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) || collength == 0) {
snprintf(colname, sizeof(colname), "field%d", x);
}
+ if ((coltype <= SQL_WCHAR) && (coltype >= SQL_WLONGVARCHAR)) {
+ maxcol = maxcol * 2;
+ }
+
ast_str_make_space(&coldata, maxcol + 1);
if (ast_str_strlen(colnames)) {
@@ -1497,7 +1502,7 @@
int dsn_num, executed = 0;
SQLHSTMT stmt;
int rows = 0, res, x;
- SQLSMALLINT colcount = 0, collength;
+ SQLSMALLINT colcount = 0, collength, coltype;
SQLLEN indicator;
struct ast_str *coldata = ast_str_thread_get(&coldata_buf, 16);
char colname[256];
@@ -1562,12 +1567,17 @@
for (x = 0; x < colcount; x++) {
maxcol = 0;
- res = SQLDescribeCol(stmt, x + 1, (unsigned char *)colname, sizeof(colname), &collength, NULL, &maxcol, NULL, NULL);
+ res = SQLDescribeCol(stmt, x + 1, (unsigned char *)colname, sizeof(colname), &collength, &coltype, &maxcol, NULL, NULL);
if (((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) || collength == 0) {
snprintf(colname, sizeof(colname), "field%d", x);
}
+ if ((coltype <= SQL_WCHAR) && (coltype >= SQL_WLONGVARCHAR)) {
+ maxcol = maxcol * 2;
+ }
+
res = ast_odbc_ast_str_SQLGetData(&coldata, maxcol, stmt, x + 1, SQL_CHAR, &indicator);
+
if (indicator == SQL_NULL_DATA) {
ast_str_set(&coldata, 0, "(nil)");
res = SQL_SUCCESS;
--
To view, visit https://gerrit.asterisk.org/c/asterisk/+/12812
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings
Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Change-Id: I50e86c8a277996f13d4a4b9b318ece0d60b279bf
Gerrit-Change-Number: 12812
Gerrit-PatchSet: 1
Gerrit-Owner: Boris P. Korzun <drtr0jan at yandex.ru>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20190828/57776e3e/attachment.html>
More information about the asterisk-code-review
mailing list