📄 databasemetadatatest.java
字号:
// jTDS JDBC Driver for Microsoft SQL Server and Sybase
// Copyright (C) 2004 The jTDS Project
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 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
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser 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
//
package net.sourceforge.jtds.test;
import java.sql.*;
/**
* Test <code>DatabaseMetaData</code>.
*
* @version $Id: DatabaseMetaDataTest.java,v 1.14 2005/06/01 17:24:14 alin_sinpalean Exp $
*/
public class DatabaseMetaDataTest extends MetaDataTestCase {
public DatabaseMetaDataTest(String name) {
super(name);
}
/**
* Test meta data functions that return boolean values.
* @throws Exception
*/
public void testBooleanOptions() throws Exception {
DatabaseMetaData dbmd = con.getMetaData();
assertFalse("dataDefinitionCausesTransactionCommit", dbmd.dataDefinitionCausesTransactionCommit());
assertFalse("dataDefinitionIgnoredInTransactions", dbmd.dataDefinitionIgnoredInTransactions());
assertTrue("deletesAreDetected", dbmd.deletesAreDetected(ResultSet.TYPE_FORWARD_ONLY));
assertTrue("deletesAreDetected", dbmd.deletesAreDetected(ResultSet.TYPE_SCROLL_INSENSITIVE));
assertFalse("doesMaxRowSizeIncludeBlobs", dbmd.doesMaxRowSizeIncludeBlobs());
assertFalse("insertsAreDetected", dbmd.insertsAreDetected(ResultSet.TYPE_FORWARD_ONLY));
assertFalse("insertsAreDetected", dbmd.insertsAreDetected(ResultSet.TYPE_SCROLL_INSENSITIVE));
assertFalse("insertsAreDetected", dbmd.insertsAreDetected(ResultSet.TYPE_SCROLL_SENSITIVE));
assertTrue("isCatalogAtStart", dbmd.isCatalogAtStart());
assertFalse("isReadOnly", dbmd.isReadOnly());
assertTrue("nullPlusNonNullIsNull", dbmd.nullPlusNonNullIsNull());
assertFalse("nullsAreSortedAtEnd", dbmd.nullsAreSortedAtEnd());
assertFalse("nullsAreSortedAtStart", dbmd.nullsAreSortedAtStart());
assertFalse("nullsAreSortedHigh", dbmd.nullsAreSortedHigh());
assertTrue("nullsAreSortedLow", dbmd.nullsAreSortedLow());
assertFalse("othersDeletesAreVisible",dbmd.othersDeletesAreVisible(ResultSet.TYPE_SCROLL_INSENSITIVE));
assertFalse("othersInsertsAreVisible",dbmd.othersInsertsAreVisible(ResultSet.TYPE_SCROLL_INSENSITIVE));
assertFalse("othersInsertsAreVisible",dbmd.othersInsertsAreVisible(ResultSet.TYPE_SCROLL_SENSITIVE));
assertTrue("othersInsertsAreVisible",dbmd.othersInsertsAreVisible(ResultSet.TYPE_SCROLL_SENSITIVE + 1));
assertFalse("othersUpdatesAreVisible",dbmd.othersUpdatesAreVisible(ResultSet.TYPE_SCROLL_INSENSITIVE));
assertTrue("othersUpdatesAreVisible",dbmd.othersUpdatesAreVisible(ResultSet.TYPE_SCROLL_SENSITIVE));
assertTrue("ownInsertsAreVisible", dbmd.ownInsertsAreVisible(ResultSet.TYPE_FORWARD_ONLY));
assertTrue("ownInsertsAreVisible", dbmd.ownInsertsAreVisible(ResultSet.TYPE_SCROLL_INSENSITIVE));
assertTrue("ownInsertsAreVisible", dbmd.ownInsertsAreVisible(ResultSet.TYPE_SCROLL_SENSITIVE));
assertTrue("ownUpdatesAreVisible", dbmd.ownUpdatesAreVisible(ResultSet.TYPE_SCROLL_INSENSITIVE));
assertTrue("ownUpdatesAreVisible", dbmd.ownUpdatesAreVisible(ResultSet.TYPE_SCROLL_SENSITIVE));
assertFalse("storesLowerCaseIdentifiers", dbmd.storesLowerCaseIdentifiers());
assertFalse("storesLowerCaseQuotedIdentifiers", dbmd.storesLowerCaseQuotedIdentifiers());
assertFalse("storesUpperCaseIdentifiers", dbmd.storesUpperCaseIdentifiers());
assertFalse("storesUpperCaseQuotedIdentifiers", dbmd.storesUpperCaseQuotedIdentifiers());
assertTrue("supportsAlterTableWithAddColumn", dbmd.supportsAlterTableWithAddColumn());
assertTrue("supportsAlterTableWithDropColumn", dbmd.supportsAlterTableWithDropColumn());
assertTrue("supportsANSI92EntryLevelSQL", dbmd.supportsANSI92EntryLevelSQL());
assertFalse("supportsANSI92FullSQL", dbmd.supportsANSI92FullSQL());
assertFalse("supportsANSI92IntermediateSQL", dbmd.supportsANSI92IntermediateSQL());
assertTrue("supportsBatchUpdates", dbmd.supportsBatchUpdates());
assertTrue("supportsCatalogsInDataManipulation", dbmd.supportsCatalogsInDataManipulation());
assertTrue("supportsCatalogsInIndexDefinitions", dbmd.supportsCatalogsInIndexDefinitions());
assertTrue("supportsCatalogsInProcedureCalls", dbmd.supportsCatalogsInProcedureCalls());
assertTrue("supportsCatalogsInTableDefinitions", dbmd.supportsCatalogsInTableDefinitions());
assertTrue("supportsColumnAliasing", dbmd.supportsColumnAliasing());
assertTrue("supportsConvert", dbmd.supportsConvert());
assertTrue("supportsCorrelatedSubqueries", dbmd.supportsCorrelatedSubqueries());
assertTrue("supportsDataDefinitionAndDataManipulationTransactions", dbmd.supportsDataDefinitionAndDataManipulationTransactions());
assertFalse("supportsDataManipulationTransactionsOnly", dbmd.supportsDataManipulationTransactionsOnly());
assertFalse("supportsDifferentTableCorrelationNames", dbmd.supportsDifferentTableCorrelationNames());
assertTrue("supportsExpressionsInOrderBy", dbmd.supportsExpressionsInOrderBy());
assertFalse("supportsExtendedSQLGrammar", dbmd.supportsExtendedSQLGrammar());
assertTrue("supportsGroupBy", dbmd.supportsGroupBy());
assertTrue("supportsGroupByBeyondSelect", dbmd.supportsGroupByBeyondSelect());
assertTrue("supportsGroupByUnrelated", dbmd.supportsGroupByUnrelated());
assertTrue("supportsLimitedOuterJoins", dbmd.supportsLimitedOuterJoins());
assertTrue("supportsMinimumSQLGrammar", dbmd.supportsMinimumSQLGrammar());
assertTrue("supportsMultipleResultSets", dbmd.supportsMultipleResultSets());
assertTrue("supportsMultipleTransactions", dbmd.supportsMultipleTransactions());
assertTrue("supportsNonNullableColumns", dbmd.supportsNonNullableColumns());
assertTrue("supportsOpenStatementsAcrossCommit", dbmd.supportsOpenStatementsAcrossCommit());
assertTrue("supportsOpenStatementsAcrossRollback", dbmd.supportsOpenStatementsAcrossRollback());
assertTrue("supportsOrderByUnrelated", dbmd.supportsOrderByUnrelated());
assertTrue("supportsOuterJoins", dbmd.supportsOuterJoins());
assertTrue("supportsResultSetConcurrency", dbmd.supportsResultSetConcurrency(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY));
assertTrue("supportsResultSetConcurrency", dbmd.supportsResultSetConcurrency(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE));
assertTrue("supportsResultSetConcurrency", dbmd.supportsResultSetConcurrency(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY));
assertTrue("supportsResultSetConcurrency", dbmd.supportsResultSetConcurrency(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE + 1));
assertTrue("supportsResultSetConcurrency", dbmd.supportsResultSetConcurrency(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE + 2));
assertTrue("supportsResultSetType", dbmd.supportsResultSetType(ResultSet.TYPE_FORWARD_ONLY));
assertTrue("supportsResultSetType", dbmd.supportsResultSetType(ResultSet.TYPE_SCROLL_INSENSITIVE));
assertTrue("supportsResultSetType", dbmd.supportsResultSetType(ResultSet.TYPE_SCROLL_SENSITIVE));
assertTrue("supportsResultSetType", dbmd.supportsResultSetType(ResultSet.TYPE_SCROLL_SENSITIVE + 1));
assertTrue("supportsSchemasInDataManipulation", dbmd.supportsSchemasInDataManipulation());
assertTrue("supportsSchemasInIndexDefinitions", dbmd.supportsSchemasInIndexDefinitions());
assertTrue("supportsSchemasInProcedureCalls", dbmd.supportsSchemasInProcedureCalls());
assertTrue("supportsSchemasInTableDefinitions", dbmd.supportsSchemasInTableDefinitions());
assertTrue("supportsStoredProcedures", dbmd.supportsStoredProcedures());
assertTrue("supportsSubqueriesInComparisons", dbmd.supportsSubqueriesInComparisons());
assertTrue("supportsSubqueriesInExists", dbmd.supportsSubqueriesInExists());
assertTrue("supportsSubqueriesInIns", dbmd.supportsSubqueriesInIns());
assertTrue("supportsSubqueriesInQuantifieds", dbmd.supportsSubqueriesInQuantifieds());
assertTrue("supportsTableCorrelationNames", dbmd.supportsTableCorrelationNames());
assertTrue("supportsTransactionIsolationLevel", dbmd.supportsTransactionIsolationLevel(Connection.TRANSACTION_READ_COMMITTED));
assertTrue("supportsTransactionIsolationLevel", dbmd.supportsTransactionIsolationLevel(Connection.TRANSACTION_READ_UNCOMMITTED));
assertTrue("supportsTransactionIsolationLevel", dbmd.supportsTransactionIsolationLevel(Connection.TRANSACTION_SERIALIZABLE));
assertTrue("supportsTransactions", dbmd.supportsTransactions());
assertTrue("supportsUnion", dbmd.supportsUnion());
assertTrue("supportsUnionAll", dbmd.supportsUnionAll());
assertFalse("updatesAreDetected", dbmd.updatesAreDetected(ResultSet.TYPE_FORWARD_ONLY));
assertFalse("updatesAreDetected", dbmd.updatesAreDetected(ResultSet.TYPE_SCROLL_INSENSITIVE));
assertFalse("updatesAreDetected", dbmd.updatesAreDetected(ResultSet.TYPE_SCROLL_SENSITIVE));
assertFalse("usesLocalFilePerTable", dbmd.usesLocalFilePerTable());
assertFalse("usesLocalFiles", dbmd.usesLocalFiles());
assertTrue("deletesAreDetected", dbmd.deletesAreDetected(ResultSet.TYPE_SCROLL_SENSITIVE));
assertTrue("othersDeletesAreVisible",dbmd.othersDeletesAreVisible(ResultSet.TYPE_SCROLL_SENSITIVE));
assertTrue("supportsResultSetConcurrency", dbmd.supportsResultSetConcurrency(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY));
assertTrue("supportsResultSetConcurrency", dbmd.supportsResultSetConcurrency(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE));
assertTrue("allProceduresAreCallable", dbmd.allProceduresAreCallable());
assertFalse("othersDeletesAreVisible",dbmd.othersDeletesAreVisible(ResultSet.TYPE_FORWARD_ONLY));
assertFalse("othersInsertsAreVisible",dbmd.othersInsertsAreVisible(ResultSet.TYPE_FORWARD_ONLY));
assertFalse("othersUpdatesAreVisible",dbmd.othersUpdatesAreVisible(ResultSet.TYPE_FORWARD_ONLY));
assertTrue("ownUpdatesAreVisible", dbmd.ownUpdatesAreVisible(ResultSet.TYPE_FORWARD_ONLY));
assertTrue("storesMixedCaseIdentifiers", dbmd.storesMixedCaseIdentifiers());
assertTrue("storesMixedCaseQuotedIdentifiers", dbmd.storesMixedCaseQuotedIdentifiers());
assertTrue("supportsCoreSQLGrammar", dbmd.supportsCoreSQLGrammar());
assertFalse("supportsIntegrityEnhancementFacility", dbmd.supportsIntegrityEnhancementFacility());
assertFalse("supportsMixedCaseIdentifiers", dbmd.supportsMixedCaseIdentifiers());
assertFalse("supportsMixedCaseQuotedIdentifiers", dbmd.supportsMixedCaseQuotedIdentifiers());
assertTrue("supportsPositionedDelete", dbmd.supportsPositionedDelete());
assertTrue("supportsPositionedUpdate", dbmd.supportsPositionedUpdate());
assertFalse("supportsResultSetConcurrency", dbmd.supportsResultSetConcurrency(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE));
assertFalse("supportsResultSetConcurrency", dbmd.supportsResultSetConcurrency(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE + 1));
assertFalse("supportsResultSetConcurrency", dbmd.supportsResultSetConcurrency(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE + 2));
assertTrue("supportsSchemasInPrivilegeDefinitions", dbmd.supportsSchemasInPrivilegeDefinitions());
assertFalse("supportsSelectForUpdate", dbmd.supportsSelectForUpdate());
assertTrue("supportsTransactionIsolationLevel", dbmd.supportsTransactionIsolationLevel(Connection.TRANSACTION_REPEATABLE_READ));
assertTrue("ownDeletesAreVisible", dbmd.ownDeletesAreVisible(ResultSet.TYPE_FORWARD_ONLY));
assertTrue("ownDeletesAreVisible", dbmd.ownDeletesAreVisible(ResultSet.TYPE_SCROLL_INSENSITIVE));
assertTrue("ownDeletesAreVisible", dbmd.ownDeletesAreVisible(ResultSet.TYPE_SCROLL_SENSITIVE));
assertTrue("supportsCatalogsInPrivilegeDefinitions", dbmd.supportsCatalogsInPrivilegeDefinitions());
assertTrue("supportsFullOuterJoins", dbmd.supportsFullOuterJoins());
assertTrue("supportsLikeEscapeClause", dbmd.supportsLikeEscapeClause());
assertTrue("supportsOpenCursorsAcrossCommit", dbmd.supportsOpenCursorsAcrossCommit());
assertTrue("supportsTransactionIsolationLevel", dbmd.supportsTransactionIsolationLevel(Connection.TRANSACTION_NONE));
if (dbmd.getDatabaseProductName().startsWith("Microsoft")) {
assertTrue("allTablesAreSelectable", dbmd.allTablesAreSelectable());
assertFalse("supportsOpenCursorsAcrossRollback", dbmd.supportsOpenCursorsAcrossRollback());
} else {
assertFalse("allTablesAreSelectable", dbmd.allTablesAreSelectable());
assertTrue("supportsOpenCursorsAcrossRollback", dbmd.supportsOpenCursorsAcrossRollback());
}
}
/**
* Test meta data functions that return strings.
* @throws Exception
*/
public void testStringOptions() throws Exception {
DatabaseMetaData dbmd = con.getMetaData();
assertEquals("getCatalogSeparator", ".", dbmd.getCatalogSeparator());
assertEquals("getCatalogTerm","database", dbmd.getCatalogTerm());
assertNotNull("getDatabaseProductName", dbmd.getDatabaseProductName());
assertNotNull("getDatabaseProductVersion", dbmd.getDatabaseProductVersion());
assertNotNull("getDriverName", dbmd.getDriverName());
assertNotNull("getDriverVersion", dbmd.getDriverVersion());
assertEquals("getExtraNameCharacters","$#@", dbmd.getExtraNameCharacters());
assertEquals("getIdentifierQuoteString","\"", dbmd.getIdentifierQuoteString());
assertEquals("getNumericFunctions","abs,acos,asin,atan,atan2,ceiling,cos,cot,degrees,exp,floor,log,log10,mod,pi,power,radians,rand,round,sign,sin,sqrt,tan", dbmd.getNumericFunctions());
assertEquals("getProcedureTerm","stored procedure", dbmd.getProcedureTerm());
assertEquals("getSchemaTerm","owner", dbmd.getSchemaTerm());
assertEquals("getSearchStringEscape","\\", dbmd.getSearchStringEscape());
assertEquals("getSQLKeywords","ARITH_OVERFLOW,BREAK,BROWSE,BULK,CHAR_CONVERT,CHECKPOINT,CLUSTERED,COMPUTE,CONFIRM,CONTROLROW,DATA_PGS,DATABASE,DBCC,DISK,DUMMY,DUMP,ENDTRAN,ERRLVL,ERRORDATA,ERROREXIT,EXIT,FILLFACTOR,HOLDLOCK,IDENTITY_INSERT,IF,INDEX,KILL,LINENO,LOAD,MAX_ROWS_PER_PAGE,MIRROR,MIRROREXIT,NOHOLDLOCK,NONCLUSTERED,NUMERIC_TRUNCATION,OFF,OFFSETS,ONCE,ONLINE,OVER,PARTITION,PERM,PERMANENT,PLAN,PRINT,PROC,PROCESSEXIT,RAISERROR,READ,READTEXT,RECONFIGURE,REPLACE,RESERVED_PGS,RETURN,ROLE,ROWCNT,ROWCOUNT,RULE,SAVE,SETUSER,SHARED,SHUTDOWN,SOME,STATISTICS,STRIPE,SYB_IDENTITY,SYB_RESTREE,SYB_TERMINATE,TEMP,TEXTSIZE,TRAN,TRIGGER,TRUNCATE,TSEQUAL,UNPARTITION,USE,USED_PGS,USER_OPTION,WAITFOR,WHILE,WRITETEXT", dbmd.getSQLKeywords());
assertEquals("getSystemFunctions","database,ifnull,user,convert", dbmd.getSystemFunctions());
assertEquals("getTimeDateFunctions","curdate,curtime,dayname,dayofmonth,dayofweek,dayofyear,hour,minute,month,monthname,now,quarter,timestampadd,timestampdiff,second,week,year", dbmd.getTimeDateFunctions());
assertNotNull("getURL", dbmd.getURL());
assertNotNull("getUserName", dbmd.getUserName());
if (dbmd.getDatabaseProductName().startsWith("Microsoft")) {
assertEquals("getStringFunctions","ascii,char,concat,difference,insert,lcase,left,length,locate,ltrim,repeat,replace,right,rtrim,soundex,space,substring,ucase", dbmd.getStringFunctions());
} else {
assertEquals("getStringFunctions","ascii,char,concat,difference,insert,lcase,length,ltrim,repeat,right,rtrim,soundex,space,substring,ucase", dbmd.getStringFunctions());
}
}
/**
* Test meta data function that return integer values.
* @throws Exception
*/
public void testIntOptions() throws Exception {
DatabaseMetaData dbmd = con.getMetaData();
int sysnamelen = (dbmd.getDatabaseProductName().startsWith("Microsoft"))? 128: 30;
assertEquals("getDefaultTransactionIsolation",Connection.TRANSACTION_READ_COMMITTED, dbmd.getDefaultTransactionIsolation());
assertTrue("getDriverMajorVersion", dbmd.getDriverMajorVersion() >= 0);
assertTrue("getDriverMinorVersion", dbmd.getDriverMinorVersion() >=0);
assertEquals("getMaxBinaryLiteralLength", 131072, dbmd.getMaxBinaryLiteralLength());
assertEquals("getMaxCatalogNameLength",sysnamelen, dbmd.getMaxCatalogNameLength());
assertEquals("getMaxCharLiteralLength", 131072, dbmd.getMaxCharLiteralLength());
assertEquals("getMaxColumnNameLength",sysnamelen, dbmd.getMaxColumnNameLength());
assertEquals("getMaxColumnsInIndex",16, dbmd.getMaxColumnsInIndex());
assertEquals("getMaxColumnsInSelect",4096, dbmd.getMaxColumnsInSelect());
assertEquals("getMaxConnections",32767, dbmd.getMaxConnections());
assertEquals("getMaxCursorNameLength",sysnamelen, dbmd.getMaxCursorNameLength());
assertEquals("getMaxProcedureNameLength",sysnamelen, dbmd.getMaxProcedureNameLength());
assertEquals("getMaxSchemaNameLength",sysnamelen, dbmd.getMaxSchemaNameLength());
assertEquals("getMaxStatementLength",0, dbmd.getMaxStatementLength());
assertEquals("getMaxStatements", 0, dbmd.getMaxStatements());
assertEquals("getMaxTableNameLength",sysnamelen, dbmd.getMaxTableNameLength());
assertEquals("getMaxUserNameLength",sysnamelen, dbmd.getMaxUserNameLength());
if (dbmd.getDatabaseProductName().startsWith("Microsoft")) {
assertEquals("getMaxColumnsInGroupBy",0, dbmd.getMaxColumnsInGroupBy());
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -