Type:
Bug
Priority:
Major
Resolution:
Fixed
Affects Version/s:
2.3.1
Component/s:
None
Text column should be bound as MYSQL_TYPE_STRING
The testcase:
static int test_conc_new(MYSQL *mysql)
{
MYSQL_STMT *stmt;
MYSQL_BIND my_bind[3];
char data[8];
ulong length[3];
int rc, int_col;
short smint_col;
my_bool is_null[3];
char *query = "SELECT text_col, smint_col, int_col FROM test_conc_new";
rc= mysql_query(mysql, "drop table if exists test_conc_new");
check_mysql_rc(rc, mysql);
rc= mysql_query(mysql, "CREATE TABLE test_conc_new (text_col TEXT, smint_col SMALLINT, int_col INT)");
check_mysql_rc(rc, mysql);
rc= mysql_query(mysql, "INSERT INTO test_conc_new VALUES('data01', 21893, 1718038908), ('data2', -25734, -1857802040)");
check_mysql_rc(rc, mysql);
stmt= mysql_stmt_init(mysql);
FAIL_IF(!stmt, mysql_error(mysql));
rc= mysql_stmt_prepare(stmt, query, (unsigned long)strlen(query));
check_stmt_rc(rc, stmt);
memset(my_bind, '\0', sizeof(my_bind));
my_bind[0].buffer_type= MYSQL_TYPE_STRING;
my_bind[0].buffer= (void *)data;
my_bind[0].buffer_length= sizeof(data);
my_bind[0].is_null= &is_null[0];
my_bind[0].length= &length[0];
my_bind[1].buffer_type= MYSQL_TYPE_SHORT;
my_bind[1].buffer= &smint_col;
my_bind[1].buffer_length= 2;
my_bind[1].is_null= &is_null[1];
my_bind[1].length= &length[1];
my_bind[2].buffer_type= MYSQL_TYPE_LONG;
my_bind[2].buffer= &int_col;
my_bind[2].buffer_length= 4;
my_bind[2].is_null= &is_null[2];
my_bind[2].length= &length[2];
rc= mysql_stmt_execute(stmt);
check_stmt_rc(rc, stmt);
rc= mysql_stmt_bind_result(stmt, my_bind);
check_stmt_rc(rc, stmt);
rc= mysql_stmt_fetch(stmt);
check_stmt_rc(rc, stmt);
FAIL_IF(length[0] != 6, "Wrong fetched string length");
FAIL_IF(length[1] != 2, "Wrong fetched short length");
FAIL_IF(length[2] != 4, "Wrong fetched int length");
FAIL_IF(strncmp(data, "data01", length[0] + 1) != 0, "Wrong string value");
FAIL_IF(smint_col != 21893, "Expected 21893");
FAIL_IF(int_col != 1718038908, "Expected 1718038908");
rc= mysql_stmt_fetch(stmt);
check_stmt_rc(rc, stmt);
FAIL_IF(length[0] != 5, "Wrong fetched string length");
FAIL_IF(length[1] != 2, "Wrong fetched short length");
FAIL_IF(length[2] != 4, "Wrong fetched int length");
FAIL_IF(strncmp(data, "data2", length[0] + 1) != 0, "Wrong string value");
FAIL_IF(smint_col != -25734, "Expected 21893");
FAIL_IF(int_col != -1857802040, "Expected 1718038908");
rc= mysql_stmt_fetch(stmt);
FAIL_IF(rc != MYSQL_NO_DATA, "Expected MYSQL_NO_DATA");
mysql_stmt_close(stmt);
rc= mysql_query(mysql, "drop table test_conc_new");
check_mysql_rc(rc, mysql);
return OK;
}
The reason is that connector decrements field length before calculating next field value ptr. It does that because of terminating NULL it adds. But that NULL was not considered in the field length previously calculated. Following patch seems to fix the problem, and does not cause any testcase to fail.
diff --git a/libmariadb/my_stmt_codec.c b/libmariadb/my_stmt_codec.c
index fdaed55..a5d5b46 100644
--- a/libmariadb/my_stmt_codec.c
+++ b/libmariadb/my_stmt_codec.c
@@ -935,10 +935,6 @@ void ps_fetch_bin(MYSQL_BIND *r_param, const MYSQL_FIELD *field,
}
}
*r_param->error= copylen > r_param->buffer_length;
- /* don't count trailing zero if we fetch into string */
- if (r_param->buffer_type == MYSQL_TYPE_STRING &&
- !*r_param->error)
- field_length--;
(*row)+= field_length;
}
/* }}} */
causes
ODBC-58
Any field going after a TEXT field in the selecion list, is fetched incorrectly
Closed
Transition
Time In Source Status
Execution Times
Open
Closed
25d 9h 35m
1
{"report":{"fcp":762.0999999046326,"ttfb":160.7000002861023,"pageVisibility":"visible","entityId":58299,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":1,"journeyId":"6773d10b-afbf-463d-acf9-623e9568e919","navigationType":0,"readyForUser":866.7000002861023,"redirectCount":0,"resourceLoadedEnd":876.2000002861023,"resourceLoadedStart":165.80000019073486,"resourceTiming":[{"duration":43,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2bsh/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":165.80000019073486,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":165.80000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":208.80000019073486,"responseStart":0,"secureConnectionStart":0},{"duration":42.90000009536743,"initiatorType":"link","name":"https://jira.mariadb.org/s/7ebd35e77e471bc30ff0eba799ebc151-CDN/lu2bsh/820016/12ta74/eb142f92e4bd16bd1ef8b08c1b9d5d56/_/download/contextbatch/css/jira.browse.project,project.issue.navigator,jira.view.issue,jira.general,jira.global,atl.general,-_super/batch.css?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&slack-enabled=true","startTime":166,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":166,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":208.90000009536743,"responseStart":0,"secureConnectionStart":0},{"duration":75.69999980926514,"initiatorType":"script","name":"https://jira.mariadb.org/s/b09d0d077992e4331b5f9ec0d3ec448c-CDN/lu2bsh/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":166.2000002861023,"connectEnd":166.2000002861023,"connectStart":166.2000002861023,"domainLookupEnd":166.2000002861023,"domainLookupStart":166.2000002861023,"fetchStart":166.2000002861023,"redirectEnd":0,"redirectStart":0,"requestStart":166.2000002861023,"responseEnd":241.90000009536743,"responseStart":241.90000009536743,"secureConnectionStart":166.2000002861023},{"duration":202.39999961853027,"initiatorType":"script","name":"https://jira.mariadb.org/s/b47ab3df14096803b180217eb8482517-CDN/lu2bsh/820016/12ta74/eb142f92e4bd16bd1ef8b08c1b9d5d56/_/download/contextbatch/js/jira.browse.project,project.issue.navigator,jira.view.issue,jira.general,jira.global,atl.general,-_super/batch.js?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&locale=en&slack-enabled=true","startTime":166.2000002861023,"connectEnd":166.2000002861023,"connectStart":166.2000002861023,"domainLookupEnd":166.2000002861023,"domainLookupStart":166.2000002861023,"fetchStart":166.2000002861023,"redirectEnd":0,"redirectStart":0,"requestStart":166.2000002861023,"responseEnd":368.59999990463257,"responseStart":368.59999990463257,"secureConnectionStart":166.2000002861023},{"duration":206.69999980926514,"initiatorType":"script","name":"https://jira.mariadb.org/s/6c569cbf8087ab04e40d0bef98627457-CDN/lu2bsh/820016/12ta74/c92c0caa9a024ae85b0ebdbed7fb4bd7/_/download/contextbatch/js/atl.global,-_super/batch.js?locale=en","startTime":166.40000009536743,"connectEnd":166.40000009536743,"connectStart":166.40000009536743,"domainLookupEnd":166.40000009536743,"domainLookupStart":166.40000009536743,"fetchStart":166.40000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":166.40000009536743,"responseEnd":373.09999990463257,"responseStart":373.09999990463257,"secureConnectionStart":166.40000009536743},{"duration":208.10000038146973,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bsh/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-localisation-moment/jira.webresources:calendar-localisation-moment.js","startTime":166.59999990463257,"connectEnd":166.59999990463257,"connectStart":166.59999990463257,"domainLookupEnd":166.59999990463257,"domainLookupStart":166.59999990463257,"fetchStart":166.59999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":166.59999990463257,"responseEnd":374.7000002861023,"responseStart":374.7000002861023,"secureConnectionStart":166.59999990463257},{"duration":207.7000002861023,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bsh/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-en/jira.webresources:calendar-en.js","startTime":166.59999990463257,"connectEnd":166.59999990463257,"connectStart":166.59999990463257,"domainLookupEnd":166.59999990463257,"domainLookupStart":166.59999990463257,"fetchStart":166.59999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":166.59999990463257,"responseEnd":374.30000019073486,"responseStart":374.30000019073486,"secureConnectionStart":166.59999990463257},{"duration":208.7999997138977,"initiatorType":"link","name":"https://jira.mariadb.org/s/b04b06a02d1959df322d9cded3aeecc1-CDN/lu2bsh/820016/12ta74/a2ff6aa845ffc9a1d22fe23d9ee791fc/_/download/contextbatch/css/jira.global.look-and-feel,-_super/batch.css","startTime":166.7000002861023,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":166.7000002861023,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":375.5,"responseStart":0,"secureConnectionStart":0},{"duration":208.40000009536743,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":166.80000019073486,"connectEnd":166.80000019073486,"connectStart":166.80000019073486,"domainLookupEnd":166.80000019073486,"domainLookupStart":166.80000019073486,"fetchStart":166.80000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":166.80000019073486,"responseEnd":375.2000002861023,"responseStart":375.2000002861023,"secureConnectionStart":166.80000019073486},{"duration":208.90000009536743,"initiatorType":"link","name":"https://jira.mariadb.org/s/3ac36323ba5e4eb0af2aa7ac7211b4bb-CDN/lu2bsh/820016/12ta74/d176f0986478cc64f24226b3d20c140d/_/download/contextbatch/css/com.atlassian.jira.projects.sidebar.init,-_super,-project.issue.navigator,-jira.view.issue/batch.css?jira.create.linked.issue=true","startTime":166.90000009536743,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":166.90000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":375.80000019073486,"responseStart":0,"secureConnectionStart":0},{"duration":208.7000002861023,"initiatorType":"script","name":"https://jira.mariadb.org/s/81b5d7c27af3ebc078cc4a36383678ba-CDN/lu2bsh/820016/12ta74/d176f0986478cc64f24226b3d20c140d/_/download/contextbatch/js/com.atlassian.jira.projects.sidebar.init,-_super,-project.issue.navigator,-jira.view.issue/batch.js?jira.create.linked.issue=true&locale=en","startTime":167,"connectEnd":167,"connectStart":167,"domainLookupEnd":167,"domainLookupStart":167,"fetchStart":167,"redirectEnd":0,"redirectStart":0,"requestStart":167,"responseEnd":375.7000002861023,"responseStart":375.7000002861023,"secureConnectionStart":167},{"duration":408.3999996185303,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bsh/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-js/jira.webresources:bigpipe-js.js","startTime":173.2000002861023,"connectEnd":173.2000002861023,"connectStart":173.2000002861023,"domainLookupEnd":173.2000002861023,"domainLookupStart":173.2000002861023,"fetchStart":173.2000002861023,"redirectEnd":0,"redirectStart":0,"requestStart":173.2000002861023,"responseEnd":581.5999999046326,"responseStart":581.5999999046326,"secureConnectionStart":173.2000002861023},{"duration":532.5,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bsh/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-init/jira.webresources:bigpipe-init.js","startTime":173.5,"connectEnd":173.5,"connectStart":173.5,"domainLookupEnd":173.5,"domainLookupStart":173.5,"fetchStart":173.5,"redirectEnd":0,"redirectStart":0,"requestStart":173.5,"responseEnd":706,"responseStart":706,"secureConnectionStart":173.5},{"duration":181.30000019073486,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":400.59999990463257,"connectEnd":400.59999990463257,"connectStart":400.59999990463257,"domainLookupEnd":400.59999990463257,"domainLookupStart":400.59999990463257,"fetchStart":400.59999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":400.59999990463257,"responseEnd":581.9000000953674,"responseStart":581.9000000953674,"secureConnectionStart":400.59999990463257},{"duration":129,"initiatorType":"link","name":"https://jira.mariadb.org/s/d5715adaadd168a9002b108b2b039b50-CDN/lu2bsh/820016/12ta74/be4b45e9cec53099498fa61c8b7acba4/_/download/contextbatch/css/jira.project.sidebar,-_super,-project.issue.navigator,-jira.general,-jira.browse.project,-jira.view.issue,-jira.global,-atl.general,-com.atlassian.jira.projects.sidebar.init/batch.css?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&slack-enabled=true","startTime":655.5999999046326,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":655.5999999046326,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":784.5999999046326,"responseStart":0,"secureConnectionStart":0},{"duration":215.09999990463257,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bsh/820016/12ta74/e65b778d185daf5aee24936755b43da6/_/download/contextbatch/js/browser-metrics-plugin.contrib,-_super,-project.issue.navigator,-jira.view.issue,-atl.general/batch.js?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&slack-enabled=true","startTime":656.5,"connectEnd":656.5,"connectStart":656.5,"domainLookupEnd":656.5,"domainLookupStart":656.5,"fetchStart":656.5,"redirectEnd":0,"redirectStart":0,"requestStart":656.5,"responseEnd":871.5999999046326,"responseStart":871.5999999046326,"secureConnectionStart":656.5},{"duration":219.2000002861023,"initiatorType":"script","name":"https://jira.mariadb.org/s/a000436f14ae82363031988faf35ddba-CDN/lu2bsh/820016/12ta74/be4b45e9cec53099498fa61c8b7acba4/_/download/contextbatch/js/jira.project.sidebar,-_super,-project.issue.navigator,-jira.general,-jira.browse.project,-jira.view.issue,-jira.global,-atl.general,-com.atlassian.jira.projects.sidebar.init/batch.js?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&locale=en&slack-enabled=true","startTime":657,"connectEnd":657,"connectStart":657,"domainLookupEnd":657,"domainLookupStart":657,"fetchStart":657,"redirectEnd":0,"redirectStart":0,"requestStart":657,"responseEnd":876.2000002861023,"responseStart":876.2000002861023,"secureConnectionStart":657},{"duration":131.59999990463257,"initiatorType":"script","name":"https://www.google-analytics.com/analytics.js","startTime":754.8000001907349,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":754.8000001907349,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":886.4000000953674,"responseStart":0,"secureConnectionStart":0}],"fetchStart":0,"domainLookupStart":0,"domainLookupEnd":0,"connectStart":0,"connectEnd":0,"requestStart":8,"responseStart":160,"responseEnd":172,"domLoading":164,"domInteractive":950,"domContentLoadedEventStart":950,"domContentLoadedEventEnd":1007,"domComplete":1322,"loadEventStart":1322,"loadEventEnd":1322,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":918.7000002861023},{"name":"bigPipe.sidebar-id.end","time":919.5},{"name":"bigPipe.activity-panel-pipe-id.start","time":919.7000002861023},{"name":"bigPipe.activity-panel-pipe-id.end","time":920.7000002861023},{"name":"activityTabFullyLoaded","time":1021}],"measures":[],"correlationId":"c636cba5393d44","effectiveType":"4g","downlink":10,"rtt":0,"serverDuration":84,"dbReadsTimeInMs":15,"dbConnsTimeInMs":22,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}