mysql - Character encodings of strings in gradle -
so in gradle build, why java string
"foo" acceptable mysql database utf-8 encoding, gstring "${somevalue}" not be?
what's happening this:
sql.withtransaction { def batchresult = sql.withbatch( 20, 'insert table(job_id, log_name, scenario_name, classification, value) values (?,?,?,?,?)'){ stmt -> rows.each { r -> def jobid = "${system.getenv('job_name')}:${system.getenv('build_number')}" def classifier = "{'observer_id':${r['observer_id']}, 'sensor_name':${r['sensor_name']}}" stmt.addbatch( jobid, "foo", project.scenariofilename, classifier, r['count(1)']) } } this fails because utf-8 encoded database rejects value of jobid (and project.scenariofilename, , classifier), spewing escaped characters \xac unacceptable.
but what's funny is, if this
stmt.addbatch( new string(jobidstr.getbytes("utf-16"),"utf-8"), "foo", new string(project.scenariofilename.getbytes("utf-16"),"utf-8"), new string(classifier.getbytes("utf-16"),"utf-8"), r['count(1)'] ) it works.
so why "foo" seen utf-8, "${system.getenv('job_name')}" not?
incidentally, setting systemprop.file.encoding=utf-8 in gradle.properties doesn't change anything.
add .tostring() @ end of gstrings ("${..}:${..}".tostring()) when using in groovy sql.
Comments
Post a Comment