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