Skip to content

Commit 95015a1

Browse files
committed
IT: define tests for by-name binding with reused bind marker
In these tests, we use the same bind marker (:abc) to bind values to 3 different columns. We then validate the results. There are two test cases - one for prepared statements, and other one for unprepared statements.
1 parent 98faa07 commit 95015a1

File tree

1 file changed

+69
-13
lines changed

1 file changed

+69
-13
lines changed

tests/src/integration/tests/test_by_name.cpp

+69-13
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@
3737
"INSERT INTO %s " \
3838
"(key, abc, \"ABC\", \"aBc\") " \
3939
"VALUES (?, ?, ?, ?)"
40+
#define INSERT_SAME_MARKER_FORMAT \
41+
"INSERT INTO %s " \
42+
"(key, abc, \"ABC\", \"aBc\") " \
43+
"VALUES (:key, :abc, :abc, :abc)"
4044
#define INSERT_ALL_FORMAT \
4145
"INSERT INTO %s " \
4246
"(key, a, b, c, abc, \"ABC\", \"aBc\") " \
@@ -174,6 +178,28 @@ class ByNameTests : public Integration {
174178
ASSERT_TRUE(row.column_by_name<Float>("\"ABC\"").is_null());
175179
ASSERT_TRUE(row.column_by_name<Float>("\"aBc\"").is_null());
176180
}
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+
}
177203
};
178204

179205
/**
@@ -287,20 +313,50 @@ CASSANDRA_INTEGRATION_TEST_F(ByNameTests, MultipleBinds) {
287313
Prepared prepared =
288314
session_.prepare(format_string(INSERT_CASE_SENSITIVE_FORMAT, table_name_.c_str()));
289315
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+
}
294318

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);
304360
}
305361

306362
/**

0 commit comments

Comments
 (0)