1 package SQLite.JDBC2z; 2 3 import java.sql.*; 4 5 public class JDBCResultSetMetaData implements java.sql.ResultSetMetaData { 6 7 private JDBCResultSet r; 8 JDBCResultSetMetaData(JDBCResultSet r)9 public JDBCResultSetMetaData(JDBCResultSet r) { 10 this.r = r; 11 } 12 getCatalogName(int column)13 public String getCatalogName(int column) throws java.sql.SQLException { 14 return null; 15 } 16 getColumnClassName(int column)17 public String getColumnClassName(int column) throws java.sql.SQLException { 18 column--; 19 if (r != null && r.tr != null) { 20 if (column < 0 || column >= r.tr.ncolumns) { 21 return null; 22 } 23 if (r.tr instanceof TableResultX) { 24 switch (((TableResultX) r.tr).sql_type[column]) { 25 case Types.SMALLINT: return "java.lang.Short"; 26 case Types.INTEGER: return "java.lang.Integer"; 27 case Types.REAL: 28 case Types.DOUBLE: return "java.lang.Double"; 29 case Types.FLOAT: return "java.lang.Float"; 30 case Types.BIGINT: return "java.lang.Long"; 31 case Types.DATE: return "java.sql.Date"; 32 case Types.TIME: return "java.sql.Time"; 33 case Types.TIMESTAMP: return "java.sql.Timestamp"; 34 case Types.BINARY: 35 case Types.VARBINARY: return "[B"; 36 /* defaults to varchar below */ 37 } 38 } 39 return "java.lang.String"; 40 } 41 return null; 42 } 43 getColumnCount()44 public int getColumnCount() throws java.sql.SQLException { 45 if (r != null && r.tr != null) { 46 return r.tr.ncolumns; 47 } 48 return 0; 49 } 50 getColumnDisplaySize(int column)51 public int getColumnDisplaySize(int column) throws java.sql.SQLException { 52 return 0; 53 } 54 getColumnLabel(int column)55 public String getColumnLabel(int column) throws java.sql.SQLException { 56 column--; 57 String c = null; 58 if (r != null && r.tr != null) { 59 if (column < 0 || column >= r.tr.ncolumns) { 60 return c; 61 } 62 c = r.tr.column[column]; 63 } 64 return c; 65 } 66 getColumnName(int column)67 public String getColumnName(int column) throws java.sql.SQLException { 68 column--; 69 String c = null; 70 if (r != null && r.tr != null) { 71 if (column < 0 || column >= r.tr.ncolumns) { 72 return c; 73 } 74 c = r.tr.column[column]; 75 if (c != null) { 76 int i = c.indexOf('.'); 77 if (i > 0) { 78 return c.substring(i + 1); 79 } 80 } 81 } 82 return c; 83 } 84 getColumnType(int column)85 public int getColumnType(int column) throws java.sql.SQLException { 86 column--; 87 if (r != null && r.tr != null) { 88 if (column >= 0 && column < r.tr.ncolumns) { 89 if (r.tr instanceof TableResultX) { 90 return ((TableResultX) r.tr).sql_type[column]; 91 } 92 return Types.VARCHAR; 93 } 94 } 95 throw new SQLException("bad column index"); 96 } 97 getColumnTypeName(int column)98 public String getColumnTypeName(int column) throws java.sql.SQLException { 99 column--; 100 if (r != null && r.tr != null) { 101 if (column >= 0 && column < r.tr.ncolumns) { 102 if (r.tr instanceof TableResultX) { 103 switch (((TableResultX) r.tr).sql_type[column]) { 104 case Types.SMALLINT: return "smallint"; 105 case Types.INTEGER: return "integer"; 106 case Types.DOUBLE: return "double"; 107 case Types.FLOAT: return "float"; 108 case Types.BIGINT: return "bigint"; 109 case Types.DATE: return "date"; 110 case Types.TIME: return "time"; 111 case Types.TIMESTAMP: return "timestamp"; 112 case Types.BINARY: return "binary"; 113 case Types.VARBINARY: return "varbinary"; 114 case Types.REAL: return "real"; 115 /* defaults to varchar below */ 116 } 117 } 118 return "varchar"; 119 } 120 } 121 throw new SQLException("bad column index"); 122 } 123 getPrecision(int column)124 public int getPrecision(int column) throws java.sql.SQLException { 125 return 0; 126 } 127 getScale(int column)128 public int getScale(int column) throws java.sql.SQLException { 129 return 0; 130 } 131 getSchemaName(int column)132 public String getSchemaName(int column) throws java.sql.SQLException { 133 return null; 134 } 135 getTableName(int column)136 public String getTableName(int column) throws java.sql.SQLException { 137 column--; 138 String c = null; 139 if (r != null && r.tr != null) { 140 if (column < 0 || column >= r.tr.ncolumns) { 141 return c; 142 } 143 c = r.tr.column[column]; 144 if (c != null) { 145 int i = c.indexOf('.'); 146 if (i > 0) { 147 return c.substring(0, i); 148 } 149 c = null; 150 } 151 } 152 return c; 153 } 154 isAutoIncrement(int column)155 public boolean isAutoIncrement(int column) throws java.sql.SQLException { 156 return false; 157 } 158 isCaseSensitive(int column)159 public boolean isCaseSensitive(int column) throws java.sql.SQLException { 160 return false; 161 } 162 isCurrency(int column)163 public boolean isCurrency(int column) throws java.sql.SQLException { 164 return false; 165 } 166 isDefinitelyWritable(int column)167 public boolean isDefinitelyWritable(int column) 168 throws java.sql.SQLException { 169 return true; 170 } 171 isNullable(int column)172 public int isNullable(int column) throws java.sql.SQLException { 173 return columnNullableUnknown; 174 } 175 isReadOnly(int column)176 public boolean isReadOnly(int column) throws java.sql.SQLException { 177 return false; 178 } 179 isSearchable(int column)180 public boolean isSearchable(int column) throws java.sql.SQLException { 181 return true; 182 } 183 isSigned(int column)184 public boolean isSigned(int column) throws java.sql.SQLException { 185 return false; 186 } 187 isWritable(int column)188 public boolean isWritable(int column) throws java.sql.SQLException { 189 return true; 190 } 191 findColByName(String columnName)192 int findColByName(String columnName) throws java.sql.SQLException { 193 String c = null; 194 if (r != null && r.tr != null) { 195 for (int i = 0; i < r.tr.ncolumns; i++) { 196 c = r.tr.column[i]; 197 if (c != null) { 198 if (c.compareToIgnoreCase(columnName) == 0) { 199 return i + 1; 200 } 201 int k = c.indexOf('.'); 202 if (k > 0) { 203 c = c.substring(k + 1); 204 if (c.compareToIgnoreCase(columnName) == 0) { 205 return i + 1; 206 } 207 } 208 } 209 c = null; 210 } 211 } 212 throw new SQLException("column " + columnName + " not found"); 213 } 214 unwrap(java.lang.Class<T> iface)215 public <T> T unwrap(java.lang.Class<T> iface) throws SQLException { 216 throw new SQLException("unsupported"); 217 } 218 isWrapperFor(java.lang.Class iface)219 public boolean isWrapperFor(java.lang.Class iface) throws SQLException { 220 return false; 221 } 222 223 } 224