@@ -171,11 +171,20 @@ public void testDoubleQuotedDatabaseAndSchema() throws Exception {
171
171
// To query the schema and table, we can use a normal java escaped quote. Wildcards are also
172
172
// escaped here
173
173
String schemaRandomPart = SnowflakeUtil .randomAlphaNumeric (5 );
174
- String querySchema = "TEST\\ _SCHEMA\\ _\" WITH\\ _QUOTES" + schemaRandomPart + "\" " ;
174
+ String querySchema =
175
+ TestUtil .ESCAPED_GENERATED_SCHEMA_PREFIX
176
+ + "TEST\\ _SCHEMA\\ _\" WITH\\ _QUOTES"
177
+ + schemaRandomPart
178
+ + "\" " ;
175
179
String queryTable = "TESTTABLE\\ _\" WITH\\ _QUOTES\" " ;
176
180
// Create the schema and table. With SQL commands, double quotes must be escaped with another
177
181
// quote
178
- String schemaName = "\" TEST_SCHEMA_\" \" WITH_QUOTES" + schemaRandomPart + "\" \" \" " ;
182
+ String schemaName =
183
+ "\" "
184
+ + TestUtil .GENERATED_SCHEMA_PREFIX
185
+ + "TEST_SCHEMA_\" \" WITH_QUOTES"
186
+ + schemaRandomPart
187
+ + "\" \" \" " ;
179
188
TestUtil .withSchema (
180
189
statement ,
181
190
schemaName ,
@@ -367,24 +376,26 @@ public void testGetFunctionSqlInjectionProtection() throws Throwable {
367
376
*/
368
377
@ Test
369
378
public void testGetProcedureColumnsWildcards () throws SQLException {
370
- try (Connection con = getConnection ()) {
371
- Statement statement = con .createStatement ();
379
+ try (Connection con = getConnection ();
380
+ Statement statement = con .createStatement ()) {
372
381
String database = con .getCatalog ();
373
- String schema1 = "SCH1" ;
374
- String schema2 = "SCH2" ;
382
+ String schemaPrefix =
383
+ TestUtil .GENERATED_SCHEMA_PREFIX + SnowflakeUtil .randomAlphaNumeric (5 ).toUpperCase ();
384
+ String schema1 = schemaPrefix + "SCH1" ;
385
+ String schema2 = schemaPrefix + "SCH2" ;
375
386
// Create 2 schemas, each with the same stored procedure declared in them
376
387
statement .execute ("create or replace schema " + schema1 );
377
388
statement .execute (TEST_PROC );
378
389
statement .execute ("create or replace schema " + schema2 );
379
390
statement .execute (TEST_PROC );
380
391
DatabaseMetaData metaData = con .getMetaData ();
381
- ResultSet rs = metaData . getProcedureColumns ( database , "SCH_" , "TESTPROC" , "PARAM1" );
382
- // Assert 4 rows returned for the param PARAM1 that's present in each of the 2 identical
383
- // stored procs in different schemas. A result row is returned for each procedure, making the
384
- // total rowcount 4
385
- assertEquals ( 4 , getSizeOfResultSet ( rs ));
386
- rs . close ( );
387
- statement . close ();
392
+ try ( ResultSet rs =
393
+ metaData . getProcedureColumns ( database , schemaPrefix + "SCH_" , "TESTPROC" , " PARAM1" )) {
394
+ // Assert 4 rows returned for the param PARAM1 that's present in each of the 2 identical
395
+ // stored procs in different schemas. A result row is returned for each procedure, making
396
+ // the total rowcount 4
397
+ assertEquals ( 4 , getSizeOfResultSet ( rs ) );
398
+ }
388
399
}
389
400
}
390
401
@@ -453,7 +464,7 @@ public void testGetStringValueFromColumnDef() throws SQLException {
453
464
454
465
@ Test
455
466
public void testGetColumnsNullable () throws Throwable {
456
- try (Connection connection = getConnection ()) {
467
+ try (Connection connection = getConnection (); ) {
457
468
String database = connection .getCatalog ();
458
469
String schema = connection .getSchema ();
459
470
final String targetTable = "T0" ;
@@ -484,8 +495,8 @@ public void testSessionDatabaseParameter() throws Throwable {
484
495
String altdb = "ALTERNATEDB" ;
485
496
String altschema1 = "ALTERNATESCHEMA1" ;
486
497
String altschema2 = "ALTERNATESCHEMA2" ;
487
- try (Connection connection = getConnection ()) {
488
- Statement statement = connection .createStatement ();
498
+ try (Connection connection = getConnection ();
499
+ Statement statement = connection .createStatement ()) {
489
500
String catalog = connection .getCatalog ();
490
501
String schema = connection .getSchema ();
491
502
statement .execute ("create or replace database " + altdb );
@@ -905,7 +916,12 @@ public void testHandlingSpecialChars() throws Exception {
905
916
statement .execute ("INSERT INTO \" TEST\\ 1\\ _1\" (\" C%1\" ,\" C\\ 1\\ \\ 11\" ) VALUES (0,0)" );
906
917
// test getColumns with escaped special characters in schema and table name
907
918
String specialSchemaSuffix = SnowflakeUtil .randomAlphaNumeric (5 );
908
- String specialSchema = "\" SPECIAL%_\\ SCHEMA" + specialSchemaSuffix + "\" " ;
919
+ String specialSchema =
920
+ "\" "
921
+ + TestUtil .GENERATED_SCHEMA_PREFIX
922
+ + "SPECIAL%_\\ SCHEMA"
923
+ + specialSchemaSuffix
924
+ + "\" " ;
909
925
TestUtil .withSchema (
910
926
statement ,
911
927
specialSchema ,
@@ -939,7 +955,13 @@ public void testHandlingSpecialChars() throws Exception {
939
955
940
956
String escapedTable2 = "TEST" + escapeChar + "_1" + escapeChar + "_1" ;
941
957
String escapedSchema =
942
- "SPECIAL%" + escapeChar + "_" + escapeChar + "\\ SCHEMA" + specialSchemaSuffix ;
958
+ TestUtil .ESCAPED_GENERATED_SCHEMA_PREFIX
959
+ + "SPECIAL%"
960
+ + escapeChar
961
+ + "_"
962
+ + escapeChar
963
+ + "\\ SCHEMA"
964
+ + specialSchemaSuffix ;
943
965
resultSet = metaData .getColumns (database , escapedSchema , escapedTable2 , null );
944
966
assertTrue (resultSet .next ());
945
967
assertEquals ("RNUM" , resultSet .getString ("COLUMN_NAME" ));
0 commit comments