📄 databasemetadata.java
字号:
/* * MM JDBC Drivers for MySQL * * $Id: DatabaseMetaData.java,v 1.2 1998/08/25 00:53:46 mmatthew Exp $ * * Copyright (C) 1998 Mark Matthews <mmatthew@worldserver.com> * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public * License along with this library; if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. * * See the COPYING file located in the top-level-directory of * the archive of this library for complete text of license. * * Some portions: * * Copyright (c) 1996 Bradley McLean / Jeffrey Medeiros * Modifications Copyright (c) 1996/1997 Martin Rode * Copyright (c) 1997 Peter T Mount *//** * JDBC Interface to Mysql functions * * <p> * This class provides information about the database as a whole. * * <p> * Many of the methods here return lists of information in ResultSets. * 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 show throw a java.sql.SQLException. * * <p> * Some of these methods take arguments that are String patterns. These * methods 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. * * @author Mark Matthews <mmatthew@worldserver.com> * @version $Id$ */package org.gjt.mm.mysql;import java.sql.*;import java.net.*;import java.io.*;import java.util.Vector;public class DatabaseMetaData implements java.sql.DatabaseMetaData{ private Connection _Conn; private String _Database = null; private static byte[] _Table_As_Bytes = new byte[] {'T', 'A','B', 'L', 'E'}; public DatabaseMetaData(Connection Conn, String Database) { _Conn = Conn; _Database = Database; } /** * Can all the procedures returned by getProcedures be called by the * current user? * * @return true if so */ public boolean allProceduresAreCallable() throws java.sql.SQLException { return false; // not likely we will ever check } /** * Can all the tables returned by getTable be SELECTed by the * current user? * * @return true if so */ public boolean allTablesAreSelectable() throws java.sql.SQLException { return false; // not likely we will ever check } /** * What's the url for this database? * * @return the url or null if it can't be generated */ public String getURL() throws java.sql.SQLException { return new String(_Conn.getURL()); } /** * What's our user name as known to the database? * * @return our database user name */ public String getUserName() throws java.sql.SQLException { return new String(_Conn.getUser()); } /** * Is the database in read-only mode? * * @return true if so */ public boolean isReadOnly() throws java.sql.SQLException { return false; // will this ever be true? } /** * Are NULL values sorted high? * * @return true if so */ public boolean nullsAreSortedHigh() throws java.sql.SQLException { return false; } /** * Are NULL values sorted low? * * @return true if so */ public boolean nullsAreSortedLow() throws java.sql.SQLException { return !nullsAreSortedHigh(); // a guess!? } /** * Are NULL values sorted at the start regardless of sort order? * * @return true if so */ public boolean nullsAreSortedAtStart() throws java.sql.SQLException { return false; // maybe true? } /** * Are NULL values sorted at the end regardless of sort order? * * @return true if so */ public boolean nullsAreSortedAtEnd() throws java.sql.SQLException { return false; } /** * What's the name of this database product? * * @return database product name */ public String getDatabaseProductName() throws java.sql.SQLException { return "MySQL"; } /** * What's the version of this database product? * * @return database version */ public String getDatabaseProductVersion() throws java.sql.SQLException { return new String(_Conn.getServerVersion()); } /** * What's the name of this JDBC driver? * * @return JDBC driver name */ public String getDriverName() throws java.sql.SQLException { return "Mark Matthews' MySQL Driver"; } /** * What's the version of this JDBC driver? * * @return JDBC driver version */ public String getDriverVersion() throws java.sql.SQLException { return "1.2b"; } /** * What's this JDBC driver's major version number? * * @return JDBC driver major version */ public int getDriverMajorVersion() { return Driver._MAJORVERSION; } /** * What's this JDBC driver's minor version number? * * @return JDBC driver minor version number */ public int getDriverMinorVersion() { return Driver._MINORVERSION; } /** * Does the database store tables in a local file? * * @return true if so */ public boolean usesLocalFiles() throws java.sql.SQLException { return false; } /** * Does the database use a file for each table? * * @return true if the database uses a local file for each table */ public boolean usesLocalFilePerTable() throws java.sql.SQLException { return false; } /** * Does the database support mixed case unquoted SQL identifiers? * * @return true if so */ public boolean supportsMixedCaseIdentifiers() throws java.sql.SQLException { return false; // I think } /** * Does the database store mixed case unquoted SQL identifiers in * upper case? * * @return true if so */ public boolean storesUpperCaseIdentifiers() throws java.sql.SQLException { return false; } /** * Does the database store mixed case unquoted SQL identifiers in * lower case? * * @return true if so */ public boolean storesLowerCaseIdentifiers() throws java.sql.SQLException { return false; } /** * Does the database store mixed case unquoted SQL identifiers in * mixed case? * * @return true if so */ public boolean storesMixedCaseIdentifiers() throws java.sql.SQLException { return true; // I think... } /** * Does the database support mixed case quoted SQL identifiers? * * A JDBC compliant driver will always return true. * * @return true if so */ public boolean supportsMixedCaseQuotedIdentifiers() throws java.sql.SQLException { return false; // won't work with MySQL } /** * Does the database store mixed case quoted SQL identifiers in * upper case? * * A JDBC compliant driver will always return true. * * @return true if so */ public boolean storesUpperCaseQuotedIdentifiers() throws java.sql.SQLException { return false; // don't know } /** * Does the database store mixed case quoted SQL identifiers in * lower case? * * A JDBC compliant driver will always return false. * * @return true if so */ public boolean storesLowerCaseQuotedIdentifiers() throws java.sql.SQLException { return false; } /** * Does the database store mixed case quoted SQL identifiers in * mixed case? * * A JDBC compliant driver will always return false. * * @return true if so */ public boolean storesMixedCaseQuotedIdentifiers() throws java.sql.SQLException { return false; // don't really know. } /** * What's the string used to quote SQL identifiers? * This returns a space " " if identifier quoting isn't supported. * * A JDBC compliant driver always uses a double quote character. * * @return the quoting string */ public String getIdentifierQuoteString() throws java.sql.SQLException { return " "; } /** * Get a comma separated list of all a database's SQL keywords * that are NOT also SQL92 keywords. * * @return the list */ public String getSQLKeywords() throws java.sql.SQLException { return "AUTO_INCREMENT,BINARY,BLOB,ENUM,INFILE,LOAD,MEDIUMINT,OPTION,OUTFILE,REPLACE,SET,TEXT,UNSIGNED,ZEROFILL"; } /** * Get a comma separated list of math functions. * * @return the list */ public String getNumericFunctions() throws java.sql.SQLException { return "ABS,ACOS,ASIN,ATAN,ATAN2,BIT_COUNT,CEILING,COS,COT,DEGREES,EXP,FLOOR,LOG,LOG10,MAX,MIN,MOD,PI,POW,POWER,RADIANS,RAND,ROUND,SIN,SQRT,TAN,TRUNCATE"; } /** * Get a comma separated list of string functions. * * @return the list */ public String getStringFunctions() throws java.sql.SQLException { return "ACII,CHAR,CHAR_LENGTH,CHARACTER_LENGTH,CONCAT,ELT,FIELD,FIND_IN_SET,INSERT,INSTR,INTERVAL,LCASE,LEFT,LENGTH,LOCATE,LOWER,LTRIM,MID,POSITION,OCTET_LENGTH,REPEAT,REPLACE,REVERSE,RIGHT,RTRIM,SPACE,SOUNDEX,SUBSTRING,SUBSTRING_INDEX,TRIM,UCASE,UPPER"; } /** * Get a comma separated list of system functions. * * @return the list */ public String getSystemFunctions() throws java.sql.SQLException { return "DATABASE,USER,SYSTEM_USER,SESSION_USER,PASSWORD,ENCRYPT,LAST_INSERT_ID,VERSION"; } /** * Get a comma separated list of time and date functions. * * @return the list */ public String getTimeDateFunctions() throws java.sql.SQLException { return "DAYOFWEEK,WEEKDAY,DAYOFMONTH,DAYOFYEAR,MONTH,DAYNAME,MONTHNAME,QUARTER,WEEK,YEAR,HOUR,MINUTE,SECOND,PERIOD_ADD,PERIOD_DIFF,TO_DAYS,FROM_DAYS,DATE_FORMAT,TIME_FORMAT,CURDATE,CURRENT_DATE,CURTIME,CURRENT_TIME,NOW,SYSDATE,CURRENT_TIMESTAMP,UNIX_TIMESTAMP,FROM_UNIXTIME,SEC_TO_TIME,TIME_TO_SEC"; } /** * This is the string that can be used to escape '_' or '%' in * the string pattern style catalog search parameters. * * <P>The '_' character represents any single character. * <P>The '%' character represents any sequence of zero or * more characters. * @return the string used to escape wildcard characters */ public String getSearchStringEscape() throws java.sql.SQLException { return "\\"; } /** * Get all the "extra" characters that can be used in unquoted * identifier names (those beyond a-z, 0-9 and _). * * @return the string containing the extra characters */ public String getExtraNameCharacters() throws java.sql.SQLException { return ""; } /** * Is "ALTER TABLE" with add column supported? * * @return true if so */ public boolean supportsAlterTableWithAddColumn() throws java.sql.SQLException { return true; } /**
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -