Debian Codegraph @

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

raw
1 package SQLite.JDBC2;
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
619 SQLException("schema reload failed: " + se.toString());
620 }
621 String cols[] = {
622 "TABLE_CAT", "TABLE_SCHEM", "TABLE_NAME",
623 "COLUMN_NAME", "DATA_TYPE", "TYPE_NAME",
624 "COLUMN_SIZE", "BUFFER_LENGTH", "DECIMAL_DIGITS",
625 "NUM_PREC_RADIX", "NULLABLE", "REMARKS",
626 "COLUMN_DEF", "SQL_DATA_TYPE", "SQL_DATETIME_SUB",
627 "CHAR_OCTET_LENGTH", "ORDINAL_POSITION", "IS_NULLABLE"
628 };
629 int types[] = {
630 Types.VARCHAR, Types.VARCHAR, Types.VARCHAR,
631 Types.VARCHAR, Types.SMALLINT, Types.VARCHAR,
632 Types.INTEGER, Types.INTEGER, Types.INTEGER,
633 Types.INTEGER, Types.INTEGER, Types.VARCHAR,
634 Types.VARCHAR, Types.INTEGER, Types.INTEGER,
635 Types.INTEGER, Types.INTEGER, Types.VARCHAR
636 };
637 TableResultX tr = new TableResultX();
638 tr.columns(cols);
639 tr.sql_types(types);
640 JDBCResultSet rs = new JDBCResultSet(tr, null);
641 if (rs0.tr != null && rs0.tr.nrows > 0) {
642 Hashtable h = new Hashtable();
643 for (int i = 0; i < rs0.tr.ncolumns; i++) {
644 h.put(rs0.tr.column[i], new Integer(i));
645 }
646 if (columnNamePattern != null &&
647 columnNamePattern.charAt(0) == '%') {
648 columnNamePattern = null;
649 }
650 for (int i = 0; i < rs0.tr.nrows; i++) {
651 String r0[] = (String [])(rs0.tr.rows.elementAt(i));
652 int col = ((Integer) h.get("name")).intValue();
653 if (columnNamePattern != null) {
654 if (r0[col].compareTo(columnNamePattern) != 0) {
655 continue;
656 }
657 }
658 String row[] = new String[cols.length];
659 row[0] = "";
660 row[1] = "";
661 row[2] = tableNamePattern;
662 row[3] = r0[col];
663 col = ((Integer) h.get("type")).intValue();
664 String typeStr = r0[col];
665 int type = mapSqlType(typeStr);
666 row[4] = "" + type;
667 row[5] = mapTypeName(type);
668 row[6] = "" + getD(typeStr, type);
669 row[7] = "" + getM(typeStr, type);
670 row[8] = "10";
671 row[9] = "0";
672 row[11] = null;
673 col = ((Integer) h.get("dflt_value")).intValue();
674 row[12] = r0[col];
675 row[13] = "0";
676 row[14] = "0";
677 row[15] = "65536";
678 col = ((Integer) h.get("cid")).intValue();
679 Integer cid = new Integer(r0[col]);
680 row[16] = "" + (cid.intValue() + 1);
681 col = ((Integer) h.get("notnull")).intValue();
682 row[17] = (r0[col].charAt(0) == '0') ? "YES" : "NO";
683 row[10] = (r0[col].charAt(0) == '0') ? "" + columnNullable :
684 "" + columnNoNulls;
685 tr.newrow(row);
686 }
687 }
688 return rs;
689 }
690
691 public ResultSet getColumnPrivileges(String catalog, String schema,
692 String table,
693 String columnNamePattern)
694 throws SQLException {
695 String cols[] = {
696 "TABLE_CAT", "TABLE_SCHEM", "TABLE_NAME",
697 "COLUMN_NAME", "GRANTOR", "GRANTEE",
698 "PRIVILEGE", "IS_GRANTABLE"
699 };
700 int types[] = {
701 Types.VARCHAR, Types.VARCHAR, Types.VARCHAR,
702 Types.VARCHAR, Types.VARCHAR, Types.VARCHAR,
703 Types.VARCHAR, Types.VARCHAR
704 };
705 TableResultX tr = new TableResultX();
706 tr.columns(cols);
707 tr.sql_types(types);
708 JDBCResultSet rs = new JDBCResultSet(tr, null);
709 return rs;
710 }
711
712 public ResultSet getTablePrivileges(String catalog, String schemaPattern,
713 String tableNamePattern)
714 throws SQLException {
715 String cols[] = {
716 "TABLE_CAT", "TABLE_SCHEM", "TABLE_NAME",
717 "COLUMN_NAME", "GRANTOR", "GRANTEE",
718 "PRIVILEGE", "IS_GRANTABLE"
719 };
720 int types[] = {
721 Types.VARCHAR, Types.VARCHAR, Types.VARCHAR,
722 Types.VARCHAR, Types.VARCHAR, Types.VARCHAR,
723 Types.VARCHAR, Types.VARCHAR
724 };
725 TableResultX tr = new TableResultX();
726 tr.columns(cols);
727 tr.sql_types(types);
728 JDBCResultSet rs = new JDBCResultSet(tr, null);
729 return rs;
730 }
731
732 public ResultSet getBestRowIdentifier(String catalog, String schema,
733 String table, int scope,
734 boolean nullable)
735 throws SQLException {
736 JDBCStatement s0 = new JDBCStatement(conn);
737 JDBCResultSet rs0 = null;
738 JDBCStatement s1 = new JDBCStatement(conn);
739 JDBCResultSet rs1 = null;
740 try {
741 try {
742 conn.db.exec("SELECT 1 FROM sqlite_master LIMIT 1", null);
743 } catch (SQLite.Exception se) {
744 throw new
745 SQLException("schema reload failed: " + se.toString());
746 }
747 rs0 = (JDBCResultSet)
748 (s0.executeQuery("PRAGMA index_list(" +
749 SQLite.Shell.sql_quote(table) + ")"));
750 rs1 = (JDBCResultSet)
751 (s1.executeQuery("PRAGMA table_info(" +
752 SQLite.Shell.sql_quote(table) + ")"));
753 } catch (SQLException e) {
754 throw e;
755 } finally {
756 s0.close();
757 s1.close();
758 }
759 String cols[] = {
760 "SCOPE", "COLUMN_NAME", "DATA_TYPE",
761 "TYPE_NAME", "COLUMN_SIZE", "BUFFER_LENGTH",
762 "DECIMAL_DIGITS", "PSEUDO_COLUMN"
763 };
764 int types[] = {
765 Types.SMALLINT, Types.VARCHAR, Types.SMALLINT,
766 Types.VARCHAR, Types.INTEGER, Types.INTEGER,
767 Types.SMALLINT, Types.SMALLINT
768 };
769 TableResultX tr = new TableResultX();
770 tr.columns(cols);
771 tr.sql_types(types);
772 JDBCResultSet rs = new JDBCResultSet(tr, null);
773 if (rs0 != null && rs0.tr != null && rs0.tr.nrows > 0 &&
774 rs1 != null && rs1.tr != null && rs1.tr.nrows > 0) {
775 Hashtable h0 = new Hashtable();
776 for (int i = 0; i < rs0.tr.ncolumns; i++) {
777 h0.put(rs0.tr.column[i], new Integer(i));
778 }
779 Hashtable h1 = new Hashtable();
780 for (int i = 0; i < rs1.tr.ncolumns; i++) {
781 h1.put(rs1.tr.column[i], new Integer(i));
782 }
783 for (int i = 0; i < rs0.tr.nrows; i++) {
784 String r0[] = (String [])(rs0.tr.rows.elementAt(i));
785 int col = ((Integer) h0.get("unique")).intValue();
786 String uniq = r0[col];
787 col = ((Integer) h0.get("name")).intValue();
788 String iname = r0[col];
789 if (uniq.charAt(0) == '0') {
790 continue;
791 }
792 JDBCStatement s2 = new JDBCStatement(conn);
793 JDBCResultSet rs2 = null;
794 try {
795 rs2 = (JDBCResultSet)
796 (s2.executeQuery("PRAGMA index_info(" +
797 SQLite.Shell.sql_quote(iname) + ")"));
798 } catch (SQLException e) {
799 } finally {
800 s2.close();
801 }
802 if (rs2 == null || rs2.tr == null || rs2.tr.nrows <= 0) {
803 continue;
804 }
805 Hashtable h2 = new Hashtable();
806 for (int k = 0; k < rs2.tr.ncolumns; k++) {
807 h2.put(rs2.tr.column[k], new Integer(k));
808 }
809 for (int k = 0; k < rs2.tr.nrows; k++) {
810 String r2[] = (String [])(rs2.tr.rows.elementAt(k));
811 col = ((Integer) h2.get("name")).intValue();
812 String cname = r2[col];
813 for (int m = 0; m < rs1.tr.nrows; m++) {
814 String r1[] = (String [])(rs1.tr.rows.elementAt(m));
815 col = ((Integer) h1.get("name")).intValue();
816 if (cname.compareTo(r1[col]) == 0) {
817 String row[] = new String[cols.length];
818 row[0] = "" + scope;
819 row[1] = cname;
820 row[2] = "" + Types.VARCHAR;
821 row[3] = "VARCHAR";
822 row[4] = "65536";
823 row[5] = "0";
824 row[6] = "0";
825 row[7] = "" + bestRowNotPseudo;
826 tr.newrow(row);
827 }
828 }
829 }
830 }
831 }
832 if (tr.nrows <= 0) {
833 String row[] = new String[cols.length];
834 row[0] = "" + scope;
835 row[1] = "_ROWID_";
836 row[2] = "" + Types.INTEGER;
837 row[3] = "INTEGER";
838 row[4] = "10";
839 row[5] = "0";
840 row[6] = "0";
841 row[7] = "" + bestRowPseudo;
842 tr.newrow(row);
843 }
844 return rs;
845 }
846
847 public ResultSet getVersionColumns(String catalog, String schema,
848 String table) throws SQLException {
849 String cols[] = {
850 "SCOPE", "COLUMN_NAME", "DATA_TYPE",
851 "TYPE_NAME", "COLUMN_SIZE", "BUFFER_LENGTH",
852 "DECIMAL_DIGITS", "PSEUDO_COLUMN"
853 };
854 int types[] = {
855 Types.SMALLINT, Types.VARCHAR, Types.SMALLINT,
856 Types.VARCHAR, Types.INTEGER, Types.INTEGER,
857 Types.SMALLINT, Types.SMALLINT
858 };
859 TableResultX tr = new TableResultX();
860 tr.columns(cols);
861 tr.sql_types(types);
862 JDBCResultSet rs = new JDBCResultSet(tr, null);
863 return rs;
864 }
865
866 public ResultSet getPrimaryKeys(String catalog, String schema,
867 String table) throws SQLException {
868 JDBCStatement s0 = new JDBCStatement(conn);
869 JDBCResultSet rs0 = null;
870 try {
871 try {
872 conn.db.exec("SELECT 1 FROM sqlite_master LIMIT 1", null);
873 } catch (SQLite.Exception se) {
874 throw new
875 SQLException("schema reload failed: " + se.toString());
876 }
877 rs0 = (JDBCResultSet)
878 (s0.executeQuery("PRAGMA index_list(" +
879 SQLite.Shell.sql_quote(table) + ")"));
880 } catch (SQLException e) {
881 throw e;
882 } finally {
883 s0.close();
884 }
885 String cols[] = {
886 "TABLE_CAT", "TABLE_SCHEM", "TABLE_NAME",
887 "COLUMN_NAME", "KEY_SEQ", "PK_NAME"
888 };
889 int types[] = {
890 Types.VARCHAR, Types.VARCHAR, Types.VARCHAR,
891 Types.VARCHAR, Types.SMALLINT, Types.VARCHAR
892 };
893 TableResultX tr = new TableResultX();
894 tr.columns(cols);
895 tr.sql_types(types);
896 JDBCResultSet rs = new JDBCResultSet(tr, null);
897 if (rs0 != null && rs0.tr != null && rs0.tr.nrows > 0) {
898 Hashtable h0 = new Hashtable();
899 for (int i = 0; i < rs0.tr.ncolumns; i++) {
900 h0.put(rs0.tr.column[i], new Integer(i));
901 }
902 for (int i = 0; i < rs0.tr.nrows; i++) {
903 String r0[] = (String [])(rs0.tr.rows.elementAt(i));
904 int col = ((Integer) h0.get("unique")).intValue();
905 String uniq = r0[col];
906 col = ((Integer) h0.get("name")).intValue();
907 String iname = r0[col];
908 if (uniq.charAt(0) == '0') {
909 continue;
910 }
911 JDBCStatement s1 = new JDBCStatement(conn);
912 JDBCResultSet rs1 = null;
913 try {
914 rs1 = (JDBCResultSet)
915 (s1.executeQuery("PRAGMA index_info(" +
916 SQLite.Shell.sql_quote(iname) + ")"));
917 } catch (SQLException e) {
918 } finally {
919 s1.close();
920 }
921 if (rs1 == null || rs1.tr == null || rs1.tr.nrows <= 0) {
922 continue;
923 }
924 Hashtable h1 = new Hashtable();
925 for (int k = 0; k < rs1.tr.ncolumns; k++) {
926 h1.put(rs1.tr.column[k], new Integer(k));
927 }
928 for (int k = 0; k < rs1.tr.nrows; k++) {
929 String r1[] = (String [])(rs1.tr.rows.elementAt(k));
930 String row[] = new String[cols.length];
931 row[0] = "";
932 row[1] = "";
933 row[2] = table;
934 col = ((Integer) h1.get("name")).intValue();
935 row[3] = r1[col];
936 col = ((Integer) h1.get("seqno")).intValue();
937 row[4] = Integer.toString(Integer.parseInt(r1[col]) + 1);
938 row[5] = iname;
939 tr.newrow(row);
940 }
941 }
942 }
943 if (tr.nrows > 0) {
944 return rs;
945 }
946 JDBCStatement s1 = new JDBCStatement(conn);
947 try {
948 rs0 = (JDBCResultSet)
949 (s1.executeQuery("PRAGMA table_info(" +
950 SQLite.Shell.sql_quote(table) + ")"));
951 } catch (SQLException e) {
952 throw e;
953 } finally {
954 s1.close();
955 }
956 if (rs0 != null && rs0.tr != null && rs0.tr.nrows > 0) {
957 Hashtable h0 = new Hashtable();
958 for (int i = 0; i < rs0.tr.ncolumns; i++) {
959 h0.put(rs0.tr.column[i], new Integer(i));
960 }
961 for (int i = 0; i < rs0.tr.nrows; i++) {
962 String r0[] = (String [])(rs0.tr.rows.elementAt(i));
963 int col = ((Integer) h0.get("type")).intValue();
964 String type = r0[col];
965 if (!type.equalsIgnoreCase("integer")) {
966 continue;
967 }
968 col = ((Integer) h0.get("pk")).intValue();
969 String pk = r0[col];
970 if (pk.charAt(0) == '0') {
971 continue;
972 }
973 String row[] = new String[cols.length];
974 row[0] = "";
975 row[1] = "";
976 row[2] = table;
977 col = ((Integer) h0.get("name")).intValue();
978 row[3] = r0[col];
979 col = ((Integer) h0.get("cid")).intValue();
980 row[4] = Integer.toString(Integer.parseInt(r0[col]) + 1);
981 row[5] = "";
982 tr.newrow(row);
983 }
984 }
985 return rs;
986 }
987
988 private void internalImportedKeys(String table, String pktable,
989 JDBCResultSet in, TableResultX out) {
990 Hashtable h0 = new Hashtable();
991 for (int i = 0; i < in.tr.ncolumns; i++) {
992 h0.put(in.tr.column[i], new Integer(i));
993 }
994 for (int i = 0; i < in.tr.nrows; i++) {
995 String r0[] = (String [])(in.tr.rows.elementAt(i));
996 int col = ((Integer) h0.get("table")).intValue();
997 String pktab = r0[col];
998 if (pktable != null && !pktable.equalsIgnoreCase(pktab)) {
999 continue;
1000 }
1001 col = ((Integer) h0.get("from")).intValue();
1002 String fkcol = r0[col];
1003 col = ((Integer) h0.get("to")).intValue();
1004 String pkcol = r0[col];
1005 col = ((Integer) h0.get("seq")).intValue();
1006 String seq = r0[col];
1007 String row[] = new String[out.ncolumns];
1008 row[0] = "";
1009 row[1] = "";
1010 row[2] = pktab;
1011 row[3] = pkcol;
1012 row[4] = "";
1013 row[5] = "";
1014 row[6] = table;
1015 row[7] = fkcol == null ? pkcol : fkcol;
1016 row[8] = Integer.toString(Integer.parseInt(seq) + 1);
1017 row[9] =
1018 "" + java.sql.DatabaseMetaData.importedKeyNoAction;
1019 row[10] =
1020 "" + java.sql.DatabaseMetaData.importedKeyNoAction;
1021 row[11] = null;
1022 row[12] = null;
1023 row[13] =
1024 "" + java.sql.DatabaseMetaData.importedKeyNotDeferrable;
1025 out.newrow(row);
1026 }
1027 }
1028
1029 public ResultSet getImportedKeys(String catalog, String schema,
1030 String table) throws SQLException {
1031 JDBCStatement s0 = new JDBCStatement(conn);
1032 JDBCResultSet rs0 = null;
1033 try {
1034 try {
1035 conn.db.exec("SELECT 1 FROM sqlite_master LIMIT 1", null);
1036 } catch (SQLite.Exception se) {
1037 throw new
1038 SQLException("schema reload failed: " + se.toString());
1039 }
1040 rs0 = (JDBCResultSet)
1041 (s0.executeQuery("PRAGMA foreign_key_list(" +
1042 SQLite.Shell.sql_quote(table) + ")"));
1043 } catch (SQLException e) {
1044 throw e;
1045 } finally {
1046 s0.close();
1047 }
1048 String cols[] = {
1049 "PKTABLE_CAT", "PKTABLE_SCHEM", "PKTABLE_NAME",
1050 "PKCOLUMN_NAME", "FKTABLE_CAT", "FKTABLE_SCHEM",
1051 "FKTABLE_NAME", "FKCOLUMN_NAME", "KEY_SEQ",
1052 "UPDATE_RULE", "DELETE_RULE", "FK_NAME",
1053 "PK_NAME", "DEFERRABILITY"
1054 };
1055 int types[] = {
1056 Types.VARCHAR, Types.VARCHAR, Types.VARCHAR,
1057 Types.VARCHAR, Types.VARCHAR, Types.VARCHAR,
1058 Types.VARCHAR, Types.VARCHAR, Types.SMALLINT,
1059 Types.SMALLINT, Types.SMALLINT, Types.VARCHAR,
1060 Types.VARCHAR, Types.SMALLINT
1061 };
1062 TableResultX tr = new TableResultX();
1063 tr.columns(cols);
1064 tr.sql_types(types);
1065 JDBCResultSet rs = new JDBCResultSet(tr, null);
1066 if (rs0 != null && rs0.tr != null && rs0.tr.nrows > 0) {
1067 internalImportedKeys(table, null, rs0, tr);
1068 }
1069 return rs;
1070 }
1071
1072 public ResultSet getExportedKeys(String catalog, String schema,
1073 String table) throws SQLException {
1074 String cols[] = {
1075 "PKTABLE_CAT", "PKTABLE_SCHEM", "PKTABLE_NAME",
1076 "PKCOLUMN_NAME", "FKTABLE_CAT", "FKTABLE_SCHEM",
1077 "FKTABLE_NAME", "FKCOLUMN_NAME", "KEY_SEQ",
1078 "UPDATE_RULE", "DELETE_RULE", "FK_NAME",
1079 "PK_NAME", "DEFERRABILITY"
1080 };
1081 int types[] = {
1082 Types.VARCHAR, Types.VARCHAR, Types.VARCHAR,
1083 Types.VARCHAR, Types.VARCHAR, Types.VARCHAR,
1084 Types.VARCHAR, Types.VARCHAR, Types.SMALLINT,
1085 Types.SMALLINT, Types.SMALLINT, Types.VARCHAR,
1086 Types.VARCHAR, Types.SMALLINT
1087 };
1088 TableResultX tr = new TableResultX();
1089 tr.columns(cols);
1090 tr.sql_types(types);
1091 JDBCResultSet rs = new JDBCResultSet(tr, null);
1092 return rs;
1093 }
1094
1095 public ResultSet getCrossReference(String primaryCatalog,
1096 String primarySchema,
1097 String primaryTable,
1098 String foreignCatalog,
1099 String foreignSchema,
1100 String foreignTable)
1101 throws SQLException {
1102 JDBCResultSet rs0 = null;
1103 if (foreignTable != null && foreignTable.charAt(0) != '%') {
1104 JDBCStatement s0 = new JDBCStatement(conn);
1105 try {
1106 try {
1107 conn.db.exec("SELECT 1 FROM sqlite_master LIMIT 1", null);
1108 } catch (SQLite.Exception se) {
1109 throw new
1110 SQLException("schema reload failed: " + se.toString());
1111 }
1112 rs0 = (JDBCResultSet)
1113 (s0.executeQuery("PRAGMA foreign_key_list(" +
1114 SQLite.Shell.sql_quote(foreignTable) + ")"));
1115 } catch (SQLException e) {
1116 throw e;
1117 } finally {
1118 s0.close();
1119 }
1120 }
1121 String cols[] = {
1122 "PKTABLE_CAT", "PKTABLE_SCHEM", "PKTABLE_NAME",
1123 "PKCOLUMN_NAME", "FKTABLE_CAT", "FKTABLE_SCHEM",
1124 "FKTABLE_NAME", "FKCOLUMN_NAME", "KEY_SEQ",
1125 "UPDATE_RULE", "DELETE_RULE", "FK_NAME",
1126 "PK_NAME", "DEFERRABILITY"
1127 };
1128 int types[] = {
1129 Types.VARCHAR, Types.VARCHAR, Types.VARCHAR,
1130 Types.VARCHAR, Types.VARCHAR, Types.VARCHAR,
1131 Types.VARCHAR, Types.VARCHAR, Types.SMALLINT,
1132 Types.SMALLINT, Types.SMALLINT, Types.VARCHAR,
1133 Types.VARCHAR, Types.SMALLINT
1134 };
1135 TableResultX tr = new TableResultX();
1136 tr.columns(cols);
1137 tr.sql_types(types);
1138 JDBCResultSet rs = new JDBCResultSet(tr, null);
1139 if (rs0 != null && rs0.tr != null && rs0.tr.nrows > 0) {
1140 String pktable = null;
1141 if (primaryTable != null && primaryTable.charAt(0) != '%') {
1142 pktable = primaryTable;
1143 }
1144 internalImportedKeys(foreignTable, pktable, rs0, tr);
1145 }
1146 return rs;
1147 }
1148
1149 public ResultSet getTypeInfo() throws SQLException {
1150 String cols[] = {
1151 "TYPE_NAME", "DATA_TYPE", "PRECISION",
1152 "LITERAL_PREFIX", "LITERAL_SUFFIX", "CREATE_PARAMS",
1153 "NULLABLE", "CASE_SENSITIVE", "SEARCHABLE",
1154 "UNSIGNED_ATTRIBUTE", "FIXED_PREC_SCALE", "AUTO_INCREMENT",
1155 "LOCAL_TYPE_NAME", "MINIMUM_SCALE", "MAXIMUM_SCALE",
1156 "SQL_DATA_TYPE", "SQL_DATETIME_SUB", "NUM_PREC_RADIX"
1157 };
1158 int types[] = {
1159 Types.VARCHAR, Types.SMALLINT, Types.INTEGER,
1160 Types.VARCHAR, Types.VARCHAR, Types.VARCHAR,
1161 Types.SMALLINT, Types.BIT, Types.SMALLINT,
1162 Types.BIT, Types.BIT, Types.BIT,
1163 Types.VARCHAR, Types.SMALLINT, Types.SMALLINT,
1164 Types.INTEGER, Types.INTEGER, Types.INTEGER
1165 };
1166 TableResultX tr = new TableResultX();
1167 tr.columns(cols);
1168 tr.sql_types(types);
1169 JDBCResultSet rs = new JDBCResultSet(tr, null);
1170 String row1[] = {
1171 "VARCHAR", "" + Types.VARCHAR, "65536",
1172 "'", "'", null,
1173 "" + typeNullable, "1", "" + typeSearchable,
1174 "0", "0", "0",
1175 null, "0", "0",
1176 "0", "0", "0"
1177 };
1178 tr.newrow(row1);
1179 String row2[] = {
1180 "INTEGER", "" + Types.INTEGER, "32",
1181 null, null, null,
1182 "" + typeNullable, "0", "" + typeSearchable,
1183 "0", "0", "1",
1184 null, "0", "0",
1185 "0", "0", "2"
1186 };
1187 tr.newrow(row2);
1188 String row3[] = {
1189 "DOUBLE", "" + Types.DOUBLE, "16",
1190 null, null, null,
1191 "" + typeNullable, "0", "" + typeSearchable,
1192 "0", "0", "1",
1193 null, "0", "0",
1194 "0", "0", "10"
1195 };
1196 tr.newrow(row3);
1197 String row4[] = {
1198 "FLOAT", "" + Types.FLOAT, "7",
1199 null, null, null,
1200 "" + typeNullable, "0", "" + typeSearchable,
1201 "0", "0", "1",
1202 null, "0", "0",
1203 "0", "0", "10"
1204 };
1205 tr.newrow(row4);
1206 String row5[] = {
1207 "SMALLINT", "" + Types.SMALLINT, "16",
1208 null, null, null,
1209 "" + typeNullable, "0", "" + typeSearchable,
1210 "0", "0", "1",
1211 null, "0", "0",
1212 "0", "0", "2"
1213 };
1214 tr.newrow(row5);
1215 String row6[] = {
1216 "BIT", "" + Types.BIT, "1",
1217 null, null, null,
1218 "" + typeNullable, "0", "" + typeSearchable,
1219 "0", "0", "1",
1220 null, "0", "0",
1221 "0", "0", "2"
1222 };
1223 tr.newrow(row6);
1224 String row7[] = {
1225 "TIMESTAMP", "" + Types.TIMESTAMP, "30",
1226 null, null, null,
1227 "" + typeNullable, "0", "" + typeSearchable,
1228 "0", "0", "1",
1229 null, "0", "0",
1230 "0", "0", "0"
1231 };
1232 tr.newrow(row7);
1233 String row8[] = {
1234 "DATE", "" + Types.DATE, "10",
1235 null, null, null,
1236 "" + typeNullable, "0", "" + typeSearchable,
1237 "0", "0", "1",
1238 null, "0", "0",
1239 "0", "0", "0"
1240 };
1241 tr.newrow(row8);
1242 String row9[] = {
1243 "TIME", "" + Types.TIME, "8",
1244 null, null, null,
1245 "" + typeNullable, "0", "" + typeSearchable,
1246 "0", "0", "1",
1247 null, "0", "0",
1248 "0", "0", "0"
1249 };
1250 tr.newrow(row9);
1251 String row10[] = {
1252 "BINARY", "" + Types.BINARY, "65536",
1253 null, null, null,
1254 "" + typeNullable, "0", "" + typeSearchable,
1255 "0", "0", "1",
1256 null, "0", "0",
1257 "0", "0", "0"
1258 };
1259 tr.newrow(row10);
1260 String row11[] = {
1261 "VARBINARY", "" + Types.VARBINARY, "65536",
1262 null, null, null,
1263 "" + typeNullable, "0", "" + typeSearchable,
1264 "0", "0", "1",
1265 null, "0", "0",
1266 "0", "0", "0"
1267 };
1268 tr.newrow(row11);
1269 String row12[] = {
1270 "REAL", "" + Types.REAL, "16",
1271 null, null, null,
1272 "" + typeNullable, "0", "" + typeSearchable,
1273 "0", "0", "1",
1274 null, "0", "0",
1275 "0", "0", "10"
1276 };
1277 tr.newrow(row12);
1278 return rs;
1279 }
1280
1281 public ResultSet getIndexInfo(String catalog, String schema, String table,
1282 boolean unique, boolean approximate)
1283 throws SQLException {
1284 JDBCStatement s0 = new JDBCStatement(conn);
1285 JDBCResultSet rs0 = null;
1286 try {
1287 try {
1288 conn.db.exec("SELECT 1 FROM sqlite_master LIMIT 1", null);
1289 } catch (SQLite.Exception se) {
1290 throw new
1291 SQLException("schema reload failed: " + se.toString());
1292 }
1293 rs0 = (JDBCResultSet)
1294 (s0.executeQuery("PRAGMA index_list(" +
1295 SQLite.Shell.sql_quote(table) + ")"));
1296 } catch (SQLException e) {
1297 throw e;
1298 } finally {
1299 s0.close();
1300 }
1301 String cols[] = {
1302 "TABLE_CAT", "TABLE_SCHEM", "TABLE_NAME",
1303 "NON_UNIQUE", "INDEX_QUALIFIER", "INDEX_NAME",
1304 "TYPE", "ORDINAL_POSITION", "COLUMN_NAME",
1305 "ASC_OR_DESC", "CARDINALITY", "PAGES",
1306 "FILTER_CONDITION"
1307 };
1308 int types[] = {
1309 Types.VARCHAR, Types.VARCHAR, Types.VARCHAR,
1310 Types.BIT, Types.VARCHAR, Types.VARCHAR,
1311 Types.SMALLINT, Types.SMALLINT, Types.VARCHAR,
1312 Types.VARCHAR, Types.INTEGER, Types.INTEGER,
1313 Types.VARCHAR
1314 };
1315 TableResultX tr = new TableResultX();
1316 tr.columns(cols);
1317 tr.sql_types(types);
1318 JDBCResultSet rs = new JDBCResultSet(tr, null);
1319 if (rs0 != null && rs0.tr != null && rs0.tr.nrows > 0) {
1320 Hashtable h0 = new Hashtable();
1321 for (int i = 0; i < rs0.tr.ncolumns; i++) {
1322 h0.put(rs0.tr.column[i], new Integer(i));
1323 }
1324 for (int i = 0; i < rs0.tr.nrows; i++) {
1325 String r0[] = (String [])(rs0.tr.rows.elementAt(i));
1326 int col = ((Integer) h0.get("unique")).intValue();
1327 String uniq = r0[col];
1328 col = ((Integer) h0.get("name")).intValue();
1329 String iname = r0[col];
1330 if (unique && uniq.charAt(0) == '0') {
1331 continue;
1332 }
1333 JDBCStatement s1 = new JDBCStatement(conn);
1334 JDBCResultSet rs1 = null;
1335 try {
1336 rs1 = (JDBCResultSet)
1337 (s1.executeQuery("PRAGMA index_info(" +
1338 SQLite.Shell.sql_quote(iname) + ")"));
1339 } catch (SQLException e) {
1340 } finally {
1341 s1.close();
1342 }
1343 if (rs1 == null || rs1.tr == null || rs1.tr.nrows <= 0) {
1344 continue;
1345 }
1346 Hashtable h1 = new Hashtable();
1347 for (int k = 0; k < rs1.tr.ncolumns; k++) {
1348 h1.put(rs1.tr.column[k], new Integer(k));
1349 }
1350 for (int k = 0; k < rs1.tr.nrows; k++) {
1351 String r1[] = (String [])(rs1.tr.rows.elementAt(k));
1352 String row[] = new String[cols.length];
1353 row[0] = "";
1354 row[1] = "";
1355 row[2] = table;
1356 row[3] = (uniq.charAt(0) != '0' ||
1357 (iname.charAt(0) == '(' &&
1358 iname.indexOf(" autoindex ") > 0)) ? "0" : "1";
1359 row[4] = "";
1360 row[5] = iname;
1361 row[6] = "" + tableIndexOther;
1362 col = ((Integer) h1.get("seqno")).intValue();
1363 row[7] = Integer.toString(Integer.parseInt(r1[col]) + 1);
1364 col = ((Integer) h1.get("name")).intValue();
1365 row[8] = r1[col];
1366 row[9] = "A";
1367 row[10] = "0";
1368 row[11] = "0";
1369 row[12] = null;
1370 tr.newrow(row);
1371 }
1372 }
1373 }
1374 return rs;
1375 }
1376
1377 public boolean supportsResultSetType(int type) throws SQLException {
1378 return type == ResultSet.TYPE_FORWARD_ONLY ||
1379 type == ResultSet.TYPE_SCROLL_INSENSITIVE ||
1380 type == ResultSet.TYPE_SCROLL_SENSITIVE;
1381 }
1382
1383 public boolean supportsResultSetConcurrency(int type, int concurrency)
1384 throws SQLException {
1385 if (type == ResultSet.TYPE_FORWARD_ONLY ||
1386 type == ResultSet.TYPE_SCROLL_INSENSITIVE ||
1387 type == ResultSet.TYPE_SCROLL_SENSITIVE) {
1388 return concurrency == ResultSet.CONCUR_READ_ONLY ||
1389 concurrency == ResultSet.CONCUR_UPDATABLE;
1390 }
1391 return false;
1392 }
1393
1394 public boolean ownUpdatesAreVisible(int type) throws SQLException {
1395 if (type == ResultSet.TYPE_FORWARD_ONLY ||
1396 type == ResultSet.TYPE_SCROLL_INSENSITIVE ||
1397 type == ResultSet.TYPE_SCROLL_SENSITIVE) {
1398 return true;
1399 }
1400 return false;
1401 }
1402
1403 public boolean ownDeletesAreVisible(int type) throws SQLException {
1404 if (type == ResultSet.TYPE_FORWARD_ONLY ||
1405 type == ResultSet.TYPE_SCROLL_INSENSITIVE ||
1406 type == ResultSet.TYPE_SCROLL_SENSITIVE) {
1407 return true;
1408 }
1409 return false;
1410 }
1411
1412 public boolean ownInsertsAreVisible(int type) throws SQLException {
1413 if (type == ResultSet.TYPE_FORWARD_ONLY ||
1414 type == ResultSet.TYPE_SCROLL_INSENSITIVE ||
1415 type == ResultSet.TYPE_SCROLL_SENSITIVE) {
1416 return true;
1417 }
1418 return false;
1419 }
1420
1421 public boolean othersUpdatesAreVisible(int type) throws SQLException {
1422 return false;
1423 }
1424
1425 public boolean othersDeletesAreVisible(int type) throws SQLException {
1426 return false;
1427 }
1428
1429 public boolean othersInsertsAreVisible(int type) throws SQLException {
1430 return false;
1431 }
1432
1433 public boolean updatesAreDetected(int type) throws SQLException {
1434 return false;
1435 }
1436
1437 public boolean deletesAreDetected(int type) throws SQLException {
1438 return false;
1439 }
1440
1441 public boolean insertsAreDetected(int type) throws SQLException {
1442 return false;
1443 }
1444
1445 public boolean supportsBatchUpdates() throws SQLException {
1446 return true;
1447 }
1448
1449 public ResultSet getUDTs(String catalog, String schemaPattern,
1450 String typeNamePattern, int[] types)
1451 throws SQLException {
1452 return null;
1453 }
1454
1455 public Connection getConnection() throws SQLException {
1456 return conn;
1457 }
1458
1459 static String mapTypeName(int type) {
1460 switch (type) {
1461 case Types.INTEGER: return "integer";
1462 case Types.SMALLINT: return "smallint";
1463 case Types.FLOAT: return "float";
1464 case Types.DOUBLE: return "double";
1465 case Types.TIMESTAMP: return "timestamp";
1466 case Types.DATE: return "date";
1467 case Types.TIME: return "time";
1468 case Types.BINARY: return "binary";
1469 case Types.VARBINARY: return "varbinary";
1470 case Types.REAL: return "real";
1471 }
1472 return "varchar";
1473 }
1474
1475 static int mapSqlType(String type) {
1476 if (type == null) {
1477 return Types.VARCHAR;
1478 }
1479 type = type.toLowerCase();
1480 if (type.startsWith("inter")) {
1481 return Types.VARCHAR;
1482 }
1483 if (type.startsWith("numeric") ||
1484 type.startsWith("int")) {
1485 return Types.INTEGER;
1486 }
1487 if (type.startsWith("tinyint") ||
1488 type.startsWith("smallint")) {
1489 return Types.SMALLINT;
1490 }
1491 if (type.startsWith("float")) {
1492 return Types.FLOAT;
1493 }
1494 if (type.startsWith("double")) {
1495 return Types.DOUBLE;
1496 }
1497 if (type.startsWith("datetime") ||
1498 type.startsWith("timestamp")) {
1499 return Types.TIMESTAMP;
1500 }
1501 if (type.startsWith("date")) {
1502 return Types.DATE;
1503 }
1504 if (type.startsWith("time")) {
1505 return Types.TIME;
1506 }
1507 if (type.startsWith("blob")) {
1508 return Types.BINARY;
1509 }
1510 if (type.startsWith("binary")) {
1511 return Types.BINARY;
1512 }
1513 if (type.startsWith("varbinary")) {
1514 return Types.VARBINARY;
1515 }
1516 if (type.startsWith("real")) {
1517 return Types.REAL;
1518 }
1519 return Types.VARCHAR;
1520 }
1521
1522 static int getM(String typeStr, int type) {
1523 int m = 65536;
1524 switch (type) {
1525 case Types.INTEGER: m = 11; break;
1526 case Types.SMALLINT: m = 6; break;
1527 case Types.FLOAT: m = 25; break;
1528 case Types.REAL:
1529 case Types.DOUBLE: m = 54; break;
1530 case Types.TIMESTAMP: return 30;
1531 case Types.DATE: return 10;
1532 case Types.TIME: return 8;
1533 }
1534 typeStr = typeStr.toLowerCase();
1535 int i1 = typeStr.indexOf('(');
1536 if (i1 > 0) {
1537 ++i1;
1538 int i2 = typeStr.indexOf(',', i1);
1539 if (i2 < 0) {
1540 i2 = typeStr.indexOf(')', i1);
1541 }
1542 if (i2 - i1 > 0) {
1543 String num = typeStr.substring(i1, i2);
1544 try {
1545 m = java.lang.Integer.parseInt(num, 10);
1546 } catch (NumberFormatException e) {
1547 }
1548 }
1549 }
1550 return m;
1551 }
1552
1553 static int getD(String typeStr, int type) {
1554 int d = 0;
1555 switch (type) {
1556 case Types.INTEGER: d = 10; break;
1557 case Types.SMALLINT: d = 5; break;
1558 case Types.FLOAT: d = 24; break;
1559 case Types.REAL:
1560 case Types.DOUBLE: d = 53; break;
1561 default: return getM(typeStr, type);
1562 }
1563 typeStr = typeStr.toLowerCase();
1564 int i1 = typeStr.indexOf('(');
1565 if (i1 > 0) {
1566 ++i1;
1567 int i2 = typeStr.indexOf(',', i1);
1568 if (i2 < 0) {
1569 return getM(typeStr, type);
1570 }
1571 i1 = i2;
1572 i2 = typeStr.indexOf(')', i1);
1573 if (i2 - i1 > 0) {
1574 String num = typeStr.substring(i1, i2);
1575 try {
1576 d = java.lang.Integer.parseInt(num, 10);
1577 } catch (NumberFormatException e) {
1578 }
1579 }
1580 }
1581 return d;
1582 }
1583
1584 }