JDBCResultSetMetaData.java revision 417deb1db112103aff04231b6ca79772ff7d3a21
1417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughespackage SQLite.JDBC2y; 2417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes 3417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughesimport java.sql.*; 4417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes 5417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughespublic class JDBCResultSetMetaData implements java.sql.ResultSetMetaData { 6417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes 7417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes private JDBCResultSet r; 8417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes 9417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes public JDBCResultSetMetaData(JDBCResultSet r) { 10417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes this.r = r; 11417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes } 12417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes 13417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes public String getCatalogName(int column) throws java.sql.SQLException { 14417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes return null; 15417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes } 16417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes 17417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes public String getColumnClassName(int column) throws java.sql.SQLException { 18417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes column--; 19417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes if (r != null && r.tr != null) { 20417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes if (column < 0 || column >= r.tr.ncolumns) { 21417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes return null; 22417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes } 23417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes if (r.tr instanceof TableResultX) { 24417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes switch (((TableResultX) r.tr).sql_type[column]) { 25417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes case Types.SMALLINT: return "java.lang.Short"; 26417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes case Types.INTEGER: return "java.lang.Integer"; 27417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes case Types.DOUBLE: return "java.lang.Double"; 28417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes case Types.FLOAT: return "java.lang.Float"; 29417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes case Types.BIGINT: return "java.lang.Long"; 30417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes case Types.DATE: return "java.sql.Date"; 31417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes case Types.TIME: return "java.sql.Time"; 32417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes case Types.TIMESTAMP: return "java.sql.Timestamp"; 33417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes case Types.BINARY: 34417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes case Types.VARBINARY: return "[B"; 35417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes /* defaults to varchar below */ 36417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes } 37417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes } 38417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes return "java.lang.String"; 39417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes } 40417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes return null; 41417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes } 42417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes 43417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes public int getColumnCount() throws java.sql.SQLException { 44417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes if (r != null && r.tr != null) { 45417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes return r.tr.ncolumns; 46417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes } 47417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes return 0; 48417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes } 49417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes 50417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes public int getColumnDisplaySize(int column) throws java.sql.SQLException { 51417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes return 0; 52417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes } 53417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes 54417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes public String getColumnLabel(int column) throws java.sql.SQLException { 55417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes column--; 56417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes String c = null; 57417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes if (r != null && r.tr != null) { 58417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes if (column < 0 || column >= r.tr.ncolumns) { 59417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes return c; 60417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes } 61417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes c = r.tr.column[column]; 62417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes } 63417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes return c; 64417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes } 65417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes 66417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes public String getColumnName(int column) throws java.sql.SQLException { 67417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes column--; 68417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes String c = null; 69417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes if (r != null && r.tr != null) { 70417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes if (column < 0 || column >= r.tr.ncolumns) { 71417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes return c; 72417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes } 73417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes c = r.tr.column[column]; 74417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes if (c != null) { 75417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes int i = c.indexOf('.'); 76417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes if (i > 0) { 77417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes return c.substring(i + 1); 78417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes } 79417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes } 80417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes } 81417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes return c; 82417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes } 83417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes 84417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes public int getColumnType(int column) throws java.sql.SQLException { 85417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes column--; 86417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes if (r != null && r.tr != null) { 87417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes if (column >= 0 && column < r.tr.ncolumns) { 88417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes if (r.tr instanceof TableResultX) { 89417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes return ((TableResultX) r.tr).sql_type[column]; 90417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes } 91417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes return Types.VARCHAR; 92417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes } 93417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes } 94417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes throw new SQLException("bad column index"); 95417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes } 96417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes 97417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes public String getColumnTypeName(int column) throws java.sql.SQLException { 98417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes column--; 99417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes if (r != null && r.tr != null) { 100417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes if (column >= 0 && column < r.tr.ncolumns) { 101417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes if (r.tr instanceof TableResultX) { 102417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes switch (((TableResultX) r.tr).sql_type[column]) { 103417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes case Types.SMALLINT: return "smallint"; 104417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes case Types.INTEGER: return "integer"; 105417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes case Types.DOUBLE: return "double"; 106417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes case Types.FLOAT: return "float"; 107417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes case Types.BIGINT: return "bigint"; 108417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes case Types.DATE: return "date"; 109417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes case Types.TIME: return "time"; 110417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes case Types.TIMESTAMP: return "timestamp"; 111417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes case Types.BINARY: return "binary"; 112417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes case Types.VARBINARY: return "varbinary"; 113417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes /* defaults to varchar below */ 114417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes } 115417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes } 116417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes return "varchar"; 117417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes } 118417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes } 119417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes throw new SQLException("bad column index"); 120417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes } 121417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes 122417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes public int getPrecision(int column) throws java.sql.SQLException { 123417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes return 0; 124417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes } 125417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes 126417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes public int getScale(int column) throws java.sql.SQLException { 127417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes return 0; 128417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes } 129417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes 130417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes public String getSchemaName(int column) throws java.sql.SQLException { 131417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes return null; 132417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes } 133417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes 134417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes public String getTableName(int column) throws java.sql.SQLException { 135417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes column--; 136417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes String c = null; 137417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes if (r != null && r.tr != null) { 138417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes if (column < 0 || column >= r.tr.ncolumns) { 139417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes return c; 140417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes } 141417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes c = r.tr.column[column]; 142417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes if (c != null) { 143417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes int i = c.indexOf('.'); 144417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes if (i > 0) { 145417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes return c.substring(0, i); 146417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes } 147417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes c = null; 148417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes } 149417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes } 150417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes return c; 151417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes } 152417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes 153417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes public boolean isAutoIncrement(int column) throws java.sql.SQLException { 154417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes return false; 155417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes } 156417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes 157417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes public boolean isCaseSensitive(int column) throws java.sql.SQLException { 158417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes return false; 159417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes } 160417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes 161417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes public boolean isCurrency(int column) throws java.sql.SQLException { 162417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes return false; 163417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes } 164417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes 165417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes public boolean isDefinitelyWritable(int column) 166417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes throws java.sql.SQLException { 167417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes return true; 168417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes } 169417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes 170417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes public int isNullable(int column) throws java.sql.SQLException { 171417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes return columnNullableUnknown; 172417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes } 173417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes 174417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes public boolean isReadOnly(int column) throws java.sql.SQLException { 175417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes return false; 176417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes } 177417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes 178417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes public boolean isSearchable(int column) throws java.sql.SQLException { 179417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes return true; 180417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes } 181417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes 182417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes public boolean isSigned(int column) throws java.sql.SQLException { 183417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes return false; 184417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes } 185417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes 186417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes public boolean isWritable(int column) throws java.sql.SQLException { 187417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes return true; 188417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes } 189417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes 190417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes int findColByName(String columnName) throws java.sql.SQLException { 191417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes String c = null; 192417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes if (r != null && r.tr != null) { 193417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes for (int i = 0; i < r.tr.ncolumns; i++) { 194417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes c = r.tr.column[i]; 195417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes if (c != null) { 196417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes if (c.compareToIgnoreCase(columnName) == 0) { 197417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes return i + 1; 198417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes } 199417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes int k = c.indexOf('.'); 200417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes if (k > 0) { 201417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes c = c.substring(k + 1); 202417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes if (c.compareToIgnoreCase(columnName) == 0) { 203417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes return i + 1; 204417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes } 205417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes } 206417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes } 207417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes c = null; 208417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes } 209417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes } 210417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes throw new SQLException("column " + columnName + " not found"); 211417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes } 212417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes} 213