1 21 package org.apache.derby.client.am; 22 23 import org.apache.derby.iapi.reference.DRDAConstants; 24 import org.apache.derby.iapi.reference.JDBC30Translation; 25 import org.apache.derby.iapi.reference.JDBC40Translation; 26 27 30 public class Types { 31 33 36 39 public final static int BOOLEAN = JDBC30Translation.BOOLEAN; 41 public final static int SMALLINT = java.sql.Types.SMALLINT; 43 public final static int INTEGER = java.sql.Types.INTEGER; 45 public final static int BIGINT = java.sql.Types.BIGINT; 47 50 public final static int REAL = java.sql.Types.REAL; 52 public final static int DOUBLE = java.sql.Types.DOUBLE; 54 57 public final static int DECIMAL = java.sql.Types.DECIMAL; 59 public final static int CHAR = java.sql.Types.CHAR; 61 public final static int VARCHAR = java.sql.Types.VARCHAR; 63 public final static int LONGVARCHAR = java.sql.Types.LONGVARCHAR; 65 public final static int DATE = java.sql.Types.DATE; 67 public final static int TIME = java.sql.Types.TIME; 69 public final static int TIMESTAMP = java.sql.Types.TIMESTAMP; 71 public final static int BINARY = java.sql.Types.BINARY; 73 public final static int VARBINARY = java.sql.Types.VARBINARY; 75 public final static int LONGVARBINARY = java.sql.Types.LONGVARBINARY; 77 public final static int BLOB = java.sql.Types.BLOB; 79 public final static int CLOB = java.sql.Types.CLOB; 81 private Types() { 83 } 84 85 static public String getTypeString(int type) 86 { 87 switch (type ) 88 { 89 case BIGINT: return "BIGINT"; 90 case BINARY: return "BINARY"; 91 case BLOB: return "BLOB"; 92 case BOOLEAN: return "BOOLEAN"; 93 case CHAR: return "CHAR"; 94 case CLOB: return "CLOB"; 95 case DATE: return "DATE"; 96 case DECIMAL: return "DECIMAL"; 97 case DOUBLE: return "DOUBLE"; 98 case INTEGER: return "INTEGER"; 99 case LONGVARBINARY: return "LONGVARBINARY"; 100 case LONGVARCHAR: return "LONGVARCHAR"; 101 case REAL: return "REAL"; 102 case SMALLINT: return "SMALLINT"; 103 case TIME: return "TIME"; 104 case TIMESTAMP: return "TIMESTAMP"; 105 case VARBINARY: return "VARBINARY"; 106 case VARCHAR: return "VARCHAR"; 107 case java.sql.Types.ARRAY: return "ARRAY"; 109 case java.sql.Types.DATALINK: return "DATALINK"; 110 case JDBC40Translation.NCHAR: return "NATIONAL CHAR"; 111 case JDBC40Translation.NCLOB: return "NCLOB"; 112 case JDBC40Translation.NVARCHAR: return "NATIONAL CHAR VARYING"; 113 case JDBC40Translation.LONGNVARCHAR: return "LONG NVARCHAR"; 114 case java.sql.Types.REF: return "REF"; 115 case JDBC40Translation.ROWID: return "ROWID"; 116 case JDBC40Translation.SQLXML: return "SQLXML"; 117 case java.sql.Types.STRUCT: return "STRUCT"; 118 default: return "<UNKNOWN>"; 120 } 121 } 122 123 static public int mapDERBYTypeToDriverType(boolean isDescribed, int sqlType, long length, int ccsid) { 124 switch (Utils.getNonNullableSqlType(sqlType)) { case DRDAConstants.DB2_SQLTYPE_SMALL: 126 return SMALLINT; 127 case DRDAConstants.DB2_SQLTYPE_INTEGER: 128 return INTEGER; 129 case DRDAConstants.DB2_SQLTYPE_BIGINT: 130 return BIGINT; 131 case DRDAConstants.DB2_SQLTYPE_FLOAT: 132 if (length == 16) { 134 return DECIMAL; 135 } else if (length == 8) { 137 return DOUBLE; 138 } else if (length == 4) { 139 return REAL; 140 } else { 141 return 0; 142 } 143 case DRDAConstants.DB2_SQLTYPE_DECIMAL: case DRDAConstants.DB2_SQLTYPE_NUMERIC: return DECIMAL; 146 case DRDAConstants.DB2_SQLTYPE_CHAR: if (isDescribed && (ccsid == 0xffff || ccsid == 0)) { 148 return BINARY; 149 } else { 150 return CHAR; 151 } 152 case DRDAConstants.DB2_SQLTYPE_CSTR: return CHAR; 154 case DRDAConstants.DB2_SQLTYPE_VARCHAR: if (isDescribed && (ccsid == 0xffff || ccsid == 0)) { 157 return VARBINARY; 158 } else { 159 return VARCHAR; 160 } 161 case DRDAConstants.DB2_SQLTYPE_LONG: if (isDescribed && (ccsid == 0xffff || ccsid == 0)) { 163 return LONGVARBINARY; 164 } else { 165 return LONGVARCHAR; 166 } 167 case DRDAConstants.DB2_SQLTYPE_DATE: 168 return DATE; 169 case DRDAConstants.DB2_SQLTYPE_TIME: 170 return TIME; 171 case DRDAConstants.DB2_SQLTYPE_TIMESTAMP: 172 return TIMESTAMP; 173 case DRDAConstants.DB2_SQLTYPE_CLOB: return Types.CLOB; 175 case DRDAConstants.DB2_SQLTYPE_BLOB: return java.sql.Types.BLOB; 177 default: 178 return 0; 179 } 180 } 181 } 182 | Popular Tags |