When using C API prepared statements with a client character set different from the character set used for a table column, the statement can not be replicated.
Using the Connector/C specifically with these steps:
- mysql_options(mysql, MYSQL_SET_CHARSET_NAME, "gbk");
- CREATE TABLE with a VARCHAR COLLATE utf8mb4
- mysql_stmt_prepare, mysql_stmt_bind_param
On the primary, the data given with mysql_stmt_bind_param will be interpreted as specified with MYSQL_SET_CHARSET_NAME, but the binary log will contain this:
SET @@session.character_set_client=gbk,@@session.collation_connection=28,@@session.collation_server=8/*!*/;
|
INSERT INTO test_charset SET c=X'2D3E20B8B1B1BE203C2D'
|
The hexadecimal literal here will be interpreted using the column's character set (which is not valid, because this is not UTF8).
Full C code:
#include "stdafx.h"
|
#include <assert.h>
|
#include "mysql.h"
|
|
|
int main(int argc, char* argv[])
|
{
|
int error_code;
|
MYSQL* mysql = mysql_init(NULL);
|
assert(mysql != NULL);
|
|
mysql_options(mysql, MYSQL_SET_CHARSET_NAME, "gbk");
|
MYSQL* mysql2 = mysql_real_connect(mysql, "localhost", "root", "", "test", 3307, NULL, 0);
|
assert(mysql2 != NULL);
|
error_code = mysql_query(mysql,
|
"CREATE TABLE IF NOT EXISTS `test_charset` ("
|
"`c` VARCHAR(50) NULL DEFAULT NULL COLLATE 'utf8mb4_unicode_ci',"
|
"`t` TIMESTAMP NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()"
|
")");
|
assert(error_code == 0);
|
|
MYSQL_BIND bind;
|
MYSQL_STMT *stmt = mysql_stmt_init(mysql);
|
assert(stmt != NULL);
|
char insert_statement[] = "INSERT INTO test_charset SET c=?";
|
// char insert_statement[] = "INSERT INTO test_charset SET c=CONVERT(?, CHAR)";
|
error_code = mysql_stmt_prepare(stmt, insert_statement, strlen(insert_statement));
|
assert(error_code == 0);
|
memset(&bind, 0, sizeof(bind));
|
bind.buffer_type = MYSQL_TYPE_STRING;
|
bind.buffer = "-> \xB8\xB1\xB1\xBE <-";
|
bind.buffer_length = strlen((char*)bind.buffer);
|
bind.length = &bind.buffer_length;
|
error_code = mysql_stmt_bind_param(stmt, &bind);
|
assert(error_code == 0);
|
error_code = mysql_stmt_execute(stmt);
|
assert(error_code == 0);
|
|
mysql_close(mysql);
|
|
return 0;
|
}
|
I am honestly not sure where the bug here is.
- Is my prepared statement wrong, and I should have used CONVERT(?, CHAR) in the first place?
- Is the Connector/C doing something wrong here?
- Is the statement recorded in the binary log wrong?
- Should any binary string when converted to a text string interpreted according to character_set_connection (or character_set_client)?
{"report":{"fcp":979.6999998092651,"ttfb":222.2999997138977,"pageVisibility":"visible","entityId":130287,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":0.5,"journeyId":"e490ecd2-6206-4314-8a4f-59be3718e6d2","navigationType":0,"readyForUser":1063.2999997138977,"redirectCount":0,"resourceLoadedEnd":1565.2999997138977,"resourceLoadedStart":228.69999980926514,"resourceTiming":[{"duration":260,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":228.69999980926514,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":228.69999980926514,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":488.69999980926514,"responseStart":0,"secureConnectionStart":0},{"duration":260.09999990463257,"initiatorType":"link","name":"https://jira.mariadb.org/s/7ebd35e77e471bc30ff0eba799ebc151-CDN/lu2cib/820016/12ta74/494e4c556ecbb29f90a3d3b4f09cb99c/_/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&whisper-enabled=true","startTime":229,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":229,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":489.09999990463257,"responseStart":0,"secureConnectionStart":0},{"duration":270.09999990463257,"initiatorType":"script","name":"https://jira.mariadb.org/s/0917945aaa57108d00c5076fea35e069-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":229.19999980926514,"connectEnd":229.19999980926514,"connectStart":229.19999980926514,"domainLookupEnd":229.19999980926514,"domainLookupStart":229.19999980926514,"fetchStart":229.19999980926514,"redirectEnd":0,"redirectStart":0,"requestStart":229.19999980926514,"responseEnd":499.2999997138977,"responseStart":499.2999997138977,"secureConnectionStart":229.19999980926514},{"duration":321.90000009536743,"initiatorType":"script","name":"https://jira.mariadb.org/s/2d8175ec2fa4c816e8023260bd8c1786-CDN/lu2cib/820016/12ta74/494e4c556ecbb29f90a3d3b4f09cb99c/_/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&whisper-enabled=true","startTime":229.2999997138977,"connectEnd":229.2999997138977,"connectStart":229.2999997138977,"domainLookupEnd":229.2999997138977,"domainLookupStart":229.2999997138977,"fetchStart":229.2999997138977,"redirectEnd":0,"redirectStart":0,"requestStart":229.2999997138977,"responseEnd":551.1999998092651,"responseStart":551.1999998092651,"secureConnectionStart":229.2999997138977},{"duration":325.5,"initiatorType":"script","name":"https://jira.mariadb.org/s/a9324d6758d385eb45c462685ad88f1d-CDN/lu2cib/820016/12ta74/c92c0caa9a024ae85b0ebdbed7fb4bd7/_/download/contextbatch/js/atl.global,-_super/batch.js?locale=en","startTime":229.59999990463257,"connectEnd":229.59999990463257,"connectStart":229.59999990463257,"domainLookupEnd":229.59999990463257,"domainLookupStart":229.59999990463257,"fetchStart":229.59999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":229.59999990463257,"responseEnd":555.0999999046326,"responseStart":555.0999999046326,"secureConnectionStart":229.59999990463257},{"duration":325.6000003814697,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-en/jira.webresources:calendar-en.js","startTime":229.89999961853027,"connectEnd":229.89999961853027,"connectStart":229.89999961853027,"domainLookupEnd":229.89999961853027,"domainLookupStart":229.89999961853027,"fetchStart":229.89999961853027,"redirectEnd":0,"redirectStart":0,"requestStart":229.89999961853027,"responseEnd":555.5,"responseStart":555.5,"secureConnectionStart":229.89999961853027},{"duration":325.90000009536743,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-localisation-moment/jira.webresources:calendar-localisation-moment.js","startTime":230.09999990463257,"connectEnd":230.09999990463257,"connectStart":230.09999990463257,"domainLookupEnd":230.09999990463257,"domainLookupStart":230.09999990463257,"fetchStart":230.09999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":230.09999990463257,"responseEnd":556,"responseStart":556,"secureConnectionStart":230.09999990463257},{"duration":415,"initiatorType":"link","name":"https://jira.mariadb.org/s/b04b06a02d1959df322d9cded3aeecc1-CDN/lu2cib/820016/12ta74/a2ff6aa845ffc9a1d22fe23d9ee791fc/_/download/contextbatch/css/jira.global.look-and-feel,-_super/batch.css","startTime":230.19999980926514,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":230.19999980926514,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":645.1999998092651,"responseStart":0,"secureConnectionStart":0},{"duration":326.2000002861023,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":230.39999961853027,"connectEnd":230.39999961853027,"connectStart":230.39999961853027,"domainLookupEnd":230.39999961853027,"domainLookupStart":230.39999961853027,"fetchStart":230.39999961853027,"redirectEnd":0,"redirectStart":0,"requestStart":230.39999961853027,"responseEnd":556.5999999046326,"responseStart":556.5999999046326,"secureConnectionStart":230.39999961853027},{"duration":414.7999997138977,"initiatorType":"link","name":"https://jira.mariadb.org/s/3ac36323ba5e4eb0af2aa7ac7211b4bb-CDN/lu2cib/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":230.59999990463257,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":230.59999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":645.3999996185303,"responseStart":0,"secureConnectionStart":0},{"duration":326.5,"initiatorType":"script","name":"https://jira.mariadb.org/s/5d5e8fe91fbc506585e83ea3b62ccc4b-CDN/lu2cib/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":230.69999980926514,"connectEnd":230.69999980926514,"connectStart":230.69999980926514,"domainLookupEnd":230.69999980926514,"domainLookupStart":230.69999980926514,"fetchStart":230.69999980926514,"redirectEnd":0,"redirectStart":0,"requestStart":230.69999980926514,"responseEnd":557.1999998092651,"responseStart":557.1999998092651,"secureConnectionStart":230.69999980926514},{"duration":504.5,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-js/jira.webresources:bigpipe-js.js","startTime":231.5,"connectEnd":231.5,"connectStart":231.5,"domainLookupEnd":231.5,"domainLookupStart":231.5,"fetchStart":231.5,"redirectEnd":0,"redirectStart":0,"requestStart":231.5,"responseEnd":736,"responseStart":736,"secureConnectionStart":231.5},{"duration":1318.4000000953674,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-init/jira.webresources:bigpipe-init.js","startTime":231.59999990463257,"connectEnd":231.59999990463257,"connectStart":231.59999990463257,"domainLookupEnd":231.59999990463257,"domainLookupStart":231.59999990463257,"fetchStart":231.59999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":231.59999990463257,"responseEnd":1550,"responseStart":1550,"secureConnectionStart":231.59999990463257},{"duration":79.40000009536743,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":657.0999999046326,"connectEnd":657.0999999046326,"connectStart":657.0999999046326,"domainLookupEnd":657.0999999046326,"domainLookupStart":657.0999999046326,"fetchStart":657.0999999046326,"redirectEnd":0,"redirectStart":0,"requestStart":657.0999999046326,"responseEnd":736.5,"responseStart":736.3999996185303,"secureConnectionStart":657.0999999046326},{"duration":633.5999999046326,"initiatorType":"link","name":"https://jira.mariadb.org/s/d5715adaadd168a9002b108b2b039b50-CDN/lu2cib/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&whisper-enabled=true","startTime":931.6999998092651,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":931.6999998092651,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1565.2999997138977,"responseStart":0,"secureConnectionStart":0},{"duration":667.7000002861023,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/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&whisper-enabled=true","startTime":932.7999997138977,"connectEnd":932.7999997138977,"connectStart":932.7999997138977,"domainLookupEnd":932.7999997138977,"domainLookupStart":932.7999997138977,"fetchStart":932.7999997138977,"redirectEnd":0,"redirectStart":0,"requestStart":932.7999997138977,"responseEnd":1600.5,"responseStart":1600.5,"secureConnectionStart":932.7999997138977},{"duration":674.3000001907349,"initiatorType":"script","name":"https://jira.mariadb.org/s/097ae97cb8fbec7d6ea4bbb1f26955b9-CDN/lu2cib/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&whisper-enabled=true","startTime":933.1999998092651,"connectEnd":933.1999998092651,"connectStart":933.1999998092651,"domainLookupEnd":933.1999998092651,"domainLookupStart":933.1999998092651,"fetchStart":933.1999998092651,"redirectEnd":0,"redirectStart":0,"requestStart":933.1999998092651,"responseEnd":1607.5,"responseStart":1607.5,"secureConnectionStart":933.1999998092651}],"fetchStart":0,"domainLookupStart":0,"domainLookupEnd":0,"connectStart":0,"connectEnd":0,"requestStart":31,"responseStart":222,"responseEnd":226,"domLoading":226,"domInteractive":1574,"domContentLoadedEventStart":1574,"domContentLoadedEventEnd":1617,"domComplete":2313,"loadEventStart":2313,"loadEventEnd":2314,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":1551.7999997138977},{"name":"bigPipe.sidebar-id.end","time":1552.6999998092651},{"name":"bigPipe.activity-panel-pipe-id.start","time":1552.8999996185303},{"name":"bigPipe.activity-panel-pipe-id.end","time":1554.1999998092651},{"name":"activityTabFullyLoaded","time":1632}],"measures":[],"correlationId":"676c4552a10fed","effectiveType":"4g","downlink":9.4,"rtt":0,"serverDuration":124,"dbReadsTimeInMs":9,"dbConnsTimeInMs":18,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}
I've been trying to reproduce this without the Connector/C but with prepared statements in SQL. During that I came across this, which also doesn't replicate, but the issue seems to be slightly different:
While the original issue from above was that the master replaced the bound parameter with a hexadecimal literal, here it is a normal string literal. Still, the charset information is missing.