Skip to content

Commit 23e5fd0

Browse files
committed
Fixes: correct check on truncation failure. Reinit IRD on statement closing. Logging format descriptors (#170)
* fix: only fail time*/str conversion on truncation The timestamp/time to string truncation needs to fail only if current status code (for current column) indicates that truncation occured; so status code has been added to the branching evaluation. Previously, only the current diagnostic code was used in the decision (and checked if it indicated truncation), which was incorrect since this could have been set by the conversion of a previous column in same row. * fix: re-init IRD headers on statement close On statment closing the IRD descriptor's headers should be reinitialized. The fix is for good house keeping, the defect didn't have a practical impact, since the IRD is cleared also before adding a new result set; furthermore, a new result set added to an already-used IRD would only occur if a statement handle is re-prepared, which happens very rarely (generally a client app would allocate a new handle for a new query). The commit also switches a few catalog functions to using SQLExecDirect(), instead of dupplicating its code. * fix: correct logging format specifiers Correct some format specifiers for logging, mostly s/zd/zu for size_t types. (resolved conflict around '/* ESODBC_CURL_CLOSE */' chunk) (cherry picked from commit c7aa95b)
1 parent 7cac9ea commit 23e5fd0

File tree

5 files changed

+30
-48
lines changed

5 files changed

+30
-48
lines changed

driver/catalogue.c

+2-12
Original file line numberDiff line numberDiff line change
@@ -417,12 +417,7 @@ SQLRETURN EsSQLTablesW(
417417

418418
DBGH(stmt, "tables catalog SQL [%zu]:`" LWPDL "`.", pos, (int)pos, pbuf);
419419

420-
ret = EsSQLFreeStmt(stmt, ESODBC_SQL_CLOSE);
421-
assert(SQL_SUCCEEDED(ret)); /* can't return error */
422-
ret = attach_sql(stmt, pbuf, pos);
423-
if (SQL_SUCCEEDED(ret)) {
424-
ret = EsSQLExecute(stmt);
425-
}
420+
ret = EsSQLExecDirectW(stmt, pbuf, (SQLINTEGER)pos);
426421
end:
427422
free(pbuf);
428423
return ret;
@@ -573,12 +568,7 @@ SQLRETURN EsSQLColumnsW
573568
goto end;
574569
}
575570

576-
ret = EsSQLFreeStmt(stmt, ESODBC_SQL_CLOSE);
577-
assert(SQL_SUCCEEDED(ret)); /* can't return error */
578-
ret = attach_sql(stmt, pbuf, cnt);
579-
if (SQL_SUCCEEDED(ret)) {
580-
ret = EsSQLExecute(stmt);
581-
}
571+
ret = EsSQLExecDirectW(stmt, pbuf, (SQLINTEGER)cnt);
582572
end:
583573
free(pbuf);
584574
return ret;

driver/connect.c

+23-25
Original file line numberDiff line numberDiff line change
@@ -233,8 +233,8 @@ static size_t write_callback(char *ptr, size_t size, size_t nmemb,
233233
avail = dbc->alen - dbc->apos;
234234
have = size * nmemb;
235235

236-
DBGH(dbc, "libcurl: new data chunk of size [%zd] x %zd arrived; "
237-
"available buffer: %zd/%zd.", nmemb, size, avail, dbc->alen);
236+
DBGH(dbc, "libcurl: new data chunk of size [%zu] x %zu arrived; "
237+
"available buffer: %zu/%zu.", nmemb, size, avail, dbc->alen);
238238

239239
/* do I need to grow the existing buffer? */
240240
if (avail < have) {
@@ -244,14 +244,14 @@ static size_t write_callback(char *ptr, size_t size, size_t nmemb,
244244
while (need < dbc->apos + have) {
245245
need *= 2;
246246
}
247-
DBGH(dbc, "libcurl: need to grow buffer for new chunk of %zd "
248-
"from %zd to %zd bytes.", have, dbc->alen, need);
247+
DBGH(dbc, "libcurl: need to grow buffer for new chunk of %zu "
248+
"from %zu to %zu bytes.", have, dbc->alen, need);
249249
if (dbc->amax && (dbc->amax < need)) { /* do I need more than max? */
250250
if (dbc->amax <= (size_t)dbc->alen) { /* am I at max already? */
251251
goto too_large;
252252
} else { /* am not: alloc max possible (if that's enough) */
253253
need = dbc->amax;
254-
WARNH(dbc, "libcurl: capped buffer to max: %zd", need);
254+
WARNH(dbc, "libcurl: capped buffer to max: %zu", need);
255255
/* re'eval what I have available... */
256256
avail = dbc->amax - dbc->apos;
257257
if (avail < have) {
@@ -267,7 +267,7 @@ static size_t write_callback(char *ptr, size_t size, size_t nmemb,
267267
* the chunk right past the indicated JSON length.) */
268268
wbuf = realloc(dbc->abuff, need + /*\0*/1);
269269
if (! wbuf) {
270-
ERRNH(dbc, "libcurl: failed to realloc to %zdB.", need);
270+
ERRNH(dbc, "libcurl: failed to realloc to %zuB.", need);
271271
return 0;
272272
}
273273
dbc->abuff = wbuf;
@@ -278,7 +278,7 @@ static size_t write_callback(char *ptr, size_t size, size_t nmemb,
278278
dbc->apos += have;
279279
/* Add the 0-term for UJSON4C (but don't count it - see above) */
280280
dbc->abuff[dbc->apos] = '\0';
281-
DBGH(dbc, "libcurl: copied %zdB: `%.*s`.", have, have, ptr);
281+
DBGH(dbc, "libcurl: copied %zuB: `%.*s`.", have, have, ptr);
282282

283283
/*
284284
* "Your callback should return the number of bytes actually taken care
@@ -293,8 +293,8 @@ static size_t write_callback(char *ptr, size_t size, size_t nmemb,
293293
return have;
294294

295295
too_large:
296-
ERRH(dbc, "libcurl: at %zd and can't grow past max %zd for new chunk of "
297-
"%zd bytes.", dbc->apos, dbc->amax, have);
296+
ERRH(dbc, "libcurl: at %zu and can't grow past max %zu for new chunk of "
297+
"%zu bytes.", dbc->apos, dbc->amax, have);
298298
return 0;
299299
}
300300

@@ -1093,9 +1093,8 @@ SQLRETURN config_dbc(esodbc_dbc_st *dbc, esodbc_dsn_attrs_st *attrs)
10931093
ipv6 ? "[" : "", LWSTR(&attrs->server), ipv6 ? "]" : "",
10941094
LWSTR(&attrs->port));
10951095
if (cnt <= 0) {
1096-
ERRNH(dbc, "failed to print SQL URL out of server: `" LWPDL "` [%zd], "
1097-
"port: `" LWPDL "` [%zd].", LWSTR(&attrs->server),
1098-
LWSTR(&attrs->port));
1096+
ERRNH(dbc, "failed to print SQL URL out of server: `" LWPDL "`, "
1097+
"port: `" LWPDL "`.", LWSTR(&attrs->server), LWSTR(&attrs->port));
10991098
SET_HDIAG(dbc, SQL_STATE_HY000, "printing server's SQL URL failed", 0);
11001099
goto err;
11011100
} else {
@@ -1130,9 +1129,8 @@ SQLRETURN config_dbc(esodbc_dbc_st *dbc, esodbc_dsn_attrs_st *attrs)
11301129
ipv6 ? "[" : "", LWSTR(&attrs->server), ipv6 ? "]" : "",
11311130
LWSTR(&attrs->port));
11321131
if (cnt <= 0) {
1133-
ERRNH(dbc, "failed to print root URL out of server: `" LWPDL "` [%zd],"
1134-
" port: `" LWPDL "` [%zd].", LWSTR(&attrs->server),
1135-
LWSTR(&attrs->port));
1132+
ERRNH(dbc, "failed to print root URL out of server: `" LWPDL "`,"
1133+
" port: `" LWPDL "`.", LWSTR(&attrs->server), LWSTR(&attrs->port));
11361134
SET_HDIAG(dbc, SQL_STATE_HY000, "printing server's URL failed", 0);
11371135
goto err;
11381136
} else {
@@ -1151,16 +1149,16 @@ SQLRETURN config_dbc(esodbc_dbc_st *dbc, esodbc_dsn_attrs_st *attrs)
11511149
*/
11521150
if (attrs->uid.cnt) {
11531151
if (! wstr_to_utf8(&attrs->uid, &dbc->uid)) {
1154-
ERRH(dbc, "failed to convert username [%zd] `" LWPDL "` to UTF8.",
1152+
ERRH(dbc, "failed to convert username [%zu] `" LWPDL "` to UTF8.",
11551153
attrs->uid.cnt, LWSTR(&attrs->uid));
11561154
SET_HDIAG(dbc, SQL_STATE_HY000, "username UTF8 conversion "
11571155
"failed", 0);
11581156
goto err;
11591157
}
11601158
if (attrs->pwd.cnt) {
11611159
if (! wstr_to_utf8(&attrs->pwd, &dbc->pwd)) {
1162-
ERRH(dbc, "failed to convert password [%zd] (-not shown-) to "
1163-
"UTF8.", attrs->pwd.cnt);
1160+
ERRH(dbc, "failed to convert password [%zu] `%s` to "
1161+
"UTF8.", attrs->pwd.cnt, ESODBC_PWD_VAL_SUBST);
11641162
SET_HDIAG(dbc, SQL_STATE_HY000, "password UTF8 "
11651163
"conversion failed", 0);
11661164
goto err;
@@ -1213,7 +1211,7 @@ SQLRETURN config_dbc(esodbc_dbc_st *dbc, esodbc_dsn_attrs_st *attrs)
12131211
WARNH(dbc, "no reply body limit set.");
12141212
}
12151213
}
1216-
INFOH(dbc, "max body size: %zd.", dbc->amax);
1214+
INFOH(dbc, "max body size: %zu.", dbc->amax);
12171215

12181216
/*
12191217
* set max fetch size
@@ -1240,7 +1238,7 @@ SQLRETURN config_dbc(esodbc_dbc_st *dbc, esodbc_dsn_attrs_st *attrs)
12401238
dbc->fetch.slen = (char)attrs->max_fetch_size.cnt;
12411239
dbc->fetch.str = malloc(dbc->fetch.slen + /*\0*/1);
12421240
if (! dbc->fetch.str) {
1243-
ERRNH(dbc, "failed to alloc %zdB.", dbc->fetch.slen);
1241+
ERRNH(dbc, "failed to alloc %cB.", dbc->fetch.slen);
12441242
RET_HDIAGS(dbc, SQL_STATE_HY001);
12451243
}
12461244
dbc->fetch.str[dbc->fetch.slen] = 0;
@@ -1729,8 +1727,8 @@ static BOOL elastic_intervals_name2types(wstr_st *type_name,
17291727
break;
17301728
}
17311729

1732-
ERR("unrecognized Elastic type `" LWPDL "` (%zd).", LWSTR(type_name),
1733-
type_name->cnt);
1730+
ERR("unrecognized Elastic type: [%zu] `" LWPDL "`.", type_name->cnt,
1731+
LWSTR(type_name));
17341732
return FALSE;
17351733
}
17361734

@@ -2409,7 +2407,7 @@ static BOOL load_es_types(esodbc_dbc_st *dbc)
24092407
ERRH(stmt, "Elasticsearch returned no type as supported.");
24102408
goto end;
24112409
} else if (ESODBC_MAX_NO_TYPES < row_cnt) {
2412-
ERRH(stmt, "Elasticsearch returned too many types (%d vs limit %zd).",
2410+
ERRH(stmt, "Elasticsearch returned too many types (%ld vs limit %d).",
24132411
row_cnt, ESODBC_MAX_NO_TYPES);
24142412
goto end;
24152413
} else {
@@ -2425,7 +2423,7 @@ static BOOL load_es_types(esodbc_dbc_st *dbc)
24252423
/* indicate rowset size */
24262424
if (! SQL_SUCCEEDED(EsSQLSetStmtAttrW(stmt, SQL_ATTR_ROW_ARRAY_SIZE,
24272425
(SQLPOINTER)ESODBC_MAX_NO_TYPES, 0))) {
2428-
ERRH(stmt, "failed to set rowset size (%zd).",
2426+
ERRH(stmt, "failed to set rowset size (%d).",
24292427
ESODBC_MAX_NO_TYPES);
24302428
goto end;
24312429
}
@@ -2724,7 +2722,7 @@ SQLRETURN EsSQLDriverConnectW
27242722
cnt += attrs.server.cnt + /*\0*/1;
27252723
dbc->dsn.str = malloc(cnt * sizeof(SQLWCHAR)); /* alloc for both */
27262724
if (! dbc->dsn.str) {
2727-
ERRNH(dbc, "OOM for %zdB.", (orig_dsn.cnt + 1) * sizeof(SQLWCHAR));
2725+
ERRNH(dbc, "OOM for %zuB.", (orig_dsn.cnt + 1) * sizeof(SQLWCHAR));
27282726
RET_HDIAGS(dbc, SQL_STATE_HY001);
27292727
}
27302728
/* copy DSN */

driver/convert.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -3300,7 +3300,8 @@ static SQLRETURN wstr_to_string(esodbc_rec_st *arec, esodbc_rec_st *irec,
33003300
wstr_to_wstr(arec, irec, data_ptr, octet_len_ptr, wstr, chars_0);
33013301

33023302
/* if truncation occured, only succeed if fractional seconds are cut out */
3303-
if (min_xfer && HDRH(stmt)->diag.state == SQL_STATE_01004) {
3303+
if (ret == SQL_SUCCESS_WITH_INFO && min_xfer &&
3304+
HDRH(stmt)->diag.state == SQL_STATE_01004) {
33043305
assert(SQL_SUCCEEDED(ret));
33053306

33063307
usize = (arec_type == SQL_C_CHAR) ? sizeof(SQLCHAR) : sizeof(SQLWCHAR);

driver/handles.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ SQLRETURN EsSQLFreeStmt(SQLHSTMT StatementHandle, SQLUSMALLINT Option)
451451
* pending results." */
452452
case SQL_CLOSE:
453453
DBGH(stmt, "closing.");
454-
clear_desc(stmt->ird, FALSE /*keep the header values*/);
454+
clear_desc(stmt->ird, TRUE);
455455
break;
456456

457457
/* "Sets the SQL_DESC_COUNT field of the APD to 0, releasing all

driver/info.c

+2-9
Original file line numberDiff line numberDiff line change
@@ -1209,10 +1209,9 @@ SQLRETURN EsSQLGetTypeInfoW(SQLHSTMT StatementHandle, SQLSMALLINT DataType)
12091209
{
12101210
#define SQL_TYPES_STMT "SYS TYPES"
12111211

1212-
SQLRETURN ret;
12131212
esodbc_stmt_st *stmt = STMH(StatementHandle);
12141213
SQLWCHAR wbuff[sizeof(SQL_TYPES_STMT " 32767")];
1215-
size_t cnt;
1214+
int cnt;
12161215

12171216
DBGH(stmt, "requested type description for type %hd.", DataType);
12181217
cnt = swprintf(wbuff, sizeof(wbuff)/sizeof(*wbuff),
@@ -1222,13 +1221,7 @@ SQLRETURN EsSQLGetTypeInfoW(SQLHSTMT StatementHandle, SQLSMALLINT DataType)
12221221
RET_HDIAGS(stmt, SQL_STATE_HY000);
12231222
}
12241223

1225-
ret = EsSQLFreeStmt(stmt, ESODBC_SQL_CLOSE);
1226-
assert(SQL_SUCCEEDED(ret)); /* can't return error */
1227-
ret = attach_sql(stmt, wbuff, cnt);
1228-
if (SQL_SUCCEEDED(ret)) {
1229-
ret = EsSQLExecute(stmt);
1230-
}
1231-
return ret;
1224+
return EsSQLExecDirectW(stmt, wbuff, cnt);
12321225

12331226
# undef SQL_TYPES_STMT
12341227
}

0 commit comments

Comments
 (0)