117c83b1a74c906c9a36257a3a99cd1e3730b002eJeremy Sharpepackage SQLite.JDBC2z; 2417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes 3417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughesimport java.sql.*; 4417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes 5417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughespublic class JDBCResultSetMetaData implements java.sql.ResultSetMetaData { 6417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes 7417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes private JDBCResultSet r; 87a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes 9417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes public JDBCResultSetMetaData(JDBCResultSet r) { 107a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes this.r = r; 11417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes } 12417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes 13417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes public String getCatalogName(int column) throws java.sql.SQLException { 147a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes return null; 15417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes } 16417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes 17417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes public String getColumnClassName(int column) throws java.sql.SQLException { 187a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes column--; 197a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes if (r != null && r.tr != null) { 207a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes if (column < 0 || column >= r.tr.ncolumns) { 217a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes return null; 227a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes } 237a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes if (r.tr instanceof TableResultX) { 247a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes switch (((TableResultX) r.tr).sql_type[column]) { 257a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes case Types.SMALLINT: return "java.lang.Short"; 267a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes case Types.INTEGER: return "java.lang.Integer"; 277a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes case Types.REAL: 287a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes case Types.DOUBLE: return "java.lang.Double"; 297a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes case Types.FLOAT: return "java.lang.Float"; 307a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes case Types.BIGINT: return "java.lang.Long"; 317a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes case Types.DATE: return "java.sql.Date"; 327a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes case Types.TIME: return "java.sql.Time"; 337a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes case Types.TIMESTAMP: return "java.sql.Timestamp"; 347a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes case Types.BINARY: 357a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes case Types.VARBINARY: return "[B"; 367a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes /* defaults to varchar below */ 377a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes } 387a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes } 397a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes return "java.lang.String"; 407a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes } 417a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes return null; 42417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes } 43417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes 44417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes public int getColumnCount() throws java.sql.SQLException { 457a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes if (r != null && r.tr != null) { 467a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes return r.tr.ncolumns; 477a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes } 487a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes return 0; 49417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes } 50417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes 51417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes public int getColumnDisplaySize(int column) throws java.sql.SQLException { 527a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes return 0; 53417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes } 54417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes 55417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes public String getColumnLabel(int column) throws java.sql.SQLException { 567a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes column--; 577a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes String c = null; 587a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes if (r != null && r.tr != null) { 597a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes if (column < 0 || column >= r.tr.ncolumns) { 607a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes return c; 617a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes } 627a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes c = r.tr.column[column]; 637a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes } 647a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes return c; 65417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes } 66417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes 67417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes public String getColumnName(int column) throws java.sql.SQLException { 687a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes column--; 697a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes String c = null; 707a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes if (r != null && r.tr != null) { 717a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes if (column < 0 || column >= r.tr.ncolumns) { 727a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes return c; 737a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes } 747a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes c = r.tr.column[column]; 757a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes if (c != null) { 767a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes int i = c.indexOf('.'); 777a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes if (i > 0) { 787a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes return c.substring(i + 1); 797a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes } 807a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes } 817a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes } 827a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes return c; 83417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes } 84417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes 85417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes public int getColumnType(int column) throws java.sql.SQLException { 867a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes column--; 877a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes if (r != null && r.tr != null) { 887a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes if (column >= 0 && column < r.tr.ncolumns) { 897a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes if (r.tr instanceof TableResultX) { 907a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes return ((TableResultX) r.tr).sql_type[column]; 917a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes } 927a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes return Types.VARCHAR; 937a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes } 947a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes } 957a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes throw new SQLException("bad column index"); 96417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes } 97417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes 98417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes public String getColumnTypeName(int column) throws java.sql.SQLException { 997a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes column--; 1007a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes if (r != null && r.tr != null) { 1017a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes if (column >= 0 && column < r.tr.ncolumns) { 1027a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes if (r.tr instanceof TableResultX) { 1037a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes switch (((TableResultX) r.tr).sql_type[column]) { 1047a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes case Types.SMALLINT: return "smallint"; 1057a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes case Types.INTEGER: return "integer"; 1067a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes case Types.DOUBLE: return "double"; 1077a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes case Types.FLOAT: return "float"; 1087a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes case Types.BIGINT: return "bigint"; 1097a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes case Types.DATE: return "date"; 1107a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes case Types.TIME: return "time"; 1117a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes case Types.TIMESTAMP: return "timestamp"; 1127a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes case Types.BINARY: return "binary"; 1137a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes case Types.VARBINARY: return "varbinary"; 1147a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes case Types.REAL: return "real"; 1157a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes /* defaults to varchar below */ 1167a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes } 1177a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes } 1187a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes return "varchar"; 1197a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes } 1207a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes } 1217a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes throw new SQLException("bad column index"); 122417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes } 123417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes 124417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes public int getPrecision(int column) throws java.sql.SQLException { 1257a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes return 0; 126417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes } 127417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes 128417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes public int getScale(int column) throws java.sql.SQLException { 1297a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes return 0; 130417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes } 131417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes 132417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes public String getSchemaName(int column) throws java.sql.SQLException { 1337a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes return null; 134417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes } 135417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes 136417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes public String getTableName(int column) throws java.sql.SQLException { 1377a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes column--; 1387a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes String c = null; 1397a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes if (r != null && r.tr != null) { 1407a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes if (column < 0 || column >= r.tr.ncolumns) { 1417a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes return c; 1427a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes } 1437a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes c = r.tr.column[column]; 1447a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes if (c != null) { 1457a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes int i = c.indexOf('.'); 1467a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes if (i > 0) { 1477a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes return c.substring(0, i); 1487a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes } 1497a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes c = null; 1507a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes } 1517a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes } 1527a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes return c; 153417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes } 154417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes 155417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes public boolean isAutoIncrement(int column) throws java.sql.SQLException { 1567a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes return false; 157417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes } 158417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes 159417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes public boolean isCaseSensitive(int column) throws java.sql.SQLException { 1607a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes return false; 161417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes } 162417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes 163417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes public boolean isCurrency(int column) throws java.sql.SQLException { 1647a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes return false; 165417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes } 166417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes 167417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes public boolean isDefinitelyWritable(int column) 1687a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes throws java.sql.SQLException { 1697a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes return true; 170417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes } 171417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes 172417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes public int isNullable(int column) throws java.sql.SQLException { 1737a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes return columnNullableUnknown; 174417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes } 175417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes 176417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes public boolean isReadOnly(int column) throws java.sql.SQLException { 1777a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes return false; 178417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes } 179417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes 180417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes public boolean isSearchable(int column) throws java.sql.SQLException { 1817a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes return true; 182417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes } 183417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes 184417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes public boolean isSigned(int column) throws java.sql.SQLException { 1857a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes return false; 186417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes } 187417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes 188417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes public boolean isWritable(int column) throws java.sql.SQLException { 1897a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes return true; 190417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes } 191417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes 192417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes int findColByName(String columnName) throws java.sql.SQLException { 1937a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes String c = null; 1947a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes if (r != null && r.tr != null) { 1957a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes for (int i = 0; i < r.tr.ncolumns; i++) { 1967a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes c = r.tr.column[i]; 1977a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes if (c != null) { 1987a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes if (c.compareToIgnoreCase(columnName) == 0) { 1997a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes return i + 1; 2007a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes } 2017a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes int k = c.indexOf('.'); 2027a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes if (k > 0) { 2037a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes c = c.substring(k + 1); 2047a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes if (c.compareToIgnoreCase(columnName) == 0) { 2057a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes return i + 1; 2067a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes } 2077a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes } 2087a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes } 2097a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes c = null; 2107a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes } 2117a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes } 2127a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes throw new SQLException("column " + columnName + " not found"); 213417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes } 21417c83b1a74c906c9a36257a3a99cd1e3730b002eJeremy Sharpe 21517c83b1a74c906c9a36257a3a99cd1e3730b002eJeremy Sharpe public <T> T unwrap(java.lang.Class<T> iface) throws SQLException { 21617c83b1a74c906c9a36257a3a99cd1e3730b002eJeremy Sharpe throw new SQLException("unsupported"); 21717c83b1a74c906c9a36257a3a99cd1e3730b002eJeremy Sharpe } 21817c83b1a74c906c9a36257a3a99cd1e3730b002eJeremy Sharpe 21917c83b1a74c906c9a36257a3a99cd1e3730b002eJeremy Sharpe public boolean isWrapperFor(java.lang.Class iface) throws SQLException { 22017c83b1a74c906c9a36257a3a99cd1e3730b002eJeremy Sharpe return false; 22117c83b1a74c906c9a36257a3a99cd1e3730b002eJeremy Sharpe } 22217c83b1a74c906c9a36257a3a99cd1e3730b002eJeremy Sharpe 223417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes} 224