📄 dbffiledatabasemetadata.java
字号:
/*
* dbfFileDatabaseMetaData.java
*/
package com.sqlmagic.tinysql;
/**
* Comprehensive information about the database as a whole.
*
* Many of the methods here return lists of information in
* the form of ResultSet objects.
* You can use the normal ResultSet methods such as getString and getInt
* to retrieve the data from these ResultSets. If a given form of
* metadata is not available, these methods should throw an SQLException.
*
* Some of these methods take arguments that are String patterns. These
* arguments all have names such as fooPattern. Within a pattern String, "%"
* means match any substring of 0 or more characters, and "_" means match
* any one character. Only metadata entries matching the search pattern
* are returned. If a search pattern argument is set to a null ref,
* that argument's criteria will be dropped from the search.
*
* An SQLException will be thrown if a driver does not support a meta
* data method. In the case of methods that return a ResultSet,
* either a ResultSet (which may be empty) is returned or a
* SQLException is thrown.
*
* $Author: davis $
* $Date: 2004/12/18 21:30:57 $
* $Revision: 1.1 $
*
*/
import java.sql.SQLException;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Types;
import java.util.Vector;
import java.io.File;
/**
dBase read/write access <br>
@author Brian Jepson <bjepson@home.com>
@author Marcel Ruff <ruff@swand.lake.de> Added DatabaseMetaData with JDK 2 support
@author Thomas Morgner <mgs@sherito.org> Changed DatabaseMetaData to use java.sql.Types.
*/
public class dbfFileDatabaseMetaData extends tinySQLDatabaseMetaData {
private final String emptyString = "";
public dbfFileDatabaseMetaData(Connection connection) {
super(connection);
}
public String getDatabaseProductName()
{
return "tinySQL";
}
public String getDatabaseProductVersion()
{
return tinySQLGlobals.VERSION;
}
String getDataDir()
{
String url = ((dbfFileConnection)getConnection()).url;
if (url.length() <= 13)
return null;
String dataDir = url.substring(13);
return dataDir;
}
/**
* Gets a description of all the standard SQL types supported by
* this database. They are ordered by DATA_TYPE and then by how
* closely the data type maps to the corresponding JDBC SQL type.
*
* <P>Each type description has the following columns:
* <OL>
* <LI><B>TYPE_NAME</B> String => Type name
* <LI><B>DATA_TYPE</B> short => SQL data type from java.sql.Types
* <LI><B>PRECISION</B> int => maximum precision
* <LI><B>LITERAL_PREFIX</B> String => prefix used to quote a literal
* (may be null)
* <LI><B>LITERAL_SUFFIX</B> String => suffix used to quote a literal
(may be null)
* <LI><B>CREATE_PARAMS</B> String => parameters used in creating
* the type (may be null)
* <LI><B>NULLABLE</B> short => can you use NULL for this type?
* <UL>
* <LI> typeNoNulls - does not allow NULL values
* <LI> typeNullable - allows NULL values
* <LI> typeNullableUnknown - nullability unknown
* </UL>
* <LI><B>CASE_SENSITIVE</B> boolean=> is it case sensitive?
* <LI><B>SEARCHABLE</B> short => can you use "WHERE" based on this type:
* <UL>
* <LI> typePredNone - No support
* <LI> typePredChar - Only supported with WHERE .. LIKE
* <LI> typePredBasic - Supported except for WHERE .. LIKE
* <LI> typeSearchable - Supported for all WHERE ..
* </UL>
* <LI><B>UNSIGNED_ATTRIBUTE</B> boolean => is it unsigned?
* <LI><B>FIXED_PREC_SCALE</B> boolean => can it be a money value?
* <LI><B>AUTO_INCREMENT</B> boolean => can it be used for an
* auto-increment value?
* <LI><B>LOCAL_TYPE_NAME</B> String => localized version of type name
* (may be null)
* <LI><B>MINIMUM_SCALE</B> short => minimum scale supported
* <LI><B>MAXIMUM_SCALE</B> short => maximum scale supported
* <LI><B>SQL_DATA_TYPE</B> int => unused
* <LI><B>SQL_DATETIME_SUB</B> int => unused
* <LI><B>NUM_PREC_RADIX</B> int => usually 2 or 10
* </OL>
*
* @return ResultSet - each row is a SQL type description
* @exception SQLException if a database access error occurs
*/
public ResultSet getTypeInfo() throws SQLException {
tsResultSet jrs = new tsResultSet();
tsColumn jsc = new tsColumn("TYPE_NAME");
jsc.type = Types.CHAR;
jsc.size = 10;
jrs.addColumn (jsc);
jsc = new tsColumn("DATA_TYPE");
jsc.type = Types.INTEGER;
jsc.size = 6;
jrs.addColumn (jsc);
jsc = new tsColumn("PRECISION");
jsc.type = Types.INTEGER;
jsc.size = 8;
jrs.addColumn (jsc);
jsc = new tsColumn("LITERAL_PREFIX");
jsc.type = Types.CHAR;
jsc.size = 1;
jrs.addColumn (jsc);
jsc = new tsColumn("LITERAL_SUFFIX");
jsc.type = Types.CHAR;
jsc.size = 1;
jrs.addColumn (jsc);
jsc = new tsColumn("CREATE_PARAMS");
jsc.type = Types.CHAR;
jsc.size = 20;
jrs.addColumn (jsc);
jsc = new tsColumn("NULLABLE");
jsc.type = Types.INTEGER;
jsc.size = 6;
jrs.addColumn (jsc);
jsc = new tsColumn("CASE_SENSITIVE");
jsc.type = Types.BIT;
jsc.size = 1;
jrs.addColumn (jsc);
jsc = new tsColumn("SEARCHABLE");
jsc.type = Types.INTEGER;
jsc.size = 6;
jrs.addColumn (jsc);
/*
* <LI><B>UNSIGNED_ATTRIBUTE</B> boolean => is it unsigned?
* <LI><B>FIXED_PREC_SCALE</B> boolean => can it be a money value?
* <LI><B>AUTO_INCREMENT</B> boolean => can it be used for an
* auto-increment value?
* <LI><B>LOCAL_TYPE_NAME</B> String => localized version of type name
* (may be null)
* <LI><B>MINIMUM_SCALE</B> short => minimum scale supported
* <LI><B>MAXIMUM_SCALE</B> short => maximum scale supported
* <LI><B>NUM_PREC_RADIX</B> int => usually 2 or 10
*/
// NOTE: the Hashtable in tsRow expects always a String as its value!
// so i use the toString() method here
// Perhaps in future the real type should be pushed into the Hashtable?
tsRow record = new tsRow();
record.put("TYPE_NAME", dbfFile.typeToLiteral(Types.CHAR)); // "CHAR", String
record.put("DATA_TYPE", new Integer(Types.CHAR).toString());
record.put("PRECISION", new Integer(254).toString());
record.put("LITERAL_PREFIX", "\"");
record.put("LITERAL_SUFFIX", "\"");
record.put("CREATE_PARAMS", new Integer(0).toString());
record.put("NULLABLE", new Integer(typeNullableUnknown).toString());
record.put("CASE_SENSITIVE", "N");
record.put("SEARCHABLE", new Integer(typePredBasic).toString());
jrs.addRow (record) ;
record = new tsRow();
record.put("TYPE_NAME", dbfFile.typeToLiteral(Types.FLOAT)); // "FLOAT", double
record.put("DATA_TYPE", new Integer(Types.FLOAT).toString());
record.put("PRECISION", new Integer(19).toString());
record.put("LITERAL_PREFIX", emptyString);
record.put("LITERAL_SUFFIX", emptyString);
record.put("CREATE_PARAMS", new Integer(0).toString());
record.put("NULLABLE", new Integer(typeNullableUnknown).toString());
record.put("CASE_SENSITIVE", "N");
record.put("SEARCHABLE", new Integer(typePredBasic).toString());
jrs.addRow (record) ;
record = new tsRow();
record.put("TYPE_NAME", dbfFile.typeToLiteral(Types.BIT)); // "CHAR", boolean "YyNnTtFf"
record.put("DATA_TYPE", new Integer(Types.BIT).toString());
record.put("PRECISION", new Integer(1).toString());
record.put("LITERAL_PREFIX", "\"");
record.put("LITERAL_SUFFIX", "\"");
record.put("CREATE_PARAMS", new Integer(0).toString());
record.put("NULLABLE", new Integer(typeNullableUnknown).toString());
record.put("CASE_SENSITIVE", "N");
record.put("SEARCHABLE", new Integer(typePredBasic).toString());
jrs.addRow (record) ;
record = new tsRow();
record.put("TYPE_NAME", dbfFile.typeToLiteral(Types.INTEGER)); // "INT", unsigned long
record.put("DATA_TYPE", new Integer(Types.INTEGER).toString());
record.put("PRECISION", new Integer(19).toString());
record.put("LITERAL_PREFIX", emptyString);
record.put("LITERAL_SUFFIX", emptyString);
record.put("CREATE_PARAMS", new Integer(0).toString());
record.put("NULLABLE", new Integer(typeNullableUnknown).toString());
record.put("CASE_SENSITIVE", "N");
record.put("SEARCHABLE", new Integer(typePredBasic).toString());
jrs.addRow (record) ;
record = new tsRow();
record.put("TYPE_NAME", dbfFile.typeToLiteral(Types.DATE)); // "DATE", date
record.put("DATA_TYPE", new Integer(Types.DATE).toString());
record.put("PRECISION", new Integer(8).toString());
record.put("LITERAL_PREFIX", "\"");
record.put("LITERAL_SUFFIX", "\"");
record.put("CREATE_PARAMS", new Integer(0).toString());
record.put("NULLABLE", new Integer(typeNullableUnknown).toString());
record.put("CASE_SENSITIVE", "N");
record.put("SEARCHABLE", new Integer(typePredBasic).toString());
jrs.addRow (record) ;
return new tinySQLResultSet(jrs, (tinySQLStatement)null);
}
/*
* Gets a description of tables available in a catalog.
*
* Only table descriptions matching the catalog, schema, table
* name and type criteria are returned. They are ordered by
* TABLE_TYPE, TABLE_SCHEM and TABLE_NAME.
*
* Each table description has the following columns:
*
* TABLE_CAT String => table catalog (may be null)
* TABLE_SCHEM String => table schema (may be null)
* TABLE_NAME String => table name
* TABLE_TYPE String => table type. Typical types are "TABLE",
* "VIEW", "SYSTEM TABLE", "GLOBAL TEMPORARY",
* "LOCAL TEMPORARY", "ALIAS", "SYNONYM".
* REMARKS String => explanatory comment on the table
*
* Note: Some databases may not return information for
* all tables.
*
* @param catalog a catalog name; "" retrieves those without a
* catalog; null means drop catalog name from the selection criteria
* THIS VALUE IS IGNORED
* @param schemaPattern THIS VALUE IS IGNORED
* @param tableNamePattern a table name pattern, 磏ull
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -