Source Code Cross Referenced for DatabaseInformationFull.java in  » Database-DBMS » hsql » org » hsqldb » 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 DBMS » hsql » org.hsqldb 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /* Copyright (c) 2001-2005, The HSQL Development Group
0002:         * All rights reserved.
0003:         *
0004:         * Redistribution and use in source and binary forms, with or without
0005:         * modification, are permitted provided that the following conditions are met:
0006:         *
0007:         * Redistributions of source code must retain the above copyright notice, this
0008:         * list of conditions and the following disclaimer.
0009:         *
0010:         * Redistributions in binary form must reproduce the above copyright notice,
0011:         * this list of conditions and the following disclaimer in the documentation
0012:         * and/or other materials provided with the distribution.
0013:         *
0014:         * Neither the name of the HSQL Development Group nor the names of its
0015:         * contributors may be used to endorse or promote products derived from this
0016:         * software without specific prior written permission.
0017:         *
0018:         * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0019:         * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0020:         * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0021:         * ARE DISCLAIMED. IN NO EVENT SHALL HSQL DEVELOPMENT GROUP, HSQLDB.ORG,
0022:         * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
0023:         * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
0024:         * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
0025:         * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
0026:         * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
0027:         * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
0028:         * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
0029:         */
0030:
0031:        package org.hsqldb;
0032:
0033:        import java.lang.reflect.Method;
0034:
0035:        import org.hsqldb.lib.FileUtil;
0036:        import org.hsqldb.lib.HashMap;
0037:        import org.hsqldb.lib.HashSet;
0038:        import org.hsqldb.lib.HsqlArrayList;
0039:        import org.hsqldb.lib.Iterator;
0040:        import org.hsqldb.persist.DataFileCache;
0041:        import org.hsqldb.persist.HsqlDatabaseProperties;
0042:        import org.hsqldb.persist.TextCache;
0043:        import org.hsqldb.scriptio.ScriptWriterBase;
0044:        import org.hsqldb.store.ValuePool;
0045:
0046:        // fredt@users - 1.7.2 - structural modifications to allow inheritance
0047:        // boucherb@users - 1.7.2 - 20020225
0048:        // - factored out all reusable code into DIXXX support classes
0049:        // - completed Fred's work on allowing inheritance
0050:        // boucherb@users - 1.7.2 - 20020304 - bug fixes, refinements, better java docs
0051:        // fredt@users - 1.8.0 - updated to report latest enhancements and changes
0052:        // boucherb@users - 1.8.0 - 20050515 - furhter SQL 2003 metadata support
0053:
0054:        /**
0055:         * Extends DatabaseInformationMain to provide additional system table
0056:         * support. <p>
0057:         *
0058:         * @author boucherb@users
0059:         * @version 1.8.0
0060:         * @since 1.7.2
0061:         */
0062:        final class DatabaseInformationFull extends
0063:                org.hsqldb.DatabaseInformationMain {
0064:
0065:            /** Provides SQL function/procedure reporting support. */
0066:            protected DIProcedureInfo pi;
0067:
0068:            /**
0069:             * Constructs a new DatabaseInformationFull instance. <p>
0070:             *
0071:             * @param db the database for which to produce system tables.
0072:             * @throws HsqlException if a database access error occurs.
0073:             */
0074:            DatabaseInformationFull(Database db) throws HsqlException {
0075:
0076:                super (db);
0077:
0078:                pi = new DIProcedureInfo(ns);
0079:            }
0080:
0081:            /**
0082:             * Retrieves the system table corresponding to the specified index. <p>
0083:             *
0084:             * @param tableIndex index identifying the system table to generate
0085:             * @throws HsqlException if a database access error occurs
0086:             * @return the system table corresponding to the specified index
0087:             */
0088:            protected Table generateTable(int tableIndex) throws HsqlException {
0089:
0090:                switch (tableIndex) {
0091:
0092:                case SYSTEM_PROCEDURECOLUMNS:
0093:                    return SYSTEM_PROCEDURECOLUMNS();
0094:
0095:                case SYSTEM_PROCEDURES:
0096:                    return SYSTEM_PROCEDURES();
0097:
0098:                case SYSTEM_SUPERTABLES:
0099:                    return SYSTEM_SUPERTABLES();
0100:
0101:                case SYSTEM_SUPERTYPES:
0102:                    return SYSTEM_SUPERTYPES();
0103:
0104:                case SYSTEM_UDTATTRIBUTES:
0105:                    return SYSTEM_UDTATTRIBUTES();
0106:
0107:                case SYSTEM_UDTS:
0108:                    return SYSTEM_UDTS();
0109:
0110:                case SYSTEM_VERSIONCOLUMNS:
0111:                    return SYSTEM_VERSIONCOLUMNS();
0112:
0113:                    // HSQLDB-specific
0114:                case SYSTEM_ALIASES:
0115:                    return SYSTEM_ALIASES();
0116:
0117:                case SYSTEM_CACHEINFO:
0118:                    return SYSTEM_CACHEINFO();
0119:
0120:                case SYSTEM_CLASSPRIVILEGES:
0121:                    return SYSTEM_CLASSPRIVILEGES();
0122:
0123:                case SYSTEM_SESSIONINFO:
0124:                    return SYSTEM_SESSIONINFO();
0125:
0126:                case SYSTEM_PROPERTIES:
0127:                    return SYSTEM_PROPERTIES();
0128:
0129:                case SYSTEM_SESSIONS:
0130:                    return SYSTEM_SESSIONS();
0131:
0132:                case SYSTEM_TRIGGERCOLUMNS:
0133:                    return SYSTEM_TRIGGERCOLUMNS();
0134:
0135:                case SYSTEM_TRIGGERS:
0136:                    return SYSTEM_TRIGGERS();
0137:
0138:                case SYSTEM_VIEWS:
0139:                    return SYSTEM_VIEWS();
0140:
0141:                case SYSTEM_TEXTTABLES:
0142:                    return SYSTEM_TEXTTABLES();
0143:
0144:                case SYSTEM_USAGE_PRIVILEGES:
0145:                    return SYSTEM_USAGE_PRIVILEGES();
0146:
0147:                case SYSTEM_CHECK_COLUMN_USAGE:
0148:                    return SYSTEM_CHECK_COLUMN_USAGE();
0149:
0150:                case SYSTEM_CHECK_ROUTINE_USAGE:
0151:                    return SYSTEM_CHECK_ROUTINE_USAGE();
0152:
0153:                case SYSTEM_CHECK_TABLE_USAGE:
0154:                    return SYSTEM_CHECK_TABLE_USAGE();
0155:
0156:                case SYSTEM_TABLE_CONSTRAINTS:
0157:                    return SYSTEM_TABLE_CONSTRAINTS();
0158:
0159:                case SYSTEM_VIEW_TABLE_USAGE:
0160:                    return SYSTEM_VIEW_TABLE_USAGE();
0161:
0162:                case SYSTEM_VIEW_COLUMN_USAGE:
0163:                    return SYSTEM_VIEW_COLUMN_USAGE();
0164:
0165:                case SYSTEM_VIEW_ROUTINE_USAGE:
0166:                    return SYSTEM_VIEW_ROUTINE_USAGE();
0167:
0168:                case SYSTEM_AUTHORIZATIONS: {
0169:                    return SYSTEM_AUTHORIZATIONS();
0170:                }
0171:                case SYSTEM_ROLE_AUTHORIZATION_DESCRIPTORS: {
0172:                    return SYSTEM_ROLE_AUTHORIZATION_DESCRIPTORS();
0173:                }
0174:                case SYSTEM_SCHEMATA: {
0175:                    return SYSTEM_SCHEMATA();
0176:                }
0177:                case SYSTEM_COLLATIONS: {
0178:                    return SYSTEM_COLLATIONS();
0179:                }
0180:                default:
0181:                    return super .generateTable(tableIndex);
0182:                }
0183:            }
0184:
0185:            /**
0186:             * Retrieves a <code>Table</code> object describing the aliases defined
0187:             * within this database. <p>
0188:             *
0189:             * Currently two types of alias are reported: DOMAIN alaises (alternate
0190:             * names for column data types when issuing "CREATE TABLE" DDL) and
0191:             * ROUTINE aliases (alternate names that can be used when invoking
0192:             * routines as SQL functions or stored procedures). <p>
0193:             *
0194:             * Each row is an alias description with the following columns: <p>
0195:             *
0196:             * <pre class="SqlCodeExample">
0197:             * OBJECT_TYPE  VARCHAR   type of the aliased object
0198:             * OBJECT_CAT   VARCHAR   catalog of the aliased object
0199:             * OBJECT_SCHEM VARCHAR   schema of the aliased object
0200:             * OBJECT_NAME  VARCHAR   simple identifier of the aliased object
0201:             * ALIAS_CAT    VARCHAR   catalog in which alias is defined
0202:             * ALIAS_SCHEM  VARCHAR   schema in which alias is defined
0203:             * ALIAS        VARCHAR   alias for the indicated object
0204:             * </pre> <p>
0205:             *
0206:             * <b>Note:</b> Up to and including HSQLDB 1.7.2, user-defined aliases
0207:             * are supported only for SQL function and stored procedure calls
0208:             * (indicated by the value "ROUTINE" in the OBJECT_TYPE
0209:             * column), and there is no syntax for dropping aliases, only for
0210:             * creating them. <p>
0211:             * @return a Table object describing the accessisble
0212:             *      aliases in the context of the calling session
0213:             * @throws HsqlException if an error occurs while producing the table
0214:             */
0215:            Table SYSTEM_ALIASES() throws HsqlException {
0216:
0217:                Table t = sysTables[SYSTEM_ALIASES];
0218:
0219:                if (t == null) {
0220:                    t = createBlankTable(sysTableHsqlNames[SYSTEM_ALIASES]);
0221:
0222:                    addColumn(t, "OBJECT_TYPE", Types.VARCHAR, 32, false); // not null
0223:                    addColumn(t, "OBJECT_CAT", Types.VARCHAR);
0224:                    addColumn(t, "OBJECT_SCHEM", Types.VARCHAR);
0225:                    addColumn(t, "OBJECT_NAME", Types.VARCHAR, false); // not null
0226:                    addColumn(t, "ALIAS_CAT", Types.VARCHAR);
0227:                    addColumn(t, "ALIAS_SCHEM", Types.VARCHAR);
0228:                    addColumn(t, "ALIAS", Types.VARCHAR, false); // not null
0229:
0230:                    // order: OBJECT_TYPE, OBJECT_NAME, ALIAS.
0231:                    // true PK.
0232:                    t.createPrimaryKey(null, new int[] { 0, 3, 6 }, true);
0233:
0234:                    return t;
0235:                }
0236:
0237:                // Holders for calculated column values
0238:                String cat;
0239:                String schem;
0240:                String alias;
0241:                String objName;
0242:                String objType;
0243:
0244:                // Intermediate holders
0245:                String className;
0246:                HashMap hAliases;
0247:                Iterator aliases;
0248:                Object[] row;
0249:                int pos;
0250:
0251:                // Column number mappings
0252:                final int ialias_object_type = 0;
0253:                final int ialias_object_cat = 1;
0254:                final int ialias_object_schem = 2;
0255:                final int ialias_object_name = 3;
0256:                final int ialias_cat = 4;
0257:                final int ialias_schem = 5;
0258:                final int ialias = 6;
0259:
0260:                // Initialization
0261:                hAliases = database.getAliasMap();
0262:                aliases = hAliases.keySet().iterator();
0263:                objType = "ROUTINE";
0264:
0265:                // Do it.
0266:                while (aliases.hasNext()) {
0267:                    row = t.getEmptyRowData();
0268:                    alias = (String) aliases.next();
0269:                    objName = (String) hAliases.get(alias);
0270:
0271:                    // must have class grant to see method call aliases
0272:                    pos = objName.lastIndexOf('.');
0273:
0274:                    if (pos <= 0) {
0275:
0276:                        // should never occur in practice, as this is typically a Java
0277:                        // method name, but there's nothing preventing a user from
0278:                        // creating an alias entry that is not in method FQN form;
0279:                        // such entries are not illegal, only useless.  Probably,
0280:                        // we should eventually try to disallow them.
0281:                        continue;
0282:                    }
0283:
0284:                    className = objName.substring(0, pos);
0285:
0286:                    if (!session.isAccessible(className)) {
0287:                        continue;
0288:                    }
0289:
0290:                    cat = ns.getCatalogName(objName);
0291:                    schem = ns.getSchemaName(className);
0292:                    row[ialias_object_type] = objType;
0293:                    row[ialias_object_cat] = cat;
0294:                    row[ialias_object_schem] = schem;
0295:                    row[ialias_object_name] = objName;
0296:                    row[ialias_cat] = cat;
0297:                    row[ialias_schem] = schem;
0298:                    row[ialias] = alias;
0299:
0300:                    t.insertSys(row);
0301:                }
0302:
0303:                // must have create/alter table rights to see domain aliases
0304:                if (session.isAdmin()) {
0305:                    Iterator typeAliases = Types.typeAliases.keySet()
0306:                            .iterator();
0307:
0308:                    objType = "DOMAIN";
0309:
0310:                    while (typeAliases.hasNext()) {
0311:                        row = t.getEmptyRowData();
0312:                        alias = (String) typeAliases.next();
0313:
0314:                        int tn = Types.typeAliases
0315:                                .get(alias, Integer.MIN_VALUE);
0316:
0317:                        objName = Types.getTypeString(tn);
0318:
0319:                        if (alias.equals(objName)) {
0320:                            continue;
0321:                        }
0322:
0323:                        cat = ns.getCatalogName(objName);
0324:                        schem = ns.getSchemaName(objName);
0325:                        row[ialias_object_type] = objType;
0326:                        row[ialias_object_cat] = cat;
0327:                        row[ialias_object_schem] = schem;
0328:                        row[ialias_object_name] = objName;
0329:                        row[ialias_cat] = cat;
0330:                        row[ialias_schem] = schem;
0331:                        row[ialias] = alias;
0332:
0333:                        t.insertSys(row);
0334:                    }
0335:                }
0336:
0337:                t.setDataReadOnly(true);
0338:
0339:                return t;
0340:            }
0341:
0342:            /**
0343:             * Retrieves a <code>Table</code> object describing the current
0344:             * state of all row caching objects for the accessible
0345:             * tables defined within this database. <p>
0346:             *
0347:             * Currently, the row caching objects for which state is reported are: <p>
0348:             *
0349:             * <OL>
0350:             * <LI> the system-wide <code>Cache</code> object used by CACHED tables.
0351:             * <LI> any <code>TextCache</code> objects in use by [TEMP] TEXT tables.
0352:             * </OL> <p>
0353:             *
0354:             * Each row is a cache object state description with the following
0355:             * columns: <p>
0356:             *
0357:             * <pre class="SqlCodeExample">
0358:             * CACHE_FILE          VARCHAR   absolute path of cache data file
0359:             * MAX_CACHE_SIZE      INTEGER   maximum allowable cached Row objects
0360:             * MAX_CACHE_BYTE_SIZE INTEGER   maximum allowable size of cached Row objects
0361:             * CACHE_LENGTH        INTEGER   number of data bytes currently cached
0362:             * CACHE_SIZE          INTEGER   number of rows currently cached
0363:             * FREE_BYTES          INTEGER   total bytes in available file allocation units
0364:             * FREE_COUNT          INTEGER   total # of allocation units available
0365:             * FREE_POS            INTEGER   largest file position allocated + 1
0366:             * </pre> <p>
0367:             *
0368:             * <b>Notes:</b> <p>
0369:             *
0370:             * <code>TextCache</code> objects do not maintain a free list because
0371:             * deleted rows are only marked deleted and never reused. As such, the
0372:             * columns FREE_BYTES, SMALLEST_FREE_ITEM, LARGEST_FREE_ITEM, and
0373:             * FREE_COUNT are always reported as zero for rows reporting on
0374:             * <code>TextCache</code> objects. <p>
0375:             *
0376:             * Currently, CACHE_SIZE, FREE_BYTES, SMALLEST_FREE_ITEM, LARGEST_FREE_ITEM,
0377:             * FREE_COUNT and FREE_POS are the only dynamically changing values.
0378:             * All others are constant for the life of a cache object. In a future
0379:             * release, other column values may also change over the life of a cache
0380:             * object, as SQL syntax may eventually be introduced to allow runtime
0381:             * modification of certain cache properties. <p>
0382:             *
0383:             * @return a description of the current state of all row caching
0384:             *      objects associated with the accessible tables of the database
0385:             * @throws HsqlException if an error occurs while producing the table
0386:             */
0387:            Table SYSTEM_CACHEINFO() throws HsqlException {
0388:
0389:                Table t = sysTables[SYSTEM_CACHEINFO];
0390:
0391:                if (t == null) {
0392:                    t = createBlankTable(sysTableHsqlNames[SYSTEM_CACHEINFO]);
0393:
0394:                    addColumn(t, "CACHE_FILE", Types.VARCHAR, false); // not null
0395:                    addColumn(t, "MAX_CACHE_COUNT", Types.INTEGER, false); // not null
0396:                    addColumn(t, "MAX_CACHE_BYTES", Types.BIGINT, false); // not null
0397:                    addColumn(t, "CACHE_SIZE", Types.INTEGER, false); // not null
0398:                    addColumn(t, "CACHE_BYTES", Types.BIGINT, false); // not null
0399:                    addColumn(t, "FILE_FREE_BYTES", Types.INTEGER, false); // not null
0400:                    addColumn(t, "FILE_FREE_COUNT", Types.INTEGER, false); // not null
0401:                    addColumn(t, "FILE_FREE_POS", Types.BIGINT, false); // not null
0402:                    t.createPrimaryKey(null, new int[] { 0 }, true);
0403:
0404:                    return t;
0405:                }
0406:
0407:                DataFileCache cache;
0408:                Object[] row;
0409:                HashSet cacheSet;
0410:                Iterator caches;
0411:                Iterator tables;
0412:                Table table;
0413:                int iFreeBytes;
0414:                int iLargestFreeItem;
0415:                long lSmallestFreeItem;
0416:
0417:                // column number mappings
0418:                final int icache_file = 0;
0419:                final int imax_cache_sz = 1;
0420:                final int imax_cache_bytes = 2;
0421:                final int icache_size = 3;
0422:                final int icache_length = 4;
0423:                final int ifree_bytes = 5;
0424:                final int ifree_count = 6;
0425:                final int ifree_pos = 7;
0426:
0427:                // Initialization
0428:                cacheSet = new HashSet();
0429:
0430:                // dynamic system tables are never cached
0431:                tables = database.schemaManager.allTablesIterator();
0432:
0433:                while (tables.hasNext()) {
0434:                    table = (Table) tables.next();
0435:
0436:                    if (table.isFileBased() && isAccessibleTable(table)) {
0437:                        cache = table.getCache();
0438:
0439:                        if (cache != null) {
0440:                            cacheSet.add(cache);
0441:                        }
0442:                    }
0443:                }
0444:
0445:                caches = cacheSet.iterator();
0446:
0447:                // Do it.
0448:                while (caches.hasNext()) {
0449:                    cache = (DataFileCache) caches.next();
0450:                    row = t.getEmptyRowData();
0451:                    row[icache_file] = FileUtil.canonicalOrAbsolutePath(cache
0452:                            .getFileName());
0453:                    row[imax_cache_sz] = ValuePool.getInt(cache.capacity());
0454:                    row[imax_cache_bytes] = ValuePool.getLong(cache
0455:                            .bytesCapacity());
0456:                    row[icache_size] = ValuePool.getInt(cache
0457:                            .getCachedObjectCount());
0458:                    row[icache_length] = ValuePool.getLong(cache
0459:                            .getTotalCachedBlockSize());
0460:                    row[ifree_bytes] = ValuePool.getInt(cache
0461:                            .getTotalFreeBlockSize());
0462:                    row[ifree_count] = ValuePool.getInt(cache
0463:                            .getFreeBlockCount());
0464:                    row[ifree_pos] = ValuePool.getLong(cache.getFileFreePos());
0465:
0466:                    t.insertSys(row);
0467:                }
0468:
0469:                t.setDataReadOnly(true);
0470:
0471:                return t;
0472:            }
0473:
0474:            /**
0475:             * Retrieves a <code>Table</code> object describing the visible
0476:             * access rights for all accessible Java Class objects defined
0477:             * within this database.<p>
0478:             *
0479:             * Each row is a Class privilege description with the following
0480:             * columns: <p>
0481:             *
0482:             * <pre class="SqlCodeExample">
0483:             * CLASS_CAT    VARCHAR   catalog in which the class is defined
0484:             * CLASS_SCHEM  VARCHAR   schema in which the class is defined
0485:             * CLASS_NAME   VARCHAR   fully qualified name of class
0486:             * GRANTOR      VARCHAR   grantor of access
0487:             * GRANTEE      VARCHAR   grantee of access
0488:             * PRIVILEGE    VARCHAR   name of access: {"EXECUTE" | "TRIGGER"}
0489:             * IS_GRANTABLE VARCHAR   grantable?: {"YES" | "NO" | NULL (unknown)}
0490:             * </pre>
0491:             *
0492:             * <b>Note:</b> Users with the administrative privilege implicily have
0493:             * full and unrestricted access to all Classes available to the database
0494:             * class loader.  However, only explicitly granted rights are reported
0495:             * in this table.  Explicit Class grants/revokes to admin users have no
0496:             * effect in reality, but are reported in this table anyway for
0497:             * completeness. <p>
0498:             *
0499:             * @return a <code>Table</code> object describing the visible
0500:             *        access rights for all accessible Java Class
0501:             *        objects defined within this database
0502:             * @throws HsqlException if an error occurs while producing the table
0503:             */
0504:            Table SYSTEM_CLASSPRIVILEGES() throws HsqlException {
0505:
0506:                Table t = sysTables[SYSTEM_CLASSPRIVILEGES];
0507:
0508:                if (t == null) {
0509:                    t = createBlankTable(sysTableHsqlNames[SYSTEM_CLASSPRIVILEGES]);
0510:
0511:                    addColumn(t, "CLASS_CAT", Types.VARCHAR);
0512:                    addColumn(t, "CLASS_SCHEM", Types.VARCHAR);
0513:                    addColumn(t, "CLASS_NAME", Types.VARCHAR, false); // not null
0514:                    addColumn(t, "GRANTOR", Types.VARCHAR, false); // not null
0515:                    addColumn(t, "GRANTEE", Types.VARCHAR, false); // not null
0516:                    addColumn(t, "PRIVILEGE", Types.VARCHAR, 7, false); // not null
0517:                    addColumn(t, "IS_GRANTABLE", Types.VARCHAR, 3, false); // not null
0518:                    t.createPrimaryKey(null, new int[] { 2, 4, 5 }, true);
0519:
0520:                    return t;
0521:                }
0522:
0523:                // calculated column values
0524:                String clsCat;
0525:                String clsSchem;
0526:                String clsName;
0527:                String grantorName;
0528:                String granteeName;
0529:                String privilege;
0530:                String isGrantable;
0531:
0532:                // intermediate holders
0533:                UserManager um;
0534:                HsqlArrayList users;
0535:                HashSet classNameSet;
0536:                Iterator classNames;
0537:                User granteeUser;
0538:                Object[] row;
0539:
0540:                // column number mappings
0541:                final int icls_cat = 0;
0542:                final int icls_schem = 1;
0543:                final int icls_name = 2;
0544:                final int igrantor = 3;
0545:                final int igrantee = 4;
0546:                final int iprivilege = 5;
0547:                final int iis_grntbl = 6;
0548:
0549:                // Initialization
0550:                grantorName = GranteeManager.DBA_ADMIN_ROLE_NAME;
0551:                um = database.getUserManager();
0552:                users = um.listVisibleUsers(session, true);
0553:
0554:                // Do it.
0555:                for (int i = 0; i < users.size(); i++) {
0556:                    granteeUser = (User) users.get(i);
0557:                    granteeName = granteeUser.getName();
0558:                    isGrantable = granteeUser.isAdmin() ? "YES" : "NO";
0559:                    classNameSet = granteeUser.getGrantedClassNames(false);
0560:
0561:                    if (granteeUser.isPublic()) {
0562:                        ns.addBuiltinToSet(classNameSet);
0563:                    }
0564:
0565:                    classNames = classNameSet.iterator();
0566:
0567:                    // boucherb@users 20030305 - TODO completed.
0568:                    // "EXECUTE" is closest to correct (from: SQL 200n ROUTINE_PRIVILEGES)
0569:                    // There is nothing even like CLASS_PRIVILEGES table under SQL 200n spec.
0570:                    privilege = "EXECUTE";
0571:
0572:                    while (classNames.hasNext()) {
0573:                        clsName = (String) classNames.next();
0574:                        clsCat = ns.getCatalogName(clsName);
0575:                        clsSchem = ns.getSchemaName(clsName);
0576:                        row = t.getEmptyRowData();
0577:                        row[icls_cat] = clsCat;
0578:                        row[icls_schem] = clsSchem;
0579:                        row[icls_name] = clsName;
0580:                        row[igrantor] = grantorName;
0581:                        row[igrantee] = granteeName;
0582:                        row[iprivilege] = privilege;
0583:                        row[iis_grntbl] = isGrantable;
0584:
0585:                        t.insertSys(row);
0586:                    }
0587:
0588:                    classNames = ns
0589:                            .iterateAccessibleTriggerClassNames(granteeUser);
0590:
0591:                    // boucherb@users 20030305 - TODO completed.
0592:                    // "TRIGGER" is closest to correct. (from: SQL 200n TABLE_PRIVILEGES)
0593:                    // There is nothing even like CLASS_PRIVILEGES table under SQL 200n spec.
0594:                    privilege = "TRIGGER";
0595:
0596:                    while (classNames.hasNext()) {
0597:                        clsName = (String) classNames.next();
0598:                        clsCat = ns.getCatalogName(clsName);
0599:                        clsSchem = ns.getSchemaName(clsName);
0600:                        row = t.getEmptyRowData();
0601:                        row[icls_cat] = clsCat;
0602:                        row[icls_schem] = clsSchem;
0603:                        row[icls_name] = clsName;
0604:                        row[igrantor] = grantorName;
0605:                        row[igrantee] = granteeName;
0606:                        row[iprivilege] = privilege;
0607:                        row[iis_grntbl] = isGrantable;
0608:
0609:                        t.insertSys(row);
0610:                    }
0611:                }
0612:
0613:                t.setDataReadOnly(true);
0614:
0615:                return t;
0616:            }
0617:
0618:            /**
0619:             * Retrieves a <code>Table</code> object describing attributes
0620:             * for the calling session context.<p>
0621:             *
0622:             * The rows report the following {key,value} pairs:<p>
0623:             *
0624:             * <pre class="SqlCodeExample">
0625:             * KEY (VARCHAR)       VALUE (VARCHAR)
0626:             * ------------------- ---------------
0627:             * SESSION_ID          the id of the calling session
0628:             * AUTOCOMMIT          YES: session is in autocommit mode, else NO
0629:             * USER                the name of user connected in the calling session
0630:             * (was READ_ONLY)
0631:             * SESSION_READONLY    TRUE: session is in read-only mode, else FALSE
0632:             * (new)
0633:             * DATABASE_READONLY   TRUE: database is in read-only mode, else FALSE
0634:             * MAXROWS             the MAXROWS setting in the calling session
0635:             * DATABASE            the name of the database
0636:             * IDENTITY            the last identity value used by calling session
0637:             * </pre>
0638:             *
0639:             * <b>Note:</b>  This table <em>may</em> become deprecated in a future
0640:             * release, as the information it reports now duplicates information
0641:             * reported in the newer SYSTEM_SESSIONS and SYSTEM_PROPERTIES
0642:             * tables. <p>
0643:             *
0644:             * @return a <code>Table</code> object describing the
0645:             *        attributes of the connection associated
0646:             *        with the current execution context
0647:             * @throws HsqlException if an error occurs while producing the table
0648:             */
0649:            Table SYSTEM_SESSIONINFO() throws HsqlException {
0650:
0651:                Table t = sysTables[SYSTEM_SESSIONINFO];
0652:
0653:                if (t == null) {
0654:                    t = createBlankTable(sysTableHsqlNames[SYSTEM_SESSIONINFO]);
0655:
0656:                    addColumn(t, "KEY", Types.VARCHAR, false); // not null
0657:                    addColumn(t, "VALUE", Types.VARCHAR, false); // not null
0658:                    t.createPrimaryKey(null);
0659:
0660:                    return t;
0661:                }
0662:
0663:                Object[] row;
0664:
0665:                row = t.getEmptyRowData();
0666:                row[0] = "SESSION_ID";
0667:                row[1] = String.valueOf(session.getId());
0668:
0669:                t.insertSys(row);
0670:
0671:                row = t.getEmptyRowData();
0672:                row[0] = "AUTOCOMMIT";
0673:                row[1] = session.isAutoCommit() ? "TRUE" : "FALSE";
0674:
0675:                t.insertSys(row);
0676:
0677:                row = t.getEmptyRowData();
0678:                row[0] = "USER";
0679:                row[1] = session.getUsername();
0680:
0681:                t.insertSys(row);
0682:
0683:                row = t.getEmptyRowData();
0684:                row[0] = "SESSION_READONLY";
0685:                row[1] = session.isReadOnly() ? "TRUE" : "FALSE";
0686:
0687:                t.insertSys(row);
0688:
0689:                row = t.getEmptyRowData();
0690:                row[0] = "DATABASE_READONLY";
0691:                row[1] = database.databaseReadOnly ? "TRUE" : "FALSE";
0692:
0693:                t.insertSys(row);
0694:
0695:                // fredt - value set by SET MAXROWS in SQL, not Statement.setMaxRows()
0696:                row = t.getEmptyRowData();
0697:                row[0] = "MAXROWS";
0698:                row[1] = String.valueOf(session.getSQLMaxRows());
0699:
0700:                t.insertSys(row);
0701:
0702:                row = t.getEmptyRowData();
0703:                row[0] = "DATABASE";
0704:                row[1] = database.getURI();
0705:
0706:                t.insertSys(row);
0707:
0708:                row = t.getEmptyRowData();
0709:                row[0] = "IDENTITY";
0710:                row[1] = String.valueOf(session.getLastIdentity());
0711:
0712:                t.insertSys(row);
0713:
0714:                row = t.getEmptyRowData();
0715:                row[0] = "SCHEMA";
0716:                row[1] = String.valueOf(session.getSchemaName(null));
0717:
0718:                t.insertSys(row);
0719:                t.setDataReadOnly(true);
0720:
0721:                return t;
0722:            }
0723:
0724:            /**
0725:             * Retrieves a <code>Table</code> object describing the capabilities
0726:             * and operating parameter properties for the engine hosting this
0727:             * database, as well as their applicability in terms of scope and
0728:             * name space. <p>
0729:             *
0730:             * Reported properties include certain predefined <code>Database</code>
0731:             * properties file values as well as certain database scope
0732:             * attributes. <p>
0733:             *
0734:             * It is intended that all <code>Database</code> attributes and
0735:             * properties that can be set via the database properties file,
0736:             * JDBC connection properties or SQL SET/ALTER statements will
0737:             * eventually be reported here or, where more applicable, in an
0738:             * ANSI/ISO conforming feature info base table in the defintion
0739:             * schema. <p>
0740:             *
0741:             * Currently, the database properties reported are: <p>
0742:             *
0743:             * <OL>
0744:             *     <LI>hsqldb.cache_file_scale - the scaling factor used to translate data and index structure file pointers
0745:             *     <LI>hsqldb.cache_scale - base-2 exponent scaling allowable cache row count
0746:             *     <LI>hsqldb.cache_size_scale - base-2 exponent scaling allowable cache byte count
0747:             *     <LI>hsqldb.cache_version -
0748:             *     <LI>hsqldb.catalogs - whether to report the database catalog (database uri)
0749:             *     <LI>hsqldb.compatible_version -
0750:             *     <LI>hsqldb.files_readonly - whether the database is in files_readonly mode
0751:             *     <LI>hsqldb.gc_interval - # new records forcing gc ({0|NULL}=>never)
0752:             *     <LI>hsqldb.max_nio_scale - scale factor for cache nio mapped buffers
0753:             *     <LI>hsqldb.nio_data_file - whether cache uses nio mapped buffers
0754:             *     <LI>hsqldb.original_version -
0755:             *     <LI>sql.enforce_strict_size - column length specifications enforced strictly (raise exception on overflow)?
0756:             *     <LI>textdb.all_quoted - default policy regarding whether to quote all character field values
0757:             *     <LI>textdb.cache_scale - base-2 exponent scaling allowable cache row count
0758:             *     <LI>textdb.cache_size_scale - base-2 exponent scaling allowable cache byte count
0759:             *     <LI>textdb.encoding - default TEXT table file encoding
0760:             *     <LI>textdb.fs - default field separator
0761:             *     <LI>textdb.vs - default varchar field separator
0762:             *     <LI>textdb.lvs - default long varchar field separator
0763:             *     <LI>textdb.ignore_first - default policy regarding whether to ignore the first line
0764:             *     <LI>textdb.quoted - default policy regarding treatement character field values that _may_ require quoting
0765:             *     <LI>IGNORECASE - create table VARCHAR_IGNORECASE?
0766:             *     <LI>LOGSIZSE - # bytes to which REDO log grows before auto-checkpoint
0767:             *     <LI>REFERENTIAL_INTEGITY - currently enforcing referential integrity?
0768:             *     <LI>SCRIPTFORMAT - 0 : TEXT, 1 : BINARY, ...
0769:             *     <LI>WRITEDELAY - does REDO log currently use buffered write strategy?
0770:             * </OL> <p>
0771:             *
0772:             * @return table describing database and session operating parameters
0773:             *      and capabilities
0774:             * @throws HsqlException if an error occurs while producing the table
0775:             */
0776:            Table SYSTEM_PROPERTIES() throws HsqlException {
0777:
0778:                Table t = sysTables[SYSTEM_PROPERTIES];
0779:
0780:                if (t == null) {
0781:                    t = createBlankTable(sysTableHsqlNames[SYSTEM_PROPERTIES]);
0782:
0783:                    addColumn(t, "PROPERTY_SCOPE", Types.VARCHAR, false);
0784:                    addColumn(t, "PROPERTY_NAMESPACE", Types.VARCHAR, false);
0785:                    addColumn(t, "PROPERTY_NAME", Types.VARCHAR, false);
0786:                    addColumn(t, "PROPERTY_VALUE", Types.VARCHAR);
0787:                    addColumn(t, "PROPERTY_CLASS", Types.VARCHAR, false);
0788:
0789:                    // order PROPERTY_SCOPE, PROPERTY_NAMESPACE, PROPERTY_NAME
0790:                    // true PK
0791:                    t.createPrimaryKey(null, new int[] { 0, 1, 2 }, true);
0792:
0793:                    return t;
0794:                }
0795:
0796:                // calculated column values
0797:                String scope;
0798:                String nameSpace;
0799:
0800:                // intermediate holders
0801:                Object[] row;
0802:                HsqlDatabaseProperties props;
0803:
0804:                // column number mappings
0805:                final int iscope = 0;
0806:                final int ins = 1;
0807:                final int iname = 2;
0808:                final int ivalue = 3;
0809:                final int iclass = 4;
0810:
0811:                // First, we want the names and values for
0812:                // all JDBC capabilities constants
0813:                scope = "SESSION";
0814:                props = database.getProperties();
0815:                nameSpace = "database.properties";
0816:
0817:                // boolean properties
0818:                Iterator it = props.getUserDefinedPropertyData().iterator();
0819:
0820:                while (it.hasNext()) {
0821:                    Object[] metaData = (Object[]) it.next();
0822:
0823:                    row = t.getEmptyRowData();
0824:                    row[iscope] = scope;
0825:                    row[ins] = nameSpace;
0826:                    row[iname] = metaData[HsqlDatabaseProperties.indexName];
0827:                    row[ivalue] = props.getProperty((String) row[iname]);
0828:                    row[iclass] = metaData[HsqlDatabaseProperties.indexClass];
0829:
0830:                    t.insertSys(row);
0831:                }
0832:
0833:                row = t.getEmptyRowData();
0834:                row[iscope] = scope;
0835:                row[ins] = nameSpace;
0836:                row[iname] = "SCRIPTFORMAT";
0837:
0838:                try {
0839:                    row[ivalue] = ScriptWriterBase.LIST_SCRIPT_FORMATS[database.logger
0840:                            .getScriptType()];
0841:                } catch (Exception e) {
0842:                }
0843:
0844:                row[iclass] = "java.lang.String";
0845:
0846:                t.insertSys(row);
0847:
0848:                // write delay
0849:                row = t.getEmptyRowData();
0850:                row[iscope] = scope;
0851:                row[ins] = nameSpace;
0852:                row[iname] = "WRITE_DELAY";
0853:                row[ivalue] = "" + database.logger.getWriteDelay();
0854:                row[iclass] = "int";
0855:
0856:                t.insertSys(row);
0857:
0858:                // ignore case
0859:                row = t.getEmptyRowData();
0860:                row[iscope] = scope;
0861:                row[ins] = nameSpace;
0862:                row[iname] = "IGNORECASE";
0863:                row[ivalue] = database.isIgnoreCase() ? "true" : "false";
0864:                row[iclass] = "boolean";
0865:
0866:                t.insertSys(row);
0867:
0868:                // referential integrity
0869:                row = t.getEmptyRowData();
0870:                row[iscope] = scope;
0871:                row[ins] = nameSpace;
0872:                row[iname] = "REFERENTIAL_INTEGRITY";
0873:                row[ivalue] = database.isReferentialIntegrity() ? "true"
0874:                        : "false";
0875:                row[iclass] = "boolean";
0876:
0877:                t.insertSys(row);
0878:                t.setDataReadOnly(true);
0879:
0880:                return t;
0881:            }
0882:
0883:            /**
0884:             * Retrieves a <code>Table</code> object describing all visible
0885:             * sessions. ADMIN users see *all* sessions
0886:             * while non-admin users see only their own session.<p>
0887:             *
0888:             * Each row is a session state description with the following columns: <p>
0889:             *
0890:             * <pre class="SqlCodeExample">
0891:             * SESSION_ID         INTEGER   session identifier
0892:             * CONNECTED          TIMESTAMP time at which session was created
0893:             * USER_NAME          VARCHAR   db user name of current session user
0894:             * IS_ADMIN           BOOLEAN   is session user an admin user?
0895:             * AUTOCOMMIT         BOOLEAN   is session in autocommit mode?
0896:             * READONLY           BOOLEAN   is session in read-only mode?
0897:             * MAXROWS            INTEGER   session's MAXROWS setting
0898:             * LAST_IDENTITY      INTEGER   last identity value used by this session
0899:             * TRANSACTION_SIZE   INTEGER   # of undo items in current transaction
0900:             * SCHEMA             VARCHAR   current schema for session
0901:             * </pre> <p>
0902:             *
0903:             * @return a <code>Table</code> object describing all visible
0904:             *      sessions
0905:             * @throws HsqlException if an error occurs while producing the table
0906:             */
0907:            Table SYSTEM_SESSIONS() throws HsqlException {
0908:
0909:                Table t = sysTables[SYSTEM_SESSIONS];
0910:
0911:                if (t == null) {
0912:                    t = createBlankTable(sysTableHsqlNames[SYSTEM_SESSIONS]);
0913:
0914:                    addColumn(t, "SESSION_ID", Types.INTEGER, false);
0915:                    addColumn(t, "CONNECTED", Types.TIMESTAMP, false);
0916:                    addColumn(t, "USER_NAME", Types.VARCHAR, false);
0917:                    addColumn(t, "IS_ADMIN", Types.BOOLEAN, false);
0918:                    addColumn(t, "AUTOCOMMIT", Types.BOOLEAN, false);
0919:                    addColumn(t, "READONLY", Types.BOOLEAN, false);
0920:                    addColumn(t, "MAXROWS", Types.INTEGER, false);
0921:
0922:                    // Note: some sessions may have a NULL LAST_IDENTITY value
0923:                    addColumn(t, "LAST_IDENTITY", Types.BIGINT);
0924:                    addColumn(t, "TRANSACTION_SIZE", Types.INTEGER, false);
0925:                    addColumn(t, "SCHEMA", Types.VARCHAR, false);
0926:
0927:                    // order:  SESSION_ID
0928:                    // true primary key
0929:                    t.createPrimaryKey(null, new int[] { 0 }, true);
0930:
0931:                    return t;
0932:                }
0933:
0934:                // intermediate holders
0935:                Session[] sessions;
0936:                Session s;
0937:                Object[] row;
0938:
0939:                // column number mappings
0940:                final int isid = 0;
0941:                final int ict = 1;
0942:                final int iuname = 2;
0943:                final int iis_admin = 3;
0944:                final int iautocmt = 4;
0945:                final int ireadonly = 5;
0946:                final int imaxrows = 6;
0947:                final int ilast_id = 7;
0948:                final int it_size = 8;
0949:                final int it_schema = 9;
0950:
0951:                // Initialisation
0952:                sessions = ns.listVisibleSessions(session);
0953:
0954:                // Do it.
0955:                for (int i = 0; i < sessions.length; i++) {
0956:                    s = sessions[i];
0957:                    row = t.getEmptyRowData();
0958:                    row[isid] = ValuePool.getInt(s.getId());
0959:                    row[ict] = HsqlDateTime.getTimestamp(s.getConnectTime());
0960:                    row[iuname] = s.getUsername();
0961:                    row[iis_admin] = ValuePool.getBoolean(s.isAdmin());
0962:                    row[iautocmt] = ValuePool.getBoolean(s.isAutoCommit());
0963:                    row[ireadonly] = ValuePool.getBoolean(s.isReadOnly());
0964:                    row[imaxrows] = ValuePool.getInt(s.getSQLMaxRows());
0965:                    row[ilast_id] = ValuePool.getLong(s.getLastIdentity()
0966:                            .longValue());
0967:                    row[it_size] = ValuePool.getInt(s.getTransactionSize());
0968:                    row[it_schema] = s.getSchemaName(null);
0969:
0970:                    t.insertSys(row);
0971:                }
0972:
0973:                t.setDataReadOnly(true);
0974:
0975:                return t;
0976:            }
0977:
0978:            /**
0979:             * Retrieves a <code>Table</code> object describing the accessible
0980:             * direct super table (if any) of each accessible table defined
0981:             * within this database. <p>
0982:             *
0983:             * Each row is a super table description with the following columns: <p>
0984:             *
0985:             * <pre class="SqlCodeExample">
0986:             * TABLE_CAT       VARCHAR   the table's catalog
0987:             * TABLE_SCHEM     VARCHAR   table schema
0988:             * TABLE_NAME      VARCHAR   table name
0989:             * SUPERTABLE_NAME VARCHAR   the direct super table's name
0990:             * </pre> <p>
0991:             * @return a <code>Table</code> object describing the accessible
0992:             *        direct supertable (if any) of each accessible
0993:             *        table defined within this database
0994:             * @throws HsqlException if an error occurs while producing the table
0995:             */
0996:            Table SYSTEM_SUPERTABLES() throws HsqlException {
0997:
0998:                Table t = sysTables[SYSTEM_SUPERTABLES];
0999:
1000:                if (t == null) {
1001:                    t = createBlankTable(sysTableHsqlNames[SYSTEM_SUPERTABLES]);
1002:
1003:                    addColumn(t, "TABLE_CAT", Types.VARCHAR);
1004:                    addColumn(t, "TABLE_SCHEM", Types.VARCHAR);
1005:                    addColumn(t, "TABLE_NAME", Types.VARCHAR, false); // not null
1006:                    addColumn(t, "SUPERTABLE_NAME", Types.VARCHAR, false); // not null
1007:                    t.createPrimaryKey(null);
1008:
1009:                    return t;
1010:                }
1011:
1012:                t.setDataReadOnly(true);
1013:
1014:                return t;
1015:            }
1016:
1017:            /**
1018:             * Retrieves a <code>Table</code> object describing the accessible
1019:             * direct super type (if any) of each accessible user-defined type (UDT)
1020:             * defined within this database. <p>
1021:             *
1022:             * Each row is a super type description with the following columns: <p>
1023:             *
1024:             * <pre class="SqlCodeExample">
1025:             * TYPE_CAT        VARCHAR   the UDT's catalog
1026:             * TYPE_SCHEM      VARCHAR   UDT's schema
1027:             * TYPE_NAME       VARCHAR   type name of the UDT
1028:             * SUPERTYPE_CAT   VARCHAR   the direct super type's catalog
1029:             * SUPERTYPE_SCHEM VARCHAR   the direct super type's schema
1030:             * SUPERTYPE_NAME  VARCHAR   the direct super type's name
1031:             * </pre> <p>
1032:             * @return a <code>Table</code> object describing the accessible
1033:             *        direct supertype (if any) of each accessible
1034:             *        user-defined type (UDT) defined within this database
1035:             * @throws HsqlException if an error occurs while producing the table
1036:             */
1037:            Table SYSTEM_SUPERTYPES() throws HsqlException {
1038:
1039:                Table t = sysTables[SYSTEM_SUPERTYPES];
1040:
1041:                if (t == null) {
1042:                    t = createBlankTable(sysTableHsqlNames[SYSTEM_SUPERTYPES]);
1043:
1044:                    addColumn(t, "TYPE_CAT", Types.VARCHAR);
1045:                    addColumn(t, "TYPE_SCHEM", Types.VARCHAR);
1046:                    addColumn(t, "TYPE_NAME", Types.VARCHAR, false); // not null
1047:                    addColumn(t, "SUPERTYPE_CAT", Types.VARCHAR);
1048:                    addColumn(t, "SUPERTYPE_SCHEM", Types.VARCHAR);
1049:                    addColumn(t, "SUPERTYPE_NAME", Types.VARCHAR, false); // not null
1050:                    t.createPrimaryKey(null);
1051:
1052:                    return t;
1053:                }
1054:
1055:                t.setDataReadOnly(true);
1056:
1057:                return t;
1058:            }
1059:
1060:            /**
1061:             * Retrieves a <code>Table</code> object describing the TEXT TABLE objects
1062:             * defined within this database. The table contains one row for each row
1063:             * in the SYSTEM_TABLES table with a HSQLDB_TYPE of  TEXT . <p>
1064:             *
1065:             * Each row is a description of the attributes that defines its TEXT TABLE,
1066:             * with the following columns:
1067:             *
1068:             * <pre class="SqlCodeExample">
1069:             * TABLE_CAT                 VARCHAR   table's catalog name
1070:             * TABLE_SCHEM               VARCHAR   table's simple schema name
1071:             * TABLE_NAME                VARCHAR   table's simple name
1072:             * DATA_SOURCE_DEFINITION    VARCHAR   the "spec" proption of the table's
1073:             *                                     SET TABLE ... SOURCE DDL declaration
1074:             * FILE_PATH                 VARCHAR   absolute file path.
1075:             * FILE_ENCODING             VARCHAR   endcoding of table's text file
1076:             * FIELD_SEPARATOR           VARCHAR   default field separator
1077:             * VARCHAR_SEPARATOR         VARCAHR   varchar field separator
1078:             * LONGVARCHAR_SEPARATOR     VARCHAR   longvarchar field separator
1079:             * IS_IGNORE_FIRST           BOOLEAN   ignores first line of file?
1080:             * IS_QUOTED                 BOOLEAN   fields are quoted if necessary?
1081:             * IS_ALL_QUOTED             BOOLEAN   all fields are quoted?
1082:             * IS_DESC                   BOOLEAN   read rows starting at end of file?
1083:             * </pre> <p>
1084:             *
1085:             * @return a <code>Table</code> object describing the text attributes
1086:             * of the accessible text tables defined within this database
1087:             * @throws HsqlException if an error occurs while producing the table
1088:             *
1089:             */
1090:            Table SYSTEM_TEXTTABLES() throws HsqlException {
1091:
1092:                Table t = sysTables[SYSTEM_TEXTTABLES];
1093:
1094:                if (t == null) {
1095:                    t = createBlankTable(sysTableHsqlNames[SYSTEM_TEXTTABLES]);
1096:
1097:                    addColumn(t, "TABLE_CAT", Types.VARCHAR);
1098:                    addColumn(t, "TABLE_SCHEM", Types.VARCHAR);
1099:                    addColumn(t, "TABLE_NAME", Types.VARCHAR, false); // not null
1100:                    addColumn(t, "DATA_SOURCE_DEFINTION", Types.VARCHAR);
1101:                    addColumn(t, "FILE_PATH", Types.VARCHAR);
1102:                    addColumn(t, "FILE_ENCODING", Types.VARCHAR);
1103:                    addColumn(t, "FIELD_SEPARATOR", Types.VARCHAR);
1104:                    addColumn(t, "VARCHAR_SEPARATOR", Types.VARCHAR);
1105:                    addColumn(t, "LONGVARCHAR_SEPARATOR", Types.VARCHAR);
1106:                    addColumn(t, "IS_IGNORE_FIRST", Types.BOOLEAN);
1107:                    addColumn(t, "IS_ALL_QUOTED", Types.BOOLEAN);
1108:                    addColumn(t, "IS_QUOTED", Types.BOOLEAN);
1109:                    addColumn(t, "IS_DESC", Types.BOOLEAN);
1110:
1111:                    // ------------------------------------------------------------
1112:                    t.createPrimaryKey();
1113:
1114:                    return t;
1115:                }
1116:
1117:                // intermediate holders
1118:                Iterator tables;
1119:                Table table;
1120:                Object[] row;
1121:
1122:                //        DITableInfo ti;
1123:                TextCache tc;
1124:
1125:                // column number mappings
1126:                final int itable_cat = 0;
1127:                final int itable_schem = 1;
1128:                final int itable_name = 2;
1129:                final int idsd = 3;
1130:                final int ifile_path = 4;
1131:                final int ifile_enc = 5;
1132:                final int ifs = 6;
1133:                final int ivfs = 7;
1134:                final int ilvfs = 8;
1135:                final int iif = 9;
1136:                final int iiq = 10;
1137:                final int iiaq = 11;
1138:                final int iid = 12;
1139:
1140:                // Initialization
1141:                tables = database.schemaManager.allTablesIterator();
1142:
1143:                // Do it.
1144:                while (tables.hasNext()) {
1145:                    table = (Table) tables.next();
1146:
1147:                    if (!table.isText() || !isAccessibleTable(table)) {
1148:                        continue;
1149:                    }
1150:
1151:                    row = t.getEmptyRowData();
1152:                    row[itable_cat] = ns.getCatalogName(table);
1153:                    row[itable_schem] = table.getSchemaName();
1154:                    row[itable_name] = table.getName().name;
1155:                    row[idsd] = table.getDataSource();
1156:
1157:                    if (table.getCache() instanceof  TextCache) {
1158:                        tc = (TextCache) table.getCache();
1159:                        row[ifile_path] = FileUtil.canonicalOrAbsolutePath(tc
1160:                                .getFileName());
1161:                        row[ifile_enc] = tc.stringEncoding;
1162:                        row[ifs] = tc.fs;
1163:                        row[ivfs] = tc.vs;
1164:                        row[ilvfs] = tc.lvs;
1165:                        row[iif] = ValuePool.getBoolean(tc.ignoreFirst);
1166:                        row[iiq] = ValuePool.getBoolean(tc.isQuoted);
1167:                        row[iiaq] = ValuePool.getBoolean(tc.isAllQuoted);
1168:                        row[iid] = ValuePool.getBoolean(table
1169:                                .isDescDataSource());
1170:                    }
1171:
1172:                    t.insertSys(row);
1173:                }
1174:
1175:                t.setDataReadOnly(true);
1176:
1177:                return t;
1178:            }
1179:
1180:            /**
1181:             * Retrieves a <code>Table</code> object describing the usage
1182:             * of accessible columns in accessible triggers defined within
1183:             * the database. <p>
1184:             *
1185:             * Each column usage description has the following columns: <p>
1186:             *
1187:             * <pre class="SqlCodeExample">
1188:             * TRIGGER_CAT   VARCHAR   Trigger catalog.
1189:             * TRIGGER_SCHEM VARCHAR   Trigger schema.
1190:             * TRIGGER_NAME  VARCHAR   Trigger name.
1191:             * TABLE_CAT     VARCHAR   Catalog of table on which the trigger is defined.
1192:             * TABLE_SCHEM   VARCHAR   Schema of table on which the trigger is defined.
1193:             * TABLE_NAME    VARCHAR   Table on which the trigger is defined.
1194:             * COLUMN_NAME   VARCHAR   Name of the column used in the trigger.
1195:             * COLUMN_LIST   VARCHAR   Specified in UPDATE clause?: ("Y" | "N"}
1196:             * COLUMN_USAGE  VARCHAR   {"NEW" | "OLD" | "IN" | "OUT" | "IN OUT"}
1197:             * </pre> <p>
1198:             * @return a <code>Table</code> object describing of the usage
1199:             *        of accessible columns in accessible triggers
1200:             *        defined within this database
1201:             * @throws HsqlException if an error occurs while producing the table
1202:             */
1203:            Table SYSTEM_TRIGGERCOLUMNS() throws HsqlException {
1204:
1205:                Table t = sysTables[SYSTEM_TRIGGERCOLUMNS];
1206:
1207:                if (t == null) {
1208:                    t = createBlankTable(sysTableHsqlNames[SYSTEM_TRIGGERCOLUMNS]);
1209:
1210:                    addColumn(t, "TRIGGER_CAT", Types.VARCHAR);
1211:                    addColumn(t, "TRIGGER_SCHEM", Types.VARCHAR);
1212:                    addColumn(t, "TRIGGER_NAME", Types.VARCHAR);
1213:                    addColumn(t, "TABLE_CAT", Types.VARCHAR);
1214:                    addColumn(t, "TABLE_SCHEM", Types.VARCHAR);
1215:                    addColumn(t, "TABLE_NAME", Types.VARCHAR);
1216:                    addColumn(t, "COLUMN_NAME", Types.VARCHAR);
1217:                    addColumn(t, "COLUMN_LIST", Types.VARCHAR);
1218:                    addColumn(t, "COLUMN_USAGE", Types.VARCHAR);
1219:
1220:                    // order:  all columns, in order, as each column
1221:                    // of each table may eventually be listed under various capacities
1222:                    // (when a more comprehensive trugger system is put in place)
1223:                    // false PK, as cat and schem may be null
1224:                    t.createPrimaryKey(null, new int[] { 0, 1, 2, 3, 4, 5, 6,
1225:                            7, 8 }, false);
1226:
1227:                    return t;
1228:                }
1229:
1230:                Result rs;
1231:
1232:                // - used appends to make class file constant pool smaller
1233:                // - saves ~ 100 bytes jar space
1234:                rs = session
1235:                        .sqlExecuteDirectNoPreChecks("select a.TRIGGER_CAT,a.TRIGGER_SCHEM,a.TRIGGER_NAME, "
1236:                                + "a.TABLE_CAT,a.TABLE_SCHEM,a.TABLE_NAME,b.COLUMN_NAME,'Y',"
1237:                                + "'IN' from INFORMATION_SCHEMA.SYSTEM_TRIGGERS a, "
1238:                                + "INFORMATION_SCHEMA.SYSTEM_COLUMNS b where "
1239:                                + "a.TABLE_NAME=b.TABLE_NAME and a.TABLE_SCHEM=b.TABLE_SCHEM");
1240:
1241:                /*
1242:                 (new StringBuffer(185)).append("SELECT").append(' ').append(
1243:                 "a.").append("TRIGGER_CAT").append(',').append("a.").append(
1244:                 "TRIGGER_SCHEM").append(',').append("a.").append(
1245:                 "TRIGGER_NAME").append(',').append("a.").append(
1246:                 "TABLE_CAT").append(',').append("a.").append(
1247:                 "TABLE_SCHEM").append(',').append("a.").append(
1248:                 "TABLE_NAME").append(',').append("b.").append(
1249:                 "COLUMN_NAME").append(',').append("'Y'").append(',').append(
1250:                 "'IN'").append(' ').append("from").append(' ').append(
1251:                 "INFORMATION_SCHEMA").append('.').append(
1252:                 "SYSTEM_TRIGGERS").append(" a,").append(
1253:                 "INFORMATION_SCHEMA").append('.').append(
1254:                 "SYSTEM_COLUMNS").append(" b ").append("where").append(
1255:                 ' ').append("a.").append("TABLE_NAME").append('=').append(
1256:                 "b.").append("TABLE_NAME").toString();
1257:                 */
1258:                t.insertSys(rs);
1259:                t.setDataReadOnly(true);
1260:
1261:                return t;
1262:            }
1263:
1264:            /**
1265:             * Retrieves a <code>Table</code> object describing the accessible
1266:             * triggers defined within the database. <p>
1267:             *
1268:             * Each row is a trigger description with the following columns: <p>
1269:             *
1270:             * <pre class="SqlCodeExample">
1271:             * TRIGGER_CAT       VARCHAR   Trigger catalog.
1272:             * TRIGGER_SCHEM     VARCHAR   Trigger Schema.
1273:             * TRIGGER_NAME      VARCHAR   Trigger Name.
1274:             * TRIGGER_TYPE      VARCHAR   {("BEFORE" | "AFTER") + [" EACH ROW"] }
1275:             * TRIGGERING_EVENT  VARCHAR   {"INSERT" | "UPDATE" | "DELETE"}
1276:             *                             (future?: "INSTEAD OF " + ("SELECT" | ...))
1277:             * TABLE_CAT         VARCHAR   Table's catalog.
1278:             * TABLE_SCHEM       VARCHAR   Table's schema.
1279:             * BASE_OBJECT_TYPE  VARCHAR   "TABLE"
1280:             *                             (future?: "VIEW" | "SCHEMA" | "DATABASE")
1281:             * TABLE_NAME        VARCHAR   Table on which trigger is defined
1282:             * COLUMN_NAME       VARCHAR   NULL (future?: nested table column name)
1283:             * REFERENCING_NAMES VARCHAR   ROW, OLD, NEW, etc.
1284:             * WHEN_CLAUSE       VARCHAR   Condition firing trigger (NULL => always)
1285:             * STATUS            VARCHAR   {"ENABLED" | "DISABLED"}
1286:             * DESCRIPTION       VARCHAR   typically, the trigger's DDL
1287:             * ACTION_TYPE       VARCHAR   "CALL" (future?: embedded language name)
1288:             * TRIGGER_BODY      VARCHAR   Statement(s) executed
1289:             * </pre> <p>
1290:             *
1291:             * @return a <code>Table</code> object describing the accessible
1292:             *    triggers defined within this database.
1293:             * @throws HsqlException if an error occurs while producing the table
1294:             */
1295:            Table SYSTEM_TRIGGERS() throws HsqlException {
1296:
1297:                Table t = sysTables[SYSTEM_TRIGGERS];
1298:
1299:                if (t == null) {
1300:                    t = createBlankTable(sysTableHsqlNames[SYSTEM_TRIGGERS]);
1301:
1302:                    addColumn(t, "TRIGGER_CAT", Types.VARCHAR);
1303:                    addColumn(t, "TRIGGER_SCHEM", Types.VARCHAR);
1304:                    addColumn(t, "TRIGGER_NAME", Types.VARCHAR, false);
1305:                    addColumn(t, "TRIGGER_TYPE", Types.VARCHAR, 15, false);
1306:                    addColumn(t, "TRIGGERING_EVENT", Types.VARCHAR, 10, false);
1307:                    addColumn(t, "TABLE_CAT", Types.VARCHAR);
1308:                    addColumn(t, "TABLE_SCHEM", Types.VARCHAR);
1309:                    addColumn(t, "BASE_OBJECT_TYPE", Types.VARCHAR, 8, false);
1310:                    addColumn(t, "TABLE_NAME", Types.VARCHAR, false);
1311:                    addColumn(t, "COLUMN_NAME", Types.VARCHAR);
1312:                    addColumn(t, "REFERENCING_NAMES", Types.VARCHAR, false);
1313:                    addColumn(t, "WHEN_CLAUSE", Types.VARCHAR);
1314:                    addColumn(t, "STATUS", Types.VARCHAR, 8, false);
1315:                    addColumn(t, "DESCRIPTION", Types.VARCHAR, false);
1316:                    addColumn(t, "ACTION_TYPE", Types.VARCHAR, false);
1317:                    addColumn(t, "TRIGGER_BODY", Types.VARCHAR, false);
1318:
1319:                    // order: TRIGGER_TYPE, TRIGGER_SCHEM, TRIGGER_NAME
1320:                    // added for unique: TRIGGER_CAT
1321:                    // false PK, as TRIGGER_SCHEM and/or TRIGGER_CAT may be null
1322:                    t.createPrimaryKey(null, new int[] { 3, 1, 2, 0 }, false);
1323:
1324:                    return t;
1325:                }
1326:
1327:                // calculated column values
1328:                String triggerCatalog;
1329:                String triggerSchema;
1330:                String triggerName;
1331:                String triggerType;
1332:                String triggeringEvent;
1333:                String tableCatalog;
1334:                String tableSchema;
1335:                String baseObjectType;
1336:                String tableName;
1337:                String columnName;
1338:                String referencingNames;
1339:                String whenClause;
1340:                String status;
1341:                String description;
1342:                String actionType;
1343:                String triggerBody;
1344:
1345:                // Intermediate holders
1346:                Iterator tables;
1347:                Table table;
1348:                HsqlArrayList[] vTrigs;
1349:                HsqlArrayList triggerList;
1350:                TriggerDef def;
1351:                Object[] row;
1352:
1353:                // column number mappings
1354:                final int itrigger_cat = 0;
1355:                final int itrigger_schem = 1;
1356:                final int itrigger_name = 2;
1357:                final int itrigger_type = 3;
1358:                final int itriggering_event = 4;
1359:                final int itable_cat = 5;
1360:                final int itable_schem = 6;
1361:                final int ibase_object_type = 7;
1362:                final int itable_name = 8;
1363:                final int icolumn_name = 9;
1364:                final int ireferencing_names = 10;
1365:                final int iwhen_clause = 11;
1366:                final int istatus = 12;
1367:                final int idescription = 13;
1368:                final int iaction_type = 14;
1369:                final int itrigger_body = 15;
1370:
1371:                // Initialization
1372:                tables = database.schemaManager.allTablesIterator();
1373:
1374:                // these are the only values supported, currently
1375:                actionType = "CALL";
1376:                baseObjectType = "TABLE";
1377:                columnName = null;
1378:                referencingNames = "ROW";
1379:                whenClause = null;
1380:
1381:                // Do it.
1382:                while (tables.hasNext()) {
1383:                    table = (Table) tables.next();
1384:                    vTrigs = table.triggerLists;
1385:
1386:                    // faster test first
1387:                    if (vTrigs == null) {
1388:                        continue;
1389:                    }
1390:
1391:                    if (!isAccessibleTable(table)) {
1392:                        continue;
1393:                    }
1394:
1395:                    tableCatalog = ns.getCatalogName(table);
1396:                    triggerCatalog = tableCatalog;
1397:                    tableSchema = table.getSchemaName();
1398:                    triggerSchema = tableSchema;
1399:                    tableName = table.getName().name;
1400:
1401:                    for (int i = 0; i < vTrigs.length; i++) {
1402:                        triggerList = vTrigs[i];
1403:
1404:                        if (triggerList == null) {
1405:                            continue;
1406:                        }
1407:
1408:                        for (int j = 0; j < triggerList.size(); j++) {
1409:                            def = (TriggerDef) triggerList.get(j);
1410:
1411:                            if (def == null) {
1412:                                continue;
1413:                            }
1414:
1415:                            triggerName = def.name.name;
1416:                            description = def.getDDL().toString();
1417:                            status = def.valid ? "ENABLED" : "DISABLED";
1418:                            triggerBody = def.triggerClassName;
1419:                            triggerType = def.when;
1420:
1421:                            if (def.forEachRow) {
1422:                                triggerType += " EACH ROW";
1423:                            }
1424:
1425:                            triggeringEvent = def.operation;
1426:                            row = t.getEmptyRowData();
1427:                            row[itrigger_cat] = triggerCatalog;
1428:                            row[itrigger_schem] = triggerSchema;
1429:                            row[itrigger_name] = triggerName;
1430:                            row[itrigger_type] = triggerType;
1431:                            row[itriggering_event] = triggeringEvent;
1432:                            row[itable_cat] = tableCatalog;
1433:                            row[itable_schem] = tableSchema;
1434:                            row[ibase_object_type] = baseObjectType;
1435:                            row[itable_name] = tableName;
1436:                            row[icolumn_name] = columnName;
1437:                            row[ireferencing_names] = referencingNames;
1438:                            row[iwhen_clause] = whenClause;
1439:                            row[istatus] = status;
1440:                            row[idescription] = description;
1441:                            row[iaction_type] = actionType;
1442:                            row[itrigger_body] = triggerBody;
1443:
1444:                            t.insertSys(row);
1445:                        }
1446:                    }
1447:                }
1448:
1449:                t.setDataReadOnly(true);
1450:
1451:                return t;
1452:            }
1453:
1454:            /**
1455:             * Retrieves a <code>Table</code> object describing the accessible
1456:             * attributes of the accessible user-defined type (UDT) objects
1457:             * defined within this database. <p>
1458:             *
1459:             * This description does not contain inherited attributes. <p>
1460:             *
1461:             * Each row is a user-defined type attributes description with the
1462:             * following columns:
1463:             *
1464:             * <pre class="SqlCodeExample">
1465:             * TYPE_CAT          VARCHAR   type catalog
1466:             * TYPE_SCHEM        VARCHAR   type schema
1467:             * TYPE_NAME         VARCHAR   type name
1468:             * ATTR_NAME         VARCHAR   attribute name
1469:             * DATA_TYPE         SMALLINT  attribute's SQL type from DITypes
1470:             * ATTR_TYPE_NAME    VARCHAR   UDT: fully qualified type name
1471:             *                            REF: fully qualified type name of target type of
1472:             *                            the reference type.
1473:             * ATTR_SIZE         INTEGER   column size.
1474:             *                            char or date types => maximum number of characters;
1475:             *                            numeric or decimal types => precision.
1476:             * DECIMAL_DIGITS    INTEGER   # of fractional digits (scale) of number type
1477:             * NUM_PREC_RADIX    INTEGER   Radix of number type
1478:             * NULLABLE          INTEGER   whether NULL is allowed
1479:             * REMARKS           VARCHAR   comment describing attribute
1480:             * ATTR_DEF          VARCHAR   default attribute value
1481:             * SQL_DATA_TYPE     INTEGER   expected value of SQL CLI SQL_DESC_TYPE in the SQLDA
1482:             * SQL_DATETIME_SUB  INTEGER   DATETIME/INTERVAL => datetime/interval subcode
1483:             * CHAR_OCTET_LENGTH INTEGER   for char types:  max bytes in column
1484:             * ORDINAL_POSITION  INTEGER   index of column in table (starting at 1)
1485:             * IS_NULLABLE       VARCHAR   "NO" => strictly no NULL values;
1486:             *                             "YES" => maybe NULL values;
1487:             *                             "" => unknown.
1488:             * SCOPE_CATALOG     VARCHAR   catalog of REF attribute scope table or NULL
1489:             * SCOPE_SCHEMA      VARCHAR   schema of REF attribute scope table or NULL
1490:             * SCOPE_TABLE       VARCHAR   name of REF attribute scope table or NULL
1491:             * SOURCE_DATA_TYPE  SMALLINT  For DISTINCT or user-generated REF DATA_TYPE:
1492:             *                            source SQL type from DITypes
1493:             *                            For other DATA_TYPE values:  NULL
1494:             * </pre>
1495:             *
1496:             * <B>Note:</B> Currently, neither the HSQLDB engine or the JDBC driver
1497:             * support UDTs, so an empty table is returned. <p>
1498:             * @return a <code>Table</code> object describing the accessible
1499:             *        attrubutes of the accessible user-defined type
1500:             *        (UDT) objects defined within this database
1501:             * @throws HsqlException if an error occurs while producing the table
1502:             */
1503:            Table SYSTEM_UDTATTRIBUTES() throws HsqlException {
1504:
1505:                Table t = sysTables[SYSTEM_UDTATTRIBUTES];
1506:
1507:                if (t == null) {
1508:                    t = createBlankTable(sysTableHsqlNames[SYSTEM_UDTATTRIBUTES]);
1509:
1510:                    addColumn(t, "TYPE_CAT", Types.VARCHAR);
1511:                    addColumn(t, "TYPE_SCHEM", Types.VARCHAR);
1512:                    addColumn(t, "TYPE_NAME", Types.VARCHAR, false); // not null
1513:                    addColumn(t, "ATTR_NAME", Types.VARCHAR, false); // not null
1514:                    addColumn(t, "DATA_TYPE", Types.SMALLINT, false); // not null
1515:                    addColumn(t, "ATTR_TYPE_NAME", Types.VARCHAR, false); // not null
1516:                    addColumn(t, "ATTR_SIZE", Types.INTEGER);
1517:                    addColumn(t, "DECIMAL_DIGITS", Types.INTEGER);
1518:                    addColumn(t, "NUM_PREC_RADIX", Types.INTEGER);
1519:                    addColumn(t, "NULLABLE", Types.INTEGER);
1520:                    addColumn(t, "REMARKS", Types.VARCHAR);
1521:                    addColumn(t, "ATTR_DEF", Types.VARCHAR);
1522:                    addColumn(t, "SQL_DATA_TYPE", Types.INTEGER);
1523:                    addColumn(t, "SQL_DATETIME_SUB", Types.INTEGER);
1524:                    addColumn(t, "CHAR_OCTET_LENGTH", Types.INTEGER);
1525:                    addColumn(t, "ORDINAL_POSITION", Types.INTEGER, false); // not null
1526:                    addColumn(t, "IS_NULLABLE", Types.VARCHAR, false); // not null
1527:                    addColumn(t, "SCOPE_CATALOG", Types.VARCHAR);
1528:                    addColumn(t, "SCOPE_SCHEMA", Types.VARCHAR);
1529:                    addColumn(t, "SCOPE_TABLE", Types.VARCHAR);
1530:                    addColumn(t, "SOURCE_DATA_TYPE", Types.SMALLINT);
1531:                    t.createPrimaryKey(null);
1532:
1533:                    return t;
1534:                }
1535:
1536:                t.setDataReadOnly(true);
1537:
1538:                return t;
1539:            }
1540:
1541:            /**
1542:             * Retrieves a <code>Table</code> object describing the accessible
1543:             * user-defined types defined in this database. <p>
1544:             *
1545:             * Schema-specific UDTs may have type JAVA_OBJECT, STRUCT, or DISTINCT.
1546:             *
1547:             * <P>Each row is a UDT descripion with the following columns:
1548:             * <OL>
1549:             *   <LI><B>TYPE_CAT</B> <code>VARCHAR</code> => the type's catalog
1550:             *   <LI><B>TYPE_SCHEM</B> <code>VARCHAR</code> => type's schema
1551:             *   <LI><B>TYPE_NAME</B> <code>VARCHAR</code> => type name
1552:             *   <LI><B>CLASS_NAME</B> <code>VARCHAR</code> => Java class name
1553:             *   <LI><B>DATA_TYPE</B> <code>VARCHAR</code> =>
1554:             *         type value defined in <code>DITypes</code>;
1555:             *         one of <code>JAVA_OBJECT</code>, <code>STRUCT</code>, or
1556:             *        <code>DISTINCT</code>
1557:             *   <LI><B>REMARKS</B> <code>VARCHAR</code> =>
1558:             *          explanatory comment on the type
1559:             *   <LI><B>BASE_TYPE</B><code>SMALLINT</code> =>
1560:             *          type code of the source type of a DISTINCT type or the
1561:             *          type that implements the user-generated reference type of the
1562:             *          SELF_REFERENCING_COLUMN of a structured type as defined in
1563:             *          DITypes (null if DATA_TYPE is not DISTINCT or not
1564:             *          STRUCT with REFERENCE_GENERATION = USER_DEFINED)
1565:             *
1566:             * </OL> <p>
1567:             *
1568:             * <B>Note:</B> Currently, neither the HSQLDB engine or the JDBC driver
1569:             * support UDTs, so an empty table is returned. <p>
1570:             *
1571:             * @return a <code>Table</code> object describing the accessible
1572:             *      user-defined types defined in this database
1573:             * @throws HsqlException if an error occurs while producing the table
1574:             */
1575:            Table SYSTEM_UDTS() throws HsqlException {
1576:
1577:                Table t = sysTables[SYSTEM_UDTS];
1578:
1579:                if (t == null) {
1580:                    t = createBlankTable(sysTableHsqlNames[SYSTEM_UDTS]);
1581:
1582:                    addColumn(t, "TYPE_CAT", Types.VARCHAR);
1583:                    addColumn(t, "TYPE_SCHEM", Types.VARCHAR);
1584:                    addColumn(t, "TYPE_NAME", Types.VARCHAR, false); // not null
1585:                    addColumn(t, "CLASS_NAME", Types.VARCHAR, false); // not null
1586:                    addColumn(t, "DATA_TYPE", Types.VARCHAR, false); // not null
1587:                    addColumn(t, "REMARKS", Types.VARCHAR);
1588:                    addColumn(t, "BASE_TYPE", Types.SMALLINT);
1589:                    t.createPrimaryKey(null);
1590:
1591:                    return t;
1592:                }
1593:
1594:                t.setDataReadOnly(true);
1595:
1596:                return t;
1597:            }
1598:
1599:            /**
1600:             * Retrieves a <code>Table</code> object describing the accessible
1601:             * columns that are automatically updated when any value in a row
1602:             * is updated. <p>
1603:             *
1604:             * Each row is a version column description with the following columns: <p>
1605:             *
1606:             * <OL>
1607:             * <LI><B>SCOPE</B> <code>SMALLINT</code> => is not used
1608:             * <LI><B>COLUMN_NAME</B> <code>VARCHAR</code> => column name
1609:             * <LI><B>DATA_TYPE</B> <code>SMALLINT</code> =>
1610:             *        SQL data type from java.sql.Types
1611:             * <LI><B>TYPE_NAME</B> <code>SMALLINT</code> =>
1612:             *       Data source dependent type name
1613:             * <LI><B>COLUMN_SIZE</B> <code>INTEGER</code> => precision
1614:             * <LI><B>BUFFER_LENGTH</B> <code>INTEGER</code> =>
1615:             *        length of column value in bytes
1616:             * <LI><B>DECIMAL_DIGITS</B> <code>SMALLINT</code> => scale
1617:             * <LI><B>PSEUDO_COLUMN</B> <code>SMALLINT</code> =>
1618:             *        is this a pseudo column like an Oracle <code>ROWID</code>:<BR>
1619:             *        (as defined in <code>java.sql.DatabaseMetadata</code>)
1620:             * <UL>
1621:             *    <LI><code>versionColumnUnknown</code> - may or may not be
1622:             *        pseudo column
1623:             *    <LI><code>versionColumnNotPseudo</code> - is NOT a pseudo column
1624:             *    <LI><code>versionColumnPseudo</code> - is a pseudo column
1625:             * </UL>
1626:             * </OL> <p>
1627:             *
1628:             * <B>Note:</B> Currently, the HSQLDB engine does not support version
1629:             * columns, so an empty table is returned. <p>
1630:             *
1631:             * @return a <code>Table</code> object describing the columns
1632:             *        that are automatically updated when any value
1633:             *        in a row is updated
1634:             * @throws HsqlException if an error occurs while producing the table
1635:             */
1636:            Table SYSTEM_VERSIONCOLUMNS() throws HsqlException {
1637:
1638:                Table t = sysTables[SYSTEM_VERSIONCOLUMNS];
1639:
1640:                if (t == null) {
1641:                    t = createBlankTable(sysTableHsqlNames[SYSTEM_VERSIONCOLUMNS]);
1642:
1643:                    // ----------------------------------------------------------------
1644:                    // required by DatabaseMetaData.getVersionColumns result set
1645:                    // ----------------------------------------------------------------
1646:                    addColumn(t, "SCOPE", Types.INTEGER);
1647:                    addColumn(t, "COLUMN_NAME", Types.VARCHAR, false); // not null
1648:                    addColumn(t, "DATA_TYPE", Types.SMALLINT, false); // not null
1649:                    addColumn(t, "TYPE_NAME", Types.VARCHAR, false); // not null
1650:                    addColumn(t, "COLUMN_SIZE", Types.SMALLINT);
1651:                    addColumn(t, "BUFFER_LENGTH", Types.INTEGER);
1652:                    addColumn(t, "DECIMAL_DIGITS", Types.SMALLINT);
1653:                    addColumn(t, "PSEUDO_COLUMN", Types.SMALLINT, false); // not null
1654:
1655:                    // -----------------------------------------------------------------
1656:                    // required by DatabaseMetaData.getVersionColumns filter parameters
1657:                    // -----------------------------------------------------------------
1658:                    addColumn(t, "TABLE_CAT", Types.VARCHAR);
1659:                    addColumn(t, "TABLE_SCHEM", Types.VARCHAR);
1660:                    addColumn(t, "TABLE_NAME", Types.VARCHAR, false); // not null
1661:
1662:                    // -----------------------------------------------------------------
1663:                    t.createPrimaryKey(null);
1664:
1665:                    return t;
1666:                }
1667:
1668:                t.setDataReadOnly(true);
1669:
1670:                return t;
1671:            }
1672:
1673:            /**
1674:             * Retrieves a <code>Table</code> object describing the VIEW objects
1675:             * defined within this database. The table contains one row for each row
1676:             * in the SYSTEM_TABLES table with a TABLE_TYPE of  VIEW . <p>
1677:             *
1678:             * Each row is a description of the query expression that defines its view,
1679:             * with the following columns:
1680:             *
1681:             * <pre class="SqlCodeExample">
1682:             * TABLE_CATALOG    VARCHAR     name of view's defining catalog.
1683:             * TABLE_SCHEMA     VARCHAR     unqualified name of view's defining schema.
1684:             * TABLE_NAME       VARCHAR     the simple name of the view.
1685:             * VIEW_DEFINITION  VARCHAR     the character representation of the
1686:             *                              &lt;query expression&gt; contained in the
1687:             *                              corresponding &lt;view descriptor&gt;.
1688:             * CHECK_OPTION     VARCHAR     {"CASCADED" | "LOCAL" | "NONE"}
1689:             * IS_UPDATABLE     VARCHAR     {"YES" | "NO"}
1690:             * VALID            BOOLEAN     Always TRUE: VIEW_DEFINITION currently
1691:             *                              represents a valid &lt;query expression&gt.
1692:             *
1693:             * </pre> <p>
1694:             *
1695:             * @return a tabular description of the text source of all
1696:             *        <code>View</code> objects accessible to
1697:             *        the user.
1698:             * @throws HsqlException if an error occurs while producing the table
1699:             */
1700:            Table SYSTEM_VIEWS() throws HsqlException {
1701:
1702:                Table t = sysTables[SYSTEM_VIEWS];
1703:
1704:                if (t == null) {
1705:                    t = createBlankTable(sysTableHsqlNames[SYSTEM_VIEWS]);
1706:
1707:                    addColumn(t, "TABLE_CATALOG", Types.VARCHAR);
1708:                    addColumn(t, "TABLE_SCHEMA", Types.VARCHAR);
1709:                    addColumn(t, "TABLE_NAME", Types.VARCHAR, true); // not null
1710:                    addColumn(t, "VIEW_DEFINITION", Types.VARCHAR, true); // not null
1711:                    addColumn(t, "CHECK_OPTION", Types.VARCHAR, 8, true); // not null
1712:                    addColumn(t, "IS_UPDATABLE", Types.VARCHAR, 3, true); // not null
1713:                    addColumn(t, "VALID", Types.BOOLEAN, true); // not null
1714:
1715:                    // order TABLE_NAME
1716:                    // added for unique: TABLE_SCHEMA, TABLE_CATALOG
1717:                    // false PK, as TABLE_SCHEMA and/or TABLE_CATALOG may be null
1718:                    t.createPrimaryKey(null, new int[] { 1, 2, 0 }, false);
1719:
1720:                    return t;
1721:                }
1722:
1723:                String defn;
1724:                Iterator tables;
1725:                Table table;
1726:                Object[] row;
1727:                final int icat = 0;
1728:                final int ischem = 1;
1729:                final int iname = 2;
1730:                final int idefn = 3;
1731:                final int icopt = 4;
1732:                final int iiupd = 5;
1733:                final int ivalid = 6;
1734:
1735:                tables = database.schemaManager.allTablesIterator();
1736:
1737:                while (tables.hasNext()) {
1738:                    table = (Table) tables.next();
1739:
1740:                    if (!table.isView() || !isAccessibleTable(table)) {
1741:                        continue;
1742:                    }
1743:
1744:                    row = t.getEmptyRowData();
1745:                    defn = ((View) table).getStatement();
1746:                    row[icat] = ns.getCatalogName(table);
1747:                    row[ischem] = table.getSchemaName();
1748:                    row[iname] = table.getName().name;
1749:                    row[idefn] = defn;
1750:                    row[icopt] = "NONE";
1751:                    row[iiupd] = "NO";
1752:                    row[ivalid] = Boolean.TRUE;
1753:
1754:                    t.insertSys(row);
1755:                }
1756:
1757:                t.setDataReadOnly(true);
1758:
1759:                return t;
1760:            }
1761:
1762:            /**
1763:             * Retrieves a <code>Table</code> object describing the
1764:             * return, parameter and result columns of the accessible
1765:             * routines defined within this database.<p>
1766:             *
1767:             * Each row is a procedure column description with the following
1768:             * columns: <p>
1769:             *
1770:             * <pre class="SqlCodeExample">
1771:             * PROCEDURE_CAT   VARCHAR   routine catalog
1772:             * PROCEDURE_SCHEM VARCHAR   routine schema
1773:             * PROCEDURE_NAME  VARCHAR   routine name
1774:             * COLUMN_NAME     VARCHAR   column/parameter name
1775:             * COLUMN_TYPE     SMALLINT  kind of column/parameter
1776:             * DATA_TYPE       SMALLINT  SQL type from DITypes
1777:             * TYPE_NAME       VARCHAR   SQL type name
1778:             * PRECISION       INTEGER   precision (length) of type
1779:             * LENGTH          INTEGER   transfer size, in bytes, if definitely known
1780:             *                           (roughly equivalent to BUFFER_SIZE for table
1781:             *                           columns)
1782:             * SCALE           SMALLINT  scale
1783:             * RADIX           SMALLINT  radix
1784:             * NULLABLE        SMALLINT  can column contain NULL?
1785:             * REMARKS         VARCHAR   explanatory comment on column
1786:             * SPECIFIC_NAME   VARCHAR   typically (but not restricted to) a
1787:             *                           fully qulified Java Method name and signature
1788:             * SEQ             INTEGER   The JDBC-specified order within
1789:             *                           runs of PROCEDURE_SCHEM, PROCEDURE_NAME,
1790:             *                           SPECIFIC_NAME, which is:
1791:             *
1792:             *                           return value (0), if any, first, followed
1793:             *                           by the parameter descriptions in call order
1794:             *                           (1..n1), followed by the result column
1795:             *                           descriptions in column number order
1796:             *                           (n1 + 1..n1 + n2)
1797:             * </pre> <p>
1798:             *
1799:             * @return a <code>Table</code> object describing the
1800:             *        return, parameter and result columns
1801:             *        of the accessible routines defined
1802:             *        within this database.
1803:             * @throws HsqlException if an error occurs while producing the table
1804:             */
1805:            Table SYSTEM_PROCEDURECOLUMNS() throws HsqlException {
1806:
1807:                Table t = sysTables[SYSTEM_PROCEDURECOLUMNS];
1808:
1809:                if (t == null) {
1810:                    return super .SYSTEM_PROCEDURECOLUMNS();
1811:                }
1812:
1813:                // calculated column values
1814:                String procedureCatalog;
1815:                String procedureSchema;
1816:                String procedureName;
1817:                String columnName;
1818:                Integer columnType;
1819:                Integer dataType;
1820:                String dataTypeName;
1821:                Integer precision;
1822:                Integer length;
1823:                Integer scale;
1824:                Integer radix;
1825:                Integer nullability;
1826:                String remark;
1827:                String specificName;
1828:                int colSequence;
1829:                int colCount;
1830:
1831:                // intermediate holders
1832:                HsqlArrayList aliasList;
1833:                Object[] info;
1834:                Method method;
1835:                Iterator methods;
1836:                Object[] row;
1837:                DITypeInfo ti;
1838:
1839:                // Initialization
1840:                methods = ns.iterateAllAccessibleMethods(session, true); // and aliases
1841:                ti = new DITypeInfo();
1842:
1843:                // no such thing as identity or ignorecase return/parameter
1844:                // procedure columns.  Future: may need to worry about this if
1845:                // result columns are ever reported
1846:                ti.setTypeSub(Types.TYPE_SUB_DEFAULT);
1847:
1848:                // Do it.
1849:                while (methods.hasNext()) {
1850:                    info = (Object[]) methods.next();
1851:                    method = (Method) info[0];
1852:                    aliasList = (HsqlArrayList) info[1];
1853:                    procedureCatalog = ns.getCatalogName(method);
1854:                    procedureSchema = ns.getSchemaName(method);
1855:
1856:                    pi.setMethod(method);
1857:
1858:                    specificName = pi.getSpecificName();
1859:                    procedureName = pi.getFQN();
1860:                    colCount = pi.getColCount();
1861:
1862:                    for (int i = 0; i < colCount; i++) {
1863:                        ti.setTypeCode(pi.getColTypeCode(i));
1864:
1865:                        columnName = pi.getColName(i);
1866:                        columnType = pi.getColUsage(i);
1867:                        dataType = pi.getColDataType(i);
1868:                        dataTypeName = ti.getTypeName();
1869:                        precision = ti.getPrecision();
1870:                        length = pi.getColLen(i);
1871:                        scale = ti.getDefaultScale();
1872:                        radix = ti.getNumPrecRadix();
1873:                        nullability = pi.getColNullability(i);
1874:                        remark = pi.getColRemark(i);
1875:                        colSequence = pi.getColSequence(i);
1876:
1877:                        addPColRows(t, aliasList, procedureCatalog,
1878:                                procedureSchema, procedureName, columnName,
1879:                                columnType, dataType, dataTypeName, precision,
1880:                                length, scale, radix, nullability, remark,
1881:                                specificName, colSequence);
1882:                    }
1883:                }
1884:
1885:                t.setDataReadOnly(true);
1886:
1887:                return t;
1888:            }
1889:
1890:            /**
1891:             * Retrieves a <code>Table</code> object describing the accessible
1892:             * routines defined within this database.
1893:             *
1894:             * Each row is a procedure description with the following
1895:             * columns: <p>
1896:             *
1897:             * <pre class="SqlCodeExample">
1898:             * PROCEDURE_CAT     VARCHAR   catalog in which routine is defined
1899:             * PROCEDURE_SCHEM   VARCHAR   schema in which routine is defined
1900:             * PROCEDURE_NAME    VARCHAR   simple routine identifier
1901:             * NUM_INPUT_PARAMS  INTEGER   number of input parameters
1902:             * NUM_OUTPUT_PARAMS INTEGER   number of output parameters
1903:             * NUM_RESULT_SETS   INTEGER   number of result sets returned
1904:             * REMARKS           VARCHAR   explanatory comment on the routine
1905:             * PROCEDURE_TYPE    SMALLINT  { Unknown | No Result | Returns Result }
1906:             * ORIGIN            VARCHAR   {ALIAS |
1907:             *                             [BUILTIN | USER DEFINED] ROUTINE |
1908:             *                             [BUILTIN | USER DEFINED] TRIGGER |
1909:             *                              ...}
1910:             * SPECIFIC_NAME     VARCHAR   typically (but not restricted to) a
1911:             *                             a fully qualified Java Method name
1912:             *                             and signature
1913:             * </pre> <p>
1914:             *
1915:             * @return a <code>Table</code> object describing the accessible
1916:             *        routines defined within the this database
1917:             * @throws HsqlException if an error occurs while producing the table
1918:             */
1919:            Table SYSTEM_PROCEDURES() throws HsqlException {
1920:
1921:                Table t = sysTables[SYSTEM_PROCEDURES];
1922:
1923:                if (t == null) {
1924:                    return super .SYSTEM_PROCEDURES();
1925:                }
1926:
1927:                // calculated column values
1928:                // ------------------------
1929:                // required
1930:                // ------------------------
1931:                String catalog;
1932:                String schema;
1933:                String procName;
1934:                Integer numInputParams;
1935:                Integer numOutputParams;
1936:                Integer numResultSets;
1937:                String remarks;
1938:                Integer procRType;
1939:
1940:                // -------------------
1941:                // extended
1942:                // -------------------
1943:                String procOrigin;
1944:                String specificName;
1945:
1946:                // intermediate holders
1947:                String alias;
1948:                HsqlArrayList aliasList;
1949:                Iterator methods;
1950:                Object[] methodInfo;
1951:                Method method;
1952:                String methodOrigin;
1953:                Object[] row;
1954:
1955:                // Initialization
1956:                methods = ns.iterateAllAccessibleMethods(session, true); //and aliases
1957:
1958:                // Do it.
1959:                while (methods.hasNext()) {
1960:                    methodInfo = (Object[]) methods.next();
1961:                    method = (Method) methodInfo[0];
1962:                    aliasList = (HsqlArrayList) methodInfo[1];
1963:                    methodOrigin = (String) methodInfo[2];
1964:
1965:                    pi.setMethod(method);
1966:
1967:                    catalog = ns.getCatalogName(method);
1968:                    schema = ns.getSchemaName(method);
1969:                    procName = pi.getFQN();
1970:                    numInputParams = pi.getInputParmCount();
1971:                    numOutputParams = pi.getOutputParmCount();
1972:                    numResultSets = pi.getResultSetCount();
1973:                    remarks = pi.getRemark();
1974:                    procRType = pi.getResultType(methodOrigin);
1975:                    procOrigin = pi.getOrigin(methodOrigin);
1976:                    specificName = pi.getSpecificName();
1977:
1978:                    addProcRows(t, aliasList, catalog, schema, procName,
1979:                            numInputParams, numOutputParams, numResultSets,
1980:                            remarks, procRType, procOrigin, specificName);
1981:                }
1982:
1983:                t.setDataReadOnly(true);
1984:
1985:                return t;
1986:            }
1987:
1988:            /**
1989:             * The SYSTEM_USAGE_PRIVILEGES table has one row for each usage privilege
1990:             * descriptor. <p>
1991:             *
1992:             * It effectively contains a representation of the usage privilege
1993:             * descriptors. <p>
1994:             *
1995:             * <b>Definition:</b> <p>
1996:             *
1997:             * <pre class="SqlCodeExample">
1998:             * CREATE TABLE SYSTEM_USAGE_PRIVILEGES (
1999:             *      GRANTOR         VARCHAR NOT NULL,
2000:             *      GRANTEE         VARCHAR NOT NULL,
2001:             *      OBJECT_CATALOG  VARCHAR NULL,
2002:             *      OBJECT_SCHEMA   VARCHAR NULL,
2003:             *      OBJECT_NAME     VARCHAR NOT NULL,
2004:             *      OBJECT_TYPE     VARCHAR NOT NULL
2005:             *
2006:             *          CHECK ( OBJECT_TYPE IN (
2007:             *                      'DOMAIN',
2008:             *                      'CHARACTER SET',
2009:             *                      'COLLATION',
2010:             *                      'TRANSLATION',
2011:             *                      'SEQUENCE' ) ),
2012:             *
2013:             *      IS_GRANTABLE    VARCHAR NOT NULL
2014:             *
2015:             *          CHECK ( IS_GRANTABLE IN ( 'YES', 'NO' ) ),
2016:             *
2017:             *      UNIQUE( GRANTOR, GRANTEE, OBJECT_CATALOG,
2018:             *              OBJECT_SCHEMA, OBJECT_NAME, OBJECT_TYPE )
2019:             * )
2020:             * </pre>
2021:             *
2022:             * <b>Description:</b><p>
2023:             *
2024:             * <ol>
2025:             * <li> The value of GRANTOR is the &lt;authorization identifier&gt; of the
2026:             *      user or role who granted usage privileges on the object of the type
2027:             *      identified by OBJECT_TYPE that is identified by OBJECT_CATALOG,
2028:             *      OBJECT_SCHEMA, and OBJECT_NAME, to the user or role identified by the
2029:             *      value of GRANTEE forthe usage privilege being described. <p>
2030:             *
2031:             * <li> The value of GRANTEE is the &lt;authorization identifier&gt; of some
2032:             *      user or role, or PUBLIC to indicate all users, to whom the usage
2033:             *      privilege being described is granted. <p>
2034:             *
2035:             * <li> The values of OBJECT_CATALOG, OBJECT_SCHEMA, and OBJECT_NAME are the
2036:             *      catalog name, unqualified schema name, and qualified identifier,
2037:             *      respectively, of the object to which the privilege applies. <p>
2038:             *
2039:             * <li> The values of OBJECT_TYPE have the following meanings: <p>
2040:             *
2041:             *      <table border cellpadding="3">
2042:             *          <tr>
2043:             *              <td nowrap>DOMAIN</td>
2044:             *              <td nowrap>The object to which the privilege applies is
2045:             *                         a domain.</td>
2046:             *          <tr>
2047:             *          <tr>
2048:             *              <td nowrap>CHARACTER SET</td>
2049:             *              <td nowrap>The object to which the privilege applies is a
2050:             *                         character set.</td>
2051:             *          <tr>
2052:             *          <tr>
2053:             *              <td nowrap>COLLATION</td>
2054:             *              <td nowrap>The object to which the privilege applies is a
2055:             *                         collation.</td>
2056:             *          <tr>
2057:             *          <tr>
2058:             *              <td nowrap>TRANSLATION</td>
2059:             *              <td nowrap>The object to which the privilege applies is a
2060:             *                         transliteration.</td>
2061:             *          <tr>
2062:             *          <tr>
2063:             *              <td nowrap>SEQUENCE</td>
2064:             *              <td nowrap>The object to which the privilege applies is a
2065:             *                         sequence generator.</td>
2066:             *          <tr>
2067:             *      </table> <p>
2068:             *
2069:             * <li> The values of IS_GRANTABLE have the following meanings: <p>
2070:             *
2071:             *      <table border cellpadding="3">
2072:             *          <tr>
2073:             *              <td nowrap>YES</td>
2074:             *              <td nowrap>The privilege being described was granted
2075:             *                         WITH GRANT OPTION and is thus grantable.</td>
2076:             *          <tr>
2077:             *          <tr>
2078:             *              <td nowrap>NO</td>
2079:             *              <td nowrap>The privilege being described was not granted
2080:             *                  WITH GRANT OPTION and is thus not grantable.</td>
2081:             *          <tr>
2082:             *      </table> <p>
2083:             * <ol>
2084:             */
2085:            Table SYSTEM_USAGE_PRIVILEGES() throws HsqlException {
2086:
2087:                Table t = sysTables[SYSTEM_USAGE_PRIVILEGES];
2088:
2089:                if (t == null) {
2090:                    t = createBlankTable(sysTableHsqlNames[SYSTEM_USAGE_PRIVILEGES]);
2091:
2092:                    addColumn(t, "GRANTOR", Types.VARCHAR, false); // not null
2093:                    addColumn(t, "GRANTEE", Types.VARCHAR, false); // not null
2094:                    addColumn(t, "OBJECT_CATALOG", Types.VARCHAR);
2095:                    addColumn(t, "OBJECT_SCHEMA", Types.VARCHAR);
2096:                    addColumn(t, "OBJECT_NAME", Types.VARCHAR, false); // not null
2097:                    addColumn(t, "OBJECT_TYPE", Types.VARCHAR, 32, false); // not null
2098:                    addColumn(t, "IS_GRANTABLE", Types.VARCHAR, 3, false); // not null
2099:
2100:                    // order: COLUMN_NAME, PRIVILEGE
2101:                    // for unique: GRANTEE, GRANTOR, TABLE_NAME, TABLE_SCHEM, TABLE_CAT
2102:                    // false PK, as TABLE_SCHEM and/or TABLE_CAT may be null
2103:                    t.createPrimaryKey(null, new int[] { 0, 1, 2, 3, 4, 5 },
2104:                            false);
2105:
2106:                    return t;
2107:                }
2108:
2109:                Result rs;
2110:
2111:                rs = session
2112:                        .sqlExecuteDirectNoPreChecks("SELECT '"
2113:                                + GranteeManager.SYSTEM_AUTHORIZATION_NAME
2114:                                + "', 'PUBLIC', SEQUENCE_CATALOG, SEQUENCE_SCHEMA, "
2115:                                + "SEQUENCE_NAME, 'SEQUENCE', 'FALSE' FROM  INFORMATION_SCHEMA.SYSTEM_SEQUENCES");
2116:
2117:                t.insertSys(rs);
2118:
2119:                rs = session
2120:                        .sqlExecuteDirectNoPreChecks("SELECT '"
2121:                                + GranteeManager.SYSTEM_AUTHORIZATION_NAME
2122:                                + "', 'PUBLIC', COLLATION_CATALOG, COLLATION_SCHEMA, "
2123:                                + "COLLATION_NAME, 'COLLATION', 'FALSE' FROM  INFORMATION_SCHEMA.SYSTEM_COLLATIONS");
2124:
2125:                t.insertSys(rs);
2126:                t.setDataReadOnly(true);
2127:
2128:                return t;
2129:            }
2130:
2131:            /**
2132:             * The CHECK_COLUMN_USAGE table has one row for each column identified by
2133:             * a &lt;column reference&gt; contained in the &lt;search condition&gt;
2134:             * of a check constraint, domain constraint, or assertion. <p>
2135:             *
2136:             * <b>Definition:</b><p>
2137:             *
2138:             * <pre class="SqlCodeExample">
2139:             * CREATE TABLE CHECK_COLUMN_USAGE (
2140:             *      CONSTRAINT_CATALOG  VARCHAR NULL,
2141:             *      CONSTRAINT_SCHEMA   VARCHAR NULL,
2142:             *      CONSTRAINT_NAME     VARCHAR NOT NULL,
2143:             *      TABLE_CATALOG       VARCHAR NULL,
2144:             *      TABLE_SCHEMA        VARCHAR NULL,
2145:             *      TABLE_NAME          VARCHAR NOT NULL,
2146:             *      COLUMN_NAME         VARCHAR NOT NULL,
2147:             *      UNIQUE( CONSTRAINT_CATALOG, CONSTRAINT_SCHEMA, CONSTRAINT_NAME,
2148:             *              TABLE_CATALOG, TABLE_SCHEMA, TABLE_NAME, COLUMN_NAME )
2149:             * )
2150:             * </pre>
2151:             *
2152:             * <b>Description:</b> <p>
2153:             *
2154:             * <ol>
2155:             * <li> The values of CONSTRAINT_CATALOG, CONSTRAINT_SCHEMA, and
2156:             *      CONSTRAINT_NAME are the catalog name, unqualified schema name,
2157:             *      and qualified identifier, respectively, of the constraint being
2158:             *      described. <p>
2159:             *
2160:             * <li> The values of TABLE_CATALOG, TABLE_SCHEMA, TABLE_NAME, and
2161:             *      COLUMN_NAME are the catalog name, unqualified schema name,
2162:             *      qualified identifier, and column name, respectively, of a column
2163:             *      identified by a &lt;column reference&gt; explicitly or implicitly
2164:             *      contained in the &lt;search condition&gt; of the constraint
2165:             *      being described.
2166:             * </ol>
2167:             */
2168:            Table SYSTEM_CHECK_COLUMN_USAGE() throws HsqlException {
2169:
2170:                Table t = sysTables[SYSTEM_CHECK_COLUMN_USAGE];
2171:
2172:                if (t == null) {
2173:                    t = createBlankTable(sysTableHsqlNames[SYSTEM_CHECK_COLUMN_USAGE]);
2174:
2175:                    addColumn(t, "CONSTRAINT_CATALOG", Types.VARCHAR);
2176:                    addColumn(t, "CONSTRAINT_SCHEMA", Types.VARCHAR);
2177:                    addColumn(t, "CONSTRAINT_NAME", Types.VARCHAR, false); // not null
2178:                    addColumn(t, "TABLE_CATALOG", Types.VARCHAR);
2179:                    addColumn(t, "TABLE_SCHEMA", Types.VARCHAR);
2180:                    addColumn(t, "TABLE_NAME", Types.VARCHAR, false); // not null
2181:                    addColumn(t, "COLUMN_NAME", Types.VARCHAR, false); // not null
2182:                    t.createPrimaryKey(null, new int[] { 0, 1, 2, 3, 4, 5, 6 },
2183:                            false);
2184:
2185:                    return t;
2186:                }
2187:
2188:                // calculated column values
2189:                String constraintCatalog;
2190:                String constraintSchema;
2191:                String constraintName;
2192:
2193:                // Intermediate holders
2194:                Iterator tables;
2195:                Table table;
2196:                Constraint[] constraints;
2197:                int constraintCount;
2198:                Constraint constraint;
2199:                Expression.Collector collector;
2200:                Expression expression;
2201:                TableFilter tableFilter;
2202:                Table columnTable;
2203:                Iterator iterator;
2204:                Result result;
2205:                Object[] resultRow;
2206:                Object[] row;
2207:
2208:                // column number mappings
2209:                final int icons_cat = 0;
2210:                final int icons_schem = 1;
2211:                final int icons_name = 2;
2212:                final int itab_cat = 3;
2213:                final int itab_schem = 4;
2214:                final int itab_name = 5;
2215:                final int itab_col = 6;
2216:
2217:                // Initialization
2218:                tables = database.schemaManager.allTablesIterator();
2219:                collector = new Expression.Collector();
2220:                result = new Result(ResultConstants.DATA, 4);
2221:                result.metaData.colTypes[0] = result.metaData.colTypes[1] = result.metaData.colTypes[2] = result.metaData.colTypes[3] = Types.VARCHAR;
2222:
2223:                // Do it.
2224:                while (tables.hasNext()) {
2225:                    table = (Table) tables.next();
2226:
2227:                    if (!isAccessibleTable(table)) {
2228:                        continue;
2229:                    }
2230:
2231:                    constraints = table.getConstraints();
2232:                    constraintCount = constraints.length;
2233:                    constraintCatalog = ns.getCatalogName(table);
2234:                    constraintSchema = table.getSchemaName();
2235:
2236:                    // process constraints
2237:                    for (int i = 0; i < constraintCount; i++) {
2238:                        constraint = (Constraint) constraints[i];
2239:
2240:                        if (constraint.getType() != Constraint.CHECK) {
2241:                            continue;
2242:                        }
2243:
2244:                        constraintName = constraint.getName().name;
2245:
2246:                        result.setRows(null);
2247:                        collector.clear();
2248:                        collector.addAll(constraint.core.check,
2249:                                Expression.COLUMN);
2250:
2251:                        iterator = collector.iterator();
2252:
2253:                        // calculate distinct column references
2254:                        while (iterator.hasNext()) {
2255:                            expression = (Expression) iterator.next();
2256:                            tableFilter = expression.getFilter();
2257:                            columnTable = tableFilter.getTable();
2258:
2259:                            if (columnTable.getTableType() == Table.SYSTEM_SUBQUERY
2260:                                    || !isAccessibleTable(columnTable)) {
2261:                                continue;
2262:                            }
2263:
2264:                            result.add(new Object[] {
2265:                                    ns.getCatalogName(columnTable),
2266:                                    columnTable.getSchemaName(),
2267:                                    columnTable.getName().name,
2268:                                    expression.getColumnName() });
2269:                        }
2270:
2271:                        /*
2272:                         result.removeDuplicates(
2273:                         database.sessionManager.getSysSession(
2274:                         database.schemaManager.INFORMATION_SCHEMA));
2275:                         */
2276:                        result.removeDuplicates(session);
2277:
2278:                        iterator = result.iterator();
2279:
2280:                        while (iterator.hasNext()) {
2281:                            row = t.getEmptyRowData();
2282:                            resultRow = (Object[]) iterator.next();
2283:                            row[icons_cat] = constraintCatalog;
2284:                            row[icons_schem] = constraintSchema;
2285:                            row[icons_name] = constraintName;
2286:                            row[itab_cat] = resultRow[0];
2287:                            row[itab_schem] = resultRow[1];
2288:                            row[itab_name] = resultRow[2];
2289:                            row[itab_col] = resultRow[3];
2290:
2291:                            t.insertSys(row);
2292:                        }
2293:                    }
2294:                }
2295:
2296:                t.setDataReadOnly(true);
2297:
2298:                return t;
2299:            }
2300:
2301:            /**
2302:             * The CHECK_ROUTINE_USAGE base table has one row for each
2303:             * SQL-invoked routine identified as the subject routine of either a
2304:             * &lt;routine invocation&gt;, a &lt;method reference&gt;, a
2305:             * &lt;method invocation&gt;, or a &lt;static method invocation&gt;
2306:             * contained in an &lt;assertion definition&gt;, a &lt;domain
2307:             * constraint&gt;, or a &lt;table constraint definition&gt;. <p>
2308:             *
2309:             * <b>Definition:</b> <p>
2310:             *
2311:             * <pre class="SqlCodeExample">
2312:             * CREATE TABLE SYSTEM_CHECK_ROUTINE_USAGE (
2313:             *      CONSTRAINT_CATALOG      VARCHAR NULL,
2314:             *      CONSTRAINT_SCHEMA       VARCHAR NULL,
2315:             *      CONSTRAINT_NAME         VARCHAR NOT NULL,
2316:             *      SPECIFIC_CATALOG        VARCHAR NULL,
2317:             *      SPECIFIC_SCHEMA         VARCHAR NULL,
2318:             *      SPECIFIC_NAME           VARCHAR NOT NULL,
2319:             *      UNIQUE( CONSTRAINT_CATALOG, CONSTRAINT_SCHEMA, CONSTRAINT_NAME,
2320:             *              SPECIFIC_CATALOG, SPECIFIC_SCHEMA, SPECIFIC_NAME )
2321:             * )
2322:             * </pre>
2323:             *
2324:             * <b>Description:</b> <p>
2325:             *
2326:             * <ol>
2327:             * <li> The CHECK_ROUTINE_USAGE table has one row for each
2328:             *      SQL-invoked routine R identified as the subject routine of either a
2329:             *      &lt;routine invocation&gt;, a &lt;method reference&gt;, a &lt;method
2330:             *      invocation&gt;, or a &lt;static method invocation&gt; contained in
2331:             *      an &lt;assertion definition&gt; or in the &lt;check constraint
2332:             *      definition&gt; contained in either a &lt;domain constraint&gt; or a
2333:             *      &lt;table constraint definition&gt;. <p>
2334:             *
2335:             * <li> The values of CONSTRAINT_CATALOG, CONSTRAINT_SCHEMA, and
2336:             *      CONSTRAINT_NAME are the catalog name, unqualified schema name, and
2337:             *      qualified identifier, respectively, of the assertion or check
2338:             *     constraint being described. <p>
2339:             *
2340:             * <li> The values of SPECIFIC_CATALOG, SPECIFIC_SCHEMA, and SPECIFIC_NAME
2341:             *      are the catalog name, unqualified schema name, and qualified
2342:             *      identifier, respectively, of the specific name of R. <p>
2343:             *
2344:             * </ol>
2345:             */
2346:            Table SYSTEM_CHECK_ROUTINE_USAGE() throws HsqlException {
2347:
2348:                Table t = sysTables[SYSTEM_CHECK_ROUTINE_USAGE];
2349:
2350:                if (t == null) {
2351:                    t = createBlankTable(sysTableHsqlNames[SYSTEM_CHECK_ROUTINE_USAGE]);
2352:
2353:                    addColumn(t, "CONSTRAINT_CATALOG", Types.VARCHAR);
2354:                    addColumn(t, "CONSTRAINT_SCHEMA", Types.VARCHAR);
2355:                    addColumn(t, "CONSTRAINT_NAME", Types.VARCHAR, false); // not null
2356:                    addColumn(t, "SPECIFIC_CATALOG", Types.VARCHAR);
2357:                    addColumn(t, "SPECIFIC_SCHEMA", Types.VARCHAR);
2358:                    addColumn(t, "SPECIFIC_NAME", Types.VARCHAR, false); // not null
2359:                    t.createPrimaryKey(null, new int[] { 0, 1, 2, 3, 4, 5 },
2360:                            false);
2361:
2362:                    return t;
2363:                }
2364:
2365:                // calculated column values
2366:                String constraintCatalog;
2367:                String constraintSchema;
2368:                String constraintName;
2369:
2370:                // Intermediate holders
2371:                Iterator tables;
2372:                Table table;
2373:                Constraint[] constraints;
2374:                int constraintCount;
2375:                Constraint constraint;
2376:                Expression.Collector collector;
2377:                Expression expression;
2378:                Function function;
2379:                Iterator iterator;
2380:                HashSet methodSet;
2381:                Method method;
2382:                Object[] row;
2383:
2384:                // column number mappings
2385:                final int icons_cat = 0;
2386:                final int icons_schem = 1;
2387:                final int icons_name = 2;
2388:                final int ir_cat = 3;
2389:                final int ir_schem = 4;
2390:                final int ir_name = 5;
2391:
2392:                tables = database.schemaManager.allTablesIterator();
2393:                collector = new Expression.Collector();
2394:
2395:                while (tables.hasNext()) {
2396:                    collector.clear();
2397:
2398:                    table = (Table) tables.next();
2399:
2400:                    if (!isAccessibleTable(table)) {
2401:                        continue;
2402:                    }
2403:
2404:                    constraints = table.getConstraints();
2405:                    constraintCount = constraints.length;
2406:                    constraintCatalog = ns.getCatalogName(table);
2407:                    constraintSchema = table.getSchemaName();
2408:
2409:                    for (int i = 0; i < constraintCount; i++) {
2410:                        constraint = (Constraint) constraints[i];
2411:
2412:                        if (constraint.getType() != Constraint.CHECK) {
2413:                            continue;
2414:                        }
2415:
2416:                        constraintName = constraint.getName().name;
2417:
2418:                        collector.addAll(constraint.core.check,
2419:                                Expression.FUNCTION);
2420:
2421:                        methodSet = new HashSet();
2422:                        iterator = collector.iterator();
2423:
2424:                        while (iterator.hasNext()) {
2425:                            expression = (Expression) iterator.next();
2426:                            function = expression.function;
2427:
2428:                            if (!session.isAccessible(function.getMethod()
2429:                                    .getDeclaringClass().getName())) {
2430:                                continue;
2431:                            }
2432:
2433:                            methodSet.add(function.getMethod());
2434:                        }
2435:
2436:                        iterator = methodSet.iterator();
2437:
2438:                        while (iterator.hasNext()) {
2439:                            method = (Method) iterator.next();
2440:                            row = t.getEmptyRowData();
2441:                            row[icons_cat] = constraintCatalog;
2442:                            row[icons_schem] = constraintSchema;
2443:                            row[icons_name] = constraintName;
2444:                            row[ir_cat] = ns.getCatalogName(method);
2445:                            row[ir_schem] = ns.getSchemaName(method);
2446:                            row[ir_name] = DINameSpace
2447:                                    .getMethodSpecificName(method);
2448:
2449:                            t.insertSys(row);
2450:                        }
2451:                    }
2452:                }
2453:
2454:                t.setDataReadOnly(true);
2455:
2456:                return t;
2457:            }
2458:
2459:            /**
2460:             * The CHECK_TABLE_USAGE table has one row for each table identified by a
2461:             * &lt;table name&gt; simply contained in a &lt;table reference&gt;
2462:             * contained in the &lt;search condition&gt; of a check constraint,
2463:             * domain constraint, or assertion. <p>
2464:             *
2465:             * <b>Definition:</b> <p>
2466:             *
2467:             * <pre class="SqlCodeExample">
2468:             * CREATE STABLE SYSTEM_CHECK_TABLE_USAGE (
2469:             *      CONSTRAINT_CATALOG      VARCHAR NULL,
2470:             *      CONSTRAINT_SCHEMA       VARCHAR NULL,
2471:             *      CONSTRAINT_NAME         VARCHAR NOT NULL,
2472:             *      TABLE_CATALOG           VARCHAR NULL,
2473:             *      TABLE_SCHEMA            VARCHAR NOT NULL,
2474:             *      TABLE_NAME INFORMATION_SCHEMA.SQL_IDENTIFIER,
2475:             *     UNIQUE( CONSTRAINT_CATALOG, CONSTRAINT_SCHEMA, CONSTRAINT_NAME,
2476:             *            TABLE_CATALOG, TABLE_SCHEMA, TABLE_NAME )
2477:             * )
2478:             * </pre>
2479:             *
2480:             * <b>Description:</b> <p>
2481:             *
2482:             * <ol>
2483:             * <li> The values of CONSTRAINT_CATALOG, CONSTRAINT_SCHEMA, and
2484:             *      CONSTRAINT_NAME are the catalog name, unqualified schema name,
2485:             *       and qualified identifier, respectively, of the constraint being
2486:             *      described. <p>
2487:             *
2488:             * <li> The values of TABLE_CATALOG, TABLE_SCHEMA, and TABLE_NAME are the
2489:             *      catalog name, unqualified schema name, and qualified identifier,
2490:             *      respectively, of a table identified by a &lt;table name&gt;
2491:             *      simply contained in a &lt;table reference&gt; contained in the
2492:             *      *lt;search condition&gt; of the constraint being described.
2493:             * </ol>
2494:             */
2495:            Table SYSTEM_CHECK_TABLE_USAGE() throws HsqlException {
2496:
2497:                Table t = sysTables[SYSTEM_CHECK_TABLE_USAGE];
2498:
2499:                if (t == null) {
2500:                    t = createBlankTable(sysTableHsqlNames[SYSTEM_CHECK_TABLE_USAGE]);
2501:
2502:                    addColumn(t, "CONSTRAINT_CATALOG", Types.VARCHAR);
2503:                    addColumn(t, "CONSTRAINT_SCHEMA", Types.VARCHAR);
2504:                    addColumn(t, "CONSTRAINT_NAME", Types.VARCHAR, false); // not null
2505:                    addColumn(t, "TABLE_CATALOG", Types.VARCHAR);
2506:                    addColumn(t, "TABLE_SCHEMA", Types.VARCHAR);
2507:                    addColumn(t, "TABLE_NAME", Types.VARCHAR, false); // not null
2508:                    t.createPrimaryKey(null, new int[] { 0, 1, 2, 3, 4, 5 },
2509:                            false);
2510:
2511:                    return t;
2512:                }
2513:
2514:                //
2515:                Result rs = session
2516:                        .sqlExecuteDirectNoPreChecks("select DISTINCT CONSTRAINT_CATALOG, CONSTRAINT_SCHEMA, "
2517:                                + "CONSTRAINT_NAME, TABLE_CATALOG, TABLE_SCHEMA, TABLE_NAME "
2518:                                + "from INFORMATION_SCHEMA.SYSTEM_CHECK_COLUMN_USAGE");
2519:
2520:                t.insertSys(rs);
2521:                t.setDataReadOnly(true);
2522:
2523:                return t;
2524:            }
2525:
2526:            /**
2527:             * The TABLE_CONSTRAINTS table has one row for each table constraint
2528:             * associated with a table.  <p>
2529:             *
2530:             * It effectively contains a representation of the table constraint
2531:             * descriptors. <p>
2532:             *
2533:             * <b>Definition:</b> <p>
2534:             *
2535:             * <pre class="SqlCodeExample">
2536:             * CREATE TABLE SYSTEM_TABLE_CONSTRAINTS (
2537:             *      CONSTRAINT_CATALOG      VARCHAR NULL,
2538:             *      CONSTRAINT_SCHEMA       VARCHAR NULL,
2539:             *      CONSTRAINT_NAME         VARCHAR NOT NULL,
2540:             *      CONSTRAINT_TYPE         VARCHAR NOT NULL,
2541:             *      TABLE_CATALOG           VARCHAR NULL,
2542:             *      TABLE_SCHEMA            VARCHAR NULL,
2543:             *      TABLE_NAME              VARCHAR NOT NULL,
2544:             *      IS_DEFERRABLE           VARCHAR NOT NULL,
2545:             *      INITIALLY_DEFERRED      VARCHAR NOT NULL,
2546:             *
2547:             *      CHECK ( CONSTRAINT_TYPE IN
2548:             *                      ( 'UNIQUE', 'PRIMARY KEY',
2549:             *                        'FOREIGN KEY', 'CHECK' ) ),
2550:             *
2551:             *      CHECK ( ( IS_DEFERRABLE, INITIALLY_DEFERRED ) IN
2552:             *              ( VALUES ( 'NO',  'NO'  ),
2553:             *                       ( 'YES', 'NO'  ),
2554:             *                       ( 'YES', 'YES' ) ) )
2555:             * )
2556:             * </pre>
2557:             *
2558:             * <b>Description:</b> <p>
2559:             *
2560:             * <ol>
2561:             * <li> The values of CONSTRAINT_CATALOG, CONSTRAINT_SCHEMA, and
2562:             *      CONSTRAINT_NAME are the catalog name, unqualified schema
2563:             *      name, and qualified identifier, respectively, of the
2564:             *      constraint being described. If the &lt;table constraint
2565:             *      definition&gt; or &lt;add table constraint definition&gt;
2566:             *      that defined the constraint did not specify a
2567:             *      &lt;constraint name&gt;, then the values of CONSTRAINT_CATALOG,
2568:             *      CONSTRAINT_SCHEMA, and CONSTRAINT_NAME are
2569:             *      implementation-defined. <p>
2570:             *
2571:             * <li> The values of CONSTRAINT_TYPE have the following meanings: <p>
2572:             *  <table border cellpadding="3">
2573:             *  <tr>
2574:             *      <td nowrap>FOREIGN KEY</td>
2575:             *      <td nowrap>The constraint being described is a
2576:             *                 foreign key constraint.</td>
2577:             *  </tr>
2578:             *  <tr>
2579:             *      <td nowrap>UNIQUE</td>
2580:             *      <td nowrap>The constraint being described is a
2581:             *                 unique constraint.</td>
2582:             *  </tr>
2583:             *  <tr>
2584:             *      <td nowrap>PRIMARY KEY</td>
2585:             *      <td nowrap>The constraint being described is a
2586:             *                 primary key constraint.</td>
2587:             *  </tr>
2588:             *  <tr>
2589:             *      <td nowrap>CHECK</td>
2590:             *      <td nowrap>The constraint being described is a
2591:             *                 check constraint.</td>
2592:             *  </tr>
2593:             * </table> <p>
2594:             *
2595:             * <li> The values of TABLE_CATALOG, TABLE_SCHEMA, and TABLE_NAME are
2596:             *      the catalog name, the unqualified schema name, and the
2597:             *      qualified identifier of the name of the table to which the
2598:             *      table constraint being described applies. <p>
2599:             *
2600:             * <li> The values of IS_DEFERRABLE have the following meanings: <p>
2601:             *
2602:             *  <table>
2603:             *      <tr>
2604:             *          <td nowrap>YES</td>
2605:             *          <td nowrap>The table constraint is deferrable.</td>
2606:             *      </tr>
2607:             *      <tr>
2608:             *          <td nowrap>NO</td>
2609:             *          <td nowrap>The table constraint is not deferrable.</td>
2610:             *      </tr>
2611:             *  </table> <p>
2612:             *
2613:             * <li> The values of INITIALLY_DEFERRED have the following meanings: <p>
2614:             *
2615:             *  <table>
2616:             *      <tr>
2617:             *          <td nowrap>YES</td>
2618:             *          <td nowrap>The table constraint is initially deferred.</td>
2619:             *      </tr>
2620:             *      <tr>
2621:             *          <td nowrap>NO</td>
2622:             *          <td nowrap>The table constraint is initially immediate.</td>
2623:             *      </tr>
2624:             *  </table> <p>
2625:             * </ol>
2626:             */
2627:            Table SYSTEM_TABLE_CONSTRAINTS() throws HsqlException {
2628:
2629:                Table t = sysTables[SYSTEM_TABLE_CONSTRAINTS];
2630:
2631:                if (t == null) {
2632:                    t = createBlankTable(sysTableHsqlNames[SYSTEM_TABLE_CONSTRAINTS]);
2633:
2634:                    addColumn(t, "CONSTRAINT_CATALOG", Types.VARCHAR);
2635:                    addColumn(t, "CONSTRAINT_SCHEMA", Types.VARCHAR);
2636:                    addColumn(t, "CONSTRAINT_NAME", Types.VARCHAR, false); // not null
2637:                    addColumn(t, "CONSTRAINT_TYPE", Types.VARCHAR, 11, false); // not null
2638:                    addColumn(t, "TABLE_CATALOG", Types.VARCHAR);
2639:                    addColumn(t, "TABLE_SCHEMA", Types.VARCHAR);
2640:                    addColumn(t, "TABLE_NAME", Types.VARCHAR, false); // not null
2641:                    addColumn(t, "IS_DEFERRABLE", Types.VARCHAR, 3, false); // not null
2642:                    addColumn(t, "INITIALLY_DEFERRED", Types.VARCHAR, 3, false); // not null
2643:
2644:                    // false PK, as CONSTRAINT_CATALOG, CONSTRAINT_SCHEMA,
2645:                    // TABLE_CATALOG and/or TABLE_SCHEMA may be null
2646:                    t.createPrimaryKey(null, new int[] { 0, 1, 2, 4, 5, 6 },
2647:                            false);
2648:
2649:                    return t;
2650:                }
2651:
2652:                // Intermediate holders
2653:                Iterator tables;
2654:                Table table;
2655:                Constraint[] constraints;
2656:                int constraintCount;
2657:                Constraint constraint;
2658:                String cat;
2659:                String schem;
2660:                HashSet constraintSet;
2661:                Object[] row;
2662:
2663:                // column number mappings
2664:                final int icons_cat = 0;
2665:                final int icons_schem = 1;
2666:                final int icons_name = 2;
2667:                final int icons_type = 3;
2668:                final int itab_cat = 4;
2669:                final int itab_schem = 5;
2670:                final int itab_name = 6;
2671:                final int iis_defr = 7;
2672:                final int iinit_defr = 8;
2673:
2674:                // initialization
2675:                tables = database.schemaManager.allTablesIterator();
2676:                constraintSet = new HashSet();
2677:                table = null; // else complier complains
2678:
2679:                // do it
2680:                while (tables.hasNext()) {
2681:                    table = (Table) tables.next();
2682:
2683:                    if (table.isView() || !isAccessibleTable(table)) {
2684:                        continue;
2685:                    }
2686:
2687:                    constraints = table.getConstraints();
2688:                    constraintCount = constraints.length;
2689:
2690:                    for (int i = 0; i < constraintCount; i++) {
2691:                        constraint = constraints[i];
2692:
2693:                        if (constraint.getType() == Constraint.FOREIGN_KEY
2694:                                && !isAccessibleTable(constraint.getRef())) {
2695:                            continue;
2696:                        }
2697:
2698:                        constraintSet.add(constraint);
2699:                    }
2700:                }
2701:
2702:                for (Iterator it = constraintSet.iterator(); it.hasNext();) {
2703:                    row = t.getEmptyRowData();
2704:                    constraint = (Constraint) it.next();
2705:
2706:                    switch (constraint.getType()) {
2707:
2708:                    case Constraint.CHECK: {
2709:                        row[icons_type] = "CHECK";
2710:                        table = constraint.getMain();
2711:
2712:                        break;
2713:                    }
2714:                    case Constraint.UNIQUE: {
2715:                        row[icons_type] = "UNIQUE";
2716:                        table = constraint.getMain();
2717:
2718:                        break;
2719:                    }
2720:                    case Constraint.FOREIGN_KEY: {
2721:                        row[icons_type] = "FOREIGN KEY";
2722:                        table = constraint.getRef();
2723:
2724:                        break;
2725:                    }
2726:                    case Constraint.PRIMARY_KEY: {
2727:                        row[icons_type] = "PRIMARY KEY";
2728:                        table = constraint.getMain();
2729:
2730:                        break;
2731:                    }
2732:                    case Constraint.MAIN:
2733:                    default: {
2734:                        continue;
2735:                    }
2736:                    }
2737:
2738:                    cat = ns.getCatalogName(table);
2739:                    schem = table.getSchemaName();
2740:                    row[icons_cat] = cat;
2741:                    row[icons_schem] = schem;
2742:                    row[icons_name] = constraint.constName.name;
2743:                    row[itab_cat] = cat;
2744:                    row[itab_schem] = schem;
2745:                    row[itab_name] = table.getName().name;
2746:                    row[iis_defr] = "NO";
2747:                    row[iinit_defr] = "NO";
2748:
2749:                    t.insertSys(row);
2750:                }
2751:
2752:                t.setDataReadOnly(true);
2753:
2754:                return t;
2755:            }
2756:
2757:            /**
2758:             * The SYSTEM_VIEW_TABLE_USAGE table has one row for each table identified
2759:             * by a &lt;table name&gt; simply contained in a &lt;table reference&gt;
2760:             * that is contained in the &lt;query expression&gt; of a view. <p>
2761:             *
2762:             * <b>Definition</b><p>
2763:             *
2764:             * <pre class="SqlCodeExample">
2765:             * CREATE TABLE SYSTEM_VIEW_TABLE_USAGE (
2766:             *      VIEW_CATALOG    VARCHAR NULL,
2767:             *      VIEW_SCHEMA     VARCHAR NULL,
2768:             *      VIEW_NAME       VARCHAR NULL,
2769:             *      TABLE_CATALOG   VARCHAR NULL,
2770:             *      TABLE_SCHEMA    VARCHAR NULL,
2771:             *      TABLE_NAME      VARCHAR NULL,
2772:             *      UNIQUE( VIEW_CATALOG, VIEW_SCHEMA, VIEW_NAME,
2773:             *              TABLE_CATALOG, TABLE_SCHEMA, TABLE_NAME )
2774:             * )
2775:             * </pre>
2776:             *
2777:             * <b>Description:</b><p>
2778:             *
2779:             * <ol>
2780:             * <li> The values of VIEW_CATALOG, VIEW_SCHEMA, and VIEW_NAME are the
2781:             *      catalog name, unqualified schema name, and qualified identifier,
2782:             *      respectively, of the view being described. <p>
2783:             *
2784:             * <li> The values of TABLE_CATALOG, TABLE_SCHEMA, and TABLE_NAME are the
2785:             *      catalog name, unqualified schema name, and qualified identifier,
2786:             *      respectively, of a table identified by a &lt;table name&gt;
2787:             *      simply contained in a &lt;table reference&gt; that is contained in
2788:             *      the &lt;query expression&gt; of the view being described.
2789:             * </ol>
2790:             */
2791:            Table SYSTEM_VIEW_TABLE_USAGE() throws HsqlException {
2792:
2793:                Table t = sysTables[SYSTEM_VIEW_TABLE_USAGE];
2794:
2795:                if (t == null) {
2796:                    t = createBlankTable(sysTableHsqlNames[SYSTEM_VIEW_TABLE_USAGE]);
2797:
2798:                    addColumn(t, "VIEW_CATALOG", Types.VARCHAR);
2799:                    addColumn(t, "VIEW_SCHEMA", Types.VARCHAR);
2800:                    addColumn(t, "VIEW_NAME", Types.VARCHAR, true); // not null
2801:                    addColumn(t, "TABLE_CATALOG", Types.VARCHAR);
2802:                    addColumn(t, "TABLE_SCHEMA", Types.VARCHAR);
2803:                    addColumn(t, "TABLE_NAME", Types.VARCHAR, true); // not null
2804:
2805:                    // false PK, as VIEW_CATALOG, VIEW_SCHEMA, TABLE_CATALOG, and/or
2806:                    // TABLE_SCHEMA may be NULL
2807:                    t.createPrimaryKey(null, new int[] { 0, 1, 2, 3, 4, 5 },
2808:                            false);
2809:
2810:                    return t;
2811:                }
2812:
2813:                //
2814:                Result rs = session
2815:                        .sqlExecuteDirectNoPreChecks("select DISTINCT VIEW_CATALOG, VIEW_SCHEMA, "
2816:                                + "VIEW_NAME, TABLE_CATALOG, TABLE_SCHEMA, TABLE_NAME "
2817:                                + "from INFORMATION_SCHEMA.SYSTEM_VIEW_COLUMN_USAGE");
2818:
2819:                t.insertSys(rs);
2820:                t.setDataReadOnly(true);
2821:
2822:                return t;
2823:            }
2824:
2825:            /**
2826:             * The SYSTEM_VIEW_COLUMN_USAGE table has one row for each column of a
2827:             * table that is explicitly or implicitly referenced in the
2828:             * &lt;query expression&gt; of the view being described. <p>
2829:             *
2830:             * <b>Definition:</b> <p>
2831:             *
2832:             * <pre class="SqlCodeExample">
2833:             * CREATE TABLE SYSTEM_VIEW_COLUMN_USAGE (
2834:             *      VIEW_CATALOG    VARCHAR NULL,
2835:             *      VIEW_SCHEMA     VARCHAR NULL,
2836:             *      VIEW_NAME       VARCHAR NOT NULL,
2837:             *      TABLE_CATALOG   VARCHAR NULL,
2838:             *      TABLE_SCHEMA    VARCHAR NULL,
2839:             *      TABLE_NAME      VARCHAR NOT NULL,
2840:             *      COLUMN_NAME     VARCHAR NOT NULL,
2841:             *      UNIQUE ( VIEW_CATALOG, VIEW_SCHEMA, VIEW_NAME,
2842:             *               TABLE_CATALOG, TABLE_SCHEMA, TABLE_NAME,
2843:             *               COLUMN_NAME )
2844:             * )
2845:             * </pre>
2846:             *
2847:             * <b>Description:</b> <p>
2848:             *
2849:             * <ol>
2850:             * <li> The values of VIEW_CATALOG, VIEW_SCHEMA, and VIEW_NAME are the
2851:             *      catalog name, unqualified schema name, and qualified identifier,
2852:             *      respectively, of the view being described. <p>
2853:             *
2854:             * <li> The values of TABLE_CATALOG, TABLE_SCHEMA, TABLE_NAME, and
2855:             *      COLUMN_NAME are the catalog name, unqualified schema name,
2856:             *      qualified identifier, and column name, respectively, of a column
2857:             *      of a table that is explicitly or implicitly referenced in the
2858:             *      &lt;query expression&gt; of the view being described.
2859:             * </ol>
2860:             */
2861:            Table SYSTEM_VIEW_COLUMN_USAGE() throws HsqlException {
2862:
2863:                Table t = sysTables[SYSTEM_VIEW_COLUMN_USAGE];
2864:
2865:                if (t == null) {
2866:                    t = createBlankTable(sysTableHsqlNames[SYSTEM_VIEW_COLUMN_USAGE]);
2867:
2868:                    addColumn(t, "VIEW_CATALOG", Types.VARCHAR);
2869:                    addColumn(t, "VIEW_SCHEMA", Types.VARCHAR);
2870:                    addColumn(t, "VIEW_NAME", Types.VARCHAR, true); // not null
2871:                    addColumn(t, "TABLE_CATALOG", Types.VARCHAR);
2872:                    addColumn(t, "TABLE_SCHEMA", Types.VARCHAR);
2873:                    addColumn(t, "TABLE_NAME", Types.VARCHAR, true); // not null
2874:                    addColumn(t, "COLUMN_NAME", Types.VARCHAR, true); // not null
2875:
2876:                    // false PK, as VIEW_CATALOG, VIEW_SCHEMA, TABLE_CATALOG, and/or
2877:                    // TABLE_SCHEMA may be NULL
2878:                    t.createPrimaryKey(null, new int[] { 0, 1, 2, 3, 4, 5, 6 },
2879:                            false);
2880:
2881:                    return t;
2882:                }
2883:
2884:                // Calculated column values
2885:                String viewCatalog;
2886:                String viewSchema;
2887:                String viewName;
2888:
2889:                // Intermediate holders
2890:                Iterator tables;
2891:                View view;
2892:                Table table;
2893:                Object[] row;
2894:                SubQuery[] subqueries;
2895:                Select select;
2896:                Expression expression;
2897:                TableFilter tableFilter;
2898:                Table columnTable;
2899:                Result result;
2900:                Object[] resultRow;
2901:                Iterator iterator;
2902:                Expression.Collector collector;
2903:
2904:                // Column number mappings
2905:                final int iv_cat = 0;
2906:                final int iv_schem = 1;
2907:                final int iv_name = 2;
2908:                final int it_cat = 3;
2909:                final int it_schem = 4;
2910:                final int it_name = 5;
2911:                final int it_cname = 6;
2912:
2913:                // Initialization
2914:                tables = database.schemaManager.allTablesIterator();
2915:                collector = new Expression.Collector();
2916:                result = new Result(ResultConstants.DATA, 4);
2917:                result.metaData.colTypes[0] = result.metaData.colTypes[1] = result.metaData.colTypes[2] = result.metaData.colTypes[3] = Types.VARCHAR;
2918:
2919:                // Do it.
2920:                while (tables.hasNext()) {
2921:                    collector.clear();
2922:                    result.setRows(null);
2923:
2924:                    table = (Table) tables.next();
2925:
2926:                    if (table.isView() && isAccessibleTable(table)) {
2927:
2928:                        // fall through
2929:                    } else {
2930:                        continue;
2931:                    }
2932:
2933:                    viewCatalog = ns.getCatalogName(table);
2934:                    viewSchema = table.getSchemaName();
2935:                    viewName = table.getName().name;
2936:                    view = (View) table;
2937:                    subqueries = view.viewSubqueries;
2938:
2939:                    collector.addAll(view.viewSelect, Expression.COLUMN);
2940:
2941:                    for (int i = 0; i < subqueries.length; i++) {
2942:                        collector.addAll(subqueries[i].select,
2943:                                Expression.COLUMN);
2944:                    }
2945:
2946:                    iterator = collector.iterator();
2947:
2948:                    while (iterator.hasNext()) {
2949:                        expression = (Expression) iterator.next();
2950:                        tableFilter = expression.getFilter();
2951:                        columnTable = tableFilter.getTable();
2952:
2953:                        if (columnTable.getTableType() == Table.SYSTEM_SUBQUERY
2954:                                || !isAccessibleTable(columnTable)) {
2955:                            continue;
2956:                        }
2957:
2958:                        result.add(new Object[] {
2959:                                ns.getCatalogName(columnTable),
2960:                                columnTable.getSchemaName(),
2961:                                columnTable.getName().name,
2962:                                expression.getColumnName() });
2963:                    }
2964:
2965:                    /*
2966:                     result.removeDuplicates(
2967:                     database.sessionManager.getSysSession(
2968:                     database.schemaManager.INFORMATION_SCHEMA));
2969:                     */
2970:                    result.removeDuplicates(session);
2971:
2972:                    iterator = result.iterator();
2973:
2974:                    while (iterator.hasNext()) {
2975:                        row = t.getEmptyRowData();
2976:                        resultRow = (Object[]) iterator.next();
2977:                        row[iv_cat] = viewCatalog;
2978:                        row[iv_schem] = viewSchema;
2979:                        row[iv_name] = viewName;
2980:                        row[it_cat] = resultRow[0];
2981:                        row[it_schem] = resultRow[1];
2982:                        row[it_name] = resultRow[2];
2983:                        row[it_cname] = resultRow[3];
2984:
2985:                        t.insertSys(row);
2986:                    }
2987:                }
2988:
2989:                t.setDataReadOnly(true);
2990:
2991:                return t;
2992:            }
2993:
2994:            /**
2995:             * The SYSTEM_VIEW_ROUTINE_USAGE table has one row for each SQL-invoked
2996:             * routine identified as the subject routine of either a &lt;routine
2997:             * invocation&gt;, a &lt;method reference&gt;, a &lt;method invocation&gt;,
2998:             * or a &lt;static method invocation&gt; contained in a &lt;view
2999:             * definition&gt;. <p>
3000:             *
3001:             * <b>Definition</b><p>
3002:             *
3003:             * <pre class="SqlCodeExample">
3004:             * CREATE TABLE VIEW_ROUTINE_USAGE (
3005:             *      TABLE_CATALOG       VARCHAR NULL,
3006:             *      TABLE_SCHEMA        VARCHAR NULL,
3007:             *      TABLE_NAME          VARCHAR NOT NULL,
3008:             *      SPECIFIC_CATALOG    VARCHAR NULL,
3009:             *      SPECIFIC_SCHEMA     VARCHAR NULL,
3010:             *      SPECIFIC_NAME       VARCHAR NOT NULL,
3011:             *      UNIQUE( TABLE_CATALOG, TABLE_SCHEMA, TABLE_NAME,
3012:             *              SPECIFIC_CATALOG, SPECIFIC_SCHEMA,
3013:             *              SPECIFIC_NAME )
3014:             * )
3015:             * </pre>
3016:             *
3017:             * <b>Description</b><p>
3018:             *
3019:             * <ol>
3020:             * <li> The values of TABLE_CATALOG, TABLE_SCHEMA, and TABLE_NAME are the
3021:             *      catalog name, unqualified schema name, and qualified identifier,
3022:             *      respectively, of the viewed table being described. <p>
3023:             *
3024:             * <li> The values of SPECIFIC_CATALOG, SPECIFIC_SCHEMA, and SPECIFIC_NAME are
3025:             *      the catalog name, unqualified schema name, and qualified identifier,
3026:             *      respectively, of the specific name of R. <p>
3027:             * </ol>
3028:             */
3029:            Table SYSTEM_VIEW_ROUTINE_USAGE() throws HsqlException {
3030:
3031:                Table t = sysTables[SYSTEM_VIEW_ROUTINE_USAGE];
3032:
3033:                if (t == null) {
3034:                    t = createBlankTable(sysTableHsqlNames[SYSTEM_VIEW_ROUTINE_USAGE]);
3035:
3036:                    addColumn(t, "TABLE_CATALOG", Types.VARCHAR);
3037:                    addColumn(t, "TABLE_SCHEMA", Types.VARCHAR);
3038:                    addColumn(t, "TABLE_NAME", Types.VARCHAR, true); // not null
3039:                    addColumn(t, "SPECIFIC_CATALOG", Types.VARCHAR);
3040:                    addColumn(t, "SPECIFIC_SCHEMA", Types.VARCHAR);
3041:                    addColumn(t, "SPECIFIC_NAME", Types.VARCHAR, true); // not null
3042:
3043:                    // false PK, as VIEW_CATALOG, VIEW_SCHEMA, TABLE_CATALOG, and/or
3044:                    // TABLE_SCHEMA may be NULL
3045:                    t.createPrimaryKey(null, new int[] { 0, 1, 2, 3, 4, 5 },
3046:                            false);
3047:
3048:                    return t;
3049:                }
3050:
3051:                // Calculated column values
3052:                String viewCat;
3053:                String viewSchem;
3054:                String viewName;
3055:
3056:                // Intermediate holders
3057:                Iterator tables;
3058:                View view;
3059:                Table table;
3060:                Object[] row;
3061:                SubQuery[] subqueries;
3062:                Select select;
3063:                Expression expression;
3064:                Function function;
3065:                Expression.Collector collector;
3066:                Method method;
3067:                HashSet methodSet;
3068:                Iterator iterator;
3069:
3070:                // Column number mappings
3071:                final int iv_cat = 0;
3072:                final int iv_schem = 1;
3073:                final int iv_name = 2;
3074:                final int ir_cat = 3;
3075:                final int ir_schem = 4;
3076:                final int ir_name = 5;
3077:                final int ir_sig = 6;
3078:
3079:                // Initialization
3080:                tables = database.schemaManager.allTablesIterator();
3081:                collector = new Expression.Collector();
3082:
3083:                // Do it.
3084:                while (tables.hasNext()) {
3085:                    collector.clear();
3086:
3087:                    table = (Table) tables.next();
3088:
3089:                    if (table.isView() && isAccessibleTable(table)) {
3090:
3091:                        // fall through
3092:                    } else {
3093:                        continue;
3094:                    }
3095:
3096:                    viewCat = ns.getCatalogName(table);
3097:                    viewSchem = table.getSchemaName();
3098:                    viewName = table.getName().name;
3099:                    view = (View) table;
3100:                    subqueries = view.viewSubqueries;
3101:
3102:                    collector.addAll(view.viewSelect, Expression.FUNCTION);
3103:
3104:                    for (int i = 0; i < subqueries.length; i++) {
3105:                        collector.addAll(subqueries[i].select,
3106:                                Expression.FUNCTION);
3107:                    }
3108:
3109:                    methodSet = new HashSet();
3110:                    iterator = collector.iterator();
3111:
3112:                    while (iterator.hasNext()) {
3113:                        expression = (Expression) iterator.next();
3114:                        function = expression.function;
3115:
3116:                        if (session.isAccessible(function.getMethod()
3117:                                .getDeclaringClass().getName())) {
3118:                            methodSet.add(function.getMethod());
3119:                        }
3120:                    }
3121:
3122:                    iterator = methodSet.iterator();
3123:
3124:                    while (iterator.hasNext()) {
3125:                        method = (Method) iterator.next();
3126:                        row = t.getEmptyRowData();
3127:                        row[iv_cat] = viewCat;
3128:                        row[iv_schem] = viewSchem;
3129:                        row[iv_name] = viewName;
3130:                        row[ir_cat] = ns.getCatalogName(method);
3131:                        row[ir_schem] = ns.getSchemaName(method);
3132:                        row[ir_name] = DINameSpace
3133:                                .getMethodSpecificName(method);
3134:
3135:                        t.insertSys(row);
3136:                    }
3137:                }
3138:
3139:                t.setDataReadOnly(true);
3140:
3141:                return t;
3142:            }
3143:
3144:            /**
3145:             * Inserts a set of procedure column description rows into the
3146:             * <code>Table</code> specified by the <code>t</code> argument. <p>
3147:             *
3148:             * @param t the table in which the rows are to be inserted
3149:             * @param l the list of procedure name aliases to which the
3150:             *        specified column values apply
3151:             * @param cat the procedure's catalog name
3152:             * @param schem the procedure's schema name
3153:             * @param pName the procedure's simple base (non-alias) name
3154:             * @param cName the procedure column name
3155:             * @param cType the column type (return, parameter, result)
3156:             * @param dType the column's data type code
3157:             * @param tName the column's canonical data type name
3158:             * @param prec the column's precision
3159:             * @param len the column's buffer length
3160:             * @param scale the column's scale (decimal digits)
3161:             * @param radix the column's numeric precision radix
3162:             * @param nullability the column's java.sql.DatbaseMetaData
3163:             *      nullabiliy code
3164:             * @param remark a human-readable remark regarding the column
3165:             * @param specificName the specific name of the procedure
3166:             *      (typically but not limited to
3167:             *      a fully qualified Java Method name and signature)
3168:             * @param seq helper value to back JDBC contract sort order
3169:             * @throws HsqlException if there is problem inserting the specified rows
3170:             *      in the table
3171:             *
3172:             */
3173:            protected void addPColRows(Table t, HsqlArrayList l, String cat,
3174:                    String schem, String pName, String cName, Integer cType,
3175:                    Integer dType, String tName, Integer prec, Integer len,
3176:                    Integer scale, Integer radix, Integer nullability,
3177:                    String remark, String specificName, int seq)
3178:                    throws HsqlException {
3179:
3180:                // column number mappings
3181:                final int icat = 0;
3182:                final int ischem = 1;
3183:                final int iname = 2;
3184:                final int icol_name = 3;
3185:                final int icol_type = 4;
3186:                final int idata_type = 5;
3187:                final int itype_name = 6;
3188:                final int iprec = 7;
3189:                final int ilength = 8;
3190:                final int iscale = 9;
3191:                final int iradix = 10;
3192:                final int inullable = 11;
3193:                final int iremark = 12;
3194:                final int isn = 13;
3195:                final int iseq = 14;
3196:                Object[] row = t.getEmptyRowData();
3197:                Integer sequence = ValuePool.getInt(seq);
3198:
3199:                row[icat] = cat;
3200:                row[ischem] = schem;
3201:                row[iname] = pName;
3202:                row[icol_name] = cName;
3203:                row[icol_type] = cType;
3204:                row[idata_type] = dType;
3205:                row[itype_name] = tName;
3206:                row[iprec] = prec;
3207:                row[ilength] = len;
3208:                row[iscale] = scale;
3209:                row[iradix] = radix;
3210:                row[inullable] = nullability;
3211:                row[iremark] = remark;
3212:                row[isn] = specificName;
3213:                row[iseq] = sequence;
3214:
3215:                t.insertSys(row);
3216:
3217:                if (l != null) {
3218:                    int size = l.size();
3219:
3220:                    for (int i = 0; i < size; i++) {
3221:                        row = t.getEmptyRowData();
3222:                        pName = (String) l.get(i);
3223:                        row[icat] = cat;
3224:                        row[ischem] = schem;
3225:                        row[iname] = pName;
3226:                        row[icol_name] = cName;
3227:                        row[icol_type] = cType;
3228:                        row[idata_type] = dType;
3229:                        row[itype_name] = tName;
3230:                        row[iprec] = prec;
3231:                        row[ilength] = len;
3232:                        row[iscale] = scale;
3233:                        row[iradix] = radix;
3234:                        row[inullable] = nullability;
3235:                        row[iremark] = remark;
3236:                        row[isn] = specificName;
3237:                        row[iseq] = sequence;
3238:
3239:                        t.insertSys(row);
3240:                    }
3241:                }
3242:            }
3243:
3244:            /**
3245:             * Inserts a set of procedure description rows into the <code>Table</code>
3246:             * object specified by the <code>t</code> argument. <p>
3247:             *
3248:             * @param t the table into which the specified rows will eventually
3249:             *      be inserted
3250:             * @param l the list of procedure name aliases to which the specified column
3251:             *      values apply
3252:             * @param cat the procedure catalog name
3253:             * @param schem the procedure schema name
3254:             * @param pName the base (non-alias) procedure name
3255:             * @param ip the procedure input parameter count
3256:             * @param op the procedure output parameter count
3257:             * @param rs the procedure result column count
3258:             * @param remark a human-readable remark regarding the procedure
3259:             * @param pType the procedure type code, indicating whether it is a
3260:             *      function, procedure, or uncatagorized (i.e. returns
3261:             *      a value, does not return a value, or it is unknown
3262:             *      if it returns a value)
3263:             * @param origin origin of the procedure, e.g.
3264:             *      (["BUILTIN" | "USER DEFINED"] "ROUTINE" | "TRIGGER") | "ALIAS", etc.
3265:             * @param specificName the specific name of the procedure
3266:             *      (typically but not limited to a
3267:             *      fully qualified Java Method name and signature)
3268:             * @throws HsqlException if there is problem inserting the specified rows
3269:             *      in the table
3270:             *
3271:             */
3272:            protected void addProcRows(Table t, HsqlArrayList l, String cat,
3273:                    String schem, String pName, Integer ip, Integer op,
3274:                    Integer rs, String remark, Integer pType, String origin,
3275:                    String specificName) throws HsqlException {
3276:
3277:                // column number mappings
3278:                final int icat = 0;
3279:                final int ischem = 1;
3280:                final int ipname = 2;
3281:                final int iinput_parms = 3;
3282:                final int ioutput_parms = 4;
3283:                final int iresult_sets = 5;
3284:                final int iremark = 6;
3285:                final int iptype = 7;
3286:                final int iporigin = 8;
3287:                final int isn = 9;
3288:                Object[] row = t.getEmptyRowData();
3289:
3290:                row[icat] = cat;
3291:                row[ischem] = schem;
3292:                row[ipname] = pName;
3293:                row[iinput_parms] = ip;
3294:                row[ioutput_parms] = op;
3295:                row[iresult_sets] = rs;
3296:                row[iremark] = remark;
3297:                row[iptype] = pType;
3298:                row[iporigin] = origin;
3299:                row[isn] = specificName;
3300:
3301:                t.insertSys(row);
3302:
3303:                if (l != null) {
3304:                    int size = l.size();
3305:
3306:                    for (int i = 0; i < size; i++) {
3307:                        row = t.getEmptyRowData();
3308:                        pName = (String) l.get(i);
3309:                        row[icat] = cat;
3310:                        row[ischem] = schem;
3311:                        row[ipname] = pName;
3312:                        row[iinput_parms] = ip;
3313:                        row[ioutput_parms] = op;
3314:                        row[iresult_sets] = rs;
3315:                        row[iremark] = remark;
3316:                        row[iptype] = pType;
3317:                        row[iporigin] = "ALIAS";
3318:                        row[isn] = specificName;
3319:
3320:                        t.insertSys(row);
3321:                    }
3322:                }
3323:            }
3324:
3325:            //------------------------------------------------------------------------------
3326:            // boucherb@users 20050515 further SQL2003 metadata support
3327:
3328:            /**
3329:             *  SYSTEM_AUTHORIZATIONS<p>
3330:             *
3331:             *  <b>Function</b><p>
3332:             *
3333:             *  The AUTHORIZATIONS table has one row for each &lt;role name&gt; and
3334:             *  one row for each &lt;authorization identifier &gt; referenced in the
3335:             *  Information Schema. These are the &lt;role name&gt;s and
3336:             *  &lt;authorization identifier&gt;s that may grant privileges as well as
3337:             *  those that may create a schema, or currently own a schema created
3338:             *  through a &lt;schema definition&gt;. <p>
3339:             *
3340:             *  <b>Definition</b><p>
3341:             *
3342:             *  <pre class="SqlCodeExample">
3343:             *  CREATE TABLE AUTHORIZATIONS (
3344:             *       AUTHORIZATION_NAME INFORMATION_SCHEMA.SQL_IDENTIFIER,
3345:             *       AUTHORIZATION_TYPE INFORMATION_SCHEMA.CHARACTER_DATA
3346:             *           CONSTRAINT AUTHORIZATIONS_AUTHORIZATION_TYPE_NOT_NULL
3347:             *               NOT NULL
3348:             *           CONSTRAINT AUTHORIZATIONS_AUTHORIZATION_TYPE_CHECK
3349:             *               CHECK ( AUTHORIZATION_TYPE IN ( 'USER', 'ROLE' ) ),
3350:             *           CONSTRAINT AUTHORIZATIONS_PRIMARY_KEY
3351:             *               PRIMARY KEY (AUTHORIZATION_NAME)
3352:             *       )
3353:             *  </pre>
3354:             *
3355:             *  <b>Description</b><p>
3356:             *
3357:             *  <ol>
3358:             *  <li> The values of AUTHORIZATION_TYPE have the following meanings:<p>
3359:             *
3360:             *  <table border cellpadding="3">
3361:             *       <tr>
3362:             *           <td nowrap>USER</td>
3363:             *           <td nowrap>The value of AUTHORIZATION_NAME is a known
3364:             *                      &lt;user identifier&gt;.</td>
3365:             *       <tr>
3366:             *       <tr>
3367:             *           <td nowrap>NO</td>
3368:             *           <td nowrap>The value of AUTHORIZATION_NAME is a &lt;role
3369:             *                      name&gt; defined by a &lt;role definition&gt;.</td>
3370:             *       <tr>
3371:             *  </table> <p>
3372:             *  </ol>
3373:             */
3374:            Table SYSTEM_AUTHORIZATIONS() throws HsqlException {
3375:
3376:                Table t = sysTables[SYSTEM_AUTHORIZATIONS];
3377:
3378:                if (t == null) {
3379:                    t = createBlankTable(sysTableHsqlNames[SYSTEM_AUTHORIZATIONS]);
3380:
3381:                    addColumn(t, "AUTHORIZATION_NAME", Types.VARCHAR, true); // not null
3382:                    addColumn(t, "AUTHORIZATION_TYPE", Types.VARCHAR, true); // not null
3383:
3384:                    // true PK
3385:                    t.createPrimaryKey(null, new int[] { 0 }, true);
3386:
3387:                    return t;
3388:                }
3389:
3390:                // Intermediate holders
3391:                HsqlArrayList users;
3392:                Iterator roles;
3393:                User user;
3394:                int userCount;
3395:                Object[] row;
3396:
3397:                // Initialization
3398:                users = database.getUserManager().listVisibleUsers(session,
3399:                        false);
3400:                userCount = users.size();
3401:
3402:                // Do it.
3403:                for (int i = 0; i < users.size(); i++) {
3404:                    row = t.getEmptyRowData();
3405:                    user = (User) users.get(i);
3406:                    row[0] = user.getName();
3407:                    row[1] = "USER";
3408:
3409:                    t.insertSys(row);
3410:                }
3411:
3412:                roles = database.getGranteeManager().getRoleNames().iterator();
3413:
3414:                while (roles.hasNext()) {
3415:                    row = t.getEmptyRowData();
3416:                    row[0] = roles.next().toString();
3417:                    row[1] = "ROLE";
3418:
3419:                    t.insertSys(row);
3420:                }
3421:
3422:                t.setDataReadOnly(true);
3423:
3424:                return t;
3425:            }
3426:
3427:            /**
3428:             * SYSTEM_COLLATIONS<p>
3429:             *
3430:             * <b>Function<b><p>
3431:             *
3432:             * The COLLATIONS table has one row for each character collation
3433:             * descriptor. <p>
3434:             *
3435:             * <b>Definition</b>
3436:             *
3437:             * <pre class="SqlCodeExample">
3438:             * CREATE TABLE COLLATIONS (
3439:             *      COLLATION_CATALOG INFORMATION_SCHEMA.SQL_IDENTIFIER,
3440:             *      COLLATION_SCHEMA INFORMATION_SCHEMA.SQL_IDENTIFIER,
3441:             *      COLLATION_NAME INFORMATION_SCHEMA.SQL_IDENTIFIER,
3442:             *      PAD_ATTRIBUTE INFORMATION_SCHEMA.CHARACTER_DATA
3443:             *          CONSTRAINT COLLATIONS_PAD_ATTRIBUTE_CHECK
3444:             *              CHECK ( PAD_ATTRIBUTE IN
3445:             *                  ( 'NO PAD', 'PAD SPACE' ) ),
3446:             *      COLLATION_TYPE INFORMATION_SCHEMA.SQL_IDENTIFIER,
3447:             *      COLLATION_DEFINITION INFORMATION_SCHEMA.CHARACTER_DATA,
3448:             *      COLLATION_DICTIONARY INFORMATION_SCHEMA.CHARACTER_DATA,
3449:             *      CHARACTER_REPERTOIRE_NAME INFORMATION_SCHEMA.SQL_IDENTIFIER
3450:             *          CONSTRAINT CHARACTER_REPERTOIRE_NAME_NOT_NULL
3451:             *              NOT NULL,
3452:             *      CONSTRAINT COLLATIONS_PRIMARY_KEY
3453:             *          PRIMARY KEY ( COLLATION_CATALOG, COLLATION_SCHEMA, COLLATION_NAME ),
3454:             *      CONSTRAINT COLLATIONS_FOREIGN_KEY_SCHEMATA
3455:             *          FOREIGN KEY ( COLLATION_CATALOG, COLLATION_SCHEMA )
3456:             *              REFERENCES SCHEMATA
3457:             * )
3458:             * </pre>
3459:             *
3460:             * <b>Description</b><p>
3461:             *
3462:             * <ol>
3463:             *      <li>The values of COLLATION_CATALOG, COLLATION_SCHEMA, and
3464:             *          COLLATION_NAME are the catalog name, unqualified schema name,
3465:             *          and qualified identifier, respectively, of the collation being
3466:             *          described.<p>
3467:             *
3468:             *      <li>The values of COLLATION_TYPE, COLLATION_DICTIONARY, and
3469:             *          COLLATION_DEFINITION are the null value (deprectated). <p>
3470:             *
3471:             *      <li>The values of PAD_ATTRIBUTE have the following meanings:<p>
3472:             *
3473:             *      <table border cellpadding="3">
3474:             *          <tr>
3475:             *              <td nowrap>NO PAD</td>
3476:             *              <td nowrap>The collation being described has the NO PAD
3477:             *                  characteristic.</td>
3478:             *          <tr>
3479:             *          <tr>
3480:             *              <td nowrap>PAD</td>
3481:             *              <td nowrap>The collation being described has the PAD SPACE
3482:             *                         characteristic.</td>
3483:             *          <tr>
3484:             *      </table> <p>
3485:             *
3486:             *      <li>The value of CHARACTER_REPERTOIRE_NAME is the name of the
3487:             *          character repertoire to which the collation being described
3488:             *          is applicable.
3489:             * </ol>
3490:             */
3491:            Table SYSTEM_COLLATIONS() throws HsqlException {
3492:
3493:                Table t = sysTables[SYSTEM_COLLATIONS];
3494:
3495:                if (t == null) {
3496:                    t = createBlankTable(sysTableHsqlNames[SYSTEM_COLLATIONS]);
3497:
3498:                    addColumn(t, "COLLATION_CATALOG", Types.VARCHAR);
3499:                    addColumn(t, "COLLATION_SCHEMA", Types.VARCHAR, true);
3500:                    addColumn(t, "COLLATION_NAME", Types.VARCHAR, true);
3501:                    addColumn(t, "PAD_ATTRIBUTE", Types.VARCHAR, 9, true);
3502:                    addColumn(t, "COLLATION_TYPE", Types.VARCHAR, true);
3503:                    addColumn(t, "COLLATION_DEFINITION", Types.VARCHAR);
3504:                    addColumn(t, "COLLATION_DICTIONARY", Types.VARCHAR);
3505:                    addColumn(t, "CHARACTER_REPERTOIRE_NAME", Types.VARCHAR,
3506:                            true);
3507:
3508:                    // false PK, as rows may have NULL COLLATION_CATALOG
3509:                    t.createPrimaryKey(null, new int[] { 0, 1, 2 }, false);
3510:
3511:                    return t;
3512:                }
3513:
3514:                Iterator collations;
3515:                String collation;
3516:                String collationSchema = SchemaManager.PUBLIC_SCHEMA;
3517:                String padAttribute = "NO PAD";
3518:                String characterRepertoireName = "UNICODE";
3519:                Object[] row;
3520:                final int icolcat = 0;
3521:                final int icolschem = 1;
3522:                final int icolname = 2;
3523:                final int ipadattr = 3;
3524:                final int icoltype = 4;
3525:                final int icoldef = 5;
3526:                final int icoldict = 6;
3527:                final int icharrep = 7;
3528:
3529:                collations = Collation.nameToJavaName.keySet().iterator();
3530:
3531:                while (collations.hasNext()) {
3532:                    row = t.getEmptyRowData();
3533:                    collation = (String) collations.next();
3534:                    row[icolcat] = ns.getCatalogName(collation);
3535:                    row[icolschem] = collationSchema;
3536:                    row[icolname] = collation;
3537:                    row[ipadattr] = padAttribute;
3538:                    row[icharrep] = characterRepertoireName;
3539:
3540:                    t.insertSys(row);
3541:                }
3542:
3543:                t.setDataReadOnly(true);
3544:
3545:                return t;
3546:            }
3547:
3548:            /**
3549:             * SYSTEM_ENABLED_ROLES<p>
3550:             *
3551:             * <b>Function</b><p>
3552:             *
3553:             * Identify the enabled roles for the current SQL-session.<p>
3554:             *
3555:             * Definition<p>
3556:             *
3557:             * <pre class="SqlCodeExample">
3558:             * CREATE RECURSIVE VIEW ENABLED_ROLES ( ROLE_NAME ) AS
3559:             *      VALUES ( CURRENT_ROLE )
3560:             *      UNION
3561:             *      SELECT RAD.ROLE_NAME
3562:             *        FROM DEFINITION_SCHEMA.ROLE_AUTHORIZATION_DESCRIPTORS RAD
3563:             *        JOIN ENABLED_ROLES R
3564:             *          ON RAD.GRANTEE = R.ROLE_NAME;
3565:             *
3566:             * GRANT SELECT ON TABLE ENABLED_ROLES
3567:             *    TO PUBLIC WITH GRANT OPTION;
3568:             * </pre>
3569:             */
3570:
3571:            /**
3572:             * SYSTEM_APPLICABLE_ROLES<p>
3573:             *
3574:             * <b>Function</b><p>
3575:             *
3576:             * Identifies the applicable roles for the current user.<p>
3577:             *
3578:             * <b>Definition</b><p>
3579:             *
3580:             * <pre class="SqlCodeExample">
3581:             * CREATE RECURSIVE VIEW APPLICABLE_ROLES ( GRANTEE, ROLE_NAME, IS_GRANTABLE ) AS
3582:             *      ( ( SELECT GRANTEE, ROLE_NAME, IS_GRANTABLE
3583:             *            FROM DEFINITION_SCHEMA.ROLE_AUTHORIZATION_DESCRIPTORS
3584:             *           WHERE ( GRANTEE IN ( CURRENT_USER, 'PUBLIC' )
3585:             *                OR GRANTEE IN ( SELECT ROLE_NAME
3586:             *                                  FROM ENABLED_ROLES ) ) )
3587:             *      UNION
3588:             *      ( SELECT RAD.GRANTEE, RAD.ROLE_NAME, RAD.IS_GRANTABLE
3589:             *          FROM DEFINITION_SCHEMA.ROLE_AUTHORIZATION_DESCRIPTORS RAD
3590:             *          JOIN APPLICABLE_ROLES R
3591:             *            ON RAD.GRANTEE = R.ROLE_NAME ) );
3592:             *
3593:             * GRANT SELECT ON TABLE APPLICABLE_ROLES
3594:             *    TO PUBLIC WITH GRANT OPTION;
3595:             * </pre>
3596:             */
3597:
3598:            /**
3599:             * SYSTEM_ROLE_AUTHORIZATION_DESCRIPTORS<p>
3600:             *
3601:             * <b>Function</b><p>
3602:             *
3603:             * Contains a representation of the role authorization descriptors.<p>
3604:             *
3605:             * <b>Definition</b>
3606:             *
3607:             * <pre class="SqlCodeExample">
3608:             * CREATE TABLE ROLE_AUTHORIZATION_DESCRIPTORS (
3609:             *      ROLE_NAME INFORMATION_SCHEMA.SQL_IDENTIFIER,
3610:             *      GRANTEE INFORMATION_SCHEMA.SQL_IDENTIFIER,
3611:             *      GRANTOR INFORMATION_SCHEMA.SQL_IDENTIFIER,
3612:             *      IS_GRANTABLE INFORMATION_SCHEMA.CHARACTER_DATA
3613:             *          CONSTRAINT ROLE_AUTHORIZATION_DESCRIPTORS_IS_GRANTABLE_CHECK
3614:             *              CHECK ( IS_GRANTABLE IN
3615:             *                  ( 'YES', 'NO' ) ),
3616:             *          CONSTRAINT ROLE_AUTHORIZATION_DESCRIPTORS_PRIMARY_KEY
3617:             *              PRIMARY KEY ( ROLE_NAME, GRANTEE ),
3618:             *          CONSTRAINT ROLE_AUTHORIZATION_DESCRIPTORS_CHECK_ROLE_NAME
3619:             *              CHECK ( ROLE_NAME IN
3620:             *                  ( SELECT AUTHORIZATION_NAME
3621:             *                      FROM AUTHORIZATIONS
3622:             *                     WHERE AUTHORIZATION_TYPE = 'ROLE' ) ),
3623:             *          CONSTRAINT ROLE_AUTHORIZATION_DESCRIPTORS_FOREIGN_KEY_AUTHORIZATIONS_GRANTOR
3624:             *              FOREIGN KEY ( GRANTOR )
3625:             *                  REFERENCES AUTHORIZATIONS,
3626:             *          CONSTRAINT ROLE_AUTHORIZATION_DESCRIPTORS_FOREIGN_KEY_AUTHORIZATIONS_GRANTEE
3627:             *              FOREIGN KEY ( GRANTEE )
3628:             *                  REFERENCES AUTHORIZATIONS
3629:             *      )
3630:             * </pre>
3631:             *
3632:             * <b>Description</b><p>
3633:             *
3634:             * <ol>
3635:             *      <li>The value of ROLE_NAME is the &lt;role name&gt; of some
3636:             *          &lt;role granted&gt; by the &lt;grant role statement&gt; or
3637:             *          the &lt;role name&gt; of a &lt;role definition&gt;. <p>
3638:             *
3639:             *      <li>The value of GRANTEE is an &lt;authorization identifier&gt;,
3640:             *          possibly PUBLIC, or &lt;role name&gt; specified as a
3641:             *          &lt;grantee&gt; contained in a &lt;grant role statement&gt;,
3642:             *          or the &lt;authorization identifier&gt; of the current
3643:             *          SQLsession when the &lt;role definition&gt; is executed. <p>
3644:             *
3645:             *      <li>The value of GRANTOR is the &lt;authorization identifier&gt;
3646:             *          of the user or role who granted the role identified by
3647:             *          ROLE_NAME to the user or role identified by the value of
3648:             *          GRANTEE. <p>
3649:             *
3650:             *      <li>The values of IS_GRANTABLE have the following meanings:<p>
3651:             *
3652:             *      <table border cellpadding="3">
3653:             *          <tr>
3654:             *              <td nowrap>YES</td>
3655:             *              <td nowrap>The described role is grantable.</td>
3656:             *          <tr>
3657:             *          <tr>
3658:             *              <td nowrap>NO</td>
3659:             *              <td nowrap>The described role is not grantable.</td>
3660:             *          <tr>
3661:             *      </table> <p>
3662:             * </ol>
3663:             */
3664:            Table SYSTEM_ROLE_AUTHORIZATION_DESCRIPTORS() throws HsqlException {
3665:
3666:                Table t = sysTables[SYSTEM_ROLE_AUTHORIZATION_DESCRIPTORS];
3667:
3668:                if (t == null) {
3669:                    t = createBlankTable(sysTableHsqlNames[SYSTEM_ROLE_AUTHORIZATION_DESCRIPTORS]);
3670:
3671:                    addColumn(t, "ROLE_NAME", Types.VARCHAR, true); // not null
3672:                    addColumn(t, "GRANTEE", Types.VARCHAR, true); // not null
3673:                    addColumn(t, "GRANTOR", Types.VARCHAR, true); // not null
3674:                    addColumn(t, "IS_GRANTABLE", Types.VARCHAR, true); // not null
3675:
3676:                    // true PK
3677:                    t.createPrimaryKey(null, new int[] { 0, 1 }, true);
3678:
3679:                    return t;
3680:                }
3681:
3682:                // Intermediate holders
3683:                String grantorName = GranteeManager.SYSTEM_AUTHORIZATION_NAME;
3684:                Iterator grantees;
3685:                Grantee grantee;
3686:                String granteeName;
3687:                Iterator roles;
3688:                String roleName;
3689:                String isGrantable;
3690:                Object[] row;
3691:                final int irole = 0;
3692:                final int igrantee = 1;
3693:                final int igrantor = 2;
3694:                final int igrantable = 3;
3695:
3696:                // Initialization
3697:                grantees = database.getGranteeManager().getGrantees()
3698:                        .iterator();
3699:
3700:                // Do it.
3701:                while (grantees.hasNext()) {
3702:                    grantee = (Grantee) grantees.next();
3703:                    granteeName = grantee.getName();
3704:                    roles = grantee.getDirectRoles().iterator();
3705:
3706:                    while (roles.hasNext()) {
3707:                        row = t.getEmptyRowData();
3708:                        roleName = (String) roles.next();
3709:                        isGrantable = grantee
3710:                                .hasRole(GranteeManager.DBA_ADMIN_ROLE_NAME) ? "YES"
3711:                                : "NO";
3712:                        row[irole] = roleName;
3713:                        row[igrantee] = granteeName;
3714:                        row[igrantor] = grantorName;
3715:                        row[igrantable] = isGrantable;
3716:
3717:                        t.insertSys(row);
3718:                    }
3719:                }
3720:
3721:                t.setDataReadOnly(true);
3722:
3723:                return t;
3724:            }
3725:
3726:            /**
3727:             * SYSTEM_SCHEMATA<p>
3728:             *
3729:             * <b>Function</b><p>
3730:             *
3731:             * The SCHEMATA table has one row for each schema. <p>
3732:             *
3733:             * <b>Definition</b><p>
3734:             *
3735:             * <pre class="SqlCodeExample">
3736:             * CREATE TABLE SCHEMATA (
3737:             *      CATALOG_NAME INFORMATION_SCHEMA.SQL_IDENTIFIER,
3738:             *      SCHEMA_NAME INFORMATION_SCHEMA.SQL_IDENTIFIER,
3739:             *      SCHEMA_OWNER INFORMATION_SCHEMA.SQL_IDENTIFIER
3740:             *          CONSTRAINT SCHEMA_OWNER_NOT_NULL
3741:             *              NOT NULL,
3742:             *      DEFAULT_CHARACTER_SET_CATALOG INFORMATION_SCHEMA.SQL_IDENTIFIER
3743:             *          CONSTRAINT DEFAULT_CHARACTER_SET_CATALOG_NOT_NULL
3744:             *              NOT NULL,
3745:             *      DEFAULT_CHARACTER_SET_SCHEMA INFORMATION_SCHEMA.SQL_IDENTIFIER
3746:             *          CONSTRAINT DEFAULT_CHARACTER_SET_SCHEMA_NOT_NULL
3747:             *              NOT NULL,
3748:             *      DEFAULT_CHARACTER_SET_NAME INFORMATION_SCHEMA.SQL_IDENTIFIER
3749:             *          CONSTRAINT DEFAULT_CHARACTER_SET_NAME_NOT_NULL
3750:             *              NOT NULL,
3751:             *      SQL_PATH INFORMATION_SCHEMA.CHARACTER_DATA,
3752:             *
3753:             *      CONSTRAINT SCHEMATA_PRIMARY_KEY
3754:             *          PRIMARY KEY ( CATALOG_NAME, SCHEMA_NAME ),
3755:             *      CONSTRAINT SCHEMATA_FOREIGN_KEY_AUTHORIZATIONS
3756:             *          FOREIGN KEY ( SCHEMA_OWNER )
3757:             *              REFERENCES AUTHORIZATIONS,
3758:             *      CONSTRAINT SCHEMATA_FOREIGN_KEY_CATALOG_NAMES
3759:             *          FOREIGN KEY ( CATALOG_NAME )
3760:             *              REFERENCES CATALOG_NAMES
3761:             *      )
3762:             * </pre>
3763:             *
3764:             * <b>Description</b><p>
3765:             *
3766:             * <ol>
3767:             *      <li>The value of CATALOG_NAME is the name of the catalog of the
3768:             *          schema described by this row.<p>
3769:             *
3770:             *      <li>The value of SCHEMA_NAME is the unqualified schema name of
3771:             *          the schema described by this row.<p>
3772:             *
3773:             *      <li>The values of SCHEMA_OWNER are the authorization identifiers
3774:             *          that own the schemata.<p>
3775:             *
3776:             *      <li>The values of DEFAULT_CHARACTER_SET_CATALOG,
3777:             *          DEFAULT_CHARACTER_SET_SCHEMA, and DEFAULT_CHARACTER_SET_NAME
3778:             *          are the catalog name, unqualified schema name, and qualified
3779:             *          identifier, respectively, of the default character set for
3780:             *          columns and domains in the schemata.<p>
3781:             *
3782:             *      <li>Case:<p>
3783:             *          <ul>
3784:             *              <li>If &lt;schema path specification&gt; was specified in
3785:             *                  the &lt;schema definition&gt; that defined the schema
3786:             *                  described by this row and the character representation
3787:             *                  of the &lt;schema path specification&gt; can be
3788:             *                  represented without truncation, then the value of
3789:             *                  SQL_PATH is that character representation.<p>
3790:             *
3791:             *              <li>Otherwise, the value of SQL_PATH is the null value.
3792:             *         </ul>
3793:             * </ol>
3794:             */
3795:            Table SYSTEM_SCHEMATA() throws HsqlException {
3796:
3797:                Table t = sysTables[SYSTEM_SCHEMATA];
3798:
3799:                if (t == null) {
3800:                    t = createBlankTable(sysTableHsqlNames[SYSTEM_SCHEMATA]);
3801:
3802:                    addColumn(t, "CATALOG_NAME", Types.VARCHAR);
3803:                    addColumn(t, "SCHEMA_NAME", Types.VARCHAR, true);
3804:                    addColumn(t, "SCHEMA_OWNER", Types.VARCHAR, true);
3805:                    addColumn(t, "DEFAULT_CHARACTER_SET_CATALOG", Types.VARCHAR);
3806:                    addColumn(t, "DEFAULT_CHARACTER_SET_SCHEMA", Types.VARCHAR,
3807:                            true);
3808:                    addColumn(t, "DEFAULT_CHARACTER_SET_NAME", Types.VARCHAR);
3809:                    addColumn(t, "SQL_PATH", Types.VARCHAR);
3810:
3811:                    // order: CATALOG_NAME, SCHEMA_NAME
3812:                    // false PK, as rows may have NULL CATALOG_NAME
3813:                    t.createPrimaryKey(null, new int[] { 0, 1 }, false);
3814:
3815:                    return t;
3816:                }
3817:
3818:                Iterator schemas;
3819:                String schema;
3820:                String schemaOwner = GranteeManager.DBA_ADMIN_ROLE_NAME;
3821:                String dcsSchema = SchemaManager.INFORMATION_SCHEMA;
3822:                String dcsName = ValuePool.getString("UTF16");
3823:                String sqlPath = null;
3824:                Object[] row;
3825:                final int ischema_catalog = 0;
3826:                final int ischema_name = 1;
3827:                final int ischema_owner = 2;
3828:                final int idef_charset_cat = 3;
3829:                final int idef_charset_schem = 4;
3830:                final int idef_charset_name = 5;
3831:                final int isql_path = 6;
3832:
3833:                // Initialization
3834:                schemas = database.schemaManager.fullSchemaNamesIterator();
3835:
3836:                // Do it.
3837:                while (schemas.hasNext()) {
3838:                    row = t.getEmptyRowData();
3839:                    schema = (String) schemas.next();
3840:                    row[ischema_catalog] = ns.getCatalogName(schema);
3841:                    row[ischema_name] = schema;
3842:                    row[ischema_owner] = schemaOwner;
3843:                    row[idef_charset_cat] = ns.getCatalogName(dcsSchema);
3844:                    row[idef_charset_schem] = dcsSchema;
3845:                    row[idef_charset_name] = dcsName;
3846:                    row[isql_path] = sqlPath;
3847:
3848:                    t.insertSys(row);
3849:                }
3850:
3851:                t.setDataReadOnly(true);
3852:
3853:                return t;
3854:            }
3855:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.