2 * Copyright (C) 2008 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 import SQLite.Constants;
20 import SQLite.Database;
21 import SQLite.Exception;
23 import SQLite.TableResult;
24 import dalvik.annotation.BrokenTest;
25 import dalvik.annotation.KnownFailure;
26 import dalvik.annotation.TestLevel;
27 import dalvik.annotation.TestTargetNew;
28 import dalvik.annotation.TestTargetClass;
31 import tests.support.DatabaseCreator;
32 import tests.support.Support_SQL;
34 import java.sql.Connection;
35 import java.sql.SQLException;
37 @TestTargetClass(Stmt.class)
38 public class StmtTest extends SQLiteTest {
40 private static Database db = null;
42 private static Stmt st = null;
44 private static final String createAllTypes =
45 "create table type (" +
47 " BoolVal BOOLEAN," + " IntVal INT," + " LongVal LONG,"
48 + " Bint BIGINT," + " Tint TINYINT," + " Sint SMALLINT,"
49 + " Mint MEDIUMINT, " +
51 " IntegerVal INTEGER, " + " RealVal REAL, "
52 + " DoubleVal DOUBLE, " + " FloatVal FLOAT, "
53 + " DecVal DECIMAL, " +
55 " NumVal NUMERIC, " + " charStr CHAR(20), "
56 + " dateVal DATE, " + " timeVal TIME, " + " TS TIMESTAMP, "
59 " DT DATETIME, " + " TBlob TINYBLOB, " + " BlobVal BLOB, "
60 + " MBlob MEDIUMBLOB, " + " LBlob LONGBLOB, " +
62 " TText TINYTEXT, " + " TextVal TEXT, "
63 + " MText MEDIUMTEXT, " + " LText LONGTEXT, " +
65 " MaxLongVal BIGINT, MinLongVal BIGINT, "+
67 " validURL URL, invalidURL URL "+
71 static final String insertAllTypes =
72 "insert into type (BoolVal, IntVal, LongVal, Bint, Tint, Sint, Mint,"
73 + "IntegerVal, RealVal, DoubleVal, FloatVal, DecVal,"
74 + "NumVal, charStr, dateVal, timeVal, TS,"
75 + "DT, TBlob, BlobVal, MBlob, LBlob,"
76 + "TText, TextVal, MText, LText, MaxLongVal, MinLongVal,"
77 + " validURL, invalidURL"
79 + "values (1, -1, 22, 2, 33,"
80 + "3, 1, 2, 3.9, 23.2, 33.3, 44,"
81 + "5, 'test string', '1799-05-26', '12:35:45', '2007-10-09 14:28:02.0',"
82 + "'1221-09-22 10:11:55', 1, 2, 3, 4,"
83 + "'Test text message tiny', 'Test text',"
84 + " 'Test text message medium', 'Test text message long', "
85 + Long.MAX_VALUE+", "+Long.MIN_VALUE+", "
89 static final String allTypesTable = "type";
91 public void setUp() throws java.lang.Exception {
93 Support_SQL.loadDriver();
95 db.open(dbFile.getPath(), 0);
96 db.exec(DatabaseCreator.CREATE_TABLE_SIMPLE1, null);
97 DatabaseCreator.fillSimpleTable1(conn);
101 public void tearDown() {
105 } catch (Exception e) {
111 Connection con = Support_SQL.getConnection();
114 } catch (Exception e) {
115 fail("Exception in tearDown: "+e.getMessage());
116 } catch (SQLException e) {
117 fail("SQLException in tearDown: "+e.getMessage());
123 * @tests {@link Stmt#Stmt()}
126 level = TestLevel.COMPLETE,
127 notes = "constructor test",
131 public void testStmt() {
132 Stmt st = new Stmt();
135 Stmt actual = db.prepare("");
137 // no black box test assertEquals(actual.error_code,st.error_code);
138 } catch (Exception e) {
139 fail("Statement setup fails: "+e.getMessage());
145 fail("Cannot execute non prepared Stmt");
146 } catch (Exception e) {
152 * @tests {@link Stmt#finalize()}
155 level = TestLevel.NOT_FEASIBLE,
156 notes = "method test",
160 public void testFinalize() {
165 * @tests {@link Stmt#prepare()}
168 level = TestLevel.COMPLETE,
169 notes = "method test",
173 public void testPrepare() {
177 fail("statement is closed");
178 } catch (Exception e) {
179 assertEquals("stmt already closed", e.getMessage());
184 st = db.prepare("select * from " + DatabaseCreator.SIMPLE_TABLE1);
185 assertFalse(st.prepare());
187 st = db.prepare("insert into " + DatabaseCreator.SIMPLE_TABLE1
188 + " values (:one,:two,:three)");
189 assertFalse(st.prepare());
191 st = db.prepare("insert into " + DatabaseCreator.SIMPLE_TABLE1
192 + " values (:one,:two,:three)");
196 assertFalse(st.prepare());
197 st = db.prepare("select * from " + DatabaseCreator.SIMPLE_TABLE1
198 + "; " + "delete from " + DatabaseCreator.SIMPLE_TABLE1
199 + " where id = 5; " + "insert into "
200 + DatabaseCreator.SIMPLE_TABLE1 + " values(5, 10, 20); "
201 + "select * from " + DatabaseCreator.SIMPLE_TABLE1 + ";");
202 assertTrue(st.prepare());
203 assertTrue(st.prepare());
204 assertTrue(st.prepare());
205 assertFalse(st.prepare());
206 } catch (Exception e) {
207 fail("statement should be ready for execution: "
214 * @tests {@link Stmt#step()}
217 level = TestLevel.COMPLETE,
218 notes = "method test",
222 public void testStep() {
225 fail("Exception expected");
226 } catch (Exception e) {
227 assertEquals("stmt already closed", e.getMessage());
232 st = db.prepare("select name from sqlite_master where type = 'table'");
234 } catch (Exception e) {
241 * @tests {@link Stmt#close()}
244 level = TestLevel.COMPLETE,
245 notes = "method test",
249 public void testClose() {
251 st = db.prepare("insert into " + DatabaseCreator.SIMPLE_TABLE1
252 + " values (:one,:two,:three)");
254 } catch (Exception e) {
262 } catch (Exception e) {
263 assertEquals("stmt already closed", e.getMessage());
269 * @tests {@link Stmt#reset()}
272 level = TestLevel.COMPLETE,
273 notes = "method test",
277 public void testReset() throws Exception {
278 db.exec("create table TEST (res integer not null)", null);
280 st = db.prepare("insert into TEST values (:one);");
284 // verify that parameter is still bound
286 assertEquals(1,st.bind_parameter_count());
289 TableResult count = db.get_table("select count(*) from TEST where res=1", null);
291 String[] row0 = (String[]) count.rows.elementAt(0);
292 assertEquals(2, Integer.parseInt(row0[0]));
296 * @tests {@link Stmt#clear_bindings()}
299 level = TestLevel.COMPLETE,
300 notes = "not supported",
301 method = "clear_bindings",
304 public void testClear_bindings() {
307 } catch (Exception e) {
308 assertEquals("unsupported", e.getMessage());
313 * @tests {@link Stmt#bind(int, int)}
316 level = TestLevel.COMPLETE,
317 notes = "method test",
319 args = {int.class, int.class}
321 public void testBindIntInt() {
324 int maxVal = Integer.MAX_VALUE;
325 int minVal = Integer.MIN_VALUE;
327 db.exec("create table TEST (res integer)", null);
328 st = db.prepare("insert into TEST values (:one);");
340 TableResult r = db.get_table("select * from TEST");
342 String[] row0 = (String[]) r.rows.elementAt(0);
343 assertEquals(input,Integer.parseInt(row0[0]));
345 String[] row1 = (String[]) r.rows.elementAt(1);
346 assertEquals(maxVal,Integer.parseInt(row1[0]));
348 String[] row2 = (String[]) r.rows.elementAt(2);
349 assertEquals(minVal,Integer.parseInt(row2[0]));
351 } catch (Exception e) {
352 fail("Error in test setup: "+e.getMessage());
358 st.bind(1,Integer.MIN_VALUE);
359 fail("Exception expected");
360 } catch (Exception e) {
366 * @tests {@link Stmt#bind(int, long)}
369 level = TestLevel.COMPLETE,
370 notes = "method test",
372 args = {int.class, long.class}
374 public void testBindIntLong() {
377 long maxVal = Long.MAX_VALUE;
378 long minVal = Long.MIN_VALUE;
380 db.exec("create table TEST (res long)", null);
381 st = db.prepare("insert into TEST values (:one);");
393 TableResult r = db.get_table("select * from TEST");
395 String[] row0 = (String[]) r.rows.elementAt(0);
396 assertEquals(input,Long.parseLong(row0[0]));
398 String[] row1 = (String[]) r.rows.elementAt(1);
399 assertEquals(maxVal,Long.parseLong(row1[0]));
401 String[] row2 = (String[]) r.rows.elementAt(2);
402 assertEquals(minVal,Long.parseLong(row2[0]));
404 } catch (Exception e) {
405 fail("Error in test setup: "+e.getMessage());
411 st.bind(1,Long.MIN_VALUE);
412 fail("Exception expected");
413 } catch (Exception e) {
419 * @tests {@link Stmt#bind(int, double)}
422 level = TestLevel.COMPLETE,
423 notes = "method test",
425 args = {int.class, double.class}
427 public void testBindIntDouble() {
430 double maxVal = Double.MAX_VALUE;
431 double minVal = Double.MIN_VALUE;
432 double negInf = Double.NEGATIVE_INFINITY;
433 double posInf = Double.POSITIVE_INFINITY;
434 double nan = Double.NaN;
436 db.exec("create table TEST (res double)", null);
437 st = db.prepare("insert into TEST values (:one);");
462 TableResult r = db.get_table("select * from TEST");
464 String[] row0 = (String[]) r.rows.elementAt(0);
465 assertTrue(Double.compare(input, Double.parseDouble(row0[0])) == 0);
467 String[] row1 = (String[]) r.rows.elementAt(1);
468 assertFalse(Double.compare(maxVal, Double.parseDouble(row1[0])) == 0);
469 assertTrue(Double.compare(maxVal, Double.parseDouble(row1[0])) < 0);
470 assertTrue(Double.isInfinite(Double.parseDouble(row1[0])));
472 String[] row2 = (String[]) r.rows.elementAt(2);
473 assertTrue(Double.compare(minVal, Double.parseDouble(row2[0])) == 0);
475 String[] row3 = (String[]) r.rows.elementAt(3);
476 assertEquals("Double.NEGATIVE_INFINITY SQLite representation",
479 String[] row4 = (String[]) r.rows.elementAt(4);
480 assertEquals("Double.POSITIVE_INFINITY SQLite representation",
483 String[] row5 = (String[]) r.rows.elementAt(4);
484 assertEquals("Double.Nan SQLite representation", "Inf", row5[0]);
486 } catch (Exception e) {
487 fail("Error in test setup: " + e.getMessage());
494 fail("Exception expected");
495 } catch (Exception e) {
501 * @tests {@link Stmt#bind(int, byte[])}
504 level = TestLevel.COMPLETE,
507 args = {int.class, byte[].class}
509 public void testBindIntByteArray() {
511 String name = "Hello World";
514 byte[] b = new byte[name.getBytes().length];
516 String stringInHex = "";
518 db.exec(DatabaseCreator.CREATE_TABLE_PARENT, null);
519 st = db.prepare("insert into " + DatabaseCreator.PARENT_TABLE
520 + " values (:one, :two);");
525 //compare what was stored with input based on Hex representation
526 // since type of column is CHAR
527 TableResult r = db.get_table("select * from "
528 + DatabaseCreator.PARENT_TABLE);
529 String[] row = (String[]) r.rows.elementAt(0);
531 for (byte aByte : b) {
532 stringInHex += Integer.toHexString(aByte);
534 stringInHex = "X'" + stringInHex + "'";
535 assertTrue(stringInHex.equalsIgnoreCase(row[1]));
537 } catch (Exception e) {
538 fail("Error in test setup: "+e.getMessage());
544 st.bind(1,name.getBytes());
545 fail("Exception expected");
546 } catch (Exception e) {
552 * @tests {@link Stmt#bind(int, String)}
555 level = TestLevel.COMPLETE,
556 notes = "method test",
558 args = {int.class, java.lang.String.class}
560 public void testBindIntString() {
561 String name = "Hello World";
565 db.exec(DatabaseCreator.CREATE_TABLE_PARENT, null);
566 st = db.prepare("insert into " + DatabaseCreator.PARENT_TABLE
567 + " values (:one, :two);");
572 TableResult r = db.get_table("select * from "
573 + DatabaseCreator.PARENT_TABLE);
574 String[] row = (String[]) r.rows.elementAt(0);
575 assertEquals(name,row[1]);
577 } catch (Exception e) {
578 fail("Error in test setup: "+e.getMessage());
585 fail("Exception expected");
586 } catch (Exception e) {
592 * @tests {@link Stmt#bind(int)}
595 level = TestLevel.COMPLETE,
596 notes = "method test",
600 public void testBindInt() {
603 st = db.prepare("insert into " + DatabaseCreator.SIMPLE_TABLE1
604 + " values (:one,:two,:three)");
611 } catch (Exception e) {
612 // What happens if null is bound to non existing variable position
613 assertEquals("parameter position out of bounds" , e.getMessage());
625 } catch (Exception e) {
626 // What happens if null is bound to NON NULL field
627 assertEquals("SQL logic error or missing database", e.getMessage());
636 } catch (Exception e) {
637 fail("Error in test setup : " + e.getMessage());
643 * @tests {@link Stmt#bind_zeroblob(int, int)}
646 level = TestLevel.NOT_FEASIBLE,
647 notes = "not supported",
648 method = "bind_zeroblob",
649 args = {int.class, int.class}
651 public void testBind_zeroblob() {
653 st.bind_zeroblob(1, 128);
654 } catch (Exception e) {
655 assertEquals("unsupported", e.getMessage());
660 * @tests {@link Stmt#bind_parameter_count()}
663 level = TestLevel.COMPLETE,
664 notes = "method test",
665 method = "bind_parameter_count",
668 public void testBind_parameter_count() {
670 st.bind_parameter_count();
671 } catch (Exception e) {
672 assertEquals("stmt already closed", e.getMessage());
676 st = db.prepare("insert into " + DatabaseCreator.SIMPLE_TABLE1
677 + " values (:one,:two,:three)");
678 assertEquals(3, st.bind_parameter_count());
679 } catch (Exception e) {
680 fail("Error in test setup : " + e.getMessage());
685 st = db.prepare("insert into " + DatabaseCreator.SIMPLE_TABLE1
686 + " values (?, ?, ?)");
687 assertEquals(3, st.bind_parameter_count());
688 } catch (Exception e) {
689 fail("Error in test setup : " + e.getMessage());
694 st = db.prepare("select * from " + DatabaseCreator.SIMPLE_TABLE1);
695 assertEquals(0, st.bind_parameter_count());
696 } catch (Exception e) {
697 fail("Error in test setup : " + e.getMessage());
703 st.bind_parameter_count();
704 fail("Exception expected");
705 } catch (Exception e) {
712 * @tests {@link Stmt#bind_parameter_name(int)}
715 level = TestLevel.COMPLETE,
716 notes = "method test",
717 method = "bind_parameter_name",
720 public void testBind_parameter_name() {
722 st.bind_parameter_name(1);
723 fail("Exception expected");
724 } catch (Exception e) {
725 assertEquals("stmt already closed", e.getMessage());
729 st = db.prepare("insert into " + DatabaseCreator.SIMPLE_TABLE1
730 + " values (:one,:two,:three)");
731 assertEquals(":one", st.bind_parameter_name(1));
732 assertEquals(":two", st.bind_parameter_name(2));
733 assertEquals(":three", st.bind_parameter_name(3));
734 String name = st.bind_parameter_name(4);
735 } catch (Exception e) {
736 assertEquals("parameter position out of bounds",e.getMessage());
741 * @tests {@link Stmt#bind_parameter_index(String)}
744 level = TestLevel.COMPLETE,
745 notes = "method test",
746 method = "bind_parameter_index",
747 args = {java.lang.String.class}
749 public void testBind_parameter_index() {
752 st.bind_parameter_index("");
753 fail("Exception expected");
754 } catch (Exception e) {
755 assertEquals("stmt already closed", e.getMessage());
759 st = db.prepare("insert into " + DatabaseCreator.SIMPLE_TABLE1
760 + " values (:one,:two,:three)");
761 assertEquals(3, st.bind_parameter_index(":three"));
762 } catch (Exception e) {
763 fail("Error in test setup : " + e.getMessage());
768 st = db.prepare("insert into " + DatabaseCreator.SIMPLE_TABLE1
769 + " values (:one,:two,:three)");
770 assertEquals(0, st.bind_parameter_index(":t"));
771 } catch (Exception e) {
772 fail("Error in test setup : " + e.getMessage());
777 st = db.prepare("insert into " + DatabaseCreator.SIMPLE_TABLE1
778 + " values (?, ?, ?)");
779 assertEquals(0, st.bind_parameter_index("?"));
780 } catch (Exception e) {
781 fail("Error in test setup : " + e.getMessage());
789 * @tests {@link Stmt#column_int(int)}
792 level = TestLevel.COMPLETE,
793 notes = "method test",
794 method = "column_int",
797 public void testColumn_int() throws Exception {
798 db.exec(createAllTypes, null);
799 db.exec(insertAllTypes, null);
801 int columnObjectCastFromLong;
802 Object columnObject = null;
804 String selectStmt = "select * from "+DatabaseCreator.SIMPLE_TABLE1;
806 st = db.prepare(selectStmt);
808 // select 'speed' value
809 columnObject = st.column(1);
810 intColumn = st.column_int(1);
811 assertNotNull(intColumn);
813 assertTrue("Integer".equalsIgnoreCase(st.column_decltype(1)));
814 int stSpeed = Integer.parseInt(columnObject.toString());
815 assertNotNull(stSpeed);
816 assertEquals( intColumn, stSpeed);
817 assertEquals(10,stSpeed);
819 selectStmt = "select TextVal from "+allTypesTable;
821 st = db.prepare(selectStmt);
823 // select double value
826 } catch (Exception e) {
832 * @tests {@link Stmt#column_long(int)}
835 level = TestLevel.COMPLETE,
836 notes = "method test",
837 method = "column_long",
840 public void testColumn_long() {
841 Object columnObject = null;
842 int columnObjectCastFromLong;
845 String selectStmt = "select * from "+DatabaseCreator.SIMPLE_TABLE1;
846 st = db.prepare(selectStmt);
848 columnObject = st.column(1);
849 longColumn = st.column_long(1);
850 assertNotNull(longColumn);
851 // column declared as integer
852 assertTrue("Integer".equalsIgnoreCase(st.column_decltype(1)));
853 int stSpeed = Integer.parseInt(columnObject.toString());
854 assertNotNull(stSpeed);
855 assertEquals( longColumn, stSpeed);
856 } catch (Exception e) {
857 fail("Error in test setup : " + e.getMessage());
863 fail("Exception expected");
864 } catch (Exception e) {
865 assertEquals( "column out of bounds" , e.getMessage());
870 fail("Exception expected");
871 } catch (Exception e) {
872 assertEquals( "column out of bounds" , e.getMessage());
878 * @tests {@link Stmt#column_double(int)}
881 level = TestLevel.COMPLETE,
882 notes = "method test",
883 method = "column_double",
886 public void testColumn_double() throws Exception {
887 db.exec(createAllTypes, null);
888 db.exec(insertAllTypes, null);
890 Object columnObject = null;
891 double doubleColumn = 0;
892 double actualVal = 23.2;
893 String selectStmt = "select DoubleVal from "+allTypesTable;
895 st = db.prepare(selectStmt);
897 // select double value
898 doubleColumn = st.column_double(0);
899 assertNotNull(doubleColumn);
901 assertTrue("DOUBLE".equalsIgnoreCase(st.column_decltype(0)));
902 assertNotNull(doubleColumn);
903 assertEquals( actualVal, doubleColumn);
906 selectStmt = "select dateVal from "+allTypesTable;
908 st = db.prepare(selectStmt);
910 // select double value
913 } catch (Exception e) {
922 * @tests {@link Stmt#column_bytes(int)}
925 level = TestLevel.NOT_FEASIBLE,
926 notes = "not supported",
927 method = "column_bytes",
930 public void testColumn_bytes() throws Exception {
932 db.exec("create table B(id integer primary key, val blob)",null);
933 db.exec("insert into B values(1, zeroblob(128))", null);
934 st = db.prepare("select val from B where id = 1");
935 assertTrue(st.step());
938 } catch (Exception e) {
939 assertEquals("unsupported", e.getMessage());
945 * @tests {@link Stmt#column_string(int)}
948 level = TestLevel.COMPLETE,
949 notes = "method test",
950 method = "column_string",
953 public void testColumn_string() throws Exception {
954 db.exec(createAllTypes, null);
955 db.exec(insertAllTypes, null);
957 Object columnObject = null;
958 String stringColumn = "";
959 String actualVal = "test string";
960 String selectStmt = "select charStr from "+allTypesTable;
962 st = db.prepare(selectStmt);
964 // select string value
965 stringColumn = st.column_string(0);
966 assertNotNull(stringColumn);
968 assertTrue("CHAR(20)".equalsIgnoreCase(st.column_decltype(0)));
969 assertNotNull(stringColumn);
970 assertEquals( actualVal, stringColumn);
973 selectStmt = "select DoubleVal from "+allTypesTable;
975 st = db.prepare(selectStmt);
977 // select double value
980 } catch (Exception e) {
985 public void testColumn_type() throws Exception {
986 db.exec(createAllTypes, null);
987 db.exec(insertAllTypes, null);
988 st = db.prepare("select * from " + allTypesTable);
994 } catch (Exception e) {
1001 public static final int SQLITE_INTEGER = 1;
1002 public static final int SQLITE_FLOAT = 2;
1003 public static final int SQLITE_BLOB = 4;
1004 public static final int SQLITE_NULL = 5;
1005 public static final int SQLITE3_TEXT = 3;
1006 public static final int SQLITE_NUMERIC = -1;
1009 assertEquals(Constants.SQLITE3_TEXT, st.column_type(23)); // ok TEXT
1010 assertEquals(Constants.SQLITE3_TEXT, st.column_type(13)); // CHAR(20)
1012 assertEquals(Constants.SQLITE_FLOAT, st.column_type(8));
1013 assertEquals(Constants.SQLITE_FLOAT, st.column_type(9));
1014 assertEquals(Constants.SQLITE_FLOAT, st.column_type(10)); // FLOAT
1016 for (int i = 0; i < 8; i++) {
1017 assertEquals("Expected Integer at position " + i,
1018 Constants.SQLITE_INTEGER, st.column_type(i));
1021 assertEquals(Constants.SQLITE_NULL, st.column_type(28));
1022 assertEquals(Constants.SQLITE_NULL, st.column_type(29));
1025 assertTrue("INTEGER".equalsIgnoreCase(st.column_decltype(12)));
1026 assertEquals(Constants.SQLITE_INTEGER, st.column_type(12));
1028 assertTrue("FLOAT".equalsIgnoreCase(st.column_decltype(11)));
1029 assertEquals(Constants.SQLITE_FLOAT, st.column_type(11)); // FLOAT ->
1031 assertTrue("BLOB".equalsIgnoreCase(st.column_decltype(19)));
1032 assertEquals(Constants.SQLITE_BLOB, st.column_type(19)); // Blob got
1039 * @tests {@link Stmt#column_count() )}
1042 level = TestLevel.COMPLETE,
1043 notes = "method test",
1044 method = "column_count",
1047 @KnownFailure("Wrong value is returned in case of a prepared statment to "+
1048 "which a '*' bound ")
1049 public void testColumn_count() throws Exception {
1051 String selectStmt = "select * from "+DatabaseCreator.SIMPLE_TABLE1;
1052 st = db.prepare(selectStmt);
1054 assertEquals(3, st.column_count());
1057 int columnCount = st.column_count();
1058 assertNotNull(columnCount);
1059 assertEquals( 3, columnCount);
1061 // actual prepared statement
1062 selectStmt = "select ? from "+DatabaseCreator.SIMPLE_TABLE1;
1063 st = db.prepare(selectStmt);
1065 assertEquals(3, st.column_count());
1069 columnCount = st.column_count();
1070 assertNotNull(columnCount);
1071 assertEquals( 3, columnCount);
1077 * @tests {@link Stmt#column(int) )}
1080 level = TestLevel.COMPLETE,
1081 notes = "method test",
1085 public void testColumn() throws Exception {
1086 Object columnObject = null;
1087 int columnObjectCastFromLong;
1090 String selectStmt = "select * from "+DatabaseCreator.SIMPLE_TABLE1;
1091 TableResult res = db.get_table(selectStmt);
1092 st = db.prepare(selectStmt);
1094 columnObject = st.column(1);
1095 intColumn = st.column_int(1);
1096 assertNotNull(intColumn);
1097 assertTrue("Integer".equalsIgnoreCase(st.column_decltype(1)));
1098 int stSpeed = Integer.parseInt(columnObject.toString());
1099 assertNotNull(stSpeed);
1100 assertEquals( intColumn, stSpeed);
1101 } catch (Exception e) {
1102 fail("Error in test setup : " + e.getMessage());
1103 e.printStackTrace();
1107 assertNotNull(columnObject);
1108 int dummy = ((Integer) columnObject).intValue();
1109 fail("Cast to Integer should fail");
1110 } catch (ClassCastException e) {
1111 assertEquals("java.lang.Long", e.getMessage());
1116 fail("Exception expected");
1117 } catch (Exception e) {
1118 assertEquals( "column out of bounds" , e.getMessage());
1123 fail("Exception expected");
1124 } catch (Exception e) {
1125 assertEquals( "column out of bounds" , e.getMessage());
1130 * @tests {@link Stmt#column_table_name(int)}
1133 level = TestLevel.NOT_FEASIBLE,
1134 notes = "not supported",
1135 method = "column_table_name",
1138 public void testColumn_table_name() {
1140 st = db.prepare("select * from " + DatabaseCreator.SIMPLE_TABLE1);
1141 String name = st.column_table_name(1);
1142 fail("Function is now supported.");
1143 } catch (Exception e) {
1144 assertEquals("unsupported", e.getMessage());
1149 * @tests {@link Stmt#column_database_name(int)}
1152 level = TestLevel.NOT_FEASIBLE,
1153 notes = "not supported",
1154 method = "column_database_name",
1157 public void testColumn_database_name() {
1159 st = db.prepare("insert into " + DatabaseCreator.SIMPLE_TABLE1
1160 + " values (:one,:two,:three)");
1161 String name = st.column_database_name(1);
1162 fail("Function is now supported.");
1163 } catch (Exception e) {
1164 assertEquals("unsupported", e.getMessage());
1171 * @tests {@link Stmt#column_decltype(int)}
1174 level = TestLevel.SUFFICIENT,
1175 notes = "method test",
1176 method = "column_decltype",
1179 public void testColumn_decltype() throws Exception {
1180 db.exec(createAllTypes, null);
1181 db.exec(insertAllTypes, null);
1182 st = db.prepare("select * from " + allTypesTable);
1187 st.column_decltype(100);
1188 } catch (Exception e) {
1192 assertTrue(st.column_decltype(0), "BOOLEAN".equalsIgnoreCase(st
1193 .column_decltype(0)));
1194 assertTrue(st.column_decltype(1), "INT".equalsIgnoreCase(st
1195 .column_decltype(1)));
1196 assertTrue(st.column_decltype(2), "LONG".equalsIgnoreCase(st
1197 .column_decltype(2)));
1198 assertTrue(st.column_decltype(3), "BIGINT".equalsIgnoreCase(st
1199 .column_decltype(3)));
1200 assertTrue(st.column_decltype(4), "TINYINT".equalsIgnoreCase(st
1201 .column_decltype(4)));
1202 assertTrue(st.column_decltype(5), "SMALLINT".equalsIgnoreCase(st
1203 .column_decltype(5)));
1204 assertTrue(st.column_decltype(6), "MEDIUMINT".equalsIgnoreCase(st
1205 .column_decltype(6)));
1206 assertTrue(st.column_decltype(7), "INTEGER".equalsIgnoreCase(st
1207 .column_decltype(7)));
1208 assertTrue(st.column_decltype(8), "REAL".equalsIgnoreCase(st
1209 .column_decltype(8)));
1210 assertTrue(st.column_decltype(9), "DOUBLE".equalsIgnoreCase(st
1211 .column_decltype(9)));
1212 assertTrue(st.column_decltype(10), "FLOAT".equalsIgnoreCase(st
1213 .column_decltype(10)));
1214 assertTrue(st.column_decltype(11), "DECIMAL".equalsIgnoreCase(st
1215 .column_decltype(11)));
1216 assertTrue(st.column_decltype(12), "NUMERIC".equalsIgnoreCase(st
1217 .column_decltype(12)));
1218 assertTrue(st.column_decltype(13), "CHAR(20)".equalsIgnoreCase(st
1219 .column_decltype(13)));
1221 assertTrue(st.column_decltype(19), "BLOB".equalsIgnoreCase(st
1222 .column_decltype(19)));
1224 assertTrue(st.column_decltype(23), "TEXT".equalsIgnoreCase(st
1225 .column_decltype(23)));
1226 assertTrue(st.column_decltype(28), "URL".equalsIgnoreCase(st
1227 .column_decltype(28)));
1228 assertTrue(st.column_decltype(29), "URL".equalsIgnoreCase(st
1229 .column_decltype(29)));
1233 * @tests {@link Stmt#column_origin_name(int)}
1236 level = TestLevel.NOT_FEASIBLE,
1237 notes = "not supported",
1238 method = "column_origin_name",
1241 public void testColumn_origin_name() {
1243 st = db.prepare("select * from " + DatabaseCreator.SIMPLE_TABLE1);
1244 String name = st.column_origin_name(1);
1245 fail("Function is now supported.");
1246 } catch (Exception e) {
1247 assertEquals("unsupported", e.getMessage());