23
23
import org .testng .Assert ;
24
24
import org .testng .annotations .AfterMethod ;
25
25
import org .testng .annotations .BeforeMethod ;
26
+ import org .testng .annotations .DataProvider ;
26
27
import org .testng .annotations .Test ;
27
28
28
29
import com .clickhouse .client .BaseIntegrationTest ;
@@ -232,6 +233,31 @@ void testParamsWithInstant() throws Exception {
232
233
}
233
234
}
234
235
236
+ @ Test (dataProvider = "stringParameters" )
237
+ void testStringParams (String paramValue ) throws Exception {
238
+ String table = "test_params_unicode" ;
239
+ String column = "val" ;
240
+ client .execute ("DROP TABLE IF EXISTS " + table ).get ();
241
+ client .execute ("CREATE TABLE " + table + "(" + column + " String) Engine = Memory" ).get ();
242
+ client .query (
243
+ "INSERT INTO " + table + "(" + column + ") VALUES ('" + paramValue + "')" ).get ();
244
+ try (QueryResponse r = client .query (
245
+ "SELECT " + column + " FROM " + table + " WHERE " + column + "='" + paramValue + "'" ).get ();
246
+ ClickHouseBinaryFormatReader reader = client .newBinaryFormatReader (r ))
247
+ {
248
+ reader .next ();
249
+ Assert .assertEquals (reader .getString (1 ), paramValue );
250
+ }
251
+ try (QueryResponse r = client .query (
252
+ "SELECT " + column + " FROM " + table + " WHERE " + column + "={x:String}" ,
253
+ Collections .singletonMap ("x" , paramValue )).get ();
254
+ ClickHouseBinaryFormatReader reader = client .newBinaryFormatReader (r ))
255
+ {
256
+ reader .next ();
257
+ Assert .assertEquals (reader .getString (1 ), paramValue );
258
+ }
259
+ }
260
+
235
261
private int [] queryInstant (String tableName , String fieldName , String operator ,
236
262
Instant param , int scale ) throws InterruptedException , ExecutionException , Exception
237
263
{
@@ -255,13 +281,13 @@ private Client.Builder newClient() {
255
281
ClickHouseNode node = getServer (ClickHouseProtocol .HTTP );
256
282
boolean isSecure = isCloud ();
257
283
return new Client .Builder ()
258
- .addEndpoint (Protocol .HTTP , node .getHost (), node .getPort (), isSecure )
259
- .setUsername ("default" )
260
- .setPassword (ClickHouseServerForTest .getPassword ())
261
- .compressClientRequest (false )
262
- .setDefaultDatabase (ClickHouseServerForTest .getDatabase ())
263
- .serverSetting (ServerSettings .WAIT_ASYNC_INSERT , "1" )
264
- .serverSetting (ServerSettings .ASYNC_INSERT , "0" );
284
+ .addEndpoint (Protocol .HTTP , node .getHost (), node .getPort (), isSecure )
285
+ .setUsername ("default" )
286
+ .setPassword (ClickHouseServerForTest .getPassword ())
287
+ .compressClientRequest (false )
288
+ .setDefaultDatabase (ClickHouseServerForTest .getDatabase ())
289
+ .serverSetting (ServerSettings .WAIT_ASYNC_INSERT , "1" )
290
+ .serverSetting (ServerSettings .ASYNC_INSERT , "0" );
265
291
}
266
292
267
293
private void prepareDataSet (String table , List <String > columns , List <Supplier <Object >> valueGenerators ,
@@ -319,4 +345,18 @@ private Map<String, Object> writeValuesRow(StringBuilder insertStmtBuilder, List
319
345
return values ;
320
346
}
321
347
348
+ @ DataProvider (name = "stringParameters" )
349
+ private static Object [][] createStringParameterValues () {
350
+ return new Object [][] {
351
+ { "foo" },
352
+ { "with-dashes" },
353
+ { "☺" },
354
+ { "foo/bar" },
355
+ { "foobar 20" },
356
+ { " leading_and_trailing_spaces " },
357
+ { "multi\n line\r \n dos" },
358
+ { "nicely\" quoted\' string\' " },
359
+ };
360
+ }
361
+
322
362
}
0 commit comments