@@ -397,4 +397,52 @@ public void shouldPerformRollbackToSavepoint(){
397397 long count = statement .simpleQueryForLong ();
398398 assertThat (count , is (1L ));
399399 }
400+
401+ @ Test (expected = SQLiteException .class )
402+ public void shouldThrowExceptionWithSelectStatementUsingRawExecSQL (){
403+ database .rawExecSQL ("SELECT count(*) FROM sqlite_schema;" );
404+ }
405+
406+ @ Test
407+ public void shouldPerformInsertUsingRawExecSQL (){
408+ int a = 0 , b = 0 ;
409+ database .execSQL ("create table t1(a,b);" );
410+ database .rawExecSQL ("insert into t1(a,b) values(?, ?);" , 1 , 2 );
411+ Cursor cursor = database .rawQuery ("select * from t1;" );
412+ if (cursor != null && cursor .moveToFirst ()){
413+ a = cursor .getInt (0 );
414+ b = cursor .getInt (1 );
415+ cursor .close ();
416+ }
417+ assertThat (a , is (1 ));
418+ assertThat (b , is (2 ));
419+ }
420+
421+ @ Test
422+ public void shouldPerformUpdateUsingRawExecSQL (){
423+ int a = 0 , b = 0 , c = 0 ;
424+ database .execSQL ("create table t1(a,b,c);" );
425+ database .execSQL ("insert into t1(a,b,c) values(?, ?, ?);" , new Object []{1 , 2 , 3 });
426+ database .rawExecSQL ("update t1 set b = ?, c = ? where a = ?" , 4 , 5 , 1 );
427+ Cursor cursor = database .rawQuery ("select * from t1;" );
428+ if (cursor != null && cursor .moveToFirst ()){
429+ a = cursor .getInt (0 );
430+ b = cursor .getInt (1 );
431+ c = cursor .getInt (2 );
432+ cursor .close ();
433+ }
434+ assertThat (a , is (1 ));
435+ assertThat (b , is (4 ));
436+ assertThat (c , is (5 ));
437+ }
438+
439+ @ Test
440+ public void shouldDeleteDataUsingRawExecSQL (){
441+ database .execSQL ("create table t1(a,b,c);" );
442+ database .execSQL ("insert into t1(a,b,c) values(?, ?, ?);" , new Object []{1 , 2 , 3 });
443+ SQLiteStatement statement = database .compileStatement ("select count(*) from t1;" );
444+ assertThat (statement .simpleQueryForLong (), is (1L ));
445+ database .rawExecSQL ("delete from t1;" );
446+ assertThat (statement .simpleQueryForLong (), is (0L ));
447+ }
400448}
0 commit comments