Quadcap Embeddable Database

com/quadcap/sql/meta/MetaTypes.java

Go to the documentation of this file.
00001 package com.quadcap.sql.meta; 00002 00003 /* Copyright 1999 - 2003 Quadcap Software. All rights reserved. 00004 * 00005 * This software is distributed under the Quadcap Free Software License. 00006 * This software may be used or modified for any purpose, personal or 00007 * commercial. Open Source redistributions are permitted. Commercial 00008 * redistribution of larger works derived from, or works which bundle 00009 * this software requires a "Commercial Redistribution License"; see 00010 * http://www.quadcap.com/purchase. 00011 * 00012 * Redistributions qualify as "Open Source" under one of the following terms: 00013 * 00014 * Redistributions are made at no charge beyond the reasonable cost of 00015 * materials and delivery. 00016 * 00017 * Redistributions are accompanied by a copy of the Source Code or by an 00018 * irrevocable offer to provide a copy of the Source Code for up to three 00019 * years at the cost of materials and delivery. Such redistributions 00020 * must allow further use, modification, and redistribution of the Source 00021 * Code under substantially the same terms as this license. 00022 * 00023 * Redistributions of source code must retain the copyright notices as they 00024 * appear in each source code file, these license terms, and the 00025 * disclaimer/limitation of liability set forth as paragraph 6 below. 00026 * 00027 * Redistributions in binary form must reproduce this Copyright Notice, 00028 * these license terms, and the disclaimer/limitation of liability set 00029 * forth as paragraph 6 below, in the documentation and/or other materials 00030 * provided with the distribution. 00031 * 00032 * The Software is provided on an "AS IS" basis. No warranty is 00033 * provided that the Software is free of defects, or fit for a 00034 * particular purpose. 00035 * 00036 * Limitation of Liability. Quadcap Software shall not be liable 00037 * for any damages suffered by the Licensee or any third party resulting 00038 * from use of the Software. 00039 */ 00040 00041 import java.io.IOException; 00042 00043 import java.util.Vector; 00044 00045 import java.sql.DatabaseMetaData; 00046 import java.sql.SQLException; 00047 import java.sql.Types; 00048 00049 import com.quadcap.sql.Column; 00050 import com.quadcap.sql.Row; 00051 import com.quadcap.sql.Session; 00052 00053 import com.quadcap.sql.index.Btree; 00054 import com.quadcap.sql.index.BCursor; 00055 00056 import com.quadcap.sql.types.*; 00057 00058 import com.quadcap.util.Debug; 00059 00060 /** 00061 * A Cursor supporting the <code>getTypes</code> function. 00062 * 00063 * @author Stan Bailes 00064 */ 00065 public class MetaTypes extends MetaCursor { 00066 static Column[] cols = { 00067 new Column("TYPE_NAME", typeString), // 1 00068 new Column("DATA_TYPE", typeShort), // 2 00069 new Column("PRECISION", typeInt), // 3 00070 new Column("LITERAL_PREFIX", typeString), // 4 00071 new Column("LITERAL_SUFFIX", typeString), // 5 00072 new Column("CREATE_PARAMS", typeString), // 6 00073 new Column("NULLABLE", typeShort), // 7 00074 new Column("CASE_SENSITIVE", typeBinary), // 8 00075 new Column("SEARCHABLE", typeShort), // 9 00076 new Column("UNSIGNED_ATTRIBUTE", typeBinary), // 10 00077 new Column("FIXED_PREC_SCALE", typeBinary), // 11 00078 new Column("AUTO_INCREMENT", typeBinary), // 12 00079 new Column("LOCAL_TYPE_NAME", typeString), // 13 00080 new Column("MINIMUM_SCALE", typeShort), // 14 00081 new Column("MAXIMUM_SCALE", typeShort), // 15 00082 new Column("SQL_DATA_TYPE", typeInt), // 16 00083 new Column("SQL_DATETIME_SUB", typeInt), // 17 00084 new Column("NUM_PREC_RADIX", typeInt), // 18 00085 }; 00086 00087 static Type[] types = { 00088 TypeBigInt.typeBigInt, 00089 TypeBinary.typeBinary, 00090 TypeBoolean.typeBoolean, 00091 TypeBlob.typeBlob, 00092 TypeChar.typeChar, 00093 TypeClob.typeClob, 00094 TypeDate.typeDate, 00095 TypeDecimal.typeDecimal, 00096 TypeInt.typeInt, 00097 TypeInterval.typeInterval, 00098 TypeReal.typeDouble, 00099 TypeReal.typeFloat, 00100 TypeReal.typeReal, 00101 TypeSmallInt.typeSmallInt, 00102 TypeTime.typeTime, 00103 TypeTimestamp.typeTimestamp, 00104 TypeTinyInt.typeTinyInt, 00105 TypeVarBinary.typeVarBinary, 00106 TypeVarChar.typeVarChar, 00107 }; 00108 00109 static int[] sortColumns = { 2 }; 00110 00111 /** 00112 * Cursor constructor. We're just a static repository of types 00113 */ 00114 public MetaTypes(Session session) 00115 throws SQLException 00116 { 00117 super(session, null); 00118 try { 00119 addColumns(cols); 00120 for (int i = 0; i < types.length; i++) { 00121 addType(types[i]); 00122 } 00123 sort(); 00124 } catch (ValueException e) { 00125 SQLException te = new SQLException(e.toString(), "Q000R"); 00126 te.setNextException(e); 00127 throw te; 00128 } 00129 } 00130 00131 /** 00132 * Sort by type 00133 */ 00134 public int[] getSortColumns() { 00135 return sortColumns; 00136 } 00137 00138 /** 00139 * Helper to build a row for the resultset 00140 */ 00141 void addType(Type type) throws SQLException { 00142 Row row = new Row(18); 00143 row.set(1, new ValueString(type.getTypeName())); 00144 Value dataType = new ValueShort(type.getJDBCType()); 00145 row.set(2, dataType); 00146 row.set(3, new ValueInteger(type.getMaxPrecision())); 00147 if (type.isCharType()) { 00148 row.set(4, new ValueString("'")); 00149 row.set(5, new ValueString("'")); 00150 } else { 00151 row.set(4, ValueNull.valueNull); 00152 row.set(5, ValueNull.valueNull); 00153 } 00154 row.set(6, new ValueString(type.getCreateParams())); 00155 row.set(7, new ValueShort(DatabaseMetaData.typeNullable)); 00156 row.set(8, ValueBoolean.trueBoolean); 00157 row.set(9, new ValueShort(DatabaseMetaData.typeSearchable)); 00158 row.set(10, new ValueBoolean(!type.isSigned())); 00159 00160 row.set(11, new ValueBoolean(type.isCurrency())); 00161 row.set(12, new ValueBoolean(false)); 00162 row.set(13, ValueNull.valueNull); 00163 row.set(14, new ValueShort(type.getMinScale())); 00164 row.set(15, new ValueShort(type.getMaxScale())); 00165 row.set(16, ValueNull.valueNull); 00166 row.set(17, ValueNull.valueNull); 00167 row.set(18, new ValueInteger(10)); 00168 addRow(row); 00169 } 00170 }