1 19 package com.mysql.jdbc; 20 21 import java.sql.Types ; 22 23 24 31 final class MysqlDefs { 32 static final int SLEEP = 0; 37 static final int QUIT = 1; 38 static final int INIT_DB = 2; 39 static final int QUERY = 3; 40 static final int FIELD_LIST = 4; 41 static final int CREATE_DB = 5; 42 static final int DROP_DB = 6; 43 static final int RELOAD = 7; 44 static final int SHUTDOWN = 8; 45 static final int STATISTICS = 9; 46 static final int PROCESS_INFO = 10; 47 static final int CONNECT = 11; 48 static final int PROCESS_KILL = 12; 49 static final int DEBUG = 13; 50 static final int PING = 14; 51 static final int TIME = 15; 52 static final int DELAYED_INSERT = 16; 53 static final int CHANGE_USER = 17; 54 static final int COM_BINLOG_DUMP = 18; 55 static final int COM_TABLE_DUMP = 19; 56 static final int COM_CONNECT_OUT = 20; 57 static final int COM_REGISTER_SLAVE = 21; 58 static final int COM_PREPARE = 22; 59 static final int COM_EXECUTE = 23; 60 static final int COM_LONG_DATA = 24; 61 62 static final int FIELD_TYPE_DECIMAL = 0; 64 static final int FIELD_TYPE_TINY = 1; 65 static final int FIELD_TYPE_SHORT = 2; 66 static final int FIELD_TYPE_LONG = 3; 67 static final int FIELD_TYPE_FLOAT = 4; 68 static final int FIELD_TYPE_DOUBLE = 5; 69 static final int FIELD_TYPE_NULL = 6; 70 static final int FIELD_TYPE_TIMESTAMP = 7; 71 static final int FIELD_TYPE_LONGLONG = 8; 72 static final int FIELD_TYPE_INT24 = 9; 73 static final int FIELD_TYPE_DATE = 10; 74 static final int FIELD_TYPE_TIME = 11; 75 static final int FIELD_TYPE_DATETIME = 12; 76 77 static final int FIELD_TYPE_YEAR = 13; 79 static final int FIELD_TYPE_NEWDATE = 14; 80 static final int FIELD_TYPE_ENUM = 247; 81 static final int FIELD_TYPE_SET = 248; 82 83 static final int FIELD_TYPE_TINY_BLOB = 249; 85 static final int FIELD_TYPE_MEDIUM_BLOB = 250; 86 static final int FIELD_TYPE_LONG_BLOB = 251; 87 static final int FIELD_TYPE_BLOB = 252; 88 static final int FIELD_TYPE_VAR_STRING = 253; 89 static final int FIELD_TYPE_STRING = 254; 90 static final int ER_WARNING_NOT_COMPLETE_ROLLBACK = 1196; 91 92 static final int MAX_ROWS = 50000000; 95 static final String MIN_DOUBLE_VAL_STRING = "-1.7976931348623157E+308"; 96 static final String MAX_DOUBLE_VAL_STRING = "1.7976931348623157E+308"; 97 static final String MIN_FLOAT_VAL_STRING = "-3.402823466E+38"; 98 static final String MAX_FLOAT_VAL_STRING = "3.402823466E+38"; 99 static final String NAN_VAL_STRING = "0"; 100 101 102 105 static int mysqlToJavaType(int mysqlType) { 106 int jdbcType; 107 108 switch (mysqlType) { 109 case MysqlDefs.FIELD_TYPE_DECIMAL: 110 jdbcType = Types.DECIMAL; 111 112 break; 113 114 case MysqlDefs.FIELD_TYPE_TINY: 115 jdbcType = Types.TINYINT; 116 117 break; 118 119 case MysqlDefs.FIELD_TYPE_SHORT: 120 jdbcType = Types.SMALLINT; 121 122 break; 123 124 case MysqlDefs.FIELD_TYPE_LONG: 125 jdbcType = Types.INTEGER; 126 127 break; 128 129 case MysqlDefs.FIELD_TYPE_FLOAT: 130 jdbcType = Types.REAL; 131 132 break; 133 134 case MysqlDefs.FIELD_TYPE_DOUBLE: 135 jdbcType = Types.DOUBLE; 136 137 break; 138 139 case MysqlDefs.FIELD_TYPE_NULL: 140 jdbcType = Types.NULL; 141 142 break; 143 144 case MysqlDefs.FIELD_TYPE_TIMESTAMP: 145 jdbcType = Types.TIMESTAMP; 146 147 break; 148 149 case MysqlDefs.FIELD_TYPE_LONGLONG: 150 jdbcType = Types.BIGINT; 151 152 break; 153 154 case MysqlDefs.FIELD_TYPE_INT24: 155 jdbcType = Types.INTEGER; 156 157 break; 158 159 case MysqlDefs.FIELD_TYPE_DATE: 160 jdbcType = Types.DATE; 161 162 break; 163 164 case MysqlDefs.FIELD_TYPE_TIME: 165 jdbcType = Types.TIME; 166 167 break; 168 169 case MysqlDefs.FIELD_TYPE_DATETIME: 170 jdbcType = Types.TIMESTAMP; 171 172 break; 173 174 case MysqlDefs.FIELD_TYPE_YEAR: 175 jdbcType = Types.DATE; 176 177 break; 178 179 case MysqlDefs.FIELD_TYPE_NEWDATE: 180 jdbcType = Types.DATE; 181 182 break; 183 184 case MysqlDefs.FIELD_TYPE_ENUM: 185 jdbcType = Types.CHAR; 186 187 break; 188 189 case MysqlDefs.FIELD_TYPE_SET: 190 jdbcType = Types.CHAR; 191 192 break; 193 194 case MysqlDefs.FIELD_TYPE_TINY_BLOB: 195 jdbcType = Types.VARBINARY; 196 197 break; 198 199 case MysqlDefs.FIELD_TYPE_MEDIUM_BLOB: 200 jdbcType = Types.LONGVARBINARY; 201 202 break; 203 204 case MysqlDefs.FIELD_TYPE_LONG_BLOB: 205 jdbcType = Types.LONGVARBINARY; 206 207 break; 208 209 case MysqlDefs.FIELD_TYPE_BLOB: 210 jdbcType = Types.LONGVARBINARY; 211 212 break; 213 214 case MysqlDefs.FIELD_TYPE_VAR_STRING: 215 jdbcType = Types.VARCHAR; 216 217 break; 218 219 case MysqlDefs.FIELD_TYPE_STRING: 220 jdbcType = Types.CHAR; 221 222 break; 223 224 default: 225 jdbcType = Types.VARCHAR; 226 } 227 228 return jdbcType; 229 } 230 231 234 static int mysqlToJavaType(String mysqlType) { 235 if (mysqlType.equalsIgnoreCase("TINYINT")) { 236 return java.sql.Types.TINYINT; 237 } else if (mysqlType.equalsIgnoreCase("SMALLINT")) { 238 return java.sql.Types.SMALLINT; 239 } else if (mysqlType.equalsIgnoreCase("MEDIUMINT")) { 240 return java.sql.Types.SMALLINT; 241 } else if (mysqlType.equalsIgnoreCase("INT")) { 242 return java.sql.Types.INTEGER; 243 } else if (mysqlType.equalsIgnoreCase("INTEGER")) { 244 return java.sql.Types.INTEGER; 245 } else if (mysqlType.equalsIgnoreCase("BIGINT")) { 246 return java.sql.Types.BIGINT; 247 } else if (mysqlType.equalsIgnoreCase("INT24")) { 248 return java.sql.Types.BIGINT; 249 } else if (mysqlType.equalsIgnoreCase("REAL")) { 250 return java.sql.Types.REAL; 251 } else if (mysqlType.equalsIgnoreCase("FLOAT")) { 252 return java.sql.Types.FLOAT; 253 } else if (mysqlType.equalsIgnoreCase("DECIMAL")) { 254 return java.sql.Types.DECIMAL; 255 } else if (mysqlType.equalsIgnoreCase("NUMERIC")) { 256 return java.sql.Types.NUMERIC; 257 } else if (mysqlType.equalsIgnoreCase("DOUBLE")) { 258 return java.sql.Types.DOUBLE; 259 } else if (mysqlType.equalsIgnoreCase("CHAR")) { 260 return java.sql.Types.CHAR; 261 } else if (mysqlType.equalsIgnoreCase("VARCHAR")) { 262 return java.sql.Types.VARCHAR; 263 } else if (mysqlType.equalsIgnoreCase("DATE")) { 264 return java.sql.Types.DATE; 265 } else if (mysqlType.equalsIgnoreCase("TIME")) { 266 return java.sql.Types.TIME; 267 } else if (mysqlType.equalsIgnoreCase("YEAR")) { 268 return java.sql.Types.DATE; 269 } else if (mysqlType.equalsIgnoreCase("TIMESTAMP")) { 270 return java.sql.Types.TIMESTAMP; 271 } else if (mysqlType.equalsIgnoreCase("DATETIME")) { 272 return java.sql.Types.TIMESTAMP; 273 } else if (mysqlType.equalsIgnoreCase("TINYBLOB")) { 274 return java.sql.Types.BINARY; 275 } else if (mysqlType.equalsIgnoreCase("BLOB")) { 276 return java.sql.Types.VARBINARY; 277 } else if (mysqlType.equalsIgnoreCase("MEDIUMBLOB")) { 278 return java.sql.Types.VARBINARY; 279 } else if (mysqlType.equalsIgnoreCase("LONGBLOB")) { 280 return java.sql.Types.LONGVARBINARY; 281 } else if (mysqlType.equalsIgnoreCase("TINYTEXT")) { 282 return java.sql.Types.VARCHAR; 283 } else if (mysqlType.equalsIgnoreCase("TEXT")) { 284 return java.sql.Types.LONGVARCHAR; 285 } else if (mysqlType.equalsIgnoreCase("MEDIUMTEXT")) { 286 return java.sql.Types.LONGVARCHAR; 287 } else if (mysqlType.equalsIgnoreCase("LONGTEXT")) { 288 return java.sql.Types.LONGVARCHAR; 289 } else if (mysqlType.equalsIgnoreCase("ENUM")) { 290 return java.sql.Types.CHAR; 291 } else if (mysqlType.equalsIgnoreCase("SET")) { 292 return java.sql.Types.CHAR; 293 } 294 295 return java.sql.Types.OTHER; 297 } 298 } 299 | Popular Tags |