Source Code Cross Referenced for DatabaseMetaDataTest.java in  » Database-JDBC-Connection-Pool » jTDS » net » sourceforge » jtds » test » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Database JDBC Connection Pool » jTDS » net.sourceforge.jtds.test 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        // jTDS JDBC Driver for Microsoft SQL Server and Sybase
0002:        // Copyright (C) 2004 The jTDS Project
0003:        //
0004:        // This library is free software; you can redistribute it and/or
0005:        // modify it under the terms of the GNU Lesser General Public
0006:        // License as published by the Free Software Foundation; either
0007:        // version 2.1 of the License, or (at your option) any later version.
0008:        //
0009:        // This library is distributed in the hope that it will be useful,
0010:        // but WITHOUT ANY WARRANTY; without even the implied warranty of
0011:        // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0012:        // Lesser General Public License for more details.
0013:        //
0014:        // You should have received a copy of the GNU Lesser General Public
0015:        // License along with this library; if not, write to the Free Software
0016:        // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
0017:        //
0018:        package net.sourceforge.jtds.test;
0019:
0020:        import java.sql.*;
0021:        import java.util.Properties;
0022:
0023:        /**
0024:         * Test <code>DatabaseMetaData</code>.
0025:         *
0026:         * @version $Id: DatabaseMetaDataTest.java,v 1.17 2005/11/23 16:36:20 alin_sinpalean Exp $
0027:         */
0028:        public class DatabaseMetaDataTest extends MetaDataTestCase {
0029:
0030:            public DatabaseMetaDataTest(String name) {
0031:                super (name);
0032:            }
0033:
0034:            /**
0035:             * Test meta data functions that return boolean values.
0036:             * @throws Exception
0037:             */
0038:            public void testBooleanOptions() throws Exception {
0039:                DatabaseMetaData dbmd = con.getMetaData();
0040:                assertFalse("dataDefinitionCausesTransactionCommit", dbmd
0041:                        .dataDefinitionCausesTransactionCommit());
0042:                assertFalse("dataDefinitionIgnoredInTransactions", dbmd
0043:                        .dataDefinitionIgnoredInTransactions());
0044:                assertTrue("deletesAreDetected", dbmd
0045:                        .deletesAreDetected(ResultSet.TYPE_FORWARD_ONLY));
0046:                assertTrue("deletesAreDetected", dbmd
0047:                        .deletesAreDetected(ResultSet.TYPE_SCROLL_INSENSITIVE));
0048:                assertFalse("doesMaxRowSizeIncludeBlobs", dbmd
0049:                        .doesMaxRowSizeIncludeBlobs());
0050:                assertFalse("insertsAreDetected", dbmd
0051:                        .insertsAreDetected(ResultSet.TYPE_FORWARD_ONLY));
0052:                assertFalse("insertsAreDetected", dbmd
0053:                        .insertsAreDetected(ResultSet.TYPE_SCROLL_INSENSITIVE));
0054:                assertFalse("insertsAreDetected", dbmd
0055:                        .insertsAreDetected(ResultSet.TYPE_SCROLL_SENSITIVE));
0056:                assertTrue("isCatalogAtStart", dbmd.isCatalogAtStart());
0057:                assertFalse("isReadOnly", dbmd.isReadOnly());
0058:                assertTrue("nullPlusNonNullIsNull", dbmd
0059:                        .nullPlusNonNullIsNull());
0060:                assertFalse("nullsAreSortedAtEnd", dbmd.nullsAreSortedAtEnd());
0061:                assertFalse("nullsAreSortedAtStart", dbmd
0062:                        .nullsAreSortedAtStart());
0063:                assertFalse("nullsAreSortedHigh", dbmd.nullsAreSortedHigh());
0064:                assertTrue("nullsAreSortedLow", dbmd.nullsAreSortedLow());
0065:                assertFalse(
0066:                        "othersDeletesAreVisible",
0067:                        dbmd
0068:                                .othersDeletesAreVisible(ResultSet.TYPE_SCROLL_INSENSITIVE));
0069:                assertFalse(
0070:                        "othersInsertsAreVisible",
0071:                        dbmd
0072:                                .othersInsertsAreVisible(ResultSet.TYPE_SCROLL_INSENSITIVE));
0073:                assertFalse(
0074:                        "othersInsertsAreVisible",
0075:                        dbmd
0076:                                .othersInsertsAreVisible(ResultSet.TYPE_SCROLL_SENSITIVE));
0077:                assertTrue(
0078:                        "othersInsertsAreVisible",
0079:                        dbmd
0080:                                .othersInsertsAreVisible(ResultSet.TYPE_SCROLL_SENSITIVE + 1));
0081:                assertFalse(
0082:                        "othersUpdatesAreVisible",
0083:                        dbmd
0084:                                .othersUpdatesAreVisible(ResultSet.TYPE_SCROLL_INSENSITIVE));
0085:                assertTrue(
0086:                        "othersUpdatesAreVisible",
0087:                        dbmd
0088:                                .othersUpdatesAreVisible(ResultSet.TYPE_SCROLL_SENSITIVE));
0089:                assertTrue("ownInsertsAreVisible", dbmd
0090:                        .ownInsertsAreVisible(ResultSet.TYPE_FORWARD_ONLY));
0091:                assertTrue(
0092:                        "ownInsertsAreVisible",
0093:                        dbmd
0094:                                .ownInsertsAreVisible(ResultSet.TYPE_SCROLL_INSENSITIVE));
0095:                assertTrue("ownInsertsAreVisible", dbmd
0096:                        .ownInsertsAreVisible(ResultSet.TYPE_SCROLL_SENSITIVE));
0097:                assertTrue(
0098:                        "ownUpdatesAreVisible",
0099:                        dbmd
0100:                                .ownUpdatesAreVisible(ResultSet.TYPE_SCROLL_INSENSITIVE));
0101:                assertTrue("ownUpdatesAreVisible", dbmd
0102:                        .ownUpdatesAreVisible(ResultSet.TYPE_SCROLL_SENSITIVE));
0103:                assertFalse("storesLowerCaseIdentifiers", dbmd
0104:                        .storesLowerCaseIdentifiers());
0105:                assertFalse("storesLowerCaseQuotedIdentifiers", dbmd
0106:                        .storesLowerCaseQuotedIdentifiers());
0107:                assertFalse("storesUpperCaseIdentifiers", dbmd
0108:                        .storesUpperCaseIdentifiers());
0109:                assertFalse("storesUpperCaseQuotedIdentifiers", dbmd
0110:                        .storesUpperCaseQuotedIdentifiers());
0111:                assertTrue("supportsAlterTableWithAddColumn", dbmd
0112:                        .supportsAlterTableWithAddColumn());
0113:                assertTrue("supportsAlterTableWithDropColumn", dbmd
0114:                        .supportsAlterTableWithDropColumn());
0115:                assertTrue("supportsANSI92EntryLevelSQL", dbmd
0116:                        .supportsANSI92EntryLevelSQL());
0117:                assertFalse("supportsANSI92FullSQL", dbmd
0118:                        .supportsANSI92FullSQL());
0119:                assertFalse("supportsANSI92IntermediateSQL", dbmd
0120:                        .supportsANSI92IntermediateSQL());
0121:                assertTrue("supportsBatchUpdates", dbmd.supportsBatchUpdates());
0122:                assertTrue("supportsCatalogsInDataManipulation", dbmd
0123:                        .supportsCatalogsInDataManipulation());
0124:                assertTrue("supportsCatalogsInIndexDefinitions", dbmd
0125:                        .supportsCatalogsInIndexDefinitions());
0126:                assertTrue("supportsCatalogsInProcedureCalls", dbmd
0127:                        .supportsCatalogsInProcedureCalls());
0128:                assertTrue("supportsCatalogsInTableDefinitions", dbmd
0129:                        .supportsCatalogsInTableDefinitions());
0130:                assertTrue("supportsColumnAliasing", dbmd
0131:                        .supportsColumnAliasing());
0132:                assertTrue("supportsConvert", dbmd.supportsConvert());
0133:                assertTrue("supportsCorrelatedSubqueries", dbmd
0134:                        .supportsCorrelatedSubqueries());
0135:                assertTrue(
0136:                        "supportsDataDefinitionAndDataManipulationTransactions",
0137:                        dbmd
0138:                                .supportsDataDefinitionAndDataManipulationTransactions());
0139:                assertFalse("supportsDataManipulationTransactionsOnly", dbmd
0140:                        .supportsDataManipulationTransactionsOnly());
0141:                assertFalse("supportsDifferentTableCorrelationNames", dbmd
0142:                        .supportsDifferentTableCorrelationNames());
0143:                assertTrue("supportsExpressionsInOrderBy", dbmd
0144:                        .supportsExpressionsInOrderBy());
0145:                assertFalse("supportsExtendedSQLGrammar", dbmd
0146:                        .supportsExtendedSQLGrammar());
0147:                assertTrue("supportsGroupBy", dbmd.supportsGroupBy());
0148:                assertTrue("supportsGroupByBeyondSelect", dbmd
0149:                        .supportsGroupByBeyondSelect());
0150:                assertTrue("supportsGroupByUnrelated", dbmd
0151:                        .supportsGroupByUnrelated());
0152:                assertTrue("supportsLimitedOuterJoins", dbmd
0153:                        .supportsLimitedOuterJoins());
0154:                assertTrue("supportsMinimumSQLGrammar", dbmd
0155:                        .supportsMinimumSQLGrammar());
0156:                assertTrue("supportsMultipleResultSets", dbmd
0157:                        .supportsMultipleResultSets());
0158:                assertTrue("supportsMultipleTransactions", dbmd
0159:                        .supportsMultipleTransactions());
0160:                assertTrue("supportsNonNullableColumns", dbmd
0161:                        .supportsNonNullableColumns());
0162:                assertTrue("supportsOpenStatementsAcrossCommit", dbmd
0163:                        .supportsOpenStatementsAcrossCommit());
0164:                assertTrue("supportsOpenStatementsAcrossRollback", dbmd
0165:                        .supportsOpenStatementsAcrossRollback());
0166:                assertTrue("supportsOrderByUnrelated", dbmd
0167:                        .supportsOrderByUnrelated());
0168:                assertTrue("supportsOuterJoins", dbmd.supportsOuterJoins());
0169:                assertTrue("supportsResultSetConcurrency", dbmd
0170:                        .supportsResultSetConcurrency(
0171:                                ResultSet.TYPE_FORWARD_ONLY,
0172:                                ResultSet.CONCUR_READ_ONLY));
0173:                assertTrue("supportsResultSetConcurrency", dbmd
0174:                        .supportsResultSetConcurrency(
0175:                                ResultSet.TYPE_FORWARD_ONLY,
0176:                                ResultSet.CONCUR_UPDATABLE));
0177:                assertTrue("supportsResultSetConcurrency", dbmd
0178:                        .supportsResultSetConcurrency(
0179:                                ResultSet.TYPE_SCROLL_INSENSITIVE,
0180:                                ResultSet.CONCUR_READ_ONLY));
0181:                assertTrue("supportsResultSetConcurrency", dbmd
0182:                        .supportsResultSetConcurrency(
0183:                                ResultSet.TYPE_FORWARD_ONLY,
0184:                                ResultSet.CONCUR_UPDATABLE + 1));
0185:                assertTrue("supportsResultSetConcurrency", dbmd
0186:                        .supportsResultSetConcurrency(
0187:                                ResultSet.TYPE_SCROLL_SENSITIVE,
0188:                                ResultSet.CONCUR_UPDATABLE + 2));
0189:                assertTrue("supportsResultSetType", dbmd
0190:                        .supportsResultSetType(ResultSet.TYPE_FORWARD_ONLY));
0191:                assertTrue(
0192:                        "supportsResultSetType",
0193:                        dbmd
0194:                                .supportsResultSetType(ResultSet.TYPE_SCROLL_INSENSITIVE));
0195:                assertTrue("supportsResultSetType", dbmd
0196:                        .supportsResultSetType(ResultSet.TYPE_SCROLL_SENSITIVE));
0197:                assertTrue(
0198:                        "supportsResultSetType",
0199:                        dbmd
0200:                                .supportsResultSetType(ResultSet.TYPE_SCROLL_SENSITIVE + 1));
0201:                assertTrue("supportsSchemasInDataManipulation", dbmd
0202:                        .supportsSchemasInDataManipulation());
0203:                assertTrue("supportsSchemasInIndexDefinitions", dbmd
0204:                        .supportsSchemasInIndexDefinitions());
0205:                assertTrue("supportsSchemasInProcedureCalls", dbmd
0206:                        .supportsSchemasInProcedureCalls());
0207:                assertTrue("supportsSchemasInTableDefinitions", dbmd
0208:                        .supportsSchemasInTableDefinitions());
0209:                assertTrue("supportsStoredProcedures", dbmd
0210:                        .supportsStoredProcedures());
0211:                assertTrue("supportsSubqueriesInComparisons", dbmd
0212:                        .supportsSubqueriesInComparisons());
0213:                assertTrue("supportsSubqueriesInExists", dbmd
0214:                        .supportsSubqueriesInExists());
0215:                assertTrue("supportsSubqueriesInIns", dbmd
0216:                        .supportsSubqueriesInIns());
0217:                assertTrue("supportsSubqueriesInQuantifieds", dbmd
0218:                        .supportsSubqueriesInQuantifieds());
0219:                assertTrue("supportsTableCorrelationNames", dbmd
0220:                        .supportsTableCorrelationNames());
0221:                assertTrue(
0222:                        "supportsTransactionIsolationLevel",
0223:                        dbmd
0224:                                .supportsTransactionIsolationLevel(Connection.TRANSACTION_READ_COMMITTED));
0225:                assertTrue(
0226:                        "supportsTransactionIsolationLevel",
0227:                        dbmd
0228:                                .supportsTransactionIsolationLevel(Connection.TRANSACTION_READ_UNCOMMITTED));
0229:                assertTrue(
0230:                        "supportsTransactionIsolationLevel",
0231:                        dbmd
0232:                                .supportsTransactionIsolationLevel(Connection.TRANSACTION_SERIALIZABLE));
0233:                assertTrue("supportsTransactions", dbmd.supportsTransactions());
0234:                assertTrue("supportsUnion", dbmd.supportsUnion());
0235:                assertTrue("supportsUnionAll", dbmd.supportsUnionAll());
0236:                assertFalse("updatesAreDetected", dbmd
0237:                        .updatesAreDetected(ResultSet.TYPE_FORWARD_ONLY));
0238:                assertFalse("updatesAreDetected", dbmd
0239:                        .updatesAreDetected(ResultSet.TYPE_SCROLL_INSENSITIVE));
0240:                assertFalse("updatesAreDetected", dbmd
0241:                        .updatesAreDetected(ResultSet.TYPE_SCROLL_SENSITIVE));
0242:                assertFalse("usesLocalFilePerTable", dbmd
0243:                        .usesLocalFilePerTable());
0244:                assertFalse("usesLocalFiles", dbmd.usesLocalFiles());
0245:                assertTrue("deletesAreDetected", dbmd
0246:                        .deletesAreDetected(ResultSet.TYPE_SCROLL_SENSITIVE));
0247:                assertTrue(
0248:                        "othersDeletesAreVisible",
0249:                        dbmd
0250:                                .othersDeletesAreVisible(ResultSet.TYPE_SCROLL_SENSITIVE));
0251:                assertTrue("supportsResultSetConcurrency", dbmd
0252:                        .supportsResultSetConcurrency(
0253:                                ResultSet.TYPE_SCROLL_SENSITIVE,
0254:                                ResultSet.CONCUR_READ_ONLY));
0255:                assertTrue("supportsResultSetConcurrency", dbmd
0256:                        .supportsResultSetConcurrency(
0257:                                ResultSet.TYPE_SCROLL_SENSITIVE,
0258:                                ResultSet.CONCUR_UPDATABLE));
0259:                assertTrue("allProceduresAreCallable", dbmd
0260:                        .allProceduresAreCallable());
0261:                assertFalse("othersDeletesAreVisible", dbmd
0262:                        .othersDeletesAreVisible(ResultSet.TYPE_FORWARD_ONLY));
0263:                assertFalse("othersInsertsAreVisible", dbmd
0264:                        .othersInsertsAreVisible(ResultSet.TYPE_FORWARD_ONLY));
0265:                assertFalse("othersUpdatesAreVisible", dbmd
0266:                        .othersUpdatesAreVisible(ResultSet.TYPE_FORWARD_ONLY));
0267:                assertTrue("ownUpdatesAreVisible", dbmd
0268:                        .ownUpdatesAreVisible(ResultSet.TYPE_FORWARD_ONLY));
0269:                assertTrue("storesMixedCaseIdentifiers", dbmd
0270:                        .storesMixedCaseIdentifiers());
0271:                assertTrue("storesMixedCaseQuotedIdentifiers", dbmd
0272:                        .storesMixedCaseQuotedIdentifiers());
0273:                assertTrue("supportsCoreSQLGrammar", dbmd
0274:                        .supportsCoreSQLGrammar());
0275:                assertFalse("supportsIntegrityEnhancementFacility", dbmd
0276:                        .supportsIntegrityEnhancementFacility());
0277:                assertFalse("supportsMixedCaseIdentifiers", dbmd
0278:                        .supportsMixedCaseIdentifiers());
0279:                assertFalse("supportsMixedCaseQuotedIdentifiers", dbmd
0280:                        .supportsMixedCaseQuotedIdentifiers());
0281:                assertTrue("supportsPositionedDelete", dbmd
0282:                        .supportsPositionedDelete());
0283:                assertTrue("supportsPositionedUpdate", dbmd
0284:                        .supportsPositionedUpdate());
0285:                assertFalse("supportsResultSetConcurrency", dbmd
0286:                        .supportsResultSetConcurrency(
0287:                                ResultSet.TYPE_SCROLL_INSENSITIVE,
0288:                                ResultSet.CONCUR_UPDATABLE));
0289:                assertFalse("supportsResultSetConcurrency", dbmd
0290:                        .supportsResultSetConcurrency(
0291:                                ResultSet.TYPE_SCROLL_INSENSITIVE,
0292:                                ResultSet.CONCUR_UPDATABLE + 1));
0293:                assertFalse("supportsResultSetConcurrency", dbmd
0294:                        .supportsResultSetConcurrency(
0295:                                ResultSet.TYPE_SCROLL_INSENSITIVE,
0296:                                ResultSet.CONCUR_UPDATABLE + 2));
0297:                assertTrue("supportsSchemasInPrivilegeDefinitions", dbmd
0298:                        .supportsSchemasInPrivilegeDefinitions());
0299:                assertFalse("supportsSelectForUpdate", dbmd
0300:                        .supportsSelectForUpdate());
0301:                assertTrue(
0302:                        "supportsTransactionIsolationLevel",
0303:                        dbmd
0304:                                .supportsTransactionIsolationLevel(Connection.TRANSACTION_REPEATABLE_READ));
0305:
0306:                assertTrue("ownDeletesAreVisible", dbmd
0307:                        .ownDeletesAreVisible(ResultSet.TYPE_FORWARD_ONLY));
0308:                assertTrue(
0309:                        "ownDeletesAreVisible",
0310:                        dbmd
0311:                                .ownDeletesAreVisible(ResultSet.TYPE_SCROLL_INSENSITIVE));
0312:                assertTrue("ownDeletesAreVisible", dbmd
0313:                        .ownDeletesAreVisible(ResultSet.TYPE_SCROLL_SENSITIVE));
0314:                assertTrue("supportsCatalogsInPrivilegeDefinitions", dbmd
0315:                        .supportsCatalogsInPrivilegeDefinitions());
0316:                assertTrue("supportsFullOuterJoins", dbmd
0317:                        .supportsFullOuterJoins());
0318:                assertTrue("supportsLikeEscapeClause", dbmd
0319:                        .supportsLikeEscapeClause());
0320:                assertTrue("supportsOpenCursorsAcrossCommit", dbmd
0321:                        .supportsOpenCursorsAcrossCommit());
0322:                assertFalse(
0323:                        "supportsTransactionIsolationLevel",
0324:                        dbmd
0325:                                .supportsTransactionIsolationLevel(Connection.TRANSACTION_NONE));
0326:
0327:                if (dbmd.getDatabaseProductName().startsWith("Microsoft")) {
0328:                    assertTrue("allTablesAreSelectable", dbmd
0329:                            .allTablesAreSelectable());
0330:                    assertFalse("supportsOpenCursorsAcrossRollback", dbmd
0331:                            .supportsOpenCursorsAcrossRollback());
0332:                } else {
0333:                    assertFalse("allTablesAreSelectable", dbmd
0334:                            .allTablesAreSelectable());
0335:                    assertTrue("supportsOpenCursorsAcrossRollback", dbmd
0336:                            .supportsOpenCursorsAcrossRollback());
0337:                }
0338:            }
0339:
0340:            /**
0341:             * Test meta data functions that return strings.
0342:             * @throws Exception
0343:             */
0344:            public void testStringOptions() throws Exception {
0345:                DatabaseMetaData dbmd = con.getMetaData();
0346:                assertEquals("getCatalogSeparator", ".", dbmd
0347:                        .getCatalogSeparator());
0348:                assertEquals("getCatalogTerm", "database", dbmd
0349:                        .getCatalogTerm());
0350:                assertNotNull("getDatabaseProductName", dbmd
0351:                        .getDatabaseProductName());
0352:                assertNotNull("getDatabaseProductVersion", dbmd
0353:                        .getDatabaseProductVersion());
0354:                assertNotNull("getDriverName", dbmd.getDriverName());
0355:                assertNotNull("getDriverVersion", dbmd.getDriverVersion());
0356:                assertEquals("getExtraNameCharacters", "$#@", dbmd
0357:                        .getExtraNameCharacters());
0358:                assertEquals("getIdentifierQuoteString", "\"", dbmd
0359:                        .getIdentifierQuoteString());
0360:                assertEquals(
0361:                        "getNumericFunctions",
0362:                        "abs,acos,asin,atan,atan2,ceiling,cos,cot,degrees,exp,floor,log,log10,mod,pi,power,radians,rand,round,sign,sin,sqrt,tan",
0363:                        dbmd.getNumericFunctions());
0364:                assertEquals("getProcedureTerm", "stored procedure", dbmd
0365:                        .getProcedureTerm());
0366:                assertEquals("getSchemaTerm", "owner", dbmd.getSchemaTerm());
0367:                assertEquals("getSearchStringEscape", "\\", dbmd
0368:                        .getSearchStringEscape());
0369:                assertEquals(
0370:                        "getSQLKeywords",
0371:                        "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",
0372:                        dbmd.getSQLKeywords());
0373:                assertEquals("getSystemFunctions",
0374:                        "database,ifnull,user,convert", dbmd
0375:                                .getSystemFunctions());
0376:                assertEquals(
0377:                        "getTimeDateFunctions",
0378:                        "curdate,curtime,dayname,dayofmonth,dayofweek,dayofyear,hour,minute,month,monthname,now,quarter,timestampadd,timestampdiff,second,week,year",
0379:                        dbmd.getTimeDateFunctions());
0380:                assertNotNull("getURL", dbmd.getURL());
0381:                assertNotNull("getUserName", dbmd.getUserName());
0382:                if (dbmd.getDatabaseProductName().startsWith("Microsoft")) {
0383:                    assertEquals(
0384:                            "getStringFunctions",
0385:                            "ascii,char,concat,difference,insert,lcase,left,length,locate,ltrim,repeat,replace,right,rtrim,soundex,space,substring,ucase",
0386:                            dbmd.getStringFunctions());
0387:                } else {
0388:                    assertEquals(
0389:                            "getStringFunctions",
0390:                            "ascii,char,concat,difference,insert,lcase,length,ltrim,repeat,right,rtrim,soundex,space,substring,ucase",
0391:                            dbmd.getStringFunctions());
0392:                }
0393:            }
0394:
0395:            /**
0396:             * Test meta data function that return integer values.
0397:             * @throws Exception
0398:             */
0399:            public void testIntOptions() throws Exception {
0400:                DatabaseMetaData dbmd = con.getMetaData();
0401:                int sysnamelen = (dbmd.getDatabaseProductName()
0402:                        .startsWith("Microsoft")) ? 128 : 30;
0403:                assertEquals("getDefaultTransactionIsolation",
0404:                        Connection.TRANSACTION_READ_COMMITTED, dbmd
0405:                                .getDefaultTransactionIsolation());
0406:                assertTrue("getDriverMajorVersion", dbmd
0407:                        .getDriverMajorVersion() >= 0);
0408:                assertTrue("getDriverMinorVersion", dbmd
0409:                        .getDriverMinorVersion() >= 0);
0410:                assertEquals("getMaxBinaryLiteralLength", 131072, dbmd
0411:                        .getMaxBinaryLiteralLength());
0412:                assertEquals("getMaxCatalogNameLength", sysnamelen, dbmd
0413:                        .getMaxCatalogNameLength());
0414:                assertEquals("getMaxCharLiteralLength", 131072, dbmd
0415:                        .getMaxCharLiteralLength());
0416:                assertEquals("getMaxColumnNameLength", sysnamelen, dbmd
0417:                        .getMaxColumnNameLength());
0418:                assertEquals("getMaxColumnsInIndex", 16, dbmd
0419:                        .getMaxColumnsInIndex());
0420:                assertEquals("getMaxColumnsInSelect", 4096, dbmd
0421:                        .getMaxColumnsInSelect());
0422:                assertEquals("getMaxConnections", 32767, dbmd
0423:                        .getMaxConnections());
0424:                assertEquals("getMaxCursorNameLength", sysnamelen, dbmd
0425:                        .getMaxCursorNameLength());
0426:                assertEquals("getMaxProcedureNameLength", sysnamelen, dbmd
0427:                        .getMaxProcedureNameLength());
0428:                assertEquals("getMaxSchemaNameLength", sysnamelen, dbmd
0429:                        .getMaxSchemaNameLength());
0430:                assertEquals("getMaxStatementLength", 0, dbmd
0431:                        .getMaxStatementLength());
0432:                assertEquals("getMaxStatements", 0, dbmd.getMaxStatements());
0433:                assertEquals("getMaxTableNameLength", sysnamelen, dbmd
0434:                        .getMaxTableNameLength());
0435:                assertEquals("getMaxUserNameLength", sysnamelen, dbmd
0436:                        .getMaxUserNameLength());
0437:                if (dbmd.getDatabaseProductName().startsWith("Microsoft")) {
0438:                    assertEquals("getMaxColumnsInGroupBy", 0, dbmd
0439:                            .getMaxColumnsInGroupBy());
0440:                    assertEquals("getMaxColumnsInOrderBy", 0, dbmd
0441:                            .getMaxColumnsInOrderBy());
0442:                    assertEquals("getMaxColumnsInTable", 1024, dbmd
0443:                            .getMaxColumnsInTable());
0444:                    assertEquals("getMaxIndexLength", 900, dbmd
0445:                            .getMaxIndexLength());
0446:                    assertEquals("getMaxRowSize", 8060, dbmd.getMaxRowSize());
0447:                    assertEquals("getMaxTablesInSelect", 256, dbmd
0448:                            .getMaxTablesInSelect());
0449:                } else {
0450:                    assertEquals("getMaxColumnsInGroupBy", 16, dbmd
0451:                            .getMaxColumnsInGroupBy());
0452:                    assertEquals("getMaxColumnsInOrderBy", 16, dbmd
0453:                            .getMaxColumnsInOrderBy());
0454:                    assertEquals("getMaxColumnsInTable", 250, dbmd
0455:                            .getMaxColumnsInTable());
0456:                    assertEquals("getMaxIndexLength", 255, dbmd
0457:                            .getMaxIndexLength());
0458:                    assertEquals("getMaxRowSize", 1962, dbmd.getMaxRowSize());
0459:                    assertEquals("getMaxTablesInSelect", 16, dbmd
0460:                            .getMaxTablesInSelect());
0461:                }
0462:            }
0463:
0464:            /**
0465:             * Test meta data functions that return result sets.
0466:             * @throws Exception
0467:             */
0468:            public void testResultSets() throws Exception {
0469:                try {
0470:                    DatabaseMetaData dbmd = con.getMetaData();
0471:                    ResultSet rs;
0472:                    Statement stmt = con.createStatement();
0473:                    dropTable("jTDS_META2");
0474:                    dropTable("jTDS_META");
0475:                    dropProcedure("jtds_spmeta");
0476:                    //
0477:                    // Create test data
0478:                    //
0479:                    stmt
0480:                            .execute("CREATE PROC jtds_spmeta @p1 int, @p2 varchar(30) output AS SELECT @p2 = 'test'");
0481:                    stmt
0482:                            .execute("CREATE TABLE jTDS_META (id int NOT NULL primary key , data nvarchar(255) NULL, ts timestamp)");
0483:                    stmt
0484:                            .execute("CREATE TABLE jTDS_META2 (id int NOT NULL, data2 varchar(255) NULL "
0485:                                    + ",  FOREIGN KEY (id) REFERENCES jTDS_META(id)) ");
0486:                    //
0487:                    rs = dbmd.getBestRowIdentifier(null, null, "jTDS_META",
0488:                            DatabaseMetaData.bestRowUnknown, true);
0489:                    assertTrue(checkColumnNames(rs, new String[] { "SCOPE",
0490:                            "COLUMN_NAME", "DATA_TYPE", "TYPE_NAME",
0491:                            "COLUMN_SIZE", "BUFFER_LENGTH", "DECIMAL_DIGITS",
0492:                            "PSEUDO_COLUMN" }));
0493:                    assertTrue(rs.next());
0494:                    assertEquals("id", rs.getString(2));
0495:                    //
0496:                    rs = dbmd.getCatalogs();
0497:                    assertTrue(checkColumnNames(rs,
0498:                            new String[] { "TABLE_CAT" }));
0499:                    boolean fail = true;
0500:                    while (rs.next()) {
0501:                        if (rs.getString(1).equalsIgnoreCase("master")) {
0502:                            fail = false;
0503:                            break;
0504:                        }
0505:                    }
0506:                    assertTrue(!fail);
0507:                    //
0508:                    rs = dbmd
0509:                            .getColumnPrivileges(null, null, "jTDS_META", "id");
0510:                    assertTrue(checkColumnNames(rs, new String[] { "TABLE_CAT",
0511:                            "TABLE_SCHEM", "TABLE_NAME", "COLUMN_NAME",
0512:                            "GRANTOR", "GRANTEE", "PRIVILEGE", "IS_GRANTABLE" }));
0513:                    assertTrue(rs.next());
0514:                    assertTrue(rs.getString(7).equals("INSERT")
0515:                            || rs.getString(7).equals("UPDATE")
0516:                            || rs.getString(7).equals("DELETE")
0517:                            || rs.getString(7).equals("SELECT"));
0518:                    //
0519:                    rs = dbmd.getColumns(null, null, "jTDS_META", "%");
0520:                    assertTrue(checkColumnNames(rs, new String[] { "TABLE_CAT",
0521:                            "TABLE_SCHEM", "TABLE_NAME", "COLUMN_NAME",
0522:                            "DATA_TYPE", "TYPE_NAME", "COLUMN_SIZE",
0523:                            "BUFFER_LENGTH", "DECIMAL_DIGITS",
0524:                            "NUM_PREC_RADIX", "NULLABLE", "REMARKS",
0525:                            "COLUMN_DEF", "SQL_DATA_TYPE", "SQL_DATETIME_SUB",
0526:                            "CHAR_OCTET_LENGTH", "ORDINAL_POSITION",
0527:                            "IS_NULLABLE", "SCOPE_CATALOG", "SCOPE_SCHEMA",
0528:                            "SCOPE_TABLE", "SOURCE_DATA_TYPE" }));
0529:                    assertTrue(rs.next());
0530:                    assertEquals("id", rs.getString(4));
0531:                    assertEquals(java.sql.Types.INTEGER, rs.getInt(5));
0532:                    assertTrue(rs.next());
0533:                    assertEquals("data", rs.getString(4));
0534:                    assertEquals(java.sql.Types.VARCHAR, rs.getInt(5));
0535:                    //
0536:                    rs = dbmd.getCrossReference(null, null, "jTDS_META", null,
0537:                            null, "jTDS_META2");
0538:                    assertTrue(checkColumnNames(rs, new String[] {
0539:                            "PKTABLE_CAT", "PKTABLE_SCHEM", "PKTABLE_NAME",
0540:                            "PKCOLUMN_NAME", "FKTABLE_CAT", "FKTABLE_SCHEM",
0541:                            "FKTABLE_NAME", "FKCOLUMN_NAME", "KEY_SEQ",
0542:                            "UPDATE_RULE", "DELETE_RULE", "FK_NAME", "PK_NAME",
0543:                            "DEFERRABILITY" }));
0544:                    assertTrue(rs.next());
0545:                    assertEquals("id", rs.getString(4));
0546:                    //
0547:                    rs = dbmd.getExportedKeys(null, null, "jTDS_META");
0548:                    assertTrue(checkColumnNames(rs, new String[] {
0549:                            "PKTABLE_CAT", "PKTABLE_SCHEM", "PKTABLE_NAME",
0550:                            "PKCOLUMN_NAME", "FKTABLE_CAT", "FKTABLE_SCHEM",
0551:                            "FKTABLE_NAME", "FKCOLUMN_NAME", "KEY_SEQ",
0552:                            "UPDATE_RULE", "DELETE_RULE", "FK_NAME", "PK_NAME",
0553:                            "DEFERRABILITY" }));
0554:                    assertTrue(rs.next());
0555:                    assertEquals("id", rs.getString(4));
0556:                    //
0557:                    rs = dbmd.getImportedKeys(null, null, "jTDS_META2");
0558:                    assertTrue(checkColumnNames(rs, new String[] {
0559:                            "PKTABLE_CAT", "PKTABLE_SCHEM", "PKTABLE_NAME",
0560:                            "PKCOLUMN_NAME", "FKTABLE_CAT", "FKTABLE_SCHEM",
0561:                            "FKTABLE_NAME", "FKCOLUMN_NAME", "KEY_SEQ",
0562:                            "UPDATE_RULE", "DELETE_RULE", "FK_NAME", "PK_NAME",
0563:                            "DEFERRABILITY" }));
0564:                    assertTrue(rs.next());
0565:                    assertEquals("id", rs.getString(4));
0566:                    //
0567:                    rs = dbmd
0568:                            .getIndexInfo(null, null, "jTDS_META", false, true);
0569:                    assertTrue(checkColumnNames(rs, new String[] { "TABLE_CAT",
0570:                            "TABLE_SCHEM", "TABLE_NAME", "NON_UNIQUE",
0571:                            "INDEX_QUALIFIER", "INDEX_NAME", "TYPE",
0572:                            "ORDINAL_POSITION", "COLUMN_NAME", "ASC_OR_DESC",
0573:                            "CARDINALITY", "PAGES", "FILTER_CONDITION" }));
0574:                    assertTrue(rs.next());
0575:                    assertEquals("jTDS_META", rs.getString(3));
0576:                    //
0577:                    rs = dbmd.getPrimaryKeys(null, null, "jTDS_META");
0578:                    assertTrue(checkColumnNames(rs, new String[] { "TABLE_CAT",
0579:                            "TABLE_SCHEM", "TABLE_NAME", "COLUMN_NAME",
0580:                            "KEY_SEQ", "PK_NAME" }));
0581:                    assertTrue(rs.next());
0582:                    assertEquals("id", rs.getString(4));
0583:                    //
0584:                    rs = dbmd.getProcedureColumns(null, null, "jtds_spmeta",
0585:                            "@p1");
0586:                    assertTrue(checkColumnNames(rs, new String[] {
0587:                            "PROCEDURE_CAT", "PROCEDURE_SCHEM",
0588:                            "PROCEDURE_NAME", "COLUMN_NAME", "COLUMN_TYPE",
0589:                            "DATA_TYPE", "TYPE_NAME", "PRECISION", "LENGTH",
0590:                            "SCALE", "RADIX", "NULLABLE", "REMARKS" }));
0591:                    assertTrue(rs.next());
0592:                    assertEquals("jtds_spmeta", rs.getString(3));
0593:                    assertEquals("@p1", rs.getString(4));
0594:                    //
0595:                    rs = dbmd.getProcedures(null, null, "jtds_spmeta%");
0596:                    assertTrue(checkColumnNames(rs, new String[] {
0597:                            "PROCEDURE_CAT", "PROCEDURE_SCHEM",
0598:                            "PROCEDURE_NAME", "", "", "", "REMARKS",
0599:                            "PROCEDURE_TYPE" }));
0600:                    assertTrue(rs.next());
0601:                    assertEquals("jtds_spmeta", rs.getString(3));
0602:                    //
0603:                    rs = dbmd.getSchemas();
0604:                    if (net.sourceforge.jtds.jdbc.Driver.JDBC3) {
0605:                        assertTrue(checkColumnNames(rs, new String[] {
0606:                                "TABLE_SCHEM", "TABLE_CATALOG" }));
0607:                    } else {
0608:                        assertTrue(checkColumnNames(rs,
0609:                                new String[] { "TABLE_SCHEM" }));
0610:                    }
0611:                    assertTrue(rs.next());
0612:                    //
0613:                    rs = dbmd.getTablePrivileges(null, null, "jTDS_META");
0614:                    assertTrue(checkColumnNames(rs, new String[] { "TABLE_CAT",
0615:                            "TABLE_SCHEM", "TABLE_NAME", "GRANTOR", "GRANTEE",
0616:                            "PRIVILEGE", "IS_GRANTABLE" }));
0617:                    assertTrue(rs.next());
0618:                    assertTrue(rs.getString(6).equals("INSERT")
0619:                            || rs.getString(6).equals("UPDATE")
0620:                            || rs.getString(6).equals("DELETE")
0621:                            || rs.getString(6).equals("SELECT"));
0622:                    //
0623:                    rs = dbmd.getTables(null, null, "jTDS_META",
0624:                            new String[] { "TABLE" });
0625:                    assertTrue(checkColumnNames(rs, new String[] { "TABLE_CAT",
0626:                            "TABLE_SCHEM", "TABLE_NAME", "TABLE_TYPE",
0627:                            "REMARKS", "TYPE_CAT", "TYPE_SCHEM", "TYPE_NAME",
0628:                            "SELF_REFERENCING_COL_NAME", "REF_GENERATION" }));
0629:                    assertTrue(rs.next());
0630:                    assertEquals("jTDS_META", rs.getString(3));
0631:                    //
0632:                    rs = dbmd.getTableTypes();
0633:                    assertTrue(checkColumnNames(rs,
0634:                            new String[] { "TABLE_TYPE" }));
0635:                    assertTrue(rs.next());
0636:                    assertEquals("SYSTEM TABLE", rs.getString(1));
0637:                    //
0638:                    rs = dbmd.getTypeInfo();
0639:                    assertTrue(checkColumnNames(rs, new String[] { "TYPE_NAME",
0640:                            "DATA_TYPE", "PRECISION", "LITERAL_PREFIX",
0641:                            "LITERAL_SUFFIX", "CREATE_PARAMS", "NULLABLE",
0642:                            "CASE_SENSITIVE", "SEARCHABLE",
0643:                            "UNSIGNED_ATTRIBUTE", "FIXED_PREC_SCALE",
0644:                            "AUTO_INCREMENT", "LOCAL_TYPE_NAME",
0645:                            "MINIMUM_SCALE", "MAXIMUM_SCALE", "SQL_DATA_TYPE",
0646:                            "SQL_DATETIME_SUB", "NUM_PREC_RADIX" }));
0647:                    while (rs.next()) {
0648:                        if (rs.getString(1).equalsIgnoreCase("nvarchar")) {
0649:                            assertEquals(java.sql.Types.VARCHAR, rs.getInt(2));
0650:                        }
0651:                    }
0652:                    //
0653:                    rs = dbmd.getUDTs(null, null, "%", null);
0654:                    assertTrue(checkColumnNames(rs, new String[] { "TYPE_CAT",
0655:                            "TYPE_SCHEM", "TYPE_NAME", "CLASS_NAME",
0656:                            "DATA_TYPE", "REMARKS", "BASE_TYPE" }));
0657:                    assertFalse(rs.next());
0658:                    //
0659:                    rs = dbmd.getVersionColumns(null, null, "jTDS_META");
0660:                    assertTrue(checkColumnNames(rs, new String[] { "SCOPE",
0661:                            "COLUMN_NAME", "DATA_TYPE", "TYPE_NAME",
0662:                            "COLUMN_SIZE", "BUFFER_LENGTH", "DECIMAL_DIGITS",
0663:                            "PSEUDO_COLUMN" }));
0664:                    assertTrue(rs.next());
0665:                    assertEquals("ts", rs.getString(2));
0666:                } finally {
0667:                    dropTable("jTDS_META2");
0668:                    dropTable("jTDS_META");
0669:                    dropProcedure("jtds_spmeta");
0670:                }
0671:            }
0672:
0673:            /**
0674:             * Test for bug [974036] Bug in 0.8rc1 DatabaseMetaData method getTableTypes()
0675:             */
0676:            public void testGetTableTypesOrder() throws Exception {
0677:                DatabaseMetaData dmd = con.getMetaData();
0678:                ResultSet rs = dmd.getTableTypes();
0679:                String previousType = "";
0680:
0681:                while (rs.next()) {
0682:                    String type = rs.getString(1);
0683:
0684:                    assertTrue(type.compareTo(previousType) >= 0);
0685:                    previousType = type;
0686:                }
0687:
0688:                rs.close();
0689:            }
0690:
0691:            /**
0692:             * Test for bug [998765] Exception with Sybase and metaData.getTables()
0693:             */
0694:            public void testGetTables() throws Exception {
0695:                DatabaseMetaData dmd = con.getMetaData();
0696:                ResultSet rs = dmd.getTables(null, null, null, null);
0697:
0698:                assertNotNull(rs);
0699:
0700:                rs.close();
0701:            }
0702:
0703:            /**
0704:             * Test for bug [1120168] jTDS 101 - TDS data type 0 invalid.
0705:             */
0706:            public void testGetColumnsMetaData() throws Exception {
0707:                DatabaseMetaData dmd = con.getMetaData();
0708:                ResultSet rs = dmd.getColumns(null, null,
0709:                        "Table doesn't exist", null);
0710:
0711:                assertNotNull(rs);
0712:
0713:                // Obtain the ResultSetMetaData for the dummy CachedResultSet
0714:                ResultSetMetaData rsmd = rs.getMetaData();
0715:
0716:                // Now call all methods and make sure they don't crash
0717:                // For some of them also make simple tests
0718:                assertNotNull(rsmd.getCatalogName(1));
0719:                assertNotNull(rsmd.getColumnClassName(1));
0720:                rsmd.getColumnCount();
0721:                assertTrue(0 != rsmd.getColumnDisplaySize(1));
0722:                assertNotNull(rsmd.getColumnLabel(1));
0723:                assertNotNull(rsmd.getColumnName(1));
0724:                rsmd.getColumnType(1);
0725:                assertNotNull(rsmd.getColumnTypeName(1));
0726:                rsmd.getPrecision(1);
0727:                rsmd.getScale(1);
0728:                assertNotNull(rsmd.getSchemaName(1));
0729:                assertNotNull(rsmd.getTableName(1));
0730:                rsmd.isAutoIncrement(1);
0731:                rsmd.isCaseSensitive(1);
0732:                rsmd.isCurrency(1);
0733:                rsmd.isDefinitelyWritable(1);
0734:                rsmd.isNullable(1);
0735:                rsmd.isReadOnly(1);
0736:                rsmd.isSearchable(1);
0737:                rsmd.isSigned(1);
0738:                rsmd.isWritable(1);
0739:
0740:                rs.close();
0741:            }
0742:
0743:            /**
0744:             * Test for bug [1023984] Protocol error processing table meta data.
0745:             * <p>
0746:             * Test to demonstrate failure to process the TDS table name token
0747:             * correctly. Must be run with TDS=8.0.
0748:             * @throws Exception
0749:             */
0750:            public void testTableMetaData() throws Exception {
0751:                // This test is supposed to select from a different database, in order to
0752:                // force the server to return a fully qualified table name. Do not alter.
0753:                Statement stmt = con.createStatement(
0754:                        ResultSet.TYPE_SCROLL_INSENSITIVE,
0755:                        ResultSet.CONCUR_READ_ONLY);
0756:                ResultSet rs = stmt
0757:                        .executeQuery("SELECT * FROM master.dbo.sysdatabases");
0758:
0759:                assertNotNull(rs);
0760:                ResultSetMetaData rsmd = rs.getMetaData();
0761:
0762:                assertEquals("master", rsmd.getCatalogName(1));
0763:                assertEquals("dbo", rsmd.getSchemaName(1));
0764:                assertEquals("sysdatabases", rsmd.getTableName(1));
0765:
0766:                stmt.close();
0767:                rs.close();
0768:            }
0769:
0770:            public void testColumnClassName() throws SQLException {
0771:                byte[] bytes = new byte[] { 1, 2, 3 };
0772:                String uid = "colGuid char(38)";
0773:                if (con.getMetaData().getDatabaseProductName().startsWith(
0774:                        "Microsoft")) {
0775:                    uid = "colGuid UNIQUEIDENTIFIER";
0776:                }
0777:                // Create a table w/ pretty much all the possible types
0778:                String tabdef = "CREATE TABLE #testColumnClassName("
0779:                        + "colByte TINYINT," + "colShort SMALLINT,"
0780:                        + "colInt INTEGER," + "colBigint DECIMAL(29,0),"
0781:                        + "colFloat REAL," + "colDouble FLOAT,"
0782:                        + "colDecimal DECIMAL(29,10)," + "colBit BIT,"
0783:                        + "colByteArray VARBINARY(255),"
0784:                        + "colTimestamp DATETIME," + "colBlob IMAGE,"
0785:                        + "colClob TEXT," + "colString VARCHAR(255)," + uid
0786:                        + ")";
0787:                Statement stmt = con.createStatement();
0788:                stmt.executeUpdate(tabdef);
0789:
0790:                // Insert a row into the table
0791:                PreparedStatement pstmt = con
0792:                        .prepareStatement("INSERT INTO #testColumnClassName ("
0793:                                + "colByte,colShort,colInt,colBigint,colFloat,colDouble,"
0794:                                + "colDecimal,colBit,colByteArray,colTimestamp,colBlob,colClob,"
0795:                                + "colString,colGuid) "
0796:                                + "VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
0797:                pstmt.setByte(1, (byte) 1);
0798:                pstmt.setShort(2, (short) 2222);
0799:                pstmt.setInt(3, 123456);
0800:                pstmt.setInt(4, 123456);
0801:                pstmt.setFloat(5, 0.111f);
0802:                pstmt.setDouble(6, 0.111);
0803:                pstmt.setDouble(7, 0.111111);
0804:                pstmt.setBoolean(8, true);
0805:                pstmt.setBytes(9, bytes);
0806:                pstmt.setTimestamp(10,
0807:                        new Timestamp(System.currentTimeMillis()));
0808:                pstmt.setBytes(11, bytes);
0809:                pstmt.setString(12, "Test");
0810:                pstmt.setString(13, "Test");
0811:                pstmt.setString(14, "ebd558a0-0c68-11d9-9669-0800200c9a66");
0812:                assertEquals("No row inserted", 1, pstmt.executeUpdate());
0813:                pstmt.close();
0814:
0815:                // Select the row and check that getColumnClassName matches the actual
0816:                // class
0817:                ResultSet rs = stmt
0818:                        .executeQuery("SELECT * FROM #testColumnClassName");
0819:                assertTrue("No rows in ResultSet", rs.next());
0820:                ResultSetMetaData meta = rs.getMetaData();
0821:                for (int i = 1; i <= meta.getColumnCount(); i++) {
0822:                    Object obj = rs.getObject(i);
0823:                    assertNotNull("Expecting non-null value", obj);
0824:                    String metaClass = meta.getColumnClassName(i);
0825:                    Class c;
0826:                    try {
0827:                        c = Class.forName(metaClass);
0828:                    } catch (ClassNotFoundException ex) {
0829:                        fail("Class returned by getColumnClassName() not found: "
0830:                                + metaClass);
0831:                        return;
0832:                    }
0833:                    if (!c.isAssignableFrom(obj.getClass())) {
0834:                        fail("getColumnClassName() returned " + metaClass
0835:                                + " but the actual class is "
0836:                                + obj.getClass().getName());
0837:                    }
0838:                }
0839:                stmt.close();
0840:            }
0841:
0842:            /**
0843:             * Test to check DatabaseMetaData.getColumns and ResultSetMetaData is equivalent.
0844:             * This test also checks for bug [ 1074096 ] Incorrect data type determine on dataset meta data.
0845:             * This is because getColumns will return a typename of timestamp which should now also be
0846:             * returned by the result set meta data as well.
0847:             * @throws Exception if an error condition occurs
0848:             */
0849:            public void testColumnMetaData() throws Exception {
0850:                String sql = "CREATE TABLE jTDSTYPETEST (ti tinyint not null, si smallint, i int, bi bigint, "
0851:                        + " f float, r real, d decimal(28,10), n numeric(28,10), sm smallmoney, m money, "
0852:                        + "c char(10) not null, vc varchar(255), nc nchar(10) not null, nvc nvarchar(255), "
0853:                        + " txt text, ntxt ntext, b binary(8) not null, vb varbinary(8), img image, "
0854:                        + " dt datetime, sdt smalldatetime, bt bit not null, ts timestamp, sn sysname, "
0855:                        + " ui uniqueidentifier, sv sql_variant)";
0856:
0857:                String sql7 = "CREATE TABLE jTDSTYPETEST (ti tinyint not null, si smallint, i int, "
0858:                        + " f float, r real, d decimal(28,10), n numeric(28,10), sm smallmoney, m money, "
0859:                        + "c char(10) not null, vc varchar(255), nc nchar(10) not null, nvc nvarchar(255), "
0860:                        + " txt text, ntxt ntext, b binary(8) not null, vb varbinary(8), img image, "
0861:                        + " dt datetime, sdt smalldatetime, bt bit not null, ts timestamp, sn sysname, "
0862:                        + " ui uniqueidentifier)";
0863:
0864:                String sql65 = "CREATE TABLE jTDSTYPETEST (ti tinyint not null, si smallint, i int, "
0865:                        + " f float, r real, d decimal(28,10), n numeric(28,10), sm smallmoney, m money, "
0866:                        + "c char(10) not null, vc varchar(255), "
0867:                        + " txt text, b binary(8) not null, vb varbinary(8), img image, "
0868:                        + " dt datetime, sdt smalldatetime, bt bit not null, ts timestamp, sn sysname)";
0869:
0870:                String sql125 = "CREATE TABLE jTDSTYPETEST (ti tinyint not null, si smallint, i int, "
0871:                        + " f float, r real, d decimal(28,10), n numeric(28,10), sm smallmoney, m money, "
0872:                        + "c char(10) not null, vc varchar(255), nc nchar(10) not null, nvc nvarchar(255), "
0873:                        + " txt text, b binary(8) not null, vb varbinary(8), img image, "
0874:                        + " dt datetime, sdt smalldatetime, bt bit not null, ts timestamp, sn sysname, "
0875:                        + " uc unichar(10), vuc univarchar(255), sydt date, syt time)";
0876:
0877:                try {
0878:                    dropTable("jTDSTYPETEST");
0879:                    Statement stmt = con.createStatement();
0880:                    DatabaseMetaData dbmd = con.getMetaData();
0881:                    if (dbmd.getDatabaseProductName().startsWith("Microsoft")) {
0882:                        if (dbmd.getDatabaseProductVersion().startsWith("6.5"))
0883:                            stmt.execute(sql65);
0884:                        else if (dbmd.getDatabaseProductVersion().startsWith(
0885:                                "7"))
0886:                            stmt.execute(sql7);
0887:                        else
0888:                            stmt.execute(sql);
0889:                    } else {
0890:                        if (dbmd.getDatabaseProductVersion().startsWith("12"))
0891:                            stmt.execute(sql125);
0892:                        else
0893:                            stmt.execute(sql65);
0894:                    }
0895:                    ResultSetMetaData rsmd = stmt.executeQuery(
0896:                            "SELECT * FROM jTDSTYPETEST").getMetaData();
0897:                    ResultSet rs = dbmd.getColumns(null, null, "jTDSTYPETEST",
0898:                            "%");
0899:                    //            ResultSetMetaData rsmd2 = rs.getMetaData();
0900:                    //            System.out.println();
0901:                    while (rs.next()) {
0902:                        String cn = rs.getString("COLUMN_NAME");
0903:                        int ord = rs.getInt("ORDINAL_POSITION");
0904:                        assertEquals(cn + " typename", rs
0905:                                .getString("TYPE_NAME"), rsmd
0906:                                .getColumnTypeName(ord));
0907:                        assertEquals(cn + " datatype", rs.getInt("DATA_TYPE"),
0908:                                rsmd.getColumnType(ord));
0909:                        if (rs.getInt("DATA_TYPE") != Types.REAL
0910:                                && rs.getInt("DATA_TYPE") != Types.DOUBLE) {
0911:                            // Seems to be genuine disagreement between getColumns and metadata on float data!
0912:                            assertEquals(cn + " precision", rs
0913:                                    .getInt("COLUMN_SIZE"), rsmd
0914:                                    .getPrecision(ord));
0915:                        }
0916:                        assertEquals(cn + " scale",
0917:                                rs.getInt("DECIMAL_DIGITS"), rsmd.getScale(ord));
0918:                        assertEquals(cn + " nullable", rs.getInt("NULLABLE"),
0919:                                rsmd.isNullable(ord));
0920:                    }
0921:                } finally {
0922:                    dropTable("jTDSTYPETEST");
0923:                }
0924:            }
0925:
0926:            /**
0927:             * Test for bug [1184376] Sybase getProcedureColumns bug
0928:             */
0929:            public void testProcedureColumns() throws Exception {
0930:                try {
0931:                    dropProcedure("jtds_testparam");
0932:                    Statement stmt = con.createStatement();
0933:                    stmt
0934:                            .execute("CREATE PROC jtds_testparam @p1 int, @p2 int output as\r\n"
0935:                                    + "BEGIN\r\n"
0936:                                    + "  SELECT @p2 = @p1\r\n"
0937:                                    + "END");
0938:                    stmt.close();
0939:
0940:                    DatabaseMetaData dbmd = con.getMetaData();
0941:                    String[] columnPatterns = new String[] { null, "%" };
0942:                    for (int i = 0; i < columnPatterns.length; i++) {
0943:                        ResultSet rs = dbmd.getProcedureColumns(null, null,
0944:                                "jtds_testparam", columnPatterns[i]);
0945:                        assertTrue(rs.next());
0946:                        assertEquals("@RETURN_VALUE", rs
0947:                                .getString("COLUMN_NAME"));
0948:                        assertEquals(DatabaseMetaData.procedureColumnReturn, rs
0949:                                .getInt("COLUMN_TYPE"));
0950:                        assertTrue(rs.next());
0951:                        assertEquals("@p1", rs.getString("COLUMN_NAME"));
0952:                        assertEquals(DatabaseMetaData.procedureColumnIn, rs
0953:                                .getInt("COLUMN_TYPE"));
0954:                        assertTrue(rs.next());
0955:                        assertEquals("@p2", rs.getString("COLUMN_NAME"));
0956:                        assertEquals(DatabaseMetaData.procedureColumnInOut, rs
0957:                                .getInt("COLUMN_TYPE"));
0958:                        rs.close();
0959:                    }
0960:                } finally {
0961:                    dropProcedure("jtds_testparam");
0962:                }
0963:            }
0964:
0965:            /**
0966:             * Test for bug [1245775] Column type inconsistency when useLOBs=false.
0967:             */
0968:            public void testProcedureUseLOBsFalse() throws Exception {
0969:                Properties props = new Properties();
0970:                props.setProperty("useLOBs", "false");
0971:                Connection con = getConnection(props);
0972:
0973:                try {
0974:                    DatabaseMetaData meta = con.getMetaData();
0975:                    ResultSet rs = meta.getTypeInfo();
0976:                    while (rs.next()) {
0977:                        if ("text".equalsIgnoreCase(rs.getString(1))
0978:                                || "ntext".equalsIgnoreCase(rs.getString(1))) {
0979:                            assertEquals(Types.LONGVARCHAR, rs.getInt(2));
0980:                        } else if ("image".equalsIgnoreCase(rs.getString(1))) {
0981:                            assertEquals(Types.LONGVARBINARY, rs.getInt(2));
0982:                        }
0983:                    }
0984:                } finally {
0985:                    con.close();
0986:                }
0987:
0988:                DatabaseMetaData meta = this .con.getMetaData();
0989:                ResultSet rs = meta.getTypeInfo();
0990:                while (rs.next()) {
0991:                    if ("text".equalsIgnoreCase(rs.getString(1))
0992:                            || "ntext".equalsIgnoreCase(rs.getString(1))) {
0993:                        assertEquals(Types.CLOB, rs.getInt(2));
0994:                    } else if ("image".equalsIgnoreCase(rs.getString(1))) {
0995:                        assertEquals(Types.BLOB, rs.getInt(2));
0996:                    }
0997:                }
0998:
0999:            }
1000:
1001:            public static void main(String[] args) {
1002:                junit.textui.TestRunner.run(DatabaseMetaDataTest.class);
1003:            }
1004:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.