[Asterisk-code-review] func_odbc: acf_odbc_read() and cli_odbc_read() unicode support (asterisk[16])

Friendly Automation asteriskteam at digium.com
Thu Jan 2 09:40:02 CST 2020


Friendly Automation has submitted this change. ( https://gerrit.asterisk.org/c/asterisk/+/13531 )

Change subject: func_odbc:  acf_odbc_read() and cli_odbc_read() unicode support
......................................................................

func_odbc:  acf_odbc_read() and cli_odbc_read() unicode support

Added ast_odbc_ast_str_SQLGetData() considers SQL_DESC_OCTET_LENGTH
column attribute for correct allocating the buffer.

ASTERISK-28497 #close

Change-Id: I50e86c8a277996f13d4a4b9b318ece0d60b279bf
---
M funcs/func_odbc.c
1 file changed, 12 insertions(+), 10 deletions(-)

Approvals:
  George Joseph: Looks good to me, approved
  Friendly Automation: Approved for Submit



diff --git a/funcs/func_odbc.c b/funcs/func_odbc.c
index 126a339..f9fa971 100644
--- a/funcs/func_odbc.c
+++ b/funcs/func_odbc.c
@@ -920,15 +920,17 @@
 
 			if (y == 0) {
 				char colname[256];
-				SQLULEN maxcol = 0;
+				SQLLEN octetlength = 0;
 
-				res = SQLDescribeCol(stmt, x + 1, (unsigned char *)colname, sizeof(colname), &collength, NULL, &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);
+				res = SQLDescribeCol(stmt, x + 1, (unsigned char *)colname, sizeof(colname), &collength, NULL, NULL, NULL, NULL);
+				ast_debug(3, "Got collength of %d for column '%s' (offset %d)\n", (int)collength, colname, x);
 				if (((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) || collength == 0) {
 					snprintf(colname, sizeof(colname), "field%d", x);
 				}
 
-				ast_str_make_space(&coldata, maxcol + 1);
+				SQLColAttribute(stmt, x + 1, SQL_DESC_OCTET_LENGTH, NULL, 0, NULL, &octetlength);
+
+				ast_str_make_space(&coldata, octetlength + 1);
 
 				if (ast_str_strlen(colnames)) {
 					ast_str_append(&colnames, 0, ",");
@@ -1498,10 +1500,9 @@
 		SQLHSTMT stmt;
 		int rows = 0, res, x;
 		SQLSMALLINT colcount = 0, collength;
-		SQLLEN indicator;
+		SQLLEN indicator, octetlength;
 		struct ast_str *coldata = ast_str_thread_get(&coldata_buf, 16);
 		char colname[256];
-		SQLULEN maxcol;
 
 		if (!coldata) {
 			AST_RWLIST_UNLOCK(&queries);
@@ -1560,14 +1561,15 @@
 			}
 			for (;;) {
 				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, NULL, NULL, NULL, NULL);
 					if (((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) || collength == 0) {
 						snprintf(colname, sizeof(colname), "field%d", x);
 					}
 
-					res = ast_odbc_ast_str_SQLGetData(&coldata, maxcol, stmt, x + 1, SQL_CHAR, &indicator);
+					octetlength = 0;
+					SQLColAttribute(stmt, x + 1, SQL_DESC_OCTET_LENGTH, NULL, 0, NULL, &octetlength);
+
+					res = ast_odbc_ast_str_SQLGetData(&coldata, octetlength + 1, 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/+/13531
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 16
Gerrit-Change-Id: I50e86c8a277996f13d4a4b9b318ece0d60b279bf
Gerrit-Change-Number: 13531
Gerrit-PatchSet: 1
Gerrit-Owner: Joshua Colp <jcolp at sangoma.com>
Gerrit-Reviewer: Boris P. Korzun <drtr0jan at yandex.ru>
Gerrit-Reviewer: Friendly Automation
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20200102/6a36bae1/attachment-0001.html>


More information about the asterisk-code-review mailing list