|
37 | 37 | "INSERT INTO %s " \
|
38 | 38 | "(key, abc, \"ABC\", \"aBc\") " \
|
39 | 39 | "VALUES (?, ?, ?, ?)"
|
| 40 | +#define INSERT_SAME_MARKER_FORMAT \ |
| 41 | + "INSERT INTO %s " \ |
| 42 | + "(key, abc, \"ABC\", \"aBc\") " \ |
| 43 | + "VALUES (:key, :abc, :abc, :abc)" |
40 | 44 | #define INSERT_ALL_FORMAT \
|
41 | 45 | "INSERT INTO %s " \
|
42 | 46 | "(key, a, b, c, abc, \"ABC\", \"aBc\") " \
|
@@ -174,6 +178,28 @@ class ByNameTests : public Integration {
|
174 | 178 | ASSERT_TRUE(row.column_by_name<Float>("\"ABC\"").is_null());
|
175 | 179 | ASSERT_TRUE(row.column_by_name<Float>("\"aBc\"").is_null());
|
176 | 180 | }
|
| 181 | + |
| 182 | + /** |
| 183 | + * Insert non-pk values using same bind marker |
| 184 | + * |
| 185 | + * @param statement Insert statement to use |
| 186 | + */ |
| 187 | + void insert_and_validate_multiple_binds(Statement statement) { |
| 188 | + TimeUuid key = uuid_generator_.generate_timeuuid(); |
| 189 | + statement.bind<TimeUuid>("key", key); |
| 190 | + statement.bind<Float>("abc", Float(1.23f)); // This should bind to columns `abc`, `ABC`, and `aBc` |
| 191 | + session_.execute(statement); |
| 192 | + |
| 193 | + // Validate the inserts to multiple binded columns |
| 194 | + Result result = session_.execute(default_select_all()); |
| 195 | + ASSERT_EQ(1u, result.row_count()); |
| 196 | + ASSERT_EQ(7u, result.column_count()); |
| 197 | + Row row = result.first_row(); |
| 198 | + ASSERT_EQ(key, row.column_by_name<TimeUuid>("key")); |
| 199 | + ASSERT_EQ(Float(1.23f), row.column_by_name<Float>("\"abc\"")); |
| 200 | + ASSERT_EQ(Float(1.23f), row.column_by_name<Float>("\"ABC\"")); |
| 201 | + ASSERT_EQ(Float(1.23f), row.column_by_name<Float>("\"aBc\"")); |
| 202 | + } |
177 | 203 | };
|
178 | 204 |
|
179 | 205 | /**
|
@@ -287,20 +313,50 @@ CASSANDRA_INTEGRATION_TEST_F(ByNameTests, MultipleBinds) {
|
287 | 313 | Prepared prepared =
|
288 | 314 | session_.prepare(format_string(INSERT_CASE_SENSITIVE_FORMAT, table_name_.c_str()));
|
289 | 315 | Statement statement = prepared.bind();
|
290 |
| - TimeUuid key = uuid_generator_.generate_timeuuid(); |
291 |
| - statement.bind<TimeUuid>("key", key); |
292 |
| - statement.bind<Float>("abc", Float(1.23f)); // This should bind to columns `abc`, `ABC`, and `aBc` |
293 |
| - session_.execute(statement); |
| 316 | + insert_and_validate_multiple_binds(statement); |
| 317 | +} |
294 | 318 |
|
295 |
| - // Validate the inserts to multiple binded columns |
296 |
| - Result result = session_.execute(default_select_all()); |
297 |
| - ASSERT_EQ(1u, result.row_count()); |
298 |
| - ASSERT_EQ(7u, result.column_count()); |
299 |
| - Row row = result.first_row(); |
300 |
| - ASSERT_EQ(key, row.column_by_name<TimeUuid>("key")); |
301 |
| - ASSERT_EQ(Float(1.23f), row.column_by_name<Float>("\"abc\"")); |
302 |
| - ASSERT_EQ(Float(1.23f), row.column_by_name<Float>("\"ABC\"")); |
303 |
| - ASSERT_EQ(Float(1.23f), row.column_by_name<Float>("\"aBc\"")); |
| 319 | +/** |
| 320 | + * Perform `by name` references using a prepared statement to insert multiple |
| 321 | + * values using same bind marker and validate. |
| 322 | + * |
| 323 | + * This test will perform bindings of a value to multiple columns `by name` |
| 324 | + * using same bind marker, insert using a prepared statement |
| 325 | + * and validate the results on a single node cluster. |
| 326 | + * |
| 327 | + * @test_category queries:prepared |
| 328 | + * @since core:1.0.0 |
| 329 | + * @expected_result Cassandra values are inserted and validated by name |
| 330 | + */ |
| 331 | +CASSANDRA_INTEGRATION_TEST_F(ByNameTests, PreparedMultipleBindsSameMarker) { |
| 332 | + CHECK_FAILURE; |
| 333 | + |
| 334 | + // Prepare, bind, and insert the values into the table |
| 335 | + Prepared prepared = |
| 336 | + session_.prepare(format_string(INSERT_SAME_MARKER_FORMAT, table_name_.c_str())); |
| 337 | + Statement statement = prepared.bind(); |
| 338 | + insert_and_validate_multiple_binds(statement); |
| 339 | +} |
| 340 | + |
| 341 | +/** |
| 342 | + * Perform `by name` references using a simple statement to insert multiple |
| 343 | + * values using same bind marker and validate |
| 344 | + * |
| 345 | + * This test will perform bindings of a value to multiple columns `by name` |
| 346 | + * using same bind marker, insert using a simple statement |
| 347 | + * and validate the results on a single node cluster. |
| 348 | + * |
| 349 | + * @test_category queries:basic |
| 350 | + * @cassandra_version 2.1.0 |
| 351 | + * @expected_result Cassandra values are inserted and validated by name |
| 352 | + */ |
| 353 | +CASSANDRA_INTEGRATION_TEST_F(ByNameTests, SimpleMultipleBindsSameMarker) { |
| 354 | + CHECK_FAILURE; |
| 355 | + SKIP_IF_CASSANDRA_VERSION_LT(2.1.0); |
| 356 | + |
| 357 | + // Prepare, create, insert and validate |
| 358 | + Statement statement(format_string(INSERT_SAME_MARKER_FORMAT, table_name_.c_str()), 4); |
| 359 | + insert_and_validate_multiple_binds(statement); |
304 | 360 | }
|
305 | 361 |
|
306 | 362 | /**
|
|
0 commit comments