2020import java .time .temporal .ChronoField ;
2121import java .time .temporal .ChronoUnit ;
2222import java .util .UUID ;
23+ import java .util .function .Function ;
2324
2425import org .junit .jupiter .api .AfterAll ;
2526import org .junit .jupiter .api .Assertions ;
@@ -126,21 +127,40 @@ public void executeUpdateTest(SqlQueries.JdbcQuery query) throws SQLException {
126127 }
127128 }
128129
129- @ ParameterizedTest (name = "with {0}" )
130- @ EnumSource (value =SqlQueries .JdbcQuery .class , names = { "BATCHED" , "TYPED" , "BULK" })
131- public void executeWithMissingParameter (SqlQueries .JdbcQuery query ) throws SQLException {
132- String sql = TEST_TABLE .upsertOne (query , "c_Text" , "Text" );
130+ @ Test
131+ public void executeWithMissingParameter () throws SQLException {
132+ Function <SqlQueries .JdbcQuery , String > upsert = mode -> TEST_TABLE .upsertOne (mode , "c_Text" , "Text" );
133133
134- try (PreparedStatement statement = jdbc .connection ().prepareStatement (sql )) {
135- statement .setInt (1 , 1 );
136- ExceptionAssert .sqlDataException ("Missing value for parameter" , statement ::execute );
134+ try (PreparedStatement ps = jdbc .connection ().prepareStatement (upsert .apply (SqlQueries .JdbcQuery .STANDARD ))) {
135+ ps .setInt (1 , 1 );
136+ ExceptionAssert .sqlDataException ("Missing value for parameter: $p2" , ps ::execute );
137+ }
138+
139+ try (PreparedStatement ps = jdbc .connection ().prepareStatement (upsert .apply (SqlQueries .JdbcQuery .IN_MEMORY ))) {
140+ ps .setInt (1 , 1 );
141+ ExceptionAssert .sqlDataException ("Missing value for parameter: $jp2" , ps ::execute );
142+ }
143+
144+ try (PreparedStatement ps = jdbc .connection ().prepareStatement (upsert .apply (SqlQueries .JdbcQuery .TYPED ))) {
145+ ps .setInt (1 , 1 );
146+ ExceptionAssert .sqlDataException ("Missing value for parameter: $p2" , ps ::execute );
147+ }
148+
149+ try (PreparedStatement ps = jdbc .connection ().prepareStatement (upsert .apply (SqlQueries .JdbcQuery .BATCHED ))) {
150+ ps .setInt (1 , 1 );
151+ ExceptionAssert .sqlDataException ("Missing value for parameter: $p2" , ps ::execute );
152+ }
153+
154+ try (PreparedStatement ps = jdbc .connection ().prepareStatement (upsert .apply (SqlQueries .JdbcQuery .BULK ))) {
155+ ps .setInt (1 , 1 );
156+ ExceptionAssert .sqlDataException ("Missing value for parameter: $c_Text" , ps ::execute );
137157 }
138158 }
139159
140160 @ ParameterizedTest (name = "with {0}" )
141- @ EnumSource (value =SqlQueries .JdbcQuery .class , names = { "BATCHED" , "TYPED" , "BULK" })
161+ @ EnumSource (value =SqlQueries .JdbcQuery .class , names = { "BATCHED" , "TYPED" })
142162 public void executeWithWrongType (SqlQueries .JdbcQuery query ) throws SQLException {
143- String sql = TEST_TABLE .upsertOne (query , "c_Text" , "Text" ); // Must be Optional<Text>
163+ String sql = TEST_TABLE .upsertOne (query , "c_Text" , "Text" );
144164
145165 try (PreparedStatement statement = jdbc .connection ().prepareStatement (sql )) {
146166 statement .setInt (1 , 1 );
@@ -151,41 +171,62 @@ public void executeWithWrongType(SqlQueries.JdbcQuery query) throws SQLException
151171 }
152172
153173 @ ParameterizedTest (name = "with {0}" )
154- @ EnumSource (value =SqlQueries .JdbcQuery .class , names = { "BATCHED" , "TYPED" , "BULK" })
155- public void executeWithWrongNameReal (SqlQueries .JdbcQuery query ) throws SQLException {
156- String upsert = TEST_TABLE .upsertOne (query , "c_NotText" , "Text" );
157- ExceptionAssert .ydbException ("No such column: c_NotText" , () -> jdbc .connection ().prepareStatement (upsert ));
158- };
174+ @ ValueSource (strings = { "c_NotText" , "C_TEXT" , "c_text" })
175+ public void executeWithWrongColumnName (String columnName ) throws SQLException {
176+ String errorMessage = "No such column: " + columnName ;
159177
160- @ ParameterizedTest (name = "with {0}" )
161- @ EnumSource (value =SqlQueries .JdbcQuery .class , names = { "STANDARD" , "IN_MEMORY" })
162- public void executeWithWrongNameInMemory (SqlQueries .JdbcQuery query ) throws SQLException {
163- String upsert = TEST_TABLE .upsertOne (query , "c_NotText" , "Text" );
178+ String standard = TEST_TABLE .upsertOne (SqlQueries .JdbcQuery .STANDARD , columnName , "Text" );
179+ String inMemory = TEST_TABLE .upsertOne (SqlQueries .JdbcQuery .IN_MEMORY , columnName , "Text" );
180+ String typed = TEST_TABLE .upsertOne (SqlQueries .JdbcQuery .TYPED , columnName , "Text" );
181+ String batched = TEST_TABLE .upsertOne (SqlQueries .JdbcQuery .BATCHED , columnName , "Text" );
182+ String bulk = TEST_TABLE .upsertOne (SqlQueries .JdbcQuery .BULK , columnName , "Text" );
164183
165- try (PreparedStatement statement = jdbc .connection ().prepareStatement (upsert )) {
184+ try (PreparedStatement statement = jdbc .connection ().prepareStatement (standard )) {
166185 statement .setInt (1 , 1 );
167186 statement .setString (2 , "value-1" );
168- ExceptionAssert .ydbException ("No such column: c_NotText" , statement ::execute );
187+ ExceptionAssert .ydbException (errorMessage , statement ::execute );
169188 }
170- };
171189
172- @ ParameterizedTest (name = "with {0}" )
173- @ EnumSource (value =SqlQueries .JdbcQuery .class , names = { "BATCHED" , "TYPED" , "BULK" })
174- public void executeWithWrongTableReal (SqlQueries .JdbcQuery query ) throws SQLException {
175- String upsert = new SqlQueries ("unknown_table" ).upsertOne (query , "c_NotText" , "Text" );
176- ExceptionAssert .ydbException ("Cannot find table" , () -> jdbc .connection ().prepareStatement (upsert ));
190+ try (PreparedStatement statement = jdbc .connection ().prepareStatement (inMemory )) {
191+ statement .setInt (1 , 1 );
192+ statement .setString (2 , "value-1" );
193+ ExceptionAssert .ydbException (errorMessage , statement ::execute );
194+ }
195+
196+ ExceptionAssert .ydbException (errorMessage , () -> jdbc .connection ().prepareStatement (typed ));
197+ ExceptionAssert .ydbException (errorMessage , () -> jdbc .connection ().prepareStatement (batched ));
198+ ExceptionAssert .sqlException ("Cannot parse BULK upsert: column " + columnName + " not found" ,
199+ () -> jdbc .connection ().prepareStatement (bulk ));
177200 };
178201
179202 @ ParameterizedTest (name = "with {0}" )
180- @ EnumSource (value =SqlQueries .JdbcQuery .class , names = { "STANDARD" , "IN_MEMORY" })
181- public void executeWithWrongTableInMemory (SqlQueries .JdbcQuery query ) throws SQLException {
182- String upsert = new SqlQueries ("unknown_table" ).upsertOne (query , "c_NotText" , "Text" );
203+ @ ValueSource (strings = { "unknown_table" /*, "YDB_PREPARED_TEST", "ydD_prepared_test"*/ })
204+ public void executeWithWrongTableName (String tableName ) throws SQLException {
205+ String errorMessage = "Cannot find table 'db.[" + jdbc .database () + "/" + tableName + "]" ;
206+ SqlQueries queries = new SqlQueries (tableName );
207+
208+ String standard = queries .upsertOne (SqlQueries .JdbcQuery .STANDARD , "c_Text" , "Text" );
209+ String inMemory = queries .upsertOne (SqlQueries .JdbcQuery .IN_MEMORY , "c_Text" , "Text" );
210+ String typed = queries .upsertOne (SqlQueries .JdbcQuery .TYPED , "c_Text" , "Text" );
211+ String batched = queries .upsertOne (SqlQueries .JdbcQuery .BATCHED , "c_Text" , "Text" );
212+ String bulk = queries .upsertOne (SqlQueries .JdbcQuery .BULK , "c_Text" , "Text" );
213+
214+ try (PreparedStatement statement = jdbc .connection ().prepareStatement (standard )) {
215+ statement .setInt (1 , 1 );
216+ statement .setString (2 , "value-1" );
217+ ExceptionAssert .ydbException (errorMessage , statement ::execute );
218+ }
183219
184- try (PreparedStatement statement = jdbc .connection ().prepareStatement (upsert )) {
220+ try (PreparedStatement statement = jdbc .connection ().prepareStatement (inMemory )) {
185221 statement .setInt (1 , 1 );
186222 statement .setString (2 , "value-1" );
187- ExceptionAssert .ydbException ("Cannot find table" , statement ::execute );
223+ ExceptionAssert .ydbException (errorMessage , statement ::execute );
188224 }
225+
226+ ExceptionAssert .ydbException (errorMessage , () -> jdbc .connection ().prepareStatement (typed ));
227+ ExceptionAssert .ydbException (errorMessage , () -> jdbc .connection ().prepareStatement (batched ));
228+ ExceptionAssert .sqlException ("Cannot parse BULK upsert: Status{code = SCHEME_ERROR(code=400070)}" ,
229+ () -> jdbc .connection ().prepareStatement (bulk ));
189230 };
190231
191232 @ ParameterizedTest (name = "with {0}" )
0 commit comments