Skip to content

Commit 658ebb0

Browse files
committed
IT: add test cases for interleaving by name and by index bindings
1 parent 90b157d commit 658ebb0

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed

tests/src/integration/tests/test_by_name.cpp

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,36 @@ class ByNameTests : public Integration {
111111
ASSERT_EQ(Float(3.3f), row.column_by_name<Float>("\"aBc\""));
112112
}
113113

114+
/**
115+
* Insert and validate
116+
*
117+
* @param statement Insert statement to use (case sensitive format)
118+
*/
119+
void insert_and_validate_interleaving(Statement statement) {
120+
// Insert values into the table by name
121+
TimeUuid key = uuid_generator_.generate_timeuuid();
122+
statement.bind<TimeUuid>("key", key);
123+
statement.bind<Float>(1, Float(0.0f));
124+
// This should overwrite the previous value. Thus bound_values[1] = 1.1f.
125+
statement.bind<Float>("\"abc\"", Float(1.1f));
126+
statement.bind<Float>("\"ABC\"", Float(2.2f));
127+
statement.bind<Float>("\"aBc\"", Float(3.3f));
128+
// This should overwrite the previous value.
129+
// Thus, bound_values[name_to_bound_index["aBc"]] = 4.4f.
130+
statement.bind<Float>(3, Float(4.4f));
131+
session_.execute(statement);
132+
133+
// Validate the inserts into the table
134+
Result result = session_.execute(default_select_all());
135+
ASSERT_EQ(1u, result.row_count());
136+
ASSERT_EQ(7u, result.column_count());
137+
Row row = result.first_row();
138+
ASSERT_EQ(key, row.column_by_name<TimeUuid>("key"));
139+
ASSERT_EQ(Float(1.1f), row.column_by_name<Float>("\"abc\""));
140+
ASSERT_EQ(Float(2.2f), row.column_by_name<Float>("\"ABC\""));
141+
ASSERT_EQ(Float(4.4f), row.column_by_name<Float>("\"aBc\""));
142+
}
143+
114144
/**
115145
* Insert all values into the table
116146
*
@@ -294,6 +324,42 @@ CASSANDRA_INTEGRATION_TEST_F(ByNameTests, SimpleCaseSensitive) {
294324
insert_and_validate_case_sensitive(statement);
295325
}
296326

327+
/**
328+
* Perform interleaving `by name` and `by index` binding
329+
* using a prepared statement and validate
330+
*
331+
* @test_category queries:prepared
332+
* @since core:1.0.0
333+
* @expected_result Cassandra values are inserted using
334+
* interleaving by name and by index bindng and validated
335+
*/
336+
CASSANDRA_INTEGRATION_TEST_F(ByNameTests, PreparedInterleaving) {
337+
CHECK_FAILURE;
338+
339+
// Prepare, create, insert and validate
340+
Prepared prepared =
341+
session_.prepare(format_string(INSERT_CASE_SENSITIVE_FORMAT, table_name_.c_str()));
342+
insert_and_validate_interleaving(prepared.bind());
343+
}
344+
345+
/**
346+
* Perform interleaving `by name` and `by index` binding
347+
* using a simple statement and validate
348+
*
349+
* @test_category queries:basic
350+
* @since core:2.1.0
351+
* @expected_result Cassandra values are inserted using
352+
* interleaving by name and by index bindng and validated
353+
*/
354+
CASSANDRA_INTEGRATION_TEST_F(ByNameTests, SimpleInterleaving) {
355+
CHECK_FAILURE;
356+
SKIP_IF_CASSANDRA_VERSION_LT(2.1.0);
357+
358+
// Prepare, create, insert and validate
359+
Statement statement(format_string(INSERT_CASE_SENSITIVE_FORMAT, table_name_.c_str()), 4);
360+
insert_and_validate_interleaving(statement);
361+
}
362+
297363
/**
298364
* Perform `by name` references using a prepared statement to insert multiple
299365
* value and validate

0 commit comments

Comments
 (0)