@@ -170,4 +170,122 @@ public void TypedNullParameter_ReturnsDBNull(DbType dbType)
170170
171171 AreEqual ( DBNull . Value , command . ExecuteScalar ( ) ) ;
172172 }
173+
174+ [ TestMethod ]
175+ public void CreateInsertSelect_IntegerConstant_RoundTripsThroughHeapTable ( )
176+ {
177+ using var connection = new Simulation ( StorageBackend . Pages ) . CreateOpenConnection ( ) ;
178+
179+ AreEqual ( - 1 , connection . CreateCommand ( "create table t ( v int )" ) . ExecuteNonQuery ( ) ) ;
180+ AreEqual ( 1 , connection . CreateCommand ( "insert t values ( 42 )" ) . ExecuteNonQuery ( ) ) ;
181+
182+ using var reader = connection . CreateCommand ( "select v from t" ) . ExecuteReader ( ) ;
183+ IsTrue ( reader . Read ( ) ) ;
184+ AreEqual ( "v" , reader . GetName ( 0 ) ) ;
185+ AreEqual ( 42 , reader [ 0 ] ) ;
186+ IsFalse ( reader . Read ( ) ) ;
187+ }
188+
189+ [ TestMethod ]
190+ public void CreateInsertSelect_MultipleRowsAndColumns ( )
191+ {
192+ using var connection = new Simulation ( StorageBackend . Pages ) . CreateOpenConnection ( ) ;
193+
194+ _ = connection . CreateCommand ( "create table t ( a int, b int )" ) . ExecuteNonQuery ( ) ;
195+ AreEqual ( 3 , connection . CreateCommand ( "insert t values ( 1, 10 ), ( 2, 20 ), ( 3, 30 )" ) . ExecuteNonQuery ( ) ) ;
196+
197+ using var reader = connection . CreateCommand ( "select a, b from t" ) . ExecuteReader ( ) ;
198+
199+ IsTrue ( reader . Read ( ) ) ;
200+ AreEqual ( 1 , reader [ 0 ] ) ;
201+ AreEqual ( 10 , reader [ 1 ] ) ;
202+
203+ IsTrue ( reader . Read ( ) ) ;
204+ AreEqual ( 2 , reader [ 0 ] ) ;
205+ AreEqual ( 20 , reader [ 1 ] ) ;
206+
207+ IsTrue ( reader . Read ( ) ) ;
208+ AreEqual ( 3 , reader [ 0 ] ) ;
209+ AreEqual ( 30 , reader [ 1 ] ) ;
210+
211+ IsFalse ( reader . Read ( ) ) ;
212+ }
213+
214+ [ TestMethod ]
215+ public void Insert_PartialColumnList_LeavesUnspecifiedColumnsNull ( )
216+ {
217+ using var connection = new Simulation ( StorageBackend . Pages ) . CreateOpenConnection ( ) ;
218+
219+ _ = connection . CreateCommand ( "create table t ( a int, b int )" ) . ExecuteNonQuery ( ) ;
220+ _ = connection . CreateCommand ( "insert t ( a ) values ( 7 )" ) . ExecuteNonQuery ( ) ;
221+
222+ using var reader = connection . CreateCommand ( "select a, b from t" ) . ExecuteReader ( ) ;
223+ IsTrue ( reader . Read ( ) ) ;
224+ AreEqual ( 7 , reader [ 0 ] ) ;
225+ AreEqual ( DBNull . Value , reader [ 1 ] ) ;
226+ IsFalse ( reader . Read ( ) ) ;
227+ }
228+
229+ [ TestMethod ]
230+ public void Select_FromEmptyTable_ReturnsNoRows ( )
231+ {
232+ using var connection = new Simulation ( StorageBackend . Pages ) . CreateOpenConnection ( ) ;
233+
234+ _ = connection . CreateCommand ( "create table t ( v int )" ) . ExecuteNonQuery ( ) ;
235+
236+ using var reader = connection . CreateCommand ( "select v from t" ) . ExecuteReader ( ) ;
237+ IsFalse ( reader . Read ( ) ) ;
238+ }
239+
240+ [ TestMethod ]
241+ public void CreateInsertSelect_AllSupportedColumnTypes_ViaParameters ( )
242+ {
243+ using var connection = new Simulation ( StorageBackend . Pages ) . CreateOpenConnection ( ) ;
244+
245+ _ = connection . CreateCommand ( "create table t ( b bit, ti tinyint, si smallint, i int )" ) . ExecuteNonQuery ( ) ;
246+
247+ using ( var insert = connection . CreateCommand ( ) )
248+ {
249+ insert . CommandText = "insert t values ( @b, @ti, @si, @i )" ;
250+ AddTypedParameter ( insert , "b" , DbType . Boolean , true ) ;
251+ AddTypedParameter ( insert , "ti" , DbType . Byte , ( byte ) 200 ) ;
252+ AddTypedParameter ( insert , "si" , DbType . Int16 , ( short ) - 1 ) ;
253+ AddTypedParameter ( insert , "i" , DbType . Int32 , 12345 ) ;
254+ AreEqual ( 1 , insert . ExecuteNonQuery ( ) ) ;
255+ }
256+
257+ using var reader = connection . CreateCommand ( "select b, ti, si, i from t" ) . ExecuteReader ( ) ;
258+ IsTrue ( reader . Read ( ) ) ;
259+ AreEqual ( true , reader [ 0 ] ) ;
260+ AreEqual ( ( byte ) 200 , reader [ 1 ] ) ;
261+ AreEqual ( ( short ) - 1 , reader [ 2 ] ) ;
262+ AreEqual ( 12345 , reader [ 3 ] ) ;
263+ IsFalse ( reader . Read ( ) ) ;
264+ }
265+
266+ [ TestMethod ]
267+ public void SelectFromTable_ProjectionReorderingAndSubsetting ( )
268+ {
269+ using var connection = new Simulation ( StorageBackend . Pages ) . CreateOpenConnection ( ) ;
270+
271+ _ = connection . CreateCommand ( "create table t ( a int, b int, c int )" ) . ExecuteNonQuery ( ) ;
272+ _ = connection . CreateCommand ( "insert t values ( 1, 2, 3 )" ) . ExecuteNonQuery ( ) ;
273+
274+ using var reader = connection . CreateCommand ( "select c, a from t" ) . ExecuteReader ( ) ;
275+ IsTrue ( reader . Read ( ) ) ;
276+ AreEqual ( 2 , reader . FieldCount ) ;
277+ AreEqual ( "c" , reader . GetName ( 0 ) ) ;
278+ AreEqual ( "a" , reader . GetName ( 1 ) ) ;
279+ AreEqual ( 3 , reader [ 0 ] ) ;
280+ AreEqual ( 1 , reader [ 1 ] ) ;
281+ }
282+
283+ private static void AddTypedParameter ( System . Data . Common . DbCommand command , string name , DbType dbType , object value )
284+ {
285+ var parameter = command . CreateParameter ( ) ;
286+ parameter . ParameterName = name ;
287+ parameter . DbType = dbType ;
288+ parameter . Value = value ;
289+ _ = command . Parameters . Add ( parameter ) ;
290+ }
173291}
0 commit comments