001: package com.quadcap.sql.meta;
002:
003: /* Copyright 1999 - 2003 Quadcap Software. All rights reserved.
004: *
005: * This software is distributed under the Quadcap Free Software License.
006: * This software may be used or modified for any purpose, personal or
007: * commercial. Open Source redistributions are permitted. Commercial
008: * redistribution of larger works derived from, or works which bundle
009: * this software requires a "Commercial Redistribution License"; see
010: * http://www.quadcap.com/purchase.
011: *
012: * Redistributions qualify as "Open Source" under one of the following terms:
013: *
014: * Redistributions are made at no charge beyond the reasonable cost of
015: * materials and delivery.
016: *
017: * Redistributions are accompanied by a copy of the Source Code or by an
018: * irrevocable offer to provide a copy of the Source Code for up to three
019: * years at the cost of materials and delivery. Such redistributions
020: * must allow further use, modification, and redistribution of the Source
021: * Code under substantially the same terms as this license.
022: *
023: * Redistributions of source code must retain the copyright notices as they
024: * appear in each source code file, these license terms, and the
025: * disclaimer/limitation of liability set forth as paragraph 6 below.
026: *
027: * Redistributions in binary form must reproduce this Copyright Notice,
028: * these license terms, and the disclaimer/limitation of liability set
029: * forth as paragraph 6 below, in the documentation and/or other materials
030: * provided with the distribution.
031: *
032: * The Software is provided on an "AS IS" basis. No warranty is
033: * provided that the Software is free of defects, or fit for a
034: * particular purpose.
035: *
036: * Limitation of Liability. Quadcap Software shall not be liable
037: * for any damages suffered by the Licensee or any third party resulting
038: * from use of the Software.
039: */
040:
041: import java.io.IOException;
042:
043: import java.util.Vector;
044:
045: import java.sql.DatabaseMetaData;
046: import java.sql.SQLException;
047: import java.sql.Types;
048:
049: import com.quadcap.sql.Column;
050: import com.quadcap.sql.Row;
051: import com.quadcap.sql.Session;
052:
053: import com.quadcap.sql.index.Btree;
054: import com.quadcap.sql.index.BCursor;
055:
056: import com.quadcap.sql.types.*;
057:
058: import com.quadcap.util.Debug;
059:
060: /**
061: * A Cursor supporting the <code>getTypes</code> function.
062: *
063: * @author Stan Bailes
064: */
065: public class MetaTypes extends MetaCursor {
066: static Column[] cols = { new Column("TYPE_NAME", typeString), // 1
067: new Column("DATA_TYPE", typeShort), // 2
068: new Column("PRECISION", typeInt), // 3
069: new Column("LITERAL_PREFIX", typeString), // 4
070: new Column("LITERAL_SUFFIX", typeString), // 5
071: new Column("CREATE_PARAMS", typeString), // 6
072: new Column("NULLABLE", typeShort), // 7
073: new Column("CASE_SENSITIVE", typeBinary), // 8
074: new Column("SEARCHABLE", typeShort), // 9
075: new Column("UNSIGNED_ATTRIBUTE", typeBinary), // 10
076: new Column("FIXED_PREC_SCALE", typeBinary), // 11
077: new Column("AUTO_INCREMENT", typeBinary), // 12
078: new Column("LOCAL_TYPE_NAME", typeString), // 13
079: new Column("MINIMUM_SCALE", typeShort), // 14
080: new Column("MAXIMUM_SCALE", typeShort), // 15
081: new Column("SQL_DATA_TYPE", typeInt), // 16
082: new Column("SQL_DATETIME_SUB", typeInt), // 17
083: new Column("NUM_PREC_RADIX", typeInt), // 18
084: };
085:
086: static Type[] types = { TypeBigInt.typeBigInt,
087: TypeBinary.typeBinary, TypeBoolean.typeBoolean,
088: TypeBlob.typeBlob, TypeChar.typeChar, TypeClob.typeClob,
089: TypeDate.typeDate, TypeDecimal.typeDecimal,
090: TypeInt.typeInt, TypeInterval.typeInterval,
091: TypeReal.typeDouble, TypeReal.typeFloat, TypeReal.typeReal,
092: TypeSmallInt.typeSmallInt, TypeTime.typeTime,
093: TypeTimestamp.typeTimestamp, TypeTinyInt.typeTinyInt,
094: TypeVarBinary.typeVarBinary, TypeVarChar.typeVarChar, };
095:
096: static int[] sortColumns = { 2 };
097:
098: /**
099: * Cursor constructor. We're just a static repository of types
100: */
101: public MetaTypes(Session session) throws SQLException {
102: super (session, null);
103: try {
104: addColumns(cols);
105: for (int i = 0; i < types.length; i++) {
106: addType(types[i]);
107: }
108: sort();
109: } catch (ValueException e) {
110: SQLException te = new SQLException(e.toString(), "Q000R");
111: te.setNextException(e);
112: throw te;
113: }
114: }
115:
116: /**
117: * Sort by type
118: */
119: public int[] getSortColumns() {
120: return sortColumns;
121: }
122:
123: /**
124: * Helper to build a row for the resultset
125: */
126: void addType(Type type) throws SQLException {
127: Row row = new Row(18);
128: row.set(1, new ValueString(type.getTypeName()));
129: Value dataType = new ValueShort(type.getJDBCType());
130: row.set(2, dataType);
131: row.set(3, new ValueInteger(type.getMaxPrecision()));
132: if (type.isCharType()) {
133: row.set(4, new ValueString("'"));
134: row.set(5, new ValueString("'"));
135: } else {
136: row.set(4, ValueNull.valueNull);
137: row.set(5, ValueNull.valueNull);
138: }
139: row.set(6, new ValueString(type.getCreateParams()));
140: row.set(7, new ValueShort(DatabaseMetaData.typeNullable));
141: row.set(8, ValueBoolean.trueBoolean);
142: row.set(9, new ValueShort(DatabaseMetaData.typeSearchable));
143: row.set(10, new ValueBoolean(!type.isSigned()));
144:
145: row.set(11, new ValueBoolean(type.isCurrency()));
146: row.set(12, new ValueBoolean(false));
147: row.set(13, ValueNull.valueNull);
148: row.set(14, new ValueShort(type.getMinScale()));
149: row.set(15, new ValueShort(type.getMaxScale()));
150: row.set(16, ValueNull.valueNull);
151: row.set(17, ValueNull.valueNull);
152: row.set(18, new ValueInteger(10));
153: addRow(row);
154: }
155: }
|