Skip to content

Commit

Permalink
[misc] ensure supporting session_track_system_variables='*'
Browse files Browse the repository at this point in the history
  • Loading branch information
rusher committed Sep 10, 2024
1 parent 432b3ce commit 6e133b6
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 23 deletions.
20 changes: 15 additions & 5 deletions src/main/java/org/mariadb/r2dbc/MariadbConnectionFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -157,19 +157,29 @@ public static Mono<Void> setSessionVariables(

// set session tracking
if ((client.getContext().getClientCapabilities() & Capabilities.CLIENT_SESSION_TRACK) > 0) {
sql.append(",session_track_schema=1");
sql.append(",session_track_schema=1,session_track_system_variables=");
if (!client.getContext().getVersion().isMariaDBServer()) {
// MySQL only support 8 version that always have autocommit and doesn't permit adding
// autocommit value if already present
sql.append(",session_track_system_variables=CONCAT(@@session_track_system_variables,',")
sql.append(
"IF(@@session_track_system_variables = '*', '*',"
+ " IF(@@session_track_system_variables = '', '")
.append(txIsolation)
.append("', CONCAT(@@session_track_system_variables,',")
.append(txIsolation)
.append("')");
.append("')))");
} else {
sql.append(
",session_track_system_variables=CONCAT(@@session_track_system_variables,',autocommit,")
"IF(@@session_track_system_variables = '*', '*',"
+ " IF(@@session_track_system_variables = '', 'autocommit,")
.append(txIsolation)
.append("', CONCAT(@@session_track_system_variables,',autocommit,")
.append(txIsolation)
.append("')");
.append("')))");
}

;

client
.getContext()
.setIsolationLevel(
Expand Down
60 changes: 42 additions & 18 deletions src/test/java/org/mariadb/r2dbc/integration/LoggingTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,53 +72,77 @@ void basicLogging() throws IOException {
" +-------------------------------------------------+\r\n" +
" | 0 1 2 3 4 5 6 7 8 9 a b c d e f |\r\n" +
"+--------+-------------------------------------------------+----------------+\r\n" +
"|00000000| b9 00 00 00 03 53 45 54 20 20 6e 61 6d 65 73 20 |.....SET names |\r\n" +
"|00000000| 30 01 00 00 03 53 45 54 20 20 6e 61 6d 65 73 20 |0....SET names |\r\n" +
"|00000010| 55 54 46 38 4d 42 34 2c 61 75 74 6f 63 6f 6d 6d |UTF8MB4,autocomm|\r\n" +
"|00000020| 69 74 3d 31 2c 74 78 5f 69 73 6f 6c 61 74 69 6f |it=1,tx_isolatio|\r\n" +
"|00000030| 6e 3d 27 52 45 50 45 41 54 41 42 4c 45 2d 52 45 |n='REPEATABLE-RE|\r\n" +
"|00000040| 41 44 27 2c 73 65 73 73 69 6f 6e 5f 74 72 61 63 |AD',session_trac|\r\n" +
"|00000050| 6b 5f 73 63 68 65 6d 61 3d 31 2c 73 65 73 73 69 |k_schema=1,sessi|\r\n" +
"|00000060| 6f 6e 5f 74 72 61 63 6b 5f 73 79 73 74 65 6d 5f |on_track_system_|\r\n" +
"|00000070| 76 61 72 69 61 62 6c 65 73 3d 43 4f 4e 43 41 54 |variables=CONCAT|\r\n" +
"|00000080| 28 40 40 73 65 73 73 69 6f 6e 5f 74 72 61 63 6b |(@@session_track|\r\n" +
"|00000090| 5f 73 79 73 74 65 6d 5f 76 61 72 69 61 62 6c 65 |_system_variable|\r\n" +
"|000000a0| 73 2c 27 2c 61 75 74 6f 63 6f 6d 6d 69 74 2c 74 |s,',autocommit,t|\r\n" +
"|000000b0| 78 5f 69 73 6f 6c 61 74 69 6f 6e 27 29 |x_isolation') |\r\n" +
"|00000070| 76 61 72 69 61 62 6c 65 73 3d 49 46 28 40 40 73 |variables=IF(@@s|\r\n" +
"|00000080| 65 73 73 69 6f 6e 5f 74 72 61 63 6b 5f 73 79 73 |ession_track_sys|\r\n" +
"|00000090| 74 65 6d 5f 76 61 72 69 61 62 6c 65 73 20 3d 20 |tem_variables = |\r\n" +
"|000000a0| 27 2a 27 2c 20 27 2a 27 2c 20 49 46 28 40 40 73 |'*', '*', IF(@@s|\r\n" +
"|000000b0| 65 73 73 69 6f 6e 5f 74 72 61 63 6b 5f 73 79 73 |ession_track_sys|\r\n" +
"|000000c0| 74 65 6d 5f 76 61 72 69 61 62 6c 65 73 20 3d 20 |tem_variables = |\r\n" +
"|000000d0| 27 27 2c 20 27 61 75 74 6f 63 6f 6d 6d 69 74 2c |'', 'autocommit,|\r\n" +
"|000000e0| 74 78 5f 69 73 6f 6c 61 74 69 6f 6e 27 2c 20 43 |tx_isolation', C|\r\n" +
"|000000f0| 4f 4e 43 41 54 28 40 40 73 65 73 73 69 6f 6e 5f |ONCAT(@@session_|\r\n" +
"|00000100| 74 72 61 63 6b 5f 73 79 73 74 65 6d 5f 76 61 72 |track_system_var|\r\n" +
"|00000110| 69 61 62 6c 65 73 2c 27 2c 61 75 74 6f 63 6f 6d |iables,',autocom|\r\n" +
"|00000120| 6d 69 74 2c 74 78 5f 69 73 6f 6c 61 74 69 6f 6e |mit,tx_isolation|\r\n" +
"|00000130| 27 29 29 29 |'))) |\r\n" +
"+--------+-------------------------------------------------+----------------+";
String transactionIsolation =
" +-------------------------------------------------+\r\n" +
" | 0 1 2 3 4 5 6 7 8 9 a b c d e f |\r\n" +
"+--------+-------------------------------------------------+----------------+\r\n" +
"|00000000| cb 00 00 00 03 53 45 54 20 20 6e 61 6d 65 73 20 |.....SET names |\r\n" +
"|00000000| 4b 01 00 00 03 53 45 54 20 20 6e 61 6d 65 73 20 |K....SET names |\r\n" +
"|00000010| 55 54 46 38 4d 42 34 2c 61 75 74 6f 63 6f 6d 6d |UTF8MB4,autocomm|\r\n" +
"|00000020| 69 74 3d 31 2c 74 72 61 6e 73 61 63 74 69 6f 6e |it=1,transaction|\r\n" +
"|00000030| 5f 69 73 6f 6c 61 74 69 6f 6e 3d 27 52 45 50 45 |_isolation='REPE|\r\n" +
"|00000040| 41 54 41 42 4c 45 2d 52 45 41 44 27 2c 73 65 73 |ATABLE-READ',ses|\r\n" +
"|00000050| 73 69 6f 6e 5f 74 72 61 63 6b 5f 73 63 68 65 6d |sion_track_schem|\r\n" +
"|00000060| 61 3d 31 2c 73 65 73 73 69 6f 6e 5f 74 72 61 63 |a=1,session_trac|\r\n" +
"|00000070| 6b 5f 73 79 73 74 65 6d 5f 76 61 72 69 61 62 6c |k_system_variabl|\r\n" +
"|00000080| 65 73 3d 43 4f 4e 43 41 54 28 40 40 73 65 73 73 |es=CONCAT(@@sess|\r\n" +
"|00000090| 69 6f 6e 5f 74 72 61 63 6b 5f 73 79 73 74 65 6d |ion_track_system|\r\n" +
"|000000a0| 5f 76 61 72 69 61 62 6c 65 73 2c 27 2c 61 75 74 |_variables,',aut|\r\n" +
"|000000b0| 6f 63 6f 6d 6d 69 74 2c 74 72 61 6e 73 61 63 74 |ocommit,transact|\r\n" +
"|000000c0| 69 6f 6e 5f 69 73 6f 6c 61 74 69 6f 6e 27 29 |ion_isolation') |";
"|00000080| 65 73 3d 49 46 28 40 40 73 65 73 73 69 6f 6e 5f |es=IF(@@session_|\r\n" +
"|00000090| 74 72 61 63 6b 5f 73 79 73 74 65 6d 5f 76 61 72 |track_system_var|\r\n" +
"|000000a0| 69 61 62 6c 65 73 20 3d 20 27 2a 27 2c 20 27 2a |iables = '*', '*|\r\n" +
"|000000b0| 27 2c 20 49 46 28 40 40 73 65 73 73 69 6f 6e 5f |', IF(@@session_|\r\n" +
"|000000c0| 74 72 61 63 6b 5f 73 79 73 74 65 6d 5f 76 61 72 |track_system_var|\r\n" +
"|000000d0| 69 61 62 6c 65 73 20 3d 20 27 27 2c 20 27 61 75 |iables = '', 'au|\r\n" +
"|000000e0| 74 6f 63 6f 6d 6d 69 74 2c 74 72 61 6e 73 61 63 |tocommit,transac|\r\n" +
"|000000f0| 74 69 6f 6e 5f 69 73 6f 6c 61 74 69 6f 6e 27 2c |tion_isolation',|\r\n" +
"|00000100| 20 43 4f 4e 43 41 54 28 40 40 73 65 73 73 69 6f | CONCAT(@@sessio|\r\n" +
"|00000110| 6e 5f 74 72 61 63 6b 5f 73 79 73 74 65 6d 5f 76 |n_track_system_v|\r\n" +
"|00000120| 61 72 69 61 62 6c 65 73 2c 27 2c 61 75 74 6f 63 |ariables,',autoc|\r\n" +
"|00000130| 6f 6d 6d 69 74 2c 74 72 61 6e 73 61 63 74 69 6f |ommit,transactio|\r\n" +
"|00000140| 6e 5f 69 73 6f 6c 61 74 69 6f 6e 27 29 29 29 |n_isolation'))) |\r\n" +
"+--------+-------------------------------------------------+----------------+";
String mysqlIsolation =
" +-------------------------------------------------+\r\n" +
" | 0 1 2 3 4 5 6 7 8 9 a b c d e f |\r\n" +
"+--------+-------------------------------------------------+----------------+\r\n" +
"|00000000| c0 00 00 00 03 53 45 54 20 20 6e 61 6d 65 73 20 |.....SET names |\r\n" +
"|00000000| 35 01 00 00 03 53 45 54 20 20 6e 61 6d 65 73 20 |5....SET names |\r\n" +
"|00000010| 55 54 46 38 4d 42 34 2c 61 75 74 6f 63 6f 6d 6d |UTF8MB4,autocomm|\r\n" +
"|00000020| 69 74 3d 31 2c 74 72 61 6e 73 61 63 74 69 6f 6e |it=1,transaction|\r\n" +
"|00000030| 5f 69 73 6f 6c 61 74 69 6f 6e 3d 27 52 45 50 45 |_isolation='REPE|\r\n" +
"|00000040| 41 54 41 42 4c 45 2d 52 45 41 44 27 2c 73 65 73 |ATABLE-READ',ses|\r\n" +
"|00000050| 73 69 6f 6e 5f 74 72 61 63 6b 5f 73 63 68 65 6d |sion_track_schem|\r\n" +
"|00000060| 61 3d 31 2c 73 65 73 73 69 6f 6e 5f 74 72 61 63 |a=1,session_trac|\r\n" +
"|00000070| 6b 5f 73 79 73 74 65 6d 5f 76 61 72 69 61 62 6c |k_system_variabl|\r\n" +
"|00000080| 65 73 3d 43 4f 4e 43 41 54 28 40 40 73 65 73 73 |es=CONCAT(@@sess|\r\n" +
"|00000090| 69 6f 6e 5f 74 72 61 63 6b 5f 73 79 73 74 65 6d |ion_track_system|\r\n" +
"|000000a0| 5f 76 61 72 69 61 62 6c 65 73 2c 27 2c 74 72 61 |_variables,',tra|\r\n" +
"|000000b0| 6e 73 61 63 74 69 6f 6e 5f 69 73 6f 6c 61 74 69 |nsaction_isolati|\r\n" +
"|000000c0| 6f 6e 27 29 |on') |\r\n" +
"|00000080| 65 73 3d 49 46 28 40 40 73 65 73 73 69 6f 6e 5f |es=IF(@@session_|\r\n" +
"|00000090| 74 72 61 63 6b 5f 73 79 73 74 65 6d 5f 76 61 72 |track_system_var|\r\n" +
"|000000a0| 69 61 62 6c 65 73 20 3d 20 27 2a 27 2c 20 27 2a |iables = '*', '*|\r\n" +
"|000000b0| 27 2c 20 49 46 28 40 40 73 65 73 73 69 6f 6e 5f |', IF(@@session_|\r\n" +
"|000000c0| 74 72 61 63 6b 5f 73 79 73 74 65 6d 5f 76 61 72 |track_system_var|\r\n" +
"|000000d0| 69 61 62 6c 65 73 20 3d 20 27 27 2c 20 27 74 72 |iables = '', 'tr|\r\n" +
"|000000e0| 61 6e 73 61 63 74 69 6f 6e 5f 69 73 6f 6c 61 74 |ansaction_isolat|\r\n" +
"|000000f0| 69 6f 6e 27 2c 20 43 4f 4e 43 41 54 28 40 40 73 |ion', CONCAT(@@s|\r\n" +
"|00000100| 65 73 73 69 6f 6e 5f 74 72 61 63 6b 5f 73 79 73 |ession_track_sys|\r\n" +
"|00000110| 74 65 6d 5f 76 61 72 69 61 62 6c 65 73 2c 27 2c |tem_variables,',|\r\n" +
"|00000120| 74 72 61 6e 73 61 63 74 69 6f 6e 5f 69 73 6f 6c |transaction_isol|\r\n" +
"|00000130| 61 74 69 6f 6e 27 29 29 29 |ation'))) |\r\n" +
"+--------+-------------------------------------------------+----------------+";
if ((meta.isMariaDBServer() && !meta.minVersion(11, 1, 1))
|| (meta.getMajorVersion() < 8 && !meta.minVersion(5, 7, 20))
Expand Down

0 comments on commit 6e133b6

Please sign in to comment.