Home | History | Annotate | Download | only in sqlite
      1 /*
      2  * Copyright (C) 2008 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package libcore.sqlite;
     18 
     19 import SQLite.Constants;
     20 import SQLite.Database;
     21 import SQLite.Stmt;
     22 import SQLite.TableResult;
     23 import java.sql.Connection;
     24 import tests.support.DatabaseCreator;
     25 import tests.support.Support_SQL;
     26 
     27 public class OldStmtTest extends OldSQLiteTest {
     28 
     29     private Database db;
     30     private Stmt st;
     31 
     32     private static final String CREATE_ALL_TYPES = "create table type ("
     33             + " BoolVal BOOLEAN,"
     34             + " IntVal INT,"
     35             + " LongVal LONG,"
     36             + " Bint BIGINT,"
     37             + " Tint TINYINT,"
     38             + " Sint SMALLINT,"
     39             + " Mint MEDIUMINT,"
     40             + " IntegerVal INTEGER,"
     41             + " RealVal REAL,"
     42             + " DoubleVal DOUBLE,"
     43             + " FloatVal FLOAT,"
     44             + " DecVal DECIMAL,"
     45             + " NumVal NUMERIC,"
     46             + " charStr CHAR(20),"
     47             + " dateVal DATE,"
     48             + " timeVal TIME,"
     49             + " TS TIMESTAMP,"
     50             + " DT DATETIME,"
     51             + " TBlob TINYBLOB,"
     52             + " BlobVal BLOB,"
     53             + " MBlob MEDIUMBLOB,"
     54             + " LBlob LONGBLOB,"
     55             + " TText TINYTEXT,"
     56             + " TextVal TEXT,"
     57             + " MText MEDIUMTEXT,"
     58             + " LText LONGTEXT,"
     59             + " MaxLongVal BIGINT,"
     60             + " MinLongVal BIGINT,"
     61             + " validURL URL,"
     62             + " invalidURL URL);";
     63 
     64     static final String INSERT_ALL_TYPES = "insert into type ("
     65             + "BoolVal, IntVal, LongVal, Bint, Tint, Sint, Mint,IntegerVal, RealVal, DoubleVal, "
     66             + "FloatVal, DecVal,NumVal, charStr, dateVal, timeVal, TS,DT, TBlob, BlobVal, MBlob, "
     67             + "LBlob,TText, TextVal, MText, LText, MaxLongVal, MinLongVal, validURL, invalidURL) "
     68             + "values (1, -1, 22, 2, 33,3, 1, 2, 3.9, 23.2, 33.3, 44,5, 'test string', '1799-05-26',"
     69             + "'12:35:45', '2007-10-09 14:28:02.0','1221-09-22 10:11:55', 1, 2, 3, 4,"
     70             + "'Test text message tiny', 'Test text', 'Test text message medium',"
     71             + "'Test text message long', " + Long.MAX_VALUE + ", " + Long.MIN_VALUE + ","
     72             + "null, null);";
     73 
     74     static final String ALL_TYPES_TABLE = "type";
     75 
     76     @Override public void setUp() throws Exception {
     77         super.setUp();
     78         Support_SQL.loadDriver();
     79         db = new Database();
     80         db.open(dbFile.getPath(), 0);
     81         db.exec(DatabaseCreator.CREATE_TABLE_SIMPLE1, null);
     82         DatabaseCreator.fillSimpleTable1(conn);
     83 
     84         st = new Stmt();
     85     }
     86 
     87     @Override public void tearDown() throws Exception {
     88         if (st != null) {
     89             try {
     90                 st.close();
     91             } catch (Exception e) {
     92             }
     93         }
     94         db.close();
     95         Connection con = Support_SQL.getConnection();
     96         con.close();
     97         super.tearDown();
     98     }
     99 
    100     public void testStmt() throws Exception {
    101         db.prepare("");
    102 
    103         try {
    104             st.step();
    105             fail("Cannot execute non prepared Stmt");
    106         } catch (SQLite.Exception expected) {
    107         }
    108     }
    109 
    110     public void testPrepare() throws Exception {
    111         try {
    112             st = db.prepare("");
    113             st.prepare();
    114             fail("statement is closed");
    115         } catch (SQLite.Exception expected) {
    116             assertEquals("stmt already closed", expected.getMessage());
    117         }
    118 
    119         st = new Stmt();
    120         st = db.prepare("select * from " + DatabaseCreator.SIMPLE_TABLE1);
    121         assertFalse(st.prepare());
    122         st = new Stmt();
    123         st = db.prepare("insert into " + DatabaseCreator.SIMPLE_TABLE1
    124                 + " values (:one,:two,:three)");
    125         assertFalse(st.prepare());
    126         st = new Stmt();
    127         st = db.prepare("insert into " + DatabaseCreator.SIMPLE_TABLE1
    128                 + " values (:one,:two,:three)");
    129         st.bind(1, 1);
    130         st.bind(2, 10);
    131         st.bind(3, 30);
    132         assertFalse(st.prepare());
    133         st = db.prepare("select * from " + DatabaseCreator.SIMPLE_TABLE1
    134                 + "; " + "delete from " + DatabaseCreator.SIMPLE_TABLE1
    135                 + " where id = 5; " + "insert into "
    136                 + DatabaseCreator.SIMPLE_TABLE1 + " values(5, 10, 20); "
    137                 + "select * from " + DatabaseCreator.SIMPLE_TABLE1 + ";");
    138         assertTrue(st.prepare());
    139         assertTrue(st.prepare());
    140         assertTrue(st.prepare());
    141         assertFalse(st.prepare());
    142     }
    143 
    144     public void testStep() throws Exception {
    145         try {
    146             st.step();
    147             fail("Exception expected");
    148         } catch (SQLite.Exception expected) {
    149             assertEquals("stmt already closed", expected.getMessage());
    150         }
    151 
    152         st = new Stmt();
    153         st = db.prepare("select name from sqlite_master where type = 'table'");
    154         st.step();
    155     }
    156 
    157     public void testClose() throws Exception {
    158         st = db.prepare("insert into " + DatabaseCreator.SIMPLE_TABLE1
    159                 + " values (:one,:two,:three)");
    160         st.close();
    161 
    162         try {
    163             st.step();
    164             fail("Test fails");
    165         } catch (SQLite.Exception expected) {
    166             assertEquals("stmt already closed", expected.getMessage());
    167         }
    168     }
    169 
    170     public void testReset() throws Exception {
    171         db.exec("create table TEST (res integer not null)", null);
    172 
    173         st = db.prepare("insert into TEST values (:one);");
    174         st.bind(1, 1);
    175         st.step();
    176 
    177         // verify that parameter is still bound
    178         st.reset();
    179         assertEquals(1,st.bind_parameter_count());
    180         st.step();
    181 
    182         TableResult count = db.get_table("select count(*) from TEST where res=1", null);
    183 
    184         String[] row0 = (String[]) count.rows.elementAt(0);
    185         assertEquals(2, Integer.parseInt(row0[0]));
    186     }
    187 
    188     public void testClear_bindings() {
    189         try {
    190             st.clear_bindings();
    191         } catch (SQLite.Exception expected) {
    192             assertEquals("unsupported", expected.getMessage());
    193         }
    194     }
    195 
    196     public void testBindIntInt() throws Exception {
    197         int input = 0;
    198         int maxVal = Integer.MAX_VALUE;
    199         int minVal = Integer.MIN_VALUE;
    200 
    201         db.exec("create table TEST (res integer)", null);
    202         st = db.prepare("insert into TEST values (:one);");
    203         st.bind(1, input);
    204         st.step();
    205 
    206         st.reset();
    207         st.bind(1,maxVal);
    208         st.step();
    209 
    210         st.reset();
    211         st.bind(1,minVal);
    212         st.step();
    213 
    214         TableResult r = db.get_table("select * from TEST");
    215 
    216         String[] row0 = (String[]) r.rows.elementAt(0);
    217         assertEquals(input,Integer.parseInt(row0[0]));
    218 
    219         String[] row1 = (String[]) r.rows.elementAt(1);
    220         assertEquals(maxVal,Integer.parseInt(row1[0]));
    221 
    222         String[] row2 = (String[]) r.rows.elementAt(2);
    223         assertEquals(minVal,Integer.parseInt(row2[0]));
    224 
    225         try {
    226             st.close();
    227             st.bind(1,Integer.MIN_VALUE);
    228             fail("Exception expected");
    229         } catch (SQLite.Exception expected) {
    230         }
    231     }
    232 
    233     public void testBindIntLong() throws Exception {
    234         long input = 0;
    235         long maxVal = Long.MAX_VALUE;
    236         long minVal = Long.MIN_VALUE;
    237 
    238         db.exec("create table TEST (res long)", null);
    239         st = db.prepare("insert into TEST values (:one);");
    240         st.bind(1, input);
    241         st.step();
    242 
    243         st.reset();
    244         st.bind(1,maxVal);
    245         st.step();
    246 
    247         st.reset();
    248         st.bind(1,minVal);
    249         st.step();
    250 
    251         TableResult r = db.get_table("select * from TEST");
    252 
    253         String[] row0 = (String[]) r.rows.elementAt(0);
    254         assertEquals(input,Long.parseLong(row0[0]));
    255 
    256         String[] row1 = (String[]) r.rows.elementAt(1);
    257         assertEquals(maxVal,Long.parseLong(row1[0]));
    258 
    259         String[] row2 = (String[]) r.rows.elementAt(2);
    260         assertEquals(minVal,Long.parseLong(row2[0]));
    261 
    262         try {
    263             st.close();
    264             st.bind(1,Long.MIN_VALUE);
    265             fail("Exception expected");
    266         } catch (SQLite.Exception expected) {
    267         }
    268     }
    269 
    270     public void testBindIntDouble() throws Exception {
    271         double input = 0.0;
    272         double maxVal = Double.MAX_VALUE;
    273         double minVal = Double.MIN_VALUE;
    274         double negInf = Double.NEGATIVE_INFINITY;
    275         double posInf = Double.POSITIVE_INFINITY;
    276         double nan = Double.NaN;
    277 
    278         db.exec("create table TEST (res double)", null);
    279         st = db.prepare("insert into TEST values (:one);");
    280         st.bind(1, input);
    281         st.step();
    282 
    283         st.reset();
    284         st.bind(1, maxVal);
    285         st.step();
    286 
    287         st.reset();
    288         st.bind(1, minVal);
    289         st.step();
    290 
    291         st.reset();
    292         st.bind(1, negInf);
    293         st.step();
    294 
    295         st.reset();
    296         st.bind(1, posInf);
    297         st.step();
    298 
    299         st.reset();
    300         st.bind(1, nan);
    301         st.step();
    302 
    303 
    304         TableResult r = db.get_table("select * from TEST");
    305 
    306         String[] row0 = (String[]) r.rows.elementAt(0);
    307         assertTrue(Double.compare(input, Double.parseDouble(row0[0])) == 0);
    308 
    309         String[] row1 = (String[]) r.rows.elementAt(1);
    310         assertFalse(Double.compare(maxVal, Double.parseDouble(row1[0])) == 0);
    311         assertTrue(Double.compare(maxVal, Double.parseDouble(row1[0])) < 0);
    312         assertTrue(Double.isInfinite(Double.parseDouble(row1[0])));
    313 
    314         String[] row2 = (String[]) r.rows.elementAt(2);
    315         assertTrue(Double.compare(minVal, Double.parseDouble(row2[0])) == 0);
    316 
    317         String[] row3 = (String[]) r.rows.elementAt(3);
    318         assertEquals("Double.NEGATIVE_INFINITY SQLite representation",
    319                 "-Inf", row3[0]);
    320 
    321         String[] row4 = (String[]) r.rows.elementAt(4);
    322         assertEquals("Double.POSITIVE_INFINITY SQLite representation",
    323                 "Inf", row4[0]);
    324 
    325         String[] row5 = (String[]) r.rows.elementAt(4);
    326         assertEquals("Double.Nan SQLite representation", "Inf", row5[0]);
    327 
    328         try {
    329             st.close();
    330             st.bind(1,0.0);
    331             fail("Exception expected");
    332         } catch (SQLite.Exception expected) {
    333         }
    334     }
    335 
    336     public void testBindIntByteArray() throws Exception {
    337         String name = "Hello World";
    338         byte[] b = name.getBytes();
    339         String stringInHex = "";
    340 
    341         db.exec(DatabaseCreator.CREATE_TABLE_PARENT, null);
    342         st = db.prepare("insert into " + DatabaseCreator.PARENT_TABLE
    343                 + " values (:one, :two);");
    344         st.bind(1, 2);
    345         st.bind(2, b);
    346         st.step();
    347 
    348         //compare what was stored with input based on Hex representation
    349         // since type of column is CHAR
    350         TableResult r = db.get_table("select * from "
    351                 + DatabaseCreator.PARENT_TABLE);
    352         String[] row = (String[]) r.rows.elementAt(0);
    353 
    354         for (byte aByte : b) {
    355             stringInHex += Integer.toHexString(aByte);
    356         }
    357         stringInHex = "X'" + stringInHex + "'";
    358         assertTrue(stringInHex.equalsIgnoreCase(row[1]));
    359 
    360         try {
    361             st.close();
    362             st.bind(1,name.getBytes());
    363             fail("Exception expected");
    364         } catch (SQLite.Exception expected) {
    365         }
    366     }
    367 
    368     public void testBindIntString() throws Exception {
    369         String name = "Hello World";
    370         db.exec(DatabaseCreator.CREATE_TABLE_PARENT, null);
    371         st = db.prepare("insert into " + DatabaseCreator.PARENT_TABLE
    372                 + " values (:one, :two);");
    373         st.bind(1, 2);
    374         st.bind(2, name);
    375         st.step();
    376 
    377         TableResult r = db.get_table("select * from "
    378                 + DatabaseCreator.PARENT_TABLE);
    379         String[] row = (String[]) r.rows.elementAt(0);
    380         assertEquals(name,row[1]);
    381 
    382         try {
    383             st.close();
    384             st.bind(1,name);
    385             fail("Exception expected");
    386         } catch (SQLite.Exception expected) {
    387         }
    388     }
    389 
    390     public void testBindInt() throws Exception {
    391         try {
    392             st = db.prepare("insert into " + DatabaseCreator.SIMPLE_TABLE1
    393                     + " values (:one,:two,:three)");
    394             st.bind(4);
    395             st.bind(1, 4);
    396             st.bind(2, 10);
    397             st.bind(3, 30);
    398             st.step();
    399             fail();
    400         } catch (SQLite.Exception expected) {
    401             // What happens if null is bound to non existing variable position
    402             assertEquals("parameter position out of bounds", expected.getMessage());
    403         }
    404 
    405         // functional tests
    406 
    407         try {
    408             st.reset();
    409             st.bind(1);
    410             st.bind(2, 10);
    411             st.bind(3, 30);
    412             st.step();
    413             fail();
    414         } catch (SQLite.Exception expected) {
    415             // What happens if null is bound to NON NULL field
    416             assertEquals("SQL logic error or missing database", expected.getMessage());
    417         }
    418 
    419         st.reset();
    420         st.bind(1, 3);
    421         st.bind(2);
    422         st.bind(3, 30);
    423         st.step();
    424     }
    425 
    426     public void testBind_zeroblob() {
    427         try {
    428             st.bind_zeroblob(1, 128);
    429             fail();
    430         } catch (SQLite.Exception expected) {
    431             assertEquals("unsupported", expected.getMessage());
    432         }
    433     }
    434 
    435     public void testBind_parameter_count() throws Exception {
    436         try {
    437             st.bind_parameter_count();
    438             fail();
    439         } catch (SQLite.Exception expected) {
    440             assertEquals("stmt already closed", expected.getMessage());
    441         }
    442 
    443         st = db.prepare("insert into " + DatabaseCreator.SIMPLE_TABLE1
    444                 + " values (:one,:two,:three)");
    445         assertEquals(3, st.bind_parameter_count());
    446 
    447         st = db.prepare("insert into " + DatabaseCreator.SIMPLE_TABLE1
    448                 + " values (?, ?, ?)");
    449         assertEquals(3, st.bind_parameter_count());
    450 
    451         st = db.prepare("select * from " + DatabaseCreator.SIMPLE_TABLE1);
    452         assertEquals(0, st.bind_parameter_count());
    453 
    454         try {
    455             st.close();
    456             st.bind_parameter_count();
    457             fail("Exception expected");
    458         } catch (SQLite.Exception expected) {
    459         }
    460 
    461     }
    462 
    463     public void testBind_parameter_name() {
    464         try {
    465             st.bind_parameter_name(1);
    466             fail("Exception expected");
    467         } catch (SQLite.Exception expected) {
    468             assertEquals("stmt already closed", expected.getMessage());
    469         }
    470 
    471         try {
    472             st = db.prepare("insert into " + DatabaseCreator.SIMPLE_TABLE1
    473                     + " values (:one,:two,:three)");
    474             assertEquals(":one", st.bind_parameter_name(1));
    475             assertEquals(":two", st.bind_parameter_name(2));
    476             assertEquals(":three", st.bind_parameter_name(3));
    477             st.bind_parameter_name(4);
    478             fail();
    479         } catch (SQLite.Exception expected) {
    480             assertEquals("parameter position out of bounds", expected.getMessage());
    481         }
    482     }
    483 
    484     public void testBind_parameter_index() throws Exception {
    485         try {
    486             st.bind_parameter_index("");
    487             fail("Exception expected");
    488         } catch (SQLite.Exception expected) {
    489             assertEquals("stmt already closed", expected.getMessage());
    490         }
    491 
    492         st = db.prepare("insert into " + DatabaseCreator.SIMPLE_TABLE1
    493                 + " values (:one,:two,:three)");
    494         assertEquals(3, st.bind_parameter_index(":three"));
    495 
    496         st = db.prepare("insert into " + DatabaseCreator.SIMPLE_TABLE1
    497                 + " values (:one,:two,:three)");
    498         assertEquals(0, st.bind_parameter_index(":t"));
    499 
    500         st = db.prepare("insert into " + DatabaseCreator.SIMPLE_TABLE1
    501                 + " values (?, ?, ?)");
    502         assertEquals(0, st.bind_parameter_index("?"));
    503     }
    504 
    505     public void testColumn_int() throws Exception {
    506         db.exec(CREATE_ALL_TYPES, null);
    507         db.exec(INSERT_ALL_TYPES, null);
    508 
    509         Object columnObject;
    510         int intColumn;
    511         String selectStmt = "select * from "+DatabaseCreator.SIMPLE_TABLE1;
    512 
    513         st = db.prepare(selectStmt);
    514         st.step();
    515         // select 'speed' value
    516         columnObject = st.column(1);
    517         intColumn = st.column_int(1);
    518         assertNotNull(intColumn);
    519 
    520         assertTrue("Integer".equalsIgnoreCase(st.column_decltype(1)));
    521         int stSpeed = Integer.parseInt(columnObject.toString());
    522         assertNotNull(stSpeed);
    523         assertEquals( intColumn, stSpeed);
    524         assertEquals(10,stSpeed);
    525 
    526         selectStmt = "select TextVal from "+ ALL_TYPES_TABLE;
    527 
    528         st = db.prepare(selectStmt);
    529         st.step();
    530         st.column_int(0);
    531     }
    532 
    533     public void testColumn_long() throws Exception {
    534         Object columnObject;
    535         long longColumn;
    536         String selectStmt = "select * from "+DatabaseCreator.SIMPLE_TABLE1;
    537         st = db.prepare(selectStmt);
    538         st.step();
    539         columnObject = st.column(1);
    540         longColumn = st.column_long(1);
    541         assertNotNull(longColumn);
    542         // column declared as integer
    543         assertTrue("Integer".equalsIgnoreCase(st.column_decltype(1)));
    544         int stSpeed = Integer.parseInt(columnObject.toString());
    545         assertNotNull(stSpeed);
    546         assertEquals( longColumn, stSpeed);
    547 
    548         try {
    549             st.column_long(4);
    550             fail("Exception expected");
    551         } catch (SQLite.Exception expected) {
    552             assertEquals("column out of bounds", expected.getMessage());
    553         }
    554 
    555         try {
    556             st.column_long(-1);
    557             fail("Exception expected");
    558         } catch (SQLite.Exception expected) {
    559             assertEquals("column out of bounds", expected.getMessage());
    560         }
    561     }
    562 
    563     public void testColumn_double() throws Exception {
    564         db.exec(CREATE_ALL_TYPES, null);
    565         db.exec(INSERT_ALL_TYPES, null);
    566 
    567         double doubleColumn;
    568         double actualVal = 23.2;
    569         String selectStmt = "select DoubleVal from "+ ALL_TYPES_TABLE;
    570 
    571         st = db.prepare(selectStmt);
    572         st.step();
    573         // select double value
    574         doubleColumn = st.column_double(0);
    575         assertNotNull(doubleColumn);
    576 
    577         assertTrue("DOUBLE".equalsIgnoreCase(st.column_decltype(0)));
    578         assertNotNull(doubleColumn);
    579         assertEquals( actualVal, doubleColumn);
    580 
    581         // Exception test
    582         selectStmt = "select dateVal from "+ ALL_TYPES_TABLE;
    583 
    584         st = db.prepare(selectStmt);
    585         st.step();
    586         // select double value
    587         st.column_double(0);
    588     }
    589 
    590     public void testColumn_bytes() throws Exception {
    591         db.exec("create table B(id integer primary key, val blob)",null);
    592         db.exec("insert into B values(1, zeroblob(128))", null);
    593         st = db.prepare("select val from B where id = 1");
    594         assertTrue(st.step());
    595         st.column_bytes(0);
    596     }
    597 
    598     public void testColumn_string() throws Exception {
    599         db.exec(CREATE_ALL_TYPES, null);
    600         db.exec(INSERT_ALL_TYPES, null);
    601 
    602         String stringColumn;
    603         String actualVal = "test string";
    604         String selectStmt = "select charStr from "+ ALL_TYPES_TABLE;
    605 
    606         st = db.prepare(selectStmt);
    607         st.step();
    608         // select string value
    609         stringColumn = st.column_string(0);
    610         assertNotNull(stringColumn);
    611 
    612         assertTrue("CHAR(20)".equalsIgnoreCase(st.column_decltype(0)));
    613         assertNotNull(stringColumn);
    614         assertEquals( actualVal, stringColumn);
    615 
    616         // Exception test
    617         selectStmt = "select DoubleVal from "+ ALL_TYPES_TABLE;
    618 
    619         st = db.prepare(selectStmt);
    620         st.step();
    621         st.column_string(0);
    622     }
    623 
    624     public void testColumn_type() throws Exception {
    625         db.exec(CREATE_ALL_TYPES, null);
    626         db.exec(INSERT_ALL_TYPES, null);
    627         st = db.prepare("select * from " + ALL_TYPES_TABLE);
    628         st.step();
    629 
    630         // Exception test
    631         try {
    632             st.column_type(100);
    633             fail();
    634         } catch (SQLite.Exception expected) {
    635         }
    636 
    637         /*
    638         Dictionary
    639 
    640         public static final int SQLITE_INTEGER = 1;
    641         public static final int SQLITE_FLOAT = 2;
    642         public static final int SQLITE_BLOB = 4;
    643         public static final int SQLITE_NULL = 5;
    644         public static final int SQLITE3_TEXT = 3;
    645         public static final int SQLITE_NUMERIC = -1;
    646         */
    647 
    648         assertEquals(Constants.SQLITE3_TEXT, st.column_type(23)); // ok TEXT
    649         assertEquals(Constants.SQLITE3_TEXT, st.column_type(13)); // CHAR(20)
    650 
    651         assertEquals(Constants.SQLITE_FLOAT, st.column_type(8));
    652         assertEquals(Constants.SQLITE_FLOAT, st.column_type(9));
    653         assertEquals(Constants.SQLITE_FLOAT, st.column_type(10)); // FLOAT
    654 
    655         for (int i = 0; i < 8; i++) {
    656             assertEquals("Expected Integer at position " + i,
    657                     Constants.SQLITE_INTEGER, st.column_type(i));
    658         }
    659 
    660         assertEquals(Constants.SQLITE_NULL, st.column_type(28));
    661         assertEquals(Constants.SQLITE_NULL, st.column_type(29));
    662 
    663         // Failing tests
    664         assertTrue("INTEGER".equalsIgnoreCase(st.column_decltype(12)));
    665         assertEquals(Constants.SQLITE_INTEGER, st.column_type(12));
    666 
    667         assertTrue("FLOAT".equalsIgnoreCase(st.column_decltype(11)));
    668         assertEquals(Constants.SQLITE_FLOAT, st.column_type(11)); // FLOAT ->
    669                                                                   // got INTEGER
    670         assertTrue("BLOB".equalsIgnoreCase(st.column_decltype(19)));
    671         assertEquals(Constants.SQLITE_BLOB, st.column_type(19)); // Blob got
    672                                                                  // INTEGER
    673 
    674     }
    675 
    676     /**
    677      * Wrong value is returned in case of a prepared statement to which a '*' bound
    678      */
    679     public void testColumn_count() throws Exception {
    680         String selectStmt = "select * from "+DatabaseCreator.SIMPLE_TABLE1;
    681         st = db.prepare(selectStmt);
    682 
    683         assertEquals(3, st.column_count());
    684 
    685         st.step();
    686         int columnCount = st.column_count();
    687         assertNotNull(columnCount);
    688         assertEquals( 3, columnCount);
    689 
    690         // actual prepared statement
    691         selectStmt = "select ? from "+DatabaseCreator.SIMPLE_TABLE1;
    692         st = db.prepare(selectStmt);
    693 
    694         assertEquals(3, st.column_count());
    695 
    696         st.bind(1, "*");
    697         st.step();
    698         columnCount = st.column_count();
    699         assertNotNull(columnCount);
    700         assertEquals( 3, columnCount);
    701     }
    702 
    703     public void testColumn() throws Exception {
    704         Object columnObject;
    705         int intColumn;
    706         String selectStmt = "select * from "+DatabaseCreator.SIMPLE_TABLE1;
    707         db.get_table(selectStmt);
    708         st = db.prepare(selectStmt);
    709         st.step();
    710         columnObject = st.column(1);
    711         intColumn = st.column_int(1);
    712         assertNotNull(intColumn);
    713         assertTrue("Integer".equalsIgnoreCase(st.column_decltype(1)));
    714         int stSpeed = Integer.parseInt(columnObject.toString());
    715         assertNotNull(stSpeed);
    716         assertEquals( intColumn, stSpeed);
    717 
    718         try {
    719             assertNotNull(columnObject);
    720             ((Integer) columnObject).intValue();
    721             fail("Cast to Integer should fail");
    722         } catch (ClassCastException expected) {
    723         }
    724 
    725         try {
    726             st.column(4);
    727             fail("Exception expected");
    728         } catch (SQLite.Exception expected) {
    729             assertEquals("column out of bounds", expected.getMessage());
    730         }
    731 
    732         try {
    733             st.column(-1);
    734             fail("Exception expected");
    735         } catch (SQLite.Exception expected) {
    736             assertEquals("column out of bounds", expected.getMessage());
    737         }
    738     }
    739 
    740     public void testColumn_table_name() {
    741         try {
    742             st = db.prepare("select * from " + DatabaseCreator.SIMPLE_TABLE1);
    743             st.column_table_name(1);
    744             fail("Function is now supported.");
    745         } catch (SQLite.Exception expected) {
    746             assertEquals("unsupported", expected.getMessage());
    747         }
    748     }
    749 
    750     public void testColumn_database_name() {
    751         try {
    752             st = db.prepare("insert into " + DatabaseCreator.SIMPLE_TABLE1
    753                     + " values (:one,:two,:three)");
    754             st.column_database_name(1);
    755             fail("Function is now supported.");
    756         } catch (SQLite.Exception expected) {
    757             assertEquals("unsupported", expected.getMessage());
    758         }
    759     }
    760 
    761     public void testColumn_decltype() throws Exception {
    762         db.exec(CREATE_ALL_TYPES, null);
    763         db.exec(INSERT_ALL_TYPES, null);
    764         st = db.prepare("select * from " + ALL_TYPES_TABLE);
    765         st.step();
    766 
    767         // Exception test
    768         try {
    769             st.column_decltype(100);
    770             fail();
    771         } catch (SQLite.Exception expected) {
    772         }
    773 
    774         assertTrue(st.column_decltype(0), "BOOLEAN".equalsIgnoreCase(st
    775                 .column_decltype(0)));
    776         assertTrue(st.column_decltype(1), "INT".equalsIgnoreCase(st
    777                 .column_decltype(1)));
    778         assertTrue(st.column_decltype(2), "LONG".equalsIgnoreCase(st
    779                 .column_decltype(2)));
    780         assertTrue(st.column_decltype(3), "BIGINT".equalsIgnoreCase(st
    781                 .column_decltype(3)));
    782         assertTrue(st.column_decltype(4), "TINYINT".equalsIgnoreCase(st
    783                 .column_decltype(4)));
    784         assertTrue(st.column_decltype(5), "SMALLINT".equalsIgnoreCase(st
    785                 .column_decltype(5)));
    786         assertTrue(st.column_decltype(6), "MEDIUMINT".equalsIgnoreCase(st
    787                 .column_decltype(6)));
    788         assertTrue(st.column_decltype(7), "INTEGER".equalsIgnoreCase(st
    789                 .column_decltype(7)));
    790         assertTrue(st.column_decltype(8), "REAL".equalsIgnoreCase(st
    791                 .column_decltype(8)));
    792         assertTrue(st.column_decltype(9), "DOUBLE".equalsIgnoreCase(st
    793                 .column_decltype(9)));
    794         assertTrue(st.column_decltype(10), "FLOAT".equalsIgnoreCase(st
    795                 .column_decltype(10)));
    796         assertTrue(st.column_decltype(11), "DECIMAL".equalsIgnoreCase(st
    797                 .column_decltype(11)));
    798         assertTrue(st.column_decltype(12), "NUMERIC".equalsIgnoreCase(st
    799                 .column_decltype(12)));
    800         assertTrue(st.column_decltype(13), "CHAR(20)".equalsIgnoreCase(st
    801                 .column_decltype(13)));
    802 
    803         assertTrue(st.column_decltype(19), "BLOB".equalsIgnoreCase(st
    804                 .column_decltype(19)));
    805 
    806         assertTrue(st.column_decltype(23), "TEXT".equalsIgnoreCase(st
    807                 .column_decltype(23)));
    808         assertTrue(st.column_decltype(28), "URL".equalsIgnoreCase(st
    809                 .column_decltype(28)));
    810         assertTrue(st.column_decltype(29), "URL".equalsIgnoreCase(st
    811                 .column_decltype(29)));
    812     }
    813 
    814     public void testColumn_origin_name() {
    815         try {
    816             st = db.prepare("select * from " + DatabaseCreator.SIMPLE_TABLE1);
    817             st.column_origin_name(1);
    818             fail("Function is now supported.");
    819         } catch (SQLite.Exception expected) {
    820             assertEquals("unsupported", expected.getMessage());
    821         }
    822     }
    823 }
    824