Debian Codegraph @

lang/sql/jdbc/SQLite/JDBC2x/JDBCDatabaseMetaData.java

raw
1 package SQLite.JDBC2x;
2
3 import java.sql.Connection;
4 import java.sql.DatabaseMetaData;
5 import java.sql.ResultSet;
6 import java.sql.SQLException;
7 import java.sql.Types;
8 import java.util.Hashtable;
9
10 public class JDBCDatabaseMetaData implements DatabaseMetaData {
11
12 private JDBCConnection conn;
13
14 public JDBCDatabaseMetaData(JDBCConnection conn) {
15 this.conn = conn;
16 }
17
18 public boolean allProceduresAreCallable() throws SQLException {
19 return false;
20 }
21
22 public boolean allTablesAreSelectable() throws SQLException {
23 return true;
24 }
25
26 public String getURL() throws SQLException {
27 return conn.url;
28 }
29
30 public String getUserName() throws SQLException {
31 return "";
32 }
33
34 public boolean isReadOnly() throws SQLException {
35 return false;
36 }
37
38 public boolean nullsAreSortedHigh() throws SQLException {
39 return false;
40 }
41
42 public boolean nullsAreSortedLow() throws SQLException {
43 return false;
44 }
45
46 public boolean nullsAreSortedAtStart() throws SQLException {
47 return false;
48 }
49
50 public boolean nullsAreSortedAtEnd() throws SQLException {
51 return false;
52 }
53
54 public String getDatabaseProductName() throws SQLException {
55 return "SQLite";
56 }
57
58 public String getDatabaseProductVersion() throws SQLException {
59 return SQLite.Database.version();
60 }
61
62 public String getDriverName() throws SQLException {
63 return "SQLite/JDBC";
64 }
65
66 public String getDriverVersion() throws SQLException {
67 return "" + SQLite.JDBC.MAJORVERSION + "." +
68 SQLite.Constants.drv_minor;
69 }
70
71 public int getDriverMajorVersion() {
72 return SQLite.JDBC.MAJORVERSION;
73 }
74
75 public int getDriverMinorVersion() {
76 return SQLite.Constants.drv_minor;
77 }
78
79 public boolean usesLocalFiles() throws SQLException {
80 return true;
81 }
82
83 public boolean usesLocalFilePerTable() throws SQLException {
84 return false;
85 }
86
87 public boolean supportsMixedCaseIdentifiers() throws SQLException {
88 return false;
89 }
90
91 public boolean storesUpperCaseIdentifiers() throws SQLException {
92 return false;
93 }
94
95 public boolean storesLowerCaseIdentifiers() throws SQLException {
96 return false;
97 }
98
99 public boolean storesMixedCaseIdentifiers() throws SQLException {
100 return true;
101 }
102
103 public boolean supportsMixedCaseQuotedIdentifiers() throws SQLException {
104 return false;
105 }
106
107 public boolean storesUpperCaseQuotedIdentifiers() throws SQLException {
108 return false;
109 }
110
111 public boolean storesLowerCaseQuotedIdentifiers() throws SQLException {
112 return false;
113 }
114
115 public boolean storesMixedCaseQuotedIdentifiers() throws SQLException {
116 return true;
117 }
118
119 public String getIdentifierQuoteString() throws SQLException {
120 return "\"";
121 }
122
123 public String getSQLKeywords() throws SQLException {
124 return "SELECT,UPDATE,CREATE,TABLE,VIEW,DELETE,FROM,WHERE" +
125 ",COMMIT,ROLLBACK,TRIGGER";
126 }
127
128 public String getNumericFunctions() throws SQLException {
129 return "";
130 }
131
132 public String getStringFunctions() throws SQLException {
133 return "";
134 }
135
136 public String getSystemFunctions() throws SQLException {
137 return "";
138 }
139
140 public String getTimeDateFunctions() throws SQLException {
141 return "";
142 }
143
144 public String getSearchStringEscape() throws SQLException {
145 return "\\";
146 }
147
148 public String getExtraNameCharacters() throws SQLException {
149 return "";
150 }
151
152 public boolean supportsAlterTableWithAddColumn() throws SQLException {
153 return false;
154 }
155
156 public boolean supportsAlterTableWithDropColumn() throws SQLException {
157 return false;
158 }
159
160 public boolean supportsColumnAliasing() throws SQLException {
161 return true;
162 }
163
164 public boolean nullPlusNonNullIsNull() throws SQLException {
165 return false;
166 }
167
168 public boolean supportsConvert() throws SQLException {
169 return false;
170 }
171
172 public boolean supportsConvert(int fromType, int toType)
173 throws SQLException {
174 return false;
175 }
176
177 public boolean supportsTableCorrelationNames() throws SQLException {
178 return true;
179 }
180
181 public boolean supportsDifferentTableCorrelationNames()
182 throws SQLException {
183 return false;
184 }
185
186 public boolean supportsExpressionsInOrderBy() throws SQLException {
187 return true;
188 }
189
190 public boolean supportsOrderByUnrelated() throws SQLException {
191 return true;
192 }
193
194 public boolean supportsGroupBy() throws SQLException {
195 return true;
196 }
197
198 public boolean supportsGroupByUnrelated() throws SQLException {
199 return true;
200 }
201
202 public boolean supportsGroupByBeyondSelect() throws SQLException {
203 return false;
204 }
205
206 public boolean supportsLikeEscapeClause() throws SQLException {
207 return false;
208 }
209
210 public boolean supportsMultipleResultSets() throws SQLException {
211 return false;
212 }
213
214 public boolean supportsMultipleTransactions() throws SQLException {
215 return false;
216 }
217
218 public boolean supportsNonNullableColumns() throws SQLException {
219 return true;
220 }
221
222 public boolean supportsMinimumSQLGrammar() throws SQLException {
223 return true;
224 }
225
226 public boolean supportsCoreSQLGrammar() throws SQLException {
227 return false;
228 }
229
230 public boolean supportsExtendedSQLGrammar() throws SQLException {
231 return false;
232 }
233
234 public boolean supportsANSI92EntryLevelSQL() throws SQLException {
235 return true;
236 }
237
238 public boolean supportsANSI92IntermediateSQL() throws SQLException {
239 return false;
240 }
241
242 public boolean supportsANSI92FullSQL() throws SQLException {
243 return false;
244 }
245
246 public boolean supportsIntegrityEnhancementFacility()
247 throws SQLException {
248 return false;
249 }
250
251 public boolean supportsOuterJoins() throws SQLException {
252 return false;
253 }
254
255 public boolean supportsFullOuterJoins() throws SQLException {
256 return false;
257 }
258
259 public boolean supportsLimitedOuterJoins() throws SQLException {
260 return false;
261 }
262
263 public String getSchemaTerm() throws SQLException {
264 return "";
265 }
266
267 public String getProcedureTerm() throws SQLException {
268 return "";
269 }
270
271 public String getCatalogTerm() throws SQLException {
272 return "";
273 }
274
275 public boolean isCatalogAtStart() throws SQLException {
276 return false;
277 }
278
279 public String getCatalogSeparator() throws SQLException {
280 return "";
281 }
282
283 public boolean supportsSchemasInDataManipulation() throws SQLException {
284 return false;
285 }
286
287 public boolean supportsSchemasInProcedureCalls() throws SQLException {
288 return false;
289 }
290
291 public boolean supportsSchemasInTableDefinitions() throws SQLException {
292 return false;
293 }
294
295 public boolean supportsSchemasInIndexDefinitions() throws SQLException {
296 return false;
297 }
298
299 public boolean supportsSchemasInPrivilegeDefinitions()
300 throws SQLException {
301 return false;
302 }
303
304 public boolean supportsCatalogsInDataManipulation() throws SQLException {
305 return false;
306 }
307
308 public boolean supportsCatalogsInProcedureCalls() throws SQLException {
309 return false;
310 }
311
312 public boolean supportsCatalogsInTableDefinitions() throws SQLException {
313 return false;
314 }
315
316 public boolean supportsCatalogsInIndexDefinitions() throws SQLException {
317 return false;
318 }
319
320 public boolean supportsCatalogsInPrivilegeDefinitions()
321 throws SQLException {
322 return false;
323 }
324
325 public boolean supportsPositionedDelete() throws SQLException {
326 return false;
327 }
328
329 public boolean supportsPositionedUpdate() throws SQLException {
330 return false;
331 }
332
333 public boolean supportsSelectForUpdate() throws SQLException {
334 return false;
335 }
336
337 public boolean supportsStoredProcedures() throws SQLException {
338 return false;
339 }
340
341 public boolean supportsSubqueriesInComparisons() throws SQLException {
342 return true;
343 }
344
345 public boolean supportsSubqueriesInExists() throws SQLException {
346 return true;
347 }
348
349 public boolean supportsSubqueriesInIns() throws SQLException {
350 return true;
351 }
352
353 public boolean supportsSubqueriesInQuantifieds() throws SQLException {
354 return false;
355 }
356
357 public boolean supportsCorrelatedSubqueries() throws SQLException {
358 return false;
359 }
360
361 public boolean supportsUnion() throws SQLException {
362 return true;
363 }
364
365 public boolean supportsUnionAll() throws SQLException {
366 return true;
367 }
368
369 public boolean supportsOpenCursorsAcrossCommit() throws SQLException {
370 return false;
371 }
372
373 public boolean supportsOpenCursorsAcrossRollback() throws SQLException {
374 return false;
375 }
376
377 public boolean supportsOpenStatementsAcrossCommit() throws SQLException {
378 return false;
379 }
380
381 public boolean supportsOpenStatementsAcrossRollback() throws SQLException {
382 return false;
383 }
384
385 public int getMaxBinaryLiteralLength() throws SQLException {
386 return 0;
387 }
388
389 public int getMaxCharLiteralLength() throws SQLException {
390 return 0;
391 }
392
393 public int getMaxColumnNameLength() throws SQLException {
394 return 0;
395 }
396
397 public int getMaxColumnsInGroupBy() throws SQLException {
398 return 0;
399 }
400
401 public int getMaxColumnsInIndex() throws SQLException {
402 return 0;
403 }
404
405 public int getMaxColumnsInOrderBy() throws SQLException {
406 return 0;
407 }
408
409 public int getMaxColumnsInSelect() throws SQLException {
410 return 0;
411 }
412
413 public int getMaxColumnsInTable() throws SQLException {
414 return 0;
415 }
416
417 public int getMaxConnections() throws SQLException {
418 return 0;
419 }
420
421 public int getMaxCursorNameLength() throws SQLException {
422 return 8;
423 }
424
425 public int getMaxIndexLength() throws SQLException {
426 return 0;
427 }
428
429 public int getMaxSchemaNameLength() throws SQLException {
430 return 0;
431 }
432
433 public int getMaxProcedureNameLength() throws SQLException {
434 return 0;
435 }
436
437 public int getMaxCatalogNameLength() throws SQLException {
438 return 0;
439 }
440
441 public int getMaxRowSize() throws SQLException {
442 return 0;
443 }
444
445 public boolean doesMaxRowSizeIncludeBlobs() throws SQLException {
446 return true;
447 }
448
449 public int getMaxStatementLength() throws SQLException {
450 return 0;
451 }
452
453 public int getMaxStatements() throws SQLException {
454 return 0;
455 }
456
457 public int getMaxTableNameLength() throws SQLException {
458 return 0;
459 }
460
461 public int getMaxTablesInSelect() throws SQLException {
462 return 0;
463 }
464
465 public int getMaxUserNameLength() throws SQLException {
466 return 0;
467 }
468
469 public int getDefaultTransactionIsolation() throws SQLException {
470 return Connection.TRANSACTION_SERIALIZABLE;
471 }
472
473 public boolean supportsTransactions() throws SQLException {
474 return true;
475 }
476
477 public boolean supportsTransactionIsolationLevel(int level)
478 throws SQLException {
479 return level == Connection.TRANSACTION_SERIALIZABLE;
480 }
481
482 public boolean supportsDataDefinitionAndDataManipulationTransactions()
483 throws SQLException {
484 return true;
485 }
486
487 public boolean supportsDataManipulationTransactionsOnly()
488 throws SQLException {
489 return false;
490 }
491
492 public boolean dataDefinitionCausesTransactionCommit()
493 throws SQLException {
494 return false;
495 }
496
497 public boolean dataDefinitionIgnoredInTransactions() throws SQLException {
498 return false;
499 }
500
501 public ResultSet getProcedures(String catalog, String schemaPattern,
502 String procedureNamePattern)
503 throws SQLException {
504 return null;
505 }
506
507 public ResultSet getProcedureColumns(String catalog,
508 String schemaPattern,
509 String procedureNamePattern,
510 String columnNamePattern)
511 throws SQLException {
512 return null;
513 }
514
515 public ResultSet getTables(String catalog, String schemaPattern,
516 String tableNamePattern, String types[])
517 throws SQLException {
518 JDBCStatement s = new JDBCStatement(conn);
519 StringBuffer sb = new StringBuffer(
520 "SELECT '' AS 'TABLE_CAT', " +
521 "'' AS 'TABLE_SCHEM', " +
522 "tbl_name AS 'TABLE_NAME', " +
523 "upper(type) AS 'TABLE_TYPE', " +
524 "'' AS REMARKS FROM sqlite_master " +
525 "WHERE tbl_name like ");
526 if (tableNamePattern != null) {
527 sb.append(SQLite.Shell.sql_quote(tableNamePattern));
528 } else {
529 sb.append("'%'");
530 }
531 sb.append(" AND ");
532 if (types == null || types.length == 0) {
533 sb.append("(type = 'table' or type = 'view')");
534 } else {
535 sb.append("(");
536 String sep = "";
537 for (int i = 0; i < types.length; i++) {
538 sb.append(sep);
539 sb.append("type = ");
540 sb.append(SQLite.Shell.sql_quote(types[i].toLowerCase()));
541 sep = " or ";
542 }
543 sb.append(")");
544 }
545 ResultSet rs = null;
546 try {
547 rs = s.executeQuery(sb.toString());
548 s.close();
549 } catch (SQLException e) {
550 throw e;
551 } finally {
552 s.close();
553 }
554 return rs;
555 }
556
557 public ResultSet getSchemas() throws SQLException {
558 String cols[] = { "TABLE_SCHEM" };
559 SQLite.TableResult tr = new SQLite.TableResult();
560 tr.columns(cols);
561 String row[] = { "" };
562 tr.newrow(row);
563 JDBCResultSet rs = new JDBCResultSet(tr, null);
564 return rs;
565 }
566
567 public ResultSet getCatalogs() throws SQLException {
568 String cols[] = { "TABLE_CAT" };
569 SQLite.TableResult tr = new SQLite.TableResult();
570 tr.columns(cols);
571 String row[] = { "" };
572 tr.newrow(row);
573 JDBCResultSet rs = new JDBCResultSet(tr, null);
574 return rs;
575 }
576
577 public ResultSet getTableTypes() throws SQLException {
578 String cols[] = { "TABLE_TYPE" };
579 SQLite.TableResult tr = new SQLite.TableResult();
580 tr.columns(cols);
581 String row[] = new String[1];
582 row[0] = "TABLE";
583 tr.newrow(row);
584 row = new String[1];
585 row[0] = "VIEW";
586 tr.newrow(row);
587 JDBCResultSet rs = new JDBCResultSet(tr, null);
588 return rs;
589 }
590
591 public ResultSet getColumns(String catalog, String schemaPattern,
592 String tableNamePattern,
593 String columnNamePattern)
594 throws SQLException {
595 if (conn.db == null) {
596 throw new SQLException("connection closed");
597 }
598 JDBCStatement s = new JDBCStatement(conn);
599 JDBCResultSet rs0 = null;
600 try {
601 try {
602 conn.db.exec("SELECT 1 FROM sqlite_master LIMIT 1", null);
603 } catch (SQLite.Exception se) {
604 throw new
605 SQLException("schema reload failed: " + se.toString());
606 }
607 rs0 = (JDBCResultSet)
608 (s.executeQuery("PRAGMA table_info(" +
609 SQLite.Shell.sql_quote(tableNamePattern) +
610 ")"));
611 s.close();
612 } catch (SQLException e) {
613 throw e;
614 } finally {
615 s.close();
616 }
617 if (rs0.tr.nrows < 1) {
618 throw new SQLException("no such table: " + tableNamePattern);
619 }
620 String cols[] = {
621 "TABLE_CAT", "TABLE_SCHEM", "TABLE_NAME",
622 "COLUMN_NAME", "DATA_TYPE", "TYPE_NAME",
623 "COLUMN_SIZE", "BUFFER_LENGTH", "DECIMAL_DIGITS",
624 "NUM_PREC_RADIX", "NULLABLE", "REMARKS",
625 "COLUMN_DEF", "SQL_DATA_TYPE", "SQL_DATETIME_SUB",
626 "CHAR_OCTET_LENGTH", "ORDINAL_POSITION", "IS_NULLABLE"
627 };
628 int types[] = {
629 Types.VARCHAR, Types.VARCHAR, Types.VARCHAR,
630 Types.VARCHAR, Types.SMALLINT, Types.VARCHAR,
631 Types.INTEGER, Types.INTEGER, Types.INTEGER,
632 Types.INTEGER, Types.INTEGER, Types.VARCHAR,
633 Types.VARCHAR, Types.INTEGER, Types.INTEGER,
634 Types.INTEGER, Types.INTEGER, Types.VARCHAR
635 };
636 TableResultX tr = new TableResultX();
637 tr.columns(cols);
638 tr.sql_types(types);
639 JDBCResultSet rs = new JDBCResultSet(tr, null);
640 if (rs0.tr != null && rs0.tr.nrows > 0) {
641 Hashtable h = new Hashtable();
642 for (int i = 0; i < rs0.tr.ncolumns; i++) {
643 h.put(rs0.tr.column[i], new Integer(i));
644 }
645 if (columnNamePattern != null &&
646 columnNamePattern.charAt(0) == '%') {
647 columnNamePattern = null;
648 }
649 for (int i = 0; i < rs0.tr.nrows; i++) {
650 String r0[] = (String [])(rs0.tr.rows.elementAt(i));
651 int col = ((Integer) h.get("name")).intValue();
652 if (columnNamePattern != null) {
653 if (r0[col].compareTo(columnNamePattern) != 0) {
654 continue;
655 }
656 }
657 String row[] = new String[cols.length];
658 row[0] = "";
659 row[1] = "";
660 row[2] = tableNamePattern;
661 row[3] = r0[col];
662 col = ((Integer) h.get("type")).intValue();
663 String typeStr = r0[col];
664 int type = mapSqlType(typeStr);
665 row[4] = "" + type;
666 row[5] = mapTypeName(type);
667 row[6] = "" + getD(typeStr, type);
668 row[7] = "" + getM(typeStr, type);
669 row[8] = "10";
670 row[9] = "0";
671 row[11] = null;
672 col = ((Integer) h.get("dflt_value")).intValue();
673 row[12] = r0[col];
674 row[13] = "0";
675 row[14] = "0";
676 row[15] = "65536";
677 col = ((Integer) h.get("cid")).intValue();
678 Integer cid = new Integer(r0[col]);
679 row[16] = "" + (cid.intValue() + 1);
680 col = ((Integer) h.get("notnull")).intValue();
681 row[17] = (r0[col].charAt(0) == '0') ? "YES" : "NO";
682 row[10] = (r0[col].charAt(0) == '0') ? "" + columnNullable :
683 "" + columnNoNulls;
684 tr.newrow(row);
685 }
686 }
687 return rs;
688 }
689
690 public ResultSet getColumnPrivileges(String catalog, String schema,
691 String table,
692 String columnNamePattern)
693 throws SQLException {
694 String cols[] = {
695 "TABLE_CAT", "TABLE_SCHEM", "TABLE_NAME",
696 "COLUMN_NAME", "GRANTOR", "GRANTEE",
697 "PRIVILEGE", "IS_GRANTABLE"
698 };
699 int types[] = {
700 Types.VARCHAR, Types.VARCHAR, Types.VARCHAR,
701 Types.VARCHAR, Types.VARCHAR, Types.VARCHAR,
702 Types.VARCHAR, Types.VARCHAR
703 };
704 TableResultX tr = new TableResultX();
705 tr.columns(cols);
706 tr.sql_types(types);
707 JDBCResultSet rs = new JDBCResultSet(tr, null);
708 return rs;
709 }
710
711 public ResultSet getTablePrivileges(String catalog, String schemaPattern,
712 String tableNamePattern)
713 throws SQLException {
714 String cols[] = {
715 "TABLE_CAT", "TABLE_SCHEM", "TABLE_NAME",
716 "COLUMN_NAME", "GRANTOR", "GRANTEE",
717 "PRIVILEGE", "IS_GRANTABLE"
718 };
719 int types[] = {
720 Types.VARCHAR, Types.VARCHAR, Types.VARCHAR,
721 Types.VARCHAR, Types.VARCHAR, Types.VARCHAR,
722 Types.VARCHAR, Types.VARCHAR
723 };
724 TableResultX tr = new TableResultX();
725 tr.columns(cols);
726 tr.sql_types(types);
727 JDBCResultSet rs = new JDBCResultSet(tr, null);
728 return rs;
729 }
730
731 public ResultSet getBestRowIdentifier(String catalog, String schema,
732 String table, int scope,
733 boolean nullable)
734 throws SQLException {
735 JDBCStatement s0 = new JDBCStatement(conn);
736 JDBCResultSet rs0 = null;
737 JDBCStatement s1 = new JDBCStatement(conn);
738 JDBCResultSet rs1 = null;
739 try {
740 try {
741 conn.db.exec("SELECT 1 FROM sqlite_master LIMIT 1", null);
742 } catch (SQLite.Exception se) {
743 throw new
744 SQLException("schema reload failed: " + se.toString());
745 }
746 rs0 = (JDBCResultSet)
747 (s0.executeQuery("PRAGMA index_list(" +
748 SQLite.Shell.sql_quote(table) + ")"));
749 rs1 = (JDBCResultSet)
750 (s1.executeQuery("PRAGMA table_info(" +
751 SQLite.Shell.sql_quote(table) + ")"));
752 } catch (SQLException e) {
753 throw e;
754 } finally {
755 s0.close();
756 s1.close();
757 }
758 String cols[] = {
759 "SCOPE", "COLUMN_NAME", "DATA_TYPE",
760 "TYPE_NAME", "COLUMN_SIZE", "BUFFER_LENGTH",
761 "DECIMAL_DIGITS", "PSEUDO_COLUMN"
762 };
763 int types[] = {
764 Types.SMALLINT, Types.VARCHAR, Types.SMALLINT,
765 Types.VARCHAR, Types.INTEGER, Types.INTEGER,
766 Types.SMALLINT, Types.SMALLINT
767 };
768 TableResultX tr = new TableResultX();
769 tr.columns(cols);
770 tr.sql_types(types);
771 JDBCResultSet rs = new JDBCResultSet(tr, null);
772 if (rs0 != null && rs0.tr != null && rs0.tr.nrows > 0 &&
773 rs1 != null && rs1.tr != null && rs1.tr.nrows > 0) {
774 Hashtable h0 = new Hashtable();
775 for (int i = 0; i < rs0.tr.ncolumns; i++) {
776 h0.put(rs0.tr.column[i], new Integer(i));
777 }
778 Hashtable h1 = new Hashtable();
779 for (int i = 0; i < rs1.tr.ncolumns; i++) {
780 h1.put(rs1.tr.column[i], new Integer(i));
781 }
782 for (int i = 0; i < rs0.tr.nrows; i++) {
783 String r0[] = (String [])(rs0.tr.rows.elementAt(i));
784 int col = ((Integer) h0.get("unique")).intValue();
785 String uniq = r0[col];
786 col = ((Integer) h0.get("name")).intValue();
787 String iname = r0[col];
788 if (uniq.charAt(0) == '0') {
789 continue;
790 }
791 JDBCStatement s2 = new JDBCStatement(conn);
792 JDBCResultSet rs2 = null;
793 try {
794 rs2 = (JDBCResultSet)
795 (s2.executeQuery("PRAGMA index_info(" +
796 SQLite.Shell.sql_quote(iname) + ")"));
797 } catch (SQLException e) {
798 } finally {
799 s2.close();
800 }
801 if (rs2 == null || rs2.tr == null || rs2.tr.nrows <= 0) {
802 continue;
803 }
804 Hashtable h2 = new Hashtable();
805 for (int k = 0; k < rs2.tr.ncolumns; k++) {
806 h2.put(rs2.tr.column[k], new Integer(k));
807 }
808 for (int k = 0; k < rs2.tr.nrows; k++) {
809 String r2[] = (String [])(rs2.tr.rows.elementAt(k));
810 col = ((Integer) h2.get("name")).intValue();
811 String cname = r2[col];
812 for (int m = 0; m < rs1.tr.nrows; m++) {
813 String r1[] = (String [])(rs1.tr.rows.elementAt(m));
814 col = ((Integer) h1.get("name")).intValue();
815 if (cname.compareTo(r1[col]) == 0) {
816 String row[] = new String[cols.length];
817 row[0] = "" + scope;
818 row[1] = cname;
819 row[2] = "" + Types.VARCHAR;
820 row[3] = "VARCHAR";
821 row[4] = "65536";
822 row[5] = "0";
823 row[6] = "0";
824 row[7] = "" + bestRowNotPseudo;
825 tr.newrow(row);
826 }
827 }
828 }
829 }
830 }
831 if (tr.nrows <= 0) {
832 String row[] = new String[cols.length];
833 row[0] = "" + scope;
834 row[1] = "_ROWID_";
835 row[2] = "" + Types.INTEGER;
836 row[3] = "INTEGER";
837 row[4] = "10";
838 row[5] = "0";
839 row[6] = "0";
840 row[7] = "" + bestRowPseudo;
841 tr.newrow(row);
842 }
843 return rs;
844 }
845
846 public ResultSet getVersionColumns(String catalog, String schema,
847 String table) throws SQLException {
848 String cols[] = {
849 "SCOPE", "COLUMN_NAME", "DATA_TYPE",
850 "TYPE_NAME", "COLUMN_SIZE", "BUFFER_LENGTH",
851 "DECIMAL_DIGITS", "PSEUDO_COLUMN"
852 };
853 int types[] = {
854 Types.SMALLINT, Types.VARCHAR, Types.SMALLINT,
855 Types.VARCHAR, Types.INTEGER, Types.INTEGER,
856 Types.SMALLINT, Types.SMALLINT
857 };
858 TableResultX tr = new TableResultX();
859 tr.columns(cols);
860 tr.sql_types(types);
861 JDBCResultSet rs = new JDBCResultSet(tr, null);
862 return rs;
863 }
864
865 public ResultSet getPrimaryKeys(String catalog, String schema,
866 String table) throws SQLException {
867 JDBCStatement s0 = new JDBCStatement(conn);
868 JDBCResultSet rs0 = null;
869 try {
870 try {
871 conn.db.exec("SELECT 1 FROM sqlite_master LIMIT 1", null);
872 } catch (SQLite.Exception se) {
873 throw new
874 SQLException("schema reload failed: " + se.toString());
875 }
876 rs0 = (JDBCResultSet)
877 (s0.executeQuery("PRAGMA index_list(" +
878 SQLite.Shell.sql_quote(table) + ")"));
879 } catch (SQLException e) {
880 throw e;
881 } finally {
882 s0.close();
883 }
884 String cols[] = {
885 "TABLE_CAT", "TABLE_SCHEM", "TABLE_NAME",
886 "COLUMN_NAME", "KEY_SEQ", "PK_NAME"
887 };
888 int types[] = {
889 Types.VARCHAR, Types.VARCHAR, Types.VARCHAR,
890 Types.VARCHAR, Types.SMALLINT, Types.VARCHAR
891 };
892 TableResultX tr = new TableResultX();
893 tr.columns(cols);
894 tr.sql_types(types);
895 JDBCResultSet rs = new JDBCResultSet(tr, null);
896 if (rs0 != null && rs0.tr != null && rs0.tr.nrows > 0) {
897 Hashtable h0 = new Hashtable();
898 for (int i = 0; i < rs0.tr.ncolumns; i++) {
899 h0.put(rs0.tr.column[i], new Integer(i));
900 }
901 for (int i = 0; i < rs0.tr.nrows; i++) {
902 String r0[] = (String [])(rs0.tr.rows.elementAt(i));
903 int col = ((Integer) h0.get("unique")).intValue();
904 String uniq = r0[col];
905 col = ((Integer) h0.get("name")).intValue();
906 String iname = r0[col];
907 if (uniq.charAt(0) == '0') {
908 continue;
909 }
910 JDBCStatement s1 = new JDBCStatement(conn);
911 JDBCResultSet rs1 = null;
912 try {
913 rs1 = (JDBCResultSet)
914 (s1.executeQuery("PRAGMA index_info(" +
915 SQLite.Shell.sql_quote(iname) + ")"));
916 } catch (SQLException e) {
917 } finally {
918 s1.close();
919 }
920 if (rs1 == null || rs1.tr == null || rs1.tr.nrows <= 0) {
921 continue;
922 }
923 Hashtable h1 = new Hashtable();
924 for (int k = 0; k < rs1.tr.ncolumns; k++) {
925 h1.put(rs1.tr.column[k], new Integer(k));
926 }
927 for (int k = 0; k < rs1.tr.nrows; k++) {
928 String r1[] = (String [])(rs1.tr.rows.elementAt(k));
929 String row[] = new String[cols.length];
930 row[0] = "";
931 row[1] = "";
932 row[2] = table;
933 col = ((Integer) h1.get("name")).intValue();
934 row[3] = r1[col];
935 col = ((Integer) h1.get("seqno")).intValue();
936 row[4] = Integer.toString(Integer.parseInt(r1[col]) + 1);
937 row[5] = iname;
938 tr.newrow(row);
939 }
940 }
941 }
942 if (tr.nrows > 0) {
943 return rs;
944 }
945 JDBCStatement s1 = new JDBCStatement(conn);
946 try {
947 rs0 = (JDBCResultSet)
948 (s1.executeQuery("PRAGMA table_info(" +
949 SQLite.Shell.sql_quote(table) + ")"));
950 } catch (SQLException e) {
951 throw e;
952 } finally {
953 s1.close();
954 }
955 if (rs0 != null && rs0.tr != null && rs0.tr.nrows > 0) {
956 Hashtable h0 = new Hashtable();
957 for (int i = 0; i < rs0.tr.ncolumns; i++) {
958 h0.put(rs0.tr.column[i], new Integer(i));
959 }
960 for (int i = 0; i < rs0.tr.nrows; i++) {
961 String r0[] = (String [])(rs0.tr.rows.elementAt(i));
962 int col = ((Integer) h0.get("type")).intValue();
963 String type = r0[col];
964 if (!type.equalsIgnoreCase("integer")) {
965 continue;
966 }
967 col = ((Integer) h0.get("pk")).intValue();
968 String pk = r0[col];
969 if (pk.charAt(0) == '0') {
970 continue;
971 }
972 String row[] = new String[cols.length];
973 row[0] = "";
974 row[1] = "";
975 row[2] = table;
976 col = ((Integer) h0.get("name")).intValue();
977 row[3] = r0[col];
978 col = ((Integer) h0.get("cid")).intValue();
979 row[4] = Integer.toString(Integer.parseInt(r0[col]) + 1);
980 row[5] = "";
981 tr.newrow(row);
982 }
983 }
984 return rs;
985 }
986
987 private void internalImportedKeys(String table, String pktable,
988 JDBCResultSet in, TableResultX out) {
989 Hashtable h0 = new Hashtable();
990 for (int i = 0; i < in.tr.ncolumns; i++) {
991 h0.put(in.tr.column[i], new Integer(i));
992 }
993 for (int i = 0; i < in.tr.nrows; i++) {
994 String r0[] = (String [])(in.tr.rows.elementAt(i));
995 int col = ((Integer) h0.get("table")).intValue();
996 String pktab = r0[col];
997 if (pktable != null && !pktable.equalsIgnoreCase(pktab)) {
998 continue;
999 }
1000 col = ((Integer) h0.get("from")).intValue();
1001 String fkcol = r0[col];
1002 col = ((Integer) h0.get("to")).intValue();
1003 String pkcol = r0[col];
1004 col = ((Integer) h0.get("seq")).intValue();
1005 String seq = r0[col];
1006 String row[] = new String[out.ncolumns];
1007 row[0] = "";
1008 row[1] = "";
1009 row[2] = pktab;
1010 row[3] = pkcol;
1011 row[4] = "";
1012 row[5] = "";
1013 row[6] = table;
1014 row[7] = fkcol == null ? pkcol : fkcol;
1015 row[8] = Integer.toString(Integer.parseInt(seq) + 1);
1016 row[9] =
1017 "" + java.sql.DatabaseMetaData.importedKeyNoAction;
1018 row[10] =
1019 "" + java.sql.DatabaseMetaData.importedKeyNoAction;
1020 row[11] = null;
1021 row[12] = null;
1022 row[13] =
1023 "" + java.sql.DatabaseMetaData.importedKeyNotDeferrable;
1024 out.newrow(row);
1025 }
1026 }
1027
1028 public ResultSet getImportedKeys(String catalog, String schema,
1029 String table) throws SQLException {
1030 JDBCStatement s0 = new JDBCStatement(conn);
1031 JDBCResultSet rs0 = null;
1032 try {
1033 try {
1034 conn.db.exec("SELECT 1 FROM sqlite_master LIMIT 1", null);
1035 } catch (SQLite.Exception se) {
1036 throw new
1037 SQLException("schema reload failed: " + se.toString());
1038 }
1039 rs0 = (JDBCResultSet)
1040 (s0.executeQuery("PRAGMA foreign_key_list(" +
1041 SQLite.Shell.sql_quote(table) + ")"));
1042 } catch (SQLException e) {
1043 throw e;
1044 } finally {
1045 s0.close();
1046 }
1047 String cols[] = {
1048 "PKTABLE_CAT", "PKTABLE_SCHEM", "PKTABLE_NAME",
1049 "PKCOLUMN_NAME", "FKTABLE_CAT", "FKTABLE_SCHEM",
1050 "FKTABLE_NAME", "FKCOLUMN_NAME", "KEY_SEQ",
1051 "UPDATE_RULE", "DELETE_RULE", "FK_NAME",
1052 "PK_NAME", "DEFERRABILITY"
1053 };
1054 int types[] = {
1055 Types.VARCHAR, Types.VARCHAR, Types.VARCHAR,
1056 Types.VARCHAR, Types.VARCHAR, Types.VARCHAR,
1057 Types.VARCHAR, Types.VARCHAR, Types.SMALLINT,
1058 Types.SMALLINT, Types.SMALLINT, Types.VARCHAR,
1059 Types.VARCHAR, Types.SMALLINT
1060 };
1061 TableResultX tr = new TableResultX();
1062 tr.columns(cols);
1063 tr.sql_types(types);
1064 JDBCResultSet rs = new JDBCResultSet(tr, null);
1065 if (rs0 != null && rs0.tr != null && rs0.tr.nrows > 0) {
1066 internalImportedKeys(table, null, rs0, tr);
1067 }
1068 return rs;
1069 }
1070
1071 public ResultSet getExportedKeys(String catalog, String schema,
1072 String table) throws SQLException {
1073 String cols[] = {
1074 "PKTABLE_CAT", "PKTABLE_SCHEM", "PKTABLE_NAME",
1075 "PKCOLUMN_NAME", "FKTABLE_CAT", "FKTABLE_SCHEM",
1076 "FKTABLE_NAME", "FKCOLUMN_NAME", "KEY_SEQ",
1077 "UPDATE_RULE", "DELETE_RULE", "FK_NAME",
1078 "PK_NAME", "DEFERRABILITY"
1079 };
1080 int types[] = {
1081 Types.VARCHAR, Types.VARCHAR, Types.VARCHAR,
1082 Types.VARCHAR, Types.VARCHAR, Types.VARCHAR,
1083 Types.VARCHAR, Types.VARCHAR, Types.SMALLINT,
1084 Types.SMALLINT, Types.SMALLINT, Types.VARCHAR,
1085 Types.VARCHAR, Types.SMALLINT
1086 };
1087 TableResultX tr = new TableResultX();
1088 tr.columns(cols);
1089 tr.sql_types(types);
1090 JDBCResultSet rs = new JDBCResultSet(tr, null);
1091 return rs;
1092 }
1093
1094 public ResultSet getCrossReference(String primaryCatalog,
1095 String primarySchema,
1096 String primaryTable,
1097 String foreignCatalog,
1098 String foreignSchema,
1099 String foreignTable)
1100 throws SQLException {
1101 JDBCResultSet rs0 = null;
1102 if (foreignTable != null && foreignTable.charAt(0) != '%') {
1103 JDBCStatement s0 = new JDBCStatement(conn);
1104 try {
1105 try {
1106 conn.db.exec("SELECT 1 FROM sqlite_master LIMIT 1", null);
1107 } catch (SQLite.Exception se) {
1108 throw new
1109 SQLException("schema reload failed: " + se.toString());
1110 }
1111 rs0 = (JDBCResultSet)
1112 (s0.executeQuery("PRAGMA foreign_key_list(" +
1113 SQLite.Shell.sql_quote(foreignTable) + ")"));
1114 } catch (SQLException e) {
1115 throw e;
1116 } finally {
1117 s0.close();
1118 }
1119 }
1120 String cols[] = {
1121 "PKTABLE_CAT", "PKTABLE_SCHEM", "PKTABLE_NAME",
1122 "PKCOLUMN_NAME", "FKTABLE_CAT", "FKTABLE_SCHEM",
1123 "FKTABLE_NAME", "FKCOLUMN_NAME", "KEY_SEQ",
1124 "UPDATE_RULE", "DELETE_RULE", "FK_NAME",
1125 "PK_NAME", "DEFERRABILITY"
1126 };
1127 int types[] = {
1128 Types.VARCHAR, Types.VARCHAR, Types.VARCHAR,
1129 Types.VARCHAR, Types.VARCHAR, Types.VARCHAR,
1130 Types.VARCHAR, Types.VARCHAR, Types.SMALLINT,
1131 Types.SMALLINT, Types.SMALLINT, Types.VARCHAR,
1132 Types.VARCHAR, Types.SMALLINT
1133 };
1134 TableResultX tr = new TableResultX();
1135 tr.columns(cols);
1136 tr.sql_types(types);
1137 JDBCResultSet rs = new JDBCResultSet(tr, null);
1138 if (rs0 != null && rs0.tr != null && rs0.tr.nrows > 0) {
1139 String pktable = null;
1140 if (primaryTable != null && primaryTable.charAt(0) != '%') {
1141 pktable = primaryTable;
1142 }
1143 internalImportedKeys(foreignTable, pktable, rs0, tr);
1144 }
1145 return rs;
1146 }
1147
1148 public ResultSet getTypeInfo() throws SQLException {
1149 String cols[] = {
1150 "TYPE_NAME", "DATA_TYPE", "PRECISION",
1151 "LITERAL_PREFIX", "LITERAL_SUFFIX", "CREATE_PARAMS",
1152 "NULLABLE", "CASE_SENSITIVE", "SEARCHABLE",
1153 "UNSIGNED_ATTRIBUTE", "FIXED_PREC_SCALE", "AUTO_INCREMENT",
1154 "LOCAL_TYPE_NAME", "MINIMUM_SCALE", "MAXIMUM_SCALE",
1155 "SQL_DATA_TYPE", "SQL_DATETIME_SUB", "NUM_PREC_RADIX"
1156 };
1157 int types[] = {
1158 Types.VARCHAR, Types.SMALLINT, Types.INTEGER,
1159 Types.VARCHAR, Types.VARCHAR, Types.VARCHAR,
1160 Types.SMALLINT, Types.BIT, Types.SMALLINT,
1161 Types.BIT, Types.BIT, Types.BIT,
1162 Types.VARCHAR, Types.SMALLINT, Types.SMALLINT,
1163 Types.INTEGER, Types.INTEGER, Types.INTEGER
1164 };
1165 TableResultX tr = new TableResultX();
1166 tr.columns(cols);
1167 tr.sql_types(types);
1168 JDBCResultSet rs = new JDBCResultSet(tr, null);
1169 String row1[] = {
1170 "VARCHAR", "" + Types.VARCHAR, "65536",
1171 "'", "'", null,
1172 "" + typeNullable, "1", "" + typeSearchable,
1173 "0", "0", "0",
1174 null, "0", "0",
1175 "0", "0", "0"
1176 };
1177 tr.newrow(row1);
1178 String row2[] = {
1179 "INTEGER", "" + Types.INTEGER, "32",
1180 null, null, null,
1181 "" + typeNullable, "0", "" + typeSearchable,
1182 "0", "0", "1",
1183 null, "0", "0",
1184 "0", "0", "2"
1185 };
1186 tr.newrow(row2);
1187 String row3[] = {
1188 "DOUBLE", "" + Types.DOUBLE, "16",
1189 null, null, null,
1190 "" + typeNullable, "0", "" + typeSearchable,
1191 "0", "0", "1",
1192 null, "0", "0",
1193 "0", "0", "10"
1194 };
1195 tr.newrow(row3);
1196 String row4[] = {
1197 "FLOAT", "" + Types.FLOAT, "7",
1198 null, null, null,
1199 "" + typeNullable, "0", "" + typeSearchable,
1200 "0", "0", "1",
1201 null, "0", "0",
1202 "0", "0", "10"
1203 };
1204 tr.newrow(row4);
1205 String row5[] = {
1206 "SMALLINT", "" + Types.SMALLINT, "16",
1207 null, null, null,
1208 "" + typeNullable, "0", "" + typeSearchable,
1209 "0", "0", "1",
1210 null, "0", "0",
1211 "0", "0", "2"
1212 };
1213 tr.newrow(row5);
1214 String row6[] = {
1215 "BIT", "" + Types.BIT, "1",
1216 null, null, null,
1217 "" + typeNullable, "0", "" + typeSearchable,
1218 "0", "0", "1",
1219 null, "0", "0",
1220 "0", "0", "2"
1221 };
1222 tr.newrow(row6);
1223 String row7[] = {
1224 "TIMESTAMP", "" + Types.TIMESTAMP, "30",
1225 null, null, null,
1226 "" + typeNullable, "0", "" + typeSearchable,
1227 "0", "0", "1",
1228 null, "0", "0",
1229 "0", "0", "0"
1230 };
1231 tr.newrow(row7);
1232 String row8[] = {
1233 "DATE", "" + Types.DATE, "10",
1234 null, null, null,
1235 "" + typeNullable, "0", "" + typeSearchable,
1236 "0", "0", "1",
1237 null, "0", "0",
1238 "0", "0", "0"
1239 };
1240 tr.newrow(row8);
1241 String row9[] = {
1242 "TIME", "" + Types.TIME, "8",
1243 null, null, null,
1244 "" + typeNullable, "0", "" + typeSearchable,
1245 "0", "0", "1",
1246 null, "0", "0",
1247 "0", "0", "0"
1248 };
1249 tr.newrow(row9);
1250 String row10[] = {
1251 "BINARY", "" + Types.BINARY, "65536",
1252 null, null, null,
1253 "" + typeNullable, "0", "" + typeSearchable,
1254 "0", "0", "1",
1255 null, "0", "0",
1256 "0", "0", "0"
1257 };
1258 tr.newrow(row10);
1259 String row11[] = {
1260 "VARBINARY", "" + Types.VARBINARY, "65536",
1261 null, null, null,
1262 "" + typeNullable, "0", "" + typeSearchable,
1263 "0", "0", "1",
1264 null, "0", "0",
1265 "0", "0", "0"
1266 };
1267 tr.newrow(row11);
1268 String row12[] = {
1269 "REAL", "" + Types.REAL, "16",
1270 null, null, null,
1271 "" + typeNullable, "0", "" + typeSearchable,
1272 "0", "0", "1",
1273 null, "0", "0",
1274 "0", "0", "10"
1275 };
1276 tr.newrow(row12);
1277 return rs;
1278 }
1279
1280 public ResultSet getIndexInfo(String catalog, String schema, String table,
1281 boolean unique, boolean approximate)
1282 throws SQLException {
1283 JDBCStatement s0 = new JDBCStatement(conn);
1284 JDBCResultSet rs0 = null;
1285 try {
1286 try {
1287 conn.db.exec("SELECT 1 FROM sqlite_master LIMIT 1", null);
1288 } catch (SQLite.Exception se) {
1289 throw new
1290 SQLException("schema reload failed: " + se.toString());
1291 }
1292 rs0 = (JDBCResultSet)
1293 (s0.executeQuery("PRAGMA index_list(" +
1294 SQLite.Shell.sql_quote(table) + ")"));
1295 } catch (SQLException e) {
1296 throw e;
1297 } finally {
1298 s0.close();
1299 }
1300 String cols[] = {
1301 "TABLE_CAT", "TABLE_SCHEM", "TABLE_NAME",
1302 "NON_UNIQUE", "INDEX_QUALIFIER", "INDEX_NAME",
1303 "TYPE", "ORDINAL_POSITION", "COLUMN_NAME",
1304 "ASC_OR_DESC", "CARDINALITY", "PAGES",
1305 "FILTER_CONDITION"
1306 };
1307 int types[] = {
1308 Types.VARCHAR, Types.VARCHAR, Types.VARCHAR,
1309 Types.BIT, Types.VARCHAR, Types.VARCHAR,
1310 Types.SMALLINT, Types.SMALLINT, Types.VARCHAR,
1311 Types.VARCHAR, Types.INTEGER, Types.INTEGER,
1312 Types.VARCHAR
1313 };
1314 TableResultX tr = new TableResultX();
1315 tr.columns(cols);
1316 tr.sql_types(types);
1317 JDBCResultSet rs = new JDBCResultSet(tr, null);
1318 if (rs0 != null && rs0.tr != null && rs0.tr.nrows > 0) {
1319 Hashtable h0 = new Hashtable();
1320 for (int i = 0; i < rs0.tr.ncolumns; i++) {
1321 h0.put(rs0.tr.column[i], new Integer(i));
1322 }
1323 for (int i = 0; i < rs0.tr.nrows; i++) {
1324 String r0[] = (String [])(rs0.tr.rows.elementAt(i));
1325 int col = ((Integer) h0.get("unique")).intValue();
1326 String uniq = r0[col];
1327 col = ((Integer) h0.get("name")).intValue();
1328 String iname = r0[col];
1329 if (unique && uniq.charAt(0) == '0') {
1330 continue;
1331 }
1332 JDBCStatement s1 = new JDBCStatement(conn);
1333 JDBCResultSet rs1 = null;
1334 try {
1335 rs1 = (JDBCResultSet)
1336 (s1.executeQuery("PRAGMA index_info(" +
1337 SQLite.Shell.sql_quote(iname) + ")"));
1338 } catch (SQLException e) {
1339 } finally {
1340 s1.close();
1341 }
1342 if (rs1 == null || rs1.tr == null || rs1.tr.nrows <= 0) {
1343 continue;
1344 }
1345 Hashtable h1 = new Hashtable();
1346 for (int k = 0; k < rs1.tr.ncolumns; k++) {
1347 h1.put(rs1.tr.column[k], new Integer(k));
1348 }
1349 for (int k = 0; k < rs1.tr.nrows; k++) {
1350 String r1[] = (String [])(rs1.tr.rows.elementAt(k));
1351 String row[] = new String[cols.length];
1352 row[0] = "";
1353 row[1] = "";
1354 row[2] = table;
1355 row[3] = (uniq.charAt(0) != '0' ||
1356 (iname.charAt(0) == '(' &&
1357 iname.indexOf(" autoindex ") > 0)) ? "0" : "1";
1358 row[4] = "";
1359 row[5] = iname;
1360 row[6] = "" + tableIndexOther;
1361 col = ((Integer) h1.get("seqno")).intValue();
1362 row[7] = Integer.toString(Integer.parseInt(r1[col]) + 1);
1363 col = ((Integer) h1.get("name")).intValue();
1364 row[8] = r1[col];
1365 row[9] = "A";
1366 row[10] = "0";
1367 row[11] = "0";
1368 row[12] = null;
1369 tr.newrow(row);
1370 }
1371 }
1372 }
1373 return rs;
1374 }
1375
1376 public boolean supportsResultSetType(int type) throws SQLException {
1377 return type == ResultSet.TYPE_FORWARD_ONLY ||
1378 type == ResultSet.TYPE_SCROLL_INSENSITIVE ||
1379 type == ResultSet.TYPE_SCROLL_SENSITIVE;
1380 }
1381
1382 public boolean supportsResultSetConcurrency(int type, int concurrency)
1383 throws SQLException {
1384 if (type == ResultSet.TYPE_FORWARD_ONLY ||
1385 type == ResultSet.TYPE_SCROLL_INSENSITIVE ||
1386 type == ResultSet.TYPE_SCROLL_SENSITIVE) {
1387 return concurrency == ResultSet.CONCUR_READ_ONLY ||
1388 concurrency == ResultSet.CONCUR_UPDATABLE;
1389 }
1390 return false;
1391 }
1392
1393 public boolean ownUpdatesAreVisible(int type) throws SQLException {
1394 if (type == ResultSet.TYPE_FORWARD_ONLY ||
1395 type == ResultSet.TYPE_SCROLL_INSENSITIVE ||
1396 type == ResultSet.TYPE_SCROLL_SENSITIVE) {
1397 return true;
1398 }
1399 return false;
1400 }
1401
1402 public boolean ownDeletesAreVisible(int type) throws SQLException {
1403 if (type == ResultSet.TYPE_FORWARD_ONLY ||
1404 type == ResultSet.TYPE_SCROLL_INSENSITIVE ||
1405 type == ResultSet.TYPE_SCROLL_SENSITIVE) {
1406 return true;
1407 }
1408 return false;
1409 }
1410
1411 public boolean ownInsertsAreVisible(int type) throws SQLException {
1412 if (type == ResultSet.TYPE_FORWARD_ONLY ||
1413 type == ResultSet.TYPE_SCROLL_INSENSITIVE ||
1414 type == ResultSet.TYPE_SCROLL_SENSITIVE) {
1415 return true;
1416 }
1417 return false;
1418 }
1419
1420 public boolean othersUpdatesAreVisible(int type) throws SQLException {
1421 return false;
1422 }
1423
1424 public boolean othersDeletesAreVisible(int type) throws SQLException {
1425 return false;
1426 }
1427
1428 public boolean othersInsertsAreVisible(int type) throws SQLException {
1429 return false;
1430 }
1431
1432 public boolean updatesAreDetected(int type) throws SQLException {
1433 return false;
1434 }
1435
1436 public boolean deletesAreDetected(int type) throws SQLException {
1437 return false;
1438 }
1439
1440 public boolean insertsAreDetected(int type) throws SQLException {
1441 return false;
1442 }
1443
1444 public boolean supportsBatchUpdates() throws SQLException {
1445 return true;
1446 }
1447
1448 public ResultSet getUDTs(String catalog, String schemaPattern,
1449 String typeNamePattern, int[] types)
1450 throws SQLException {
1451 return null;
1452 }
1453
1454 public Connection getConnection() throws SQLException {
1455 return conn;
1456 }
1457
1458 static String mapTypeName(int type) {
1459 switch (type) {
1460 case Types.INTEGER: return "integer";
1461 case Types.SMALLINT: return "smallint";
1462 case Types.FLOAT: return "float";
1463 case Types.DOUBLE: return "double";
1464 case Types.TIMESTAMP: return "timestamp";
1465 case Types.DATE: return "date";
1466 case Types.TIME: return "time";
1467 case Types.BINARY: return "binary";
1468 case Types.VARBINARY: return "varbinary";
1469 case Types.REAL: return "real";
1470 }
1471 return "varchar";
1472 }
1473
1474 static int mapSqlType(String type) {
1475 if (type == null) {
1476 return Types.VARCHAR;
1477 }
1478 type = type.toLowerCase();
1479 if (type.startsWith("inter")) {
1480 return Types.VARCHAR;
1481 }
1482 if (type.startsWith("numeric") ||
1483 type.startsWith("int")) {
1484 return Types.INTEGER;
1485 }
1486 if (type.startsWith("tinyint") ||
1487 type.startsWith("smallint")) {
1488 return Types.SMALLINT;
1489 }
1490 if (type.startsWith("float")) {
1491 return Types.FLOAT;
1492 }
1493 if (type.startsWith("double")) {
1494 return Types.DOUBLE;
1495 }
1496 if (type.startsWith("datetime") ||
1497 type.startsWith("timestamp")) {
1498 return Types.TIMESTAMP;
1499 }
1500 if (type.startsWith("date")) {
1501 return Types.DATE;
1502 }
1503 if (type.startsWith("time")) {
1504 return Types.TIME;
1505 }
1506 if (type.startsWith("blob")) {
1507 return Types.BINARY;
1508 }
1509 if (type.startsWith("binary")) {
1510 return Types.BINARY;
1511 }
1512 if (type.startsWith("varbinary")) {
1513 return Types.VARBINARY;
1514 }
1515 if (type.startsWith("real")) {
1516 return Types.REAL;
1517 }
1518 return Types.VARCHAR;
1519 }
1520
1521 static int getM(String typeStr, int type) {
1522 int m = 65536;
1523 switch (type) {
1524 case Types.INTEGER: m = 11; break;
1525 case Types.SMALLINT: m = 6; break;
1526 case Types.FLOAT: m = 25; break;
1527 case Types.REAL:
1528 case Types.DOUBLE: m = 54; break;
1529 case Types.TIMESTAMP: return 30;
1530 case Types.DATE: return 10;
1531 case Types.TIME: return 8;
1532 }
1533 typeStr = typeStr.toLowerCase();
1534 int i1 = typeStr.indexOf('(');
1535 if (i1 > 0) {
1536 ++i1;
1537 int i2 = typeStr.indexOf(',', i1);
1538 if (i2 < 0) {
1539 i2 = typeStr.indexOf(')', i1);
1540 }
1541 if (i2 - i1 > 0) {
1542 String num = typeStr.substring(i1, i2);
1543 try {
1544 m = java.lang.Integer.parseInt(num, 10);
1545 } catch (NumberFormatException e) {
1546 }
1547 }
1548 }
1549 return m;
1550 }
1551
1552 static int getD(String typeStr, int type) {
1553 int d = 0;
1554 switch (type) {
1555 case Types.INTEGER: d = 10; break;
1556 case Types.SMALLINT: d = 5; break;
1557 case Types.FLOAT: d = 24; break;
1558 case Types.REAL:
1559 case Types.DOUBLE: d = 53; break;
1560 default: return getM(typeStr, type);
1561 }
1562 typeStr = typeStr.toLowerCase();
1563 int i1 = typeStr.indexOf('(');
1564 if (i1 > 0) {
1565 ++i1;
1566 int i2 = typeStr.indexOf(',', i1);
1567 if (i2 < 0) {
1568 return getM(typeStr, type);
1569 }
1570 i1 = i2;
1571 i2 = typeStr.indexOf(')', i1);
1572 if (i2 - i1 > 0) {
1573 String num = typeStr.substring(i1, i2);
1574 try {
1575 d = java.lang.Integer.parseInt(num, 10);
1576 } catch (NumberFormatException e) {
1577 }
1578 }
1579 }
1580 return d;
1581 }
1582
1583 public boolean supportsSavepoints() {
1584 return false;
1585 }
1586
1587 public boolean supportsNamedParameters() {
1588 return false;
1589 }
1590
1591 public boolean supportsMultipleOpenResults() {
1592 return false;
1593 }
1594
1595 public boolean supportsGetGeneratedKeys() {
1596 return false;
1597 }
1598
1599 public boolean supportsResultSetHoldability(int x) {
1600 return false;
1601 }
1602
1603 public boolean supportsStatementPooling() {
1604 return false;
1605 }
1606
1607 public boolean locatorsUpdateCopy() throws SQLException {
1608 throw new SQLException("not supported");
1609 }
1610
1611 public ResultSet getSuperTypes(String catalog, String schemaPattern,
1612 String typeNamePattern)
1613 throws SQLException {
1614 throw new SQLException("not supported");
1615 }
1616
1617 public ResultSet getSuperTables(String catalog, String schemaPattern,
1618 String tableNamePattern)
1619 throws SQLException {
1620 throw new SQLException("not supported");
1621 }
1622
1623 public ResultSet getAttributes(String catalog, String schemaPattern,
1624 String typeNamePattern,
1625 String attributeNamePattern)
1626 throws SQLException {
1627 throw new SQLException("not supported");
1628 }
1629
1630 public int getResultSetHoldability() throws SQLException {
1631 return ResultSet.HOLD_CURSORS_OVER_COMMIT;
1632 }
1633
1634 public int getDatabaseMajorVersion() {
1635 return SQLite.JDBC.MAJORVERSION;
1636 }
1637
1638 public int getDatabaseMinorVersion() {
1639 return SQLite.Constants.drv_minor;
1640 }
1641
1642 public int getJDBCMajorVersion() {
1643 return 1;
1644 }
1645
1646 public int getJDBCMinorVersion() {
1647 return 0;
1648 }
1649
1650 public int getSQLStateType() throws SQLException {
1651 return sqlStateXOpen;
1652 }
1653
1654 }