@@ -406,15 +406,25 @@ private void postConnectionQueries() throws SQLException {
406
406
* @return sql setting session command
407
407
*/
408
408
public String createSessionVariableQuery (String serverTz , Context context ) {
409
- // In JDBC, connection must start in autocommit mode
410
- // [CONJ-269] we cannot rely on serverStatus & ServerStatus.AUTOCOMMIT before this command to
411
- // avoid this command.
412
- // if autocommit=0 is set on server configuration, DB always send Autocommit on serverStatus
413
- // flag
414
- // after setting autocommit, we can rely on serverStatus value
415
409
List <String > sessionCommands = new ArrayList <>();
416
- if (conf .autocommit () != null ) {
417
- sessionCommands .add ("autocommit=" + (conf .autocommit () ? "1" : "0" ));
410
+
411
+ // In JDBC, connection must start in autocommit mode
412
+ boolean canRelyOnConnectionFlag =
413
+ context .getVersion ().isMariaDBServer ()
414
+ && (context .getVersion ().versionFixedMajorMinorGreaterOrEqual (10 , 4 , 33 )
415
+ || context .getVersion ().versionFixedMajorMinorGreaterOrEqual (10 , 5 , 24 )
416
+ || context .getVersion ().versionFixedMajorMinorGreaterOrEqual (10 , 6 , 17 )
417
+ || context .getVersion ().versionFixedMajorMinorGreaterOrEqual (10 , 11 , 7 )
418
+ || context .getVersion ().versionFixedMajorMinorGreaterOrEqual (11 , 0 , 5 )
419
+ || context .getVersion ().versionFixedMajorMinorGreaterOrEqual (11 , 1 , 4 )
420
+ || context .getVersion ().versionFixedMajorMinorGreaterOrEqual (11 , 2 , 3 ));
421
+ if ((conf .autocommit () == null && (context .getServerStatus () & ServerStatus .AUTOCOMMIT ) == 0 )
422
+ || (conf .autocommit () != null && !canRelyOnConnectionFlag )
423
+ || (conf .autocommit () != null
424
+ && canRelyOnConnectionFlag
425
+ && ((context .getServerStatus () & ServerStatus .AUTOCOMMIT ) > 0 ) != conf .autocommit ())) {
426
+ sessionCommands .add (
427
+ "autocommit=" + ((conf .autocommit () == null || conf .autocommit ()) ? "1" : "0" ));
418
428
}
419
429
420
430
// add configured session variable if configured
0 commit comments