1 19 package com.mysql.jdbc; 20 21 import java.sql.ResultSet ; 22 import java.sql.SQLException ; 23 import java.sql.Statement ; 24 import java.sql.Types ; 25 26 import java.util.ArrayList ; 27 import java.util.Iterator ; 28 import java.util.List ; 29 import java.util.StringTokenizer ; 30 import java.util.TreeMap ; 31 32 33 57 public class DatabaseMetaData implements java.sql.DatabaseMetaData { 58 private static final byte[] TABLE_AS_BYTES = "TABLE".getBytes(); 59 60 61 private static final String SUPPORTS_FK = "SUPPORTS_FK"; 62 63 private static final int PKTABLE_CAT = 0; 68 private static final int PKTABLE_SCHEM = 1; 69 private static final int PKTABLE_NAME = 2; 70 private static final int PKCOLUMN_NAME = 3; 71 private static final int FKTABLE_CAT = 4; 72 private static final int FKTABLE_SCHEM = 5; 73 private static final int FKTABLE_NAME = 6; 74 private static final int FKCOLUMN_NAME = 7; 75 private static final int KEY_SEQ = 8; 76 private static final int UPDATE_RULE = 9; 77 private static final int DELETE_RULE = 10; 78 private static final int FK_NAME = 11; 79 private static final int PK_NAME = 12; 80 private static final int DEFERRABILITY = 13; 81 82 83 private Connection conn; 84 85 86 private String database = null; 87 88 89 private String quotedId = null; 90 91 97 public DatabaseMetaData(Connection conn, String database) { 98 this.conn = conn; 99 this.database = database; 100 101 try { 102 this.quotedId = this.conn.supportsQuotedIdentifiers() 103 ? getIdentifierQuoteString() : ""; 104 } catch (SQLException sqlEx) { 105 AssertionFailedException.shouldNotHappen(sqlEx); 108 } 109 } 110 111 114 public java.sql.ResultSet getAttributes(String arg0, String arg1, 115 String arg2, String arg3) throws SQLException { 116 Field[] fields = new Field[21]; 117 fields[0] = new Field("", "TYPE_CAT", Types.CHAR, 32); 118 fields[1] = new Field("", "TYPE_SCHEM", Types.CHAR, 32); 119 fields[2] = new Field("", "TYPE_NAME", Types.CHAR, 32); 120 fields[3] = new Field("", "ATTR_NAME", Types.CHAR, 32); 121 fields[4] = new Field("", "DATA_TYPE", Types.SMALLINT, 32); 122 fields[5] = new Field("", "ATTR_TYPE_NAME", Types.CHAR, 32); 123 fields[6] = new Field("", "ATTR_SIZE", Types.INTEGER, 32); 124 fields[7] = new Field("", "DECIMAL_DIGITS", Types.INTEGER, 32); 125 fields[8] = new Field("", "NUM_PREC_RADIX", Types.INTEGER, 32); 126 fields[9] = new Field("", "NULLABLE ", Types.INTEGER, 32); 127 fields[10] = new Field("", "REMARKS", Types.CHAR, 32); 128 fields[11] = new Field("", "ATTR_DEF", Types.CHAR, 32); 129 fields[12] = new Field("", "SQL_DATA_TYPE", Types.INTEGER, 32); 130 fields[13] = new Field("", "SQL_DATETIME_SUB", Types.INTEGER, 32); 131 fields[14] = new Field("", "CHAR_OCTET_LENGTH", Types.INTEGER, 32); 132 fields[15] = new Field("", "ORDINAL_POSITION", Types.INTEGER, 32); 133 fields[16] = new Field("", "IS_NULLABLE", Types.CHAR, 32); 134 fields[17] = new Field("", "SCOPE_CATALOG", Types.CHAR, 32); 135 fields[18] = new Field("", "SCOPE_SCHEMA", Types.CHAR, 32); 136 fields[19] = new Field("", "SCOPE_TABLE", Types.CHAR, 32); 137 fields[20] = new Field("", "SOURCE_DATA_TYPE", Types.SMALLINT, 32); 138 139 return buildResultSet(fields, new ArrayList ()); 140 } 141 142 214 public java.sql.ResultSet getBestRowIdentifier(String catalog, 215 String schema, String table, int scope, boolean nullable) 216 throws java.sql.SQLException { 217 Field[] fields = new Field[8]; 218 fields[0] = new Field("", "SCOPE", Types.SMALLINT, 5); 219 fields[1] = new Field("", "COLUMN_NAME", Types.CHAR, 32); 220 fields[2] = new Field("", "DATA_TYPE", Types.SMALLINT, 32); 221 fields[3] = new Field("", "TYPE_NAME", Types.CHAR, 32); 222 fields[4] = new Field("", "COLUMN_SIZE", Types.INTEGER, 10); 223 fields[5] = new Field("", "BUFFER_LENGTH", Types.INTEGER, 10); 224 fields[6] = new Field("", "DECIMAL_DIGITS", Types.INTEGER, 10); 225 fields[7] = new Field("", "PSEUDO_COLUMN", Types.SMALLINT, 5); 226 227 String databasePart = ""; 228 229 if (catalog != null) { 230 if (!catalog.equals("")) { 231 databasePart = " FROM " + this.quotedId + catalog 232 + this.quotedId; 233 } 234 } else { 235 databasePart = " FROM " + this.quotedId + this.database 236 + this.quotedId; 237 } 238 239 if (table == null) { 240 throw new java.sql.SQLException ("Table not specified.", SQLError.SQL_STATE_ILLEGAL_ARGUMENT); 241 } 242 243 ResultSet results = null; 244 Statement stmt = null; 245 246 try { 247 stmt = this.conn.createStatement(); 248 249 if (stmt.getMaxRows() != 0) { 250 stmt.setMaxRows(0); 251 } 252 253 StringBuffer queryBuf = new StringBuffer ("SHOW COLUMNS FROM "); 254 queryBuf.append(this.quotedId); 255 queryBuf.append(table); 256 queryBuf.append(this.quotedId); 257 queryBuf.append(databasePart); 258 259 results = stmt.executeQuery(queryBuf.toString()); 260 261 ArrayList tuples = new ArrayList (); 262 263 while (results.next()) { 264 String keyType = results.getString("Key"); 265 266 if (keyType != null) { 267 if (StringUtils.startsWithIgnoreCase(keyType, "PRI")) { 268 byte[][] rowVal = new byte[8][]; 269 rowVal[0] = Integer.toString(java.sql.DatabaseMetaData.bestRowSession) 270 .getBytes(); 271 rowVal[1] = results.getBytes("Field"); 272 273 String type = results.getString("Type"); 274 int size = MysqlIO.getMaxBuf(); 275 int decimals = 0; 276 277 280 if (type.indexOf("enum") != -1) { 281 String temp = type.substring(type.indexOf("("), 282 type.indexOf(")")); 283 java.util.StringTokenizer tokenizer = new java.util.StringTokenizer (temp, 284 ","); 285 int maxLength = 0; 286 287 while (tokenizer.hasMoreTokens()) { 288 maxLength = Math.max(maxLength, 289 (tokenizer.nextToken().length() - 2)); 290 } 291 292 size = maxLength; 293 decimals = 0; 294 type = "enum"; 295 } else if (type.indexOf("(") != -1) { 296 if (type.indexOf(",") != -1) { 297 size = Integer.parseInt(type.substring(type 298 .indexOf("(") + 1, type.indexOf(","))); 299 decimals = Integer.parseInt(type.substring(type 300 .indexOf(",") + 1, type.indexOf(")"))); 301 } else { 302 size = Integer.parseInt(type.substring(type 303 .indexOf("(") + 1, type.indexOf(")"))); 304 } 305 306 type = type.substring(type.indexOf("(")); 307 } 308 309 rowVal[2] = new byte[0]; rowVal[3] = s2b(type); 311 rowVal[4] = Integer.toString(size + decimals).getBytes(); 312 rowVal[5] = Integer.toString(size + decimals).getBytes(); 313 rowVal[6] = Integer.toString(decimals).getBytes(); 314 rowVal[7] = Integer.toString(java.sql.DatabaseMetaData.bestRowNotPseudo) 315 .getBytes(); 316 tuples.add(rowVal); 317 } 318 } 319 } 320 321 return buildResultSet(fields, tuples); 322 } finally { 323 if (results != null) { 324 try { 325 results.close(); 326 } catch (Exception ex) { 327 ; 328 } 329 330 results = null; 331 } 332 333 if (stmt != null) { 334 try { 335 stmt.close(); 336 } catch (Exception ex) { 337 ; 338 } 339 340 stmt = null; 341 } 342 } 343 } 344 345 353 public boolean isCatalogAtStart() throws java.sql.SQLException { 354 return true; 355 } 356 357 364 public String getCatalogSeparator() throws java.sql.SQLException { 365 return "."; 366 } 367 368 375 public String getCatalogTerm() throws java.sql.SQLException { 376 return "database"; 377 } 378 379 398 public java.sql.ResultSet getCatalogs() throws java.sql.SQLException { 399 java.sql.ResultSet results = null; 400 java.sql.Statement stmt = null; 401 402 try { 403 stmt = this.conn.createStatement(); 404 405 if (stmt.getMaxRows() != 0) { 406 stmt.setMaxRows(0); 407 } 408 409 results = stmt.executeQuery("SHOW DATABASES"); 410 411 java.sql.ResultSetMetaData resultsMD = results.getMetaData(); 412 Field[] fields = new Field[1]; 413 fields[0] = new Field("", "TABLE_CAT", Types.VARCHAR, 414 resultsMD.getColumnDisplaySize(1)); 415 416 ArrayList tuples = new ArrayList (); 417 418 while (results.next()) { 419 byte[][] rowVal = new byte[1][]; 420 rowVal[0] = results.getBytes(1); 421 tuples.add(rowVal); 422 } 423 424 return buildResultSet(fields, tuples); 425 } finally { 426 if (results != null) { 427 try { 428 results.close(); 429 } catch (SQLException sqlEx) { 430 AssertionFailedException.shouldNotHappen(sqlEx); 431 } 432 433 results = null; 434 } 435 436 if (stmt != null) { 437 try { 438 stmt.close(); 439 } catch (SQLException sqlEx) { 440 AssertionFailedException.shouldNotHappen(sqlEx); 441 } 442 443 stmt = null; 444 } 445 } 446 } 447 448 500 public java.sql.ResultSet getColumnPrivileges(String catalog, 501 String schema, String table, String columnNamePattern) 502 throws java.sql.SQLException { 503 Field[] fields = new Field[8]; 504 fields[0] = new Field("", "TABLE_CAT", Types.CHAR, 64); 505 fields[1] = new Field("", "TABLE_SCHEM", Types.CHAR, 1); 506 fields[2] = new Field("", "TABLE_NAME", Types.CHAR, 64); 507 fields[3] = new Field("", "COLUMN_NAME", Types.CHAR, 64); 508 fields[4] = new Field("", "GRANTOR", Types.CHAR, 77); 509 fields[5] = new Field("", "GRANTEE", Types.CHAR, 77); 510 fields[6] = new Field("", "PRIVILEGE", Types.CHAR, 64); 511 fields[7] = new Field("", "IS_GRANTABLE", Types.CHAR, 3); 512 513 StringBuffer grantQuery = new StringBuffer ( 514 "SELECT c.host, c.db, t.grantor, c.user, " 515 + "c.table_name, c.column_name, c.column_priv " 516 + "from mysql.columns_priv c, mysql.tables_priv t " 517 + "where c.host = t.host and c.db = t.db and " 518 + "c.table_name = t.table_name "); 519 520 if ((catalog != null) && (catalog.length() != 0)) { 521 grantQuery.append(" AND c.db='"); 522 grantQuery.append(catalog); 523 grantQuery.append("' "); 524 ; 525 } 526 527 grantQuery.append(" AND c.table_name ='"); 528 grantQuery.append(table); 529 grantQuery.append("' AND c.column_name like '"); 530 grantQuery.append(columnNamePattern); 531 grantQuery.append("'"); 532 533 Statement stmt = null; 534 ResultSet results = null; 535 ArrayList grantRows = new ArrayList (); 536 537 try { 538 stmt = this.conn.createStatement(); 539 540 if (stmt.getMaxRows() != 0) { 541 stmt.setMaxRows(0); 542 } 543 544 results = stmt.executeQuery(grantQuery.toString()); 545 546 while (results.next()) { 547 String host = results.getString(1); 548 String database = results.getString(2); 549 String grantor = results.getString(3); 550 String user = results.getString(4); 551 552 if ((user == null) || (user.length() == 0)) { 553 user = "%"; 554 } 555 556 StringBuffer fullUser = new StringBuffer (user); 557 558 if ((host != null) && this.conn.useHostsInPrivileges()) { 559 fullUser.append("@"); 560 fullUser.append(host); 561 } 562 563 String columnName = results.getString(6); 564 String allPrivileges = results.getString(7); 565 566 if (allPrivileges != null) { 567 allPrivileges = allPrivileges.toUpperCase(); 568 569 StringTokenizer st = new StringTokenizer (allPrivileges, ","); 570 571 while (st.hasMoreTokens()) { 572 String privilege = st.nextToken().trim(); 573 byte[][] tuple = new byte[8][]; 574 tuple[0] = s2b(database); 575 tuple[1] = null; 576 tuple[2] = s2b(table); 577 tuple[3] = s2b(columnName); 578 579 if (grantor != null) { 580 tuple[4] = s2b(grantor); 581 } else { 582 tuple[4] = null; 583 } 584 585 tuple[5] = s2b(fullUser.toString()); 586 tuple[6] = s2b(privilege); 587 tuple[7] = null; 588 grantRows.add(tuple); 589 } 590 } 591 } 592 } finally { 593 if (results != null) { 594 try { 595 results.close(); 596 } catch (Exception ex) { 597 ; 598 } 599 600 results = null; 601 } 602 603 if (stmt != null) { 604 try { 605 stmt.close(); 606 } catch (Exception ex) { 607 ; 608 } 609 610 stmt = null; 611 } 612 } 613 614 return buildResultSet(fields, grantRows); 615 } 616 617 717 public java.sql.ResultSet getColumns(String catalog, String schemaPattern, 718 String tableName, String columnNamePattern) 719 throws java.sql.SQLException { 720 String databasePart = ""; 721 722 if (columnNamePattern == null) { 723 columnNamePattern = "%"; 724 } 725 726 if (catalog != null) { 727 if (!catalog.equals("")) { 728 databasePart = " FROM " + this.quotedId + catalog 729 + this.quotedId; 730 } 731 } else { 732 databasePart = " FROM " + this.quotedId + this.database 733 + this.quotedId; 734 } 735 736 ArrayList tableNameList = new ArrayList (); 737 int tablenameLength = 0; 738 739 if (tableName == null) { 740 java.sql.ResultSet tables = null; 742 743 try { 744 tables = getTables(catalog, schemaPattern, "%", new String [0]); 745 746 while (tables.next()) { 747 String tableNameFromList = tables.getString("TABLE_NAME"); 748 tableNameList.add(tableNameFromList); 749 750 if (tableNameFromList.length() > tablenameLength) { 751 tablenameLength = tableNameFromList.length(); 752 } 753 } 754 } finally { 755 if (tables != null) { 756 try { 757 tables.close(); 758 } catch (Exception sqlEx) { 759 AssertionFailedException.shouldNotHappen(sqlEx); 760 } 761 762 tables = null; 763 } 764 } 765 } else { 766 java.sql.ResultSet tables = null; 767 768 try { 769 tables = getTables(catalog, schemaPattern, tableName, 770 new String [0]); 771 772 while (tables.next()) { 773 String tableNameFromList = tables.getString("TABLE_NAME"); 774 tableNameList.add(tableNameFromList); 775 776 if (tableNameFromList.length() > tablenameLength) { 777 tablenameLength = tableNameFromList.length(); 778 } 779 } 780 } finally { 781 if (tables != null) { 782 try { 783 tables.close(); 784 } catch (SQLException sqlEx) { 785 AssertionFailedException.shouldNotHappen(sqlEx); 786 } 787 788 tables = null; 789 } 790 } 791 } 792 793 int catalogLength = 0; 794 795 if (catalog != null) { 796 catalogLength = catalog.length(); 797 } else { 798 catalog = ""; 799 catalogLength = 0; 800 } 801 802 java.util.Iterator tableNames = tableNameList.iterator(); 803 Field[] fields = new Field[18]; 804 fields[0] = new Field("", "TABLE_CAT", Types.CHAR, catalogLength); 805 fields[1] = new Field("", "TABLE_SCHEM", Types.CHAR, 0); 806 fields[2] = new Field("", "TABLE_NAME", Types.CHAR, tablenameLength); 807 fields[3] = new Field("", "COLUMN_NAME", Types.CHAR, 32); 808 fields[4] = new Field("", "DATA_TYPE", Types.SMALLINT, 5); 809 fields[5] = new Field("", "TYPE_NAME", Types.CHAR, 16); 810 fields[6] = new Field("", "COLUMN_SIZE", Types.INTEGER, 811 Integer.toString(Integer.MAX_VALUE).length()); 812 fields[7] = new Field("", "BUFFER_LENGTH", Types.INTEGER, 10); 813 fields[8] = new Field("", "DECIMAL_DIGITS", Types.INTEGER, 10); 814 fields[9] = new Field("", "NUM_PREC_RADIX", Types.INTEGER, 10); 815 fields[10] = new Field("", "NULLABLE", Types.INTEGER, 10); 816 fields[11] = new Field("", "REMARKS", Types.CHAR, 0); 817 fields[12] = new Field("", "COLUMN_DEF", Types.CHAR, 0); 818 fields[13] = new Field("", "SQL_DATA_TYPE", Types.INTEGER, 10); 819 fields[14] = new Field("", "SQL_DATETIME_SUB", Types.INTEGER, 10); 820 fields[15] = new Field("", "CHAR_OCTET_LENGTH", Types.INTEGER, 821 Integer.toString(Integer.MAX_VALUE).length()); 822 fields[16] = new Field("", "ORDINAL_POSITION", Types.INTEGER, 10); 823 fields[17] = new Field("", "IS_NULLABLE", Types.CHAR, 3); 824 825 ArrayList tuples = new ArrayList (); 826 827 byte[] connectionCatalogAsBytes = null; 828 829 if (catalog == null) { 830 connectionCatalogAsBytes = s2b(this.conn.getCatalog()); 831 } else { 832 connectionCatalogAsBytes = s2b(catalog); 833 } 834 835 while (tableNames.hasNext()) { 836 String tableNamePattern = (String ) tableNames.next(); 837 Statement stmt = null; 838 ResultSet results = null; 839 840 try { 841 stmt = this.conn.createStatement(); 842 843 if (stmt.getMaxRows() != 0) { 844 stmt.setMaxRows(0); 845 } 846 847 StringBuffer queryBuf = new StringBuffer ("SHOW COLUMNS FROM "); 848 queryBuf.append(this.quotedId); 849 queryBuf.append(tableNamePattern); 850 queryBuf.append(this.quotedId); 851 queryBuf.append(databasePart); 852 queryBuf.append(" LIKE '"); 853 queryBuf.append(columnNamePattern); 854 queryBuf.append("'"); 855 856 results = stmt.executeQuery(queryBuf.toString()); 857 858 int ordPos = 1; 859 860 while (results.next()) { 861 byte[][] rowVal = new byte[18][]; 862 rowVal[0] = connectionCatalogAsBytes; rowVal[1] = null; 864 865 rowVal[2] = s2b(tableNamePattern); rowVal[3] = results.getBytes("Field"); 868 869 String typeInfo = results.getString("Type"); 870 871 if (Driver.DEBUG) { 872 System.out.println("Type: " + typeInfo); 873 } 874 875 String mysqlType = ""; 876 877 if (typeInfo.indexOf("(") != -1) { 878 mysqlType = typeInfo.substring(0, typeInfo.indexOf("(")); 879 } else { 880 mysqlType = typeInfo; 881 } 882 883 if (this.conn.capitalizeDBMDTypes()) { 884 mysqlType = mysqlType.toUpperCase(); 885 } 886 887 890 rowVal[4] = Integer.toString(MysqlDefs.mysqlToJavaType( 891 mysqlType)).getBytes(); 892 893 rowVal[5] = s2b(mysqlType); 896 if (typeInfo != null) { 898 if (StringUtils.startsWithIgnoreCase(typeInfo, "enum") 899 || StringUtils.startsWithIgnoreCase(typeInfo, 900 "set")) { 901 String temp = typeInfo.substring(typeInfo.indexOf( 902 "("), typeInfo.lastIndexOf(")")); 903 java.util.StringTokenizer tokenizer = new java.util.StringTokenizer (temp, 904 ","); 905 int maxLength = 0; 906 907 while (tokenizer.hasMoreTokens()) { 908 maxLength = Math.max(maxLength, 909 (tokenizer.nextToken().length() - 2)); 910 } 911 912 rowVal[6] = Integer.toString(maxLength).getBytes(); 913 rowVal[8] = new byte[] { (byte) '0' }; 914 } else if (typeInfo.indexOf(",") != -1) { 915 String size = typeInfo.substring((typeInfo.indexOf( 917 "(") + 1), (typeInfo.indexOf(","))); 918 String decimals = typeInfo.substring((typeInfo 919 .indexOf(",") + 1), (typeInfo.indexOf(")"))); 920 rowVal[6] = s2b(size); 921 rowVal[8] = s2b(decimals); 922 } else { 923 String size = "0"; 924 925 926 if (typeInfo.indexOf("(") != -1) { 927 size = typeInfo.substring((typeInfo.indexOf("(") 928 + 1), (typeInfo.indexOf(")"))); 929 } else if (typeInfo.equalsIgnoreCase("tinyint")) { 930 size = "1"; 931 } else if (typeInfo.equalsIgnoreCase("smallint")) { 932 size = "6"; 933 } else if (typeInfo.equalsIgnoreCase("mediumint")) { 934 size = "6"; 935 } else if (typeInfo.equalsIgnoreCase("int")) { 936 size = "11"; 937 } else if (typeInfo.equalsIgnoreCase("integer")) { 938 size = "11"; 939 } else if (typeInfo.equalsIgnoreCase("bigint")) { 940 size = "25"; 941 } else if (typeInfo.equalsIgnoreCase("int24")) { 942 size = "25"; 943 } else if (typeInfo.equalsIgnoreCase("real")) { 944 size = "12"; 945 } else if (typeInfo.equalsIgnoreCase("float")) { 946 size = "12"; 947 } else if (typeInfo.equalsIgnoreCase("decimal")) { 948 size = "12"; 949 } else if (typeInfo.equalsIgnoreCase("numeric")) { 950 size = "12"; 951 } else if (typeInfo.equalsIgnoreCase("double")) { 952 size = "22"; 953 } else if (typeInfo.equalsIgnoreCase("char")) { 954 size = "1"; 955 } else if (typeInfo.equalsIgnoreCase("varchar")) { 956 size = "255"; 957 } else if (typeInfo.equalsIgnoreCase("date")) { 958 size = "10"; 959 } else if (typeInfo.equalsIgnoreCase("time")) { 960 size = "8"; 961 } else if (typeInfo.equalsIgnoreCase("timestamp")) { 962 size = "19"; 963 } else if (typeInfo.equalsIgnoreCase("datetime")) { 964 size = "19"; 965 } else if (typeInfo.equalsIgnoreCase("tinyblob")) { 966 size = "255"; 967 } else if (typeInfo.equalsIgnoreCase("blob")) { 968 size = "65535"; 969 } else if (typeInfo.equalsIgnoreCase("mediumblob")) { 970 size = "16277215"; 971 } else if (typeInfo.equalsIgnoreCase("longblob")) { 972 size = Integer.toString(Integer.MAX_VALUE); 973 } else if (typeInfo.equalsIgnoreCase("tinytext")) { 974 size = "255"; 975 } else if (typeInfo.equalsIgnoreCase("text")) { 976 size = "65535"; 977 } else if (typeInfo.equalsIgnoreCase("mediumtext")) { 978 size = "16277215"; 979 } else if (typeInfo.equalsIgnoreCase("longtext")) { 980 size = Integer.toString(Integer.MAX_VALUE); 981 } else if (typeInfo.equalsIgnoreCase("enum")) { 982 size = "255"; 983 } else if (typeInfo.equalsIgnoreCase("set")) { 984 size = "255"; 985 } 986 987 rowVal[6] = size.getBytes(); 988 rowVal[8] = new byte[] { (byte) '0' }; 989 } 990 } else { 991 rowVal[8] = new byte[] { (byte) '0' }; 992 rowVal[6] = new byte[] { (byte) '0' }; 993 } 994 995 rowVal[7] = Integer.toString(MysqlIO.getMaxBuf()).getBytes(); 996 997 rowVal[9] = new byte[] { (byte) '1', (byte) '0' }; 999 1000 String nullable = results.getString("Null"); 1002 1003 if (nullable != null) { 1005 if (nullable.equals("YES")) { 1006 rowVal[10] = Integer.toString(java.sql.DatabaseMetaData.columnNullable) 1007 .getBytes(); 1008 rowVal[17] = new String ("YES").getBytes(); 1009 1010 } else { 1012 rowVal[10] = Integer.toString(java.sql.DatabaseMetaData.columnNoNulls) 1013 .getBytes(); 1014 rowVal[17] = "NO".getBytes(); 1015 } 1016 } else { 1017 rowVal[10] = Integer.toString(java.sql.DatabaseMetaData.columnNoNulls) 1018 .getBytes(); 1019 rowVal[17] = "NO".getBytes(); 1020 } 1021 1022 try { 1029 rowVal[11] = results.getBytes("Extra"); 1030 } catch (Exception E) { 1031 rowVal[11] = new byte[0]; 1032 } 1033 1034 rowVal[12] = results.getBytes("Default"); 1036 1037 rowVal[13] = new byte[] { (byte) '0' }; rowVal[14] = new byte[] { (byte) '0' }; rowVal[15] = rowVal[6]; rowVal[16] = Integer.toString(ordPos++).getBytes(); 1041 1042 tuples.add(rowVal); 1044 } 1045 } finally { 1046 if (results != null) { 1047 try { 1048 results.close(); 1049 } catch (Exception ex) { 1050 ; 1051 } 1052 1053 results = null; 1054 } 1055 1056 if (stmt != null) { 1057 try { 1058 stmt.close(); 1059 } catch (Exception ex) { 1060 ; 1061 } 1062 1063 stmt = null; 1064 } 1065 } 1066 } 1067 1068 java.sql.ResultSet results = buildResultSet(fields, tuples); 1069 1070 return results; 1071 } 1072 1073 1080 public java.sql.Connection getConnection() throws SQLException { 1081 return (java.sql.Connection ) this.conn; 1082 } 1083 1084 1188 public java.sql.ResultSet getCrossReference(String primaryCatalog, 1189 String primarySchema, String primaryTable, String foreignCatalog, 1190 String foreignSchema, String foreignTable) throws java.sql.SQLException { 1191 if (Driver.TRACE) { 1192 Object [] args = { 1193 primaryCatalog, primarySchema, primaryTable, foreignCatalog, 1194 foreignSchema, foreignTable 1195 }; 1196 Debug.methodCall(this, "getCrossReference", args); 1197 } 1198 1199 if (primaryTable == null) { 1200 throw new java.sql.SQLException ("Table not specified.", SQLError.SQL_STATE_ILLEGAL_ARGUMENT); 1201 } 1202 1203 Field[] fields = new Field[14]; 1204 fields[0] = new Field("", "PKTABLE_CAT", Types.CHAR, 255); 1205 fields[1] = new Field("", "PKTABLE_SCHEM", Types.CHAR, 0); 1206 fields[2] = new Field("", "PKTABLE_NAME", Types.CHAR, 255); 1207 fields[3] = new Field("", "PKCOLUMN_NAME", Types.CHAR, 32); 1208 fields[4] = new Field("", "FKTABLE_CAT", Types.CHAR, 255); 1209 fields[5] = new Field("", "FKTABLE_SCHEM", Types.CHAR, 0); 1210 fields[6] = new Field("", "FKTABLE_NAME", Types.CHAR, 255); 1211 fields[7] = new Field("", "FKCOLUMN_NAME", Types.CHAR, 32); 1212 fields[8] = new Field("", "KEY_SEQ", Types.SMALLINT, 2); 1213 fields[9] = new Field("", "UPDATE_RULE", Types.SMALLINT, 2); 1214 fields[10] = new Field("", "DELETE_RULE", Types.SMALLINT, 2); 1215 fields[11] = new Field("", "FK_NAME", Types.CHAR, 255); 1216 fields[12] = new Field("", "PK_NAME", Types.CHAR, 0); 1217 fields[13] = new Field("", "DEFERRABILITY", Types.INTEGER, 2); 1218 1219 if (this.conn.getIO().versionMeetsMinimum(3, 23, 0)) { 1220 Statement stmt = null; 1221 ResultSet fkresults = null; 1222 1223 try { 1224 1227 if (this.conn.getIO().versionMeetsMinimum(3, 23, 50)) { 1228 String database = this.database; 1230 1231 if (foreignCatalog != null) { 1232 if (!foreignCatalog.equals("")) { 1233 database = foreignCatalog; 1234 } 1235 } 1236 1237 fkresults = extractForeignKeyFromCreateTable(this.conn, 1238 this, database, null); 1239 } else { 1240 String databasePart = ""; 1241 1242 if (foreignCatalog != null) { 1243 if (!foreignCatalog.equals("")) { 1244 databasePart = " FROM " + foreignCatalog; 1245 } 1246 } else { 1247 databasePart = " FROM " + this.database; 1248 } 1249 1250 stmt = this.conn.createStatement(); 1251 1252 if (stmt.getMaxRows() != 0) { 1253 stmt.setMaxRows(0); 1254 } 1255 1256 fkresults = stmt.executeQuery("show table status " 1257 + databasePart); 1258 } 1259 1260 String foreignTableWithCase = getTableNameWithCase(foreignTable); 1261 String primaryTableWithCase = getTableNameWithCase(primaryTable); 1262 1263 1266 ArrayList tuples = new ArrayList (); 1267 String dummy; 1268 1269 while (fkresults.next()) { 1270 String tableType = fkresults.getString("Type"); 1271 1272 if ((tableType != null) 1273 && (tableType.equalsIgnoreCase("innodb") 1274 || tableType.equalsIgnoreCase(SUPPORTS_FK))) { 1275 String comment = fkresults.getString("Comment").trim(); 1276 1277 if (comment != null) { 1278 StringTokenizer commentTokens = new StringTokenizer (comment, 1279 ";", false); 1280 1281 if (commentTokens.hasMoreTokens()) { 1282 dummy = commentTokens.nextToken(); 1283 1284 } 1286 1287 while (commentTokens.hasMoreTokens()) { 1288 String keys = commentTokens.nextToken(); 1289 1290 int firstLeftParenIndex = keys.indexOf('('); 1293 int firstRightParenIndex = keys.indexOf(')'); 1294 1295 String constraintName = keys.substring(0, 1296 firstLeftParenIndex); 1297 1298 String referencingColumns = keys.substring(firstLeftParenIndex 1299 + 1, firstRightParenIndex); 1300 StringTokenizer referencingColumnsTokenizer = new StringTokenizer (referencingColumns, 1301 ", "); 1302 int secondLeftParenIndex = keys.indexOf('(', 1303 firstRightParenIndex + 1); 1304 int secondRightParenIndex = keys.indexOf(')', 1305 firstRightParenIndex + 1); 1306 String referencedColumns = keys.substring(secondLeftParenIndex 1307 + 1, secondRightParenIndex); 1308 StringTokenizer referencedColumnsTokenizer = new StringTokenizer (referencedColumns, 1309 ", "); 1310 int slashIndex = keys.indexOf('/'); 1311 String referencedTable = keys.substring(slashIndex 1312 + 1, secondLeftParenIndex); 1313 int keySeq = 0; 1314 1315 while (referencingColumnsTokenizer 1316 .hasMoreTokens()) { 1317 String referencingColumn = referencingColumnsTokenizer 1318 .nextToken(); 1319 1320 byte[][] tuple = new byte[14][]; 1322 tuple[4] = ((foreignCatalog == null) ? null 1323 : s2b(foreignCatalog)); 1324 tuple[5] = ((foreignSchema == null) ? null 1325 : s2b(foreignSchema)); 1326 dummy = fkresults.getString("Name"); 1328 if (dummy.compareTo(foreignTableWithCase) != 0) { 1329 continue; 1330 } else { 1331 tuple[6] = s2b(dummy); 1332 } 1333 1334 tuple[7] = s2b(referencingColumn); tuple[0] = ((primaryCatalog == null) ? null 1336 : s2b(primaryCatalog)); 1337 tuple[1] = ((primarySchema == null) ? null 1338 : s2b(primarySchema)); 1339 1340 if (referencedTable.compareTo( 1342 primaryTableWithCase) != 0) { 1343 continue; 1344 } 1345 1346 tuple[2] = s2b(referencedTable); tuple[3] = s2b(referencedColumnsTokenizer 1348 .nextToken()); tuple[8] = Integer.toString(keySeq) 1350 .getBytes(); 1352 int[] actions = getForeignKeyActions(keys); 1353 1354 tuple[9] = Integer.toString(actions[1]) 1355 .getBytes(); 1356 tuple[10] = Integer.toString(actions[0]) 1357 .getBytes(); 1358 tuple[11] = s2b(constraintName); tuple[12] = null; tuple[13] = Integer.toString(java.sql.DatabaseMetaData.importedKeyNotDeferrable) 1361 .getBytes(); 1362 tuples.add(tuple); 1363 keySeq++; 1364 } 1365 } 1366 } 1367 } 1368 } 1369 1370 if (Driver.TRACE) { 1371 StringBuffer rows = new StringBuffer (); 1372 rows.append("\n"); 1373 1374 for (int i = 0; i < tuples.size(); i++) { 1375 byte[][] b = (byte[][]) tuples.get(i); 1376 rows.append("[Row] "); 1377 1378 boolean firstTime = true; 1379 1380 for (int j = 0; j < b.length; j++) { 1381 if (!firstTime) { 1382 rows.append(", "); 1383 } else { 1384 firstTime = false; 1385 } 1386 1387 if (b[j] == null) { 1388 rows.append("null"); 1389 } else { 1390 rows.append(new String (b[j])); 1391 } 1392 } 1393 1394 rows.append("\n"); 1395 } 1396 1397 Debug.returnValue(this, "getCrossReference", rows.toString()); 1398 } 1399 1400 return buildResultSet(fields, tuples); 1401 } finally { 1402 if (fkresults != null) { 1403 try { 1404 fkresults.close(); 1405 } catch (Exception sqlEx) { 1406 AssertionFailedException.shouldNotHappen(sqlEx); 1407 } 1408 1409 fkresults = null; 1410 } 1411 1412 if (stmt != null) { 1413 try { 1414 stmt.close(); 1415 } catch (Exception ex) { 1416 ; 1417 } 1418 1419 stmt = null; 1420 } 1421 } 1422 } else { 1423 return buildResultSet(fields, new ArrayList ()); 1424 } 1425 } 1426 1427 1430 public int getDatabaseMajorVersion() throws SQLException { 1431 return this.conn.getServerMajorVersion(); 1432 } 1433 1434 1437 public int getDatabaseMinorVersion() throws SQLException { 1438 return this.conn.getServerMinorVersion(); 1439 } 1440 1441 1448 public String getDatabaseProductName() throws java.sql.SQLException { 1449 return "MySQL"; 1450 } 1451 1452 1459 public String getDatabaseProductVersion() throws java.sql.SQLException { 1460 return this.conn.getServerVersion(); 1461 } 1462 1463 1465 1475 public int getDefaultTransactionIsolation() throws java.sql.SQLException { 1476 if (this.conn.supportsIsolationLevel()) { 1477 return java.sql.Connection.TRANSACTION_READ_COMMITTED; 1478 } else { 1479 return java.sql.Connection.TRANSACTION_NONE; 1480 } 1481 } 1482 1483 1488 public int getDriverMajorVersion() { 1489 return Driver.getMajorVersionInternal(); 1490 } 1491 1492 1497 public int getDriverMinorVersion() { 1498 return Driver.getMinorVersionInternal(); 1499 } 1500 1501 1508 public String getDriverName() throws java.sql.SQLException { 1509 return "MySQL-AB JDBC Driver"; 1510 } 1511 1512 1519 public String getDriverVersion() throws java.sql.SQLException { 1520 return "mysql-connector-java-3.0.11-stable ( $Date: 2004/02/04 02:47:36 $, $Revision: 1.27.2.34 $ )"; 1521 } 1522 1523 1619 public java.sql.ResultSet getExportedKeys(String catalog, String schema, 1620 String table) throws java.sql.SQLException { 1621 if (Driver.TRACE) { 1622 Object [] args = { catalog, schema, table }; 1623 Debug.methodCall(this, "getExportedKeys", args); 1624 } 1625 1626 if (table == null) { 1627 throw new java.sql.SQLException ("Table not specified.", SQLError.SQL_STATE_ILLEGAL_ARGUMENT); 1628 } 1629 1630 Field[] fields = new Field[14]; 1631 fields[0] = new Field("", "PKTABLE_CAT", Types.CHAR, 255); 1632 fields[1] = new Field("", "PKTABLE_SCHEM", Types.CHAR, 0); 1633 fields[2] = new Field("", "PKTABLE_NAME", Types.CHAR, 255); 1634 fields[3] = new Field("", "PKCOLUMN_NAME", Types.CHAR, 32); 1635 fields[4] = new Field("", "FKTABLE_CAT", Types.CHAR, 255); 1636 fields[5] = new Field("", "FKTABLE_SCHEM", Types.CHAR, 0); 1637 fields[6] = new Field("", "FKTABLE_NAME", Types.CHAR, 255); 1638 fields[7] = new Field("", "FKCOLUMN_NAME", Types.CHAR, 32); 1639 fields[8] = new Field("", "KEY_SEQ", Types.SMALLINT, 2); 1640 fields[9] = new Field("", "UPDATE_RULE", Types.SMALLINT, 2); 1641 fields[10] = new Field("", "DELETE_RULE", Types.SMALLINT, 2); 1642 fields[11] = new Field("", "FK_NAME", Types.CHAR, 255); 1643 fields[12] = new Field("", "PK_NAME", Types.CHAR, 0); 1644 fields[13] = new Field("", "DEFERRABILITY", Types.INTEGER, 2); 1645 1646 if (this.conn.getIO().versionMeetsMinimum(3, 23, 0)) { 1647 Statement stmt = null; 1648 ResultSet fkresults = null; 1649 1650 try { 1651 1654 if (this.conn.getIO().versionMeetsMinimum(3, 23, 50)) { 1655 String database = this.database; 1657 1658 if (catalog != null) { 1659 if (!catalog.equals("")) { 1660 database = catalog; 1661 } 1662 } 1663 1664 fkresults = extractForeignKeyFromCreateTable(this.conn, 1665 this, database, null); 1666 } else { 1667 String databasePart = ""; 1668 1669 if (catalog != null) { 1670 if (!catalog.equals("")) { 1671 databasePart = " FROM " + catalog; 1672 } 1673 } else { 1674 databasePart = " FROM " + this.database; 1675 } 1676 1677 stmt = this.conn.createStatement(); 1678 1679 if (stmt.getMaxRows() != 0) { 1680 stmt.setMaxRows(0); 1681 } 1682 1683 fkresults = stmt.executeQuery("show table status " 1684 + databasePart); 1685 } 1686 1687 String tableNameWithCase = getTableNameWithCase(table); 1689 1690 1693 ArrayList tuples = new ArrayList (); 1694 1695 while (fkresults.next()) { 1696 String tableType = fkresults.getString("Type"); 1697 1698 if ((tableType != null) 1699 && (tableType.equalsIgnoreCase("innodb") 1700 || tableType.equalsIgnoreCase(SUPPORTS_FK))) { 1701 String comment = fkresults.getString("Comment").trim(); 1702 1703 if (comment != null) { 1704 StringTokenizer commentTokens = new StringTokenizer (comment, 1705 ";", false); 1706 1707 if (commentTokens.hasMoreTokens()) { 1708 commentTokens.nextToken(); 1710 while (commentTokens.hasMoreTokens()) { 1711 String keys = commentTokens.nextToken(); 1712 getExportKeyResults(catalog, 1713 tableNameWithCase, keys, tuples, 1714 fkresults.getString("Name")); 1715 } 1716 } 1717 } 1718 } 1719 } 1720 1721 if (Driver.TRACE) { 1722 StringBuffer rows = new StringBuffer (); 1723 rows.append("\n"); 1724 1725 for (int i = 0; i < tuples.size(); i++) { 1726 byte[][] b = (byte[][]) tuples.get(i); 1727 rows.append("[Row] "); 1728 1729 boolean firstTime = true; 1730 1731 for (int j = 0; j < b.length; j++) { 1732 if (!firstTime) { 1733 rows.append(", "); 1734 } else { 1735 firstTime = false; 1736 } 1737 1738 if (b[j] == null) { 1739 rows.append("null"); 1740 } else { 1741 rows.append(new String (b[j])); 1742 } 1743 } 1744 1745 rows.append("\n"); 1746 } 1747 1748 Debug.returnValue(this, "getExportedKeys", rows.toString()); 1749 } 1750 1751 return buildResultSet(fields, tuples); 1752 } finally { 1753 if (fkresults != null) { 1754 try { 1755 fkresults.close(); 1756 } catch (SQLException sqlEx) { 1757 AssertionFailedException.shouldNotHappen(sqlEx); 1758 } 1759 1760 fkresults = null; 1761 } 1762 1763 if (stmt != null) { 1764 try { 1765 stmt.close(); 1766 } catch (Exception ex) { 1767 AssertionFailedException.shouldNotHappen(ex); 1768 } 1769 1770 stmt = null; 1771 } 1772 } 1773 } else { 1774 return buildResultSet(fields, new ArrayList ()); 1775 } 1776 } 1777 1778 1786 public String getExtraNameCharacters() throws java.sql.SQLException { 1787 return "#@"; 1788 } 1789 1790 1799 public String getIdentifierQuoteString() throws java.sql.SQLException { 1800 if (this.conn.supportsQuotedIdentifiers()) { 1801 if (!this.conn.useAnsiQuotedIdentifiers()) { 1802 return "`"; 1803 } else { 1804 return "\""; 1805 } 1806 } else { 1807 return " "; 1808 } 1809 } 1810 1811 1908 public java.sql.ResultSet getImportedKeys(String catalog, String schema, 1909 String table) throws java.sql.SQLException { 1910 if (Driver.TRACE) { 1911 Object [] args = { catalog, schema, table }; 1912 Debug.methodCall(this, "getImportedKeys", args); 1913 } 1914 1915 if (table == null) { 1916 throw new java.sql.SQLException ("Table not specified.", SQLError.SQL_STATE_ILLEGAL_ARGUMENT); 1917 } 1918 1919 Field[] fields = new Field[14]; 1920 fields[0] = new Field("", "PKTABLE_CAT", Types.CHAR, 255); 1921 fields[1] = new Field("", "PKTABLE_SCHEM", Types.CHAR, 0); 1922 fields[2] = new Field("", "PKTABLE_NAME", Types.CHAR, 255); 1923 fields[3] = new Field("", "PKCOLUMN_NAME", Types.CHAR, 32); 1924 fields[4] = new Field("", "FKTABLE_CAT", Types.CHAR, 255); 1925 fields[5] = new Field("", "FKTABLE_SCHEM", Types.CHAR, 0); 1926 fields[6] = new Field("", "FKTABLE_NAME", Types.CHAR, 255); 1927 fields[7] = new Field("", "FKCOLUMN_NAME", Types.CHAR, 32); 1928 fields[8] = new Field("", "KEY_SEQ", Types.SMALLINT, 2); 1929 fields[9] = new Field("", "UPDATE_RULE", Types.SMALLINT, 2); 1930 fields[10] = new Field("", "DELETE_RULE", Types.SMALLINT, 2); 1931 fields[11] = new Field("", "FK_NAME", Types.CHAR, 255); 1932 fields[12] = new Field("", "PK_NAME", Types.CHAR, 0); 1933 fields[13] = new Field("", "DEFERRABILITY", Types.INTEGER, 2); 1934 1935 if (this.conn.getIO().versionMeetsMinimum(3, 23, 0)) { 1936 Statement stmt = null; 1937 ResultSet fkresults = null; 1938 1939 try { 1940 1943 if (this.conn.getIO().versionMeetsMinimum(3, 23, 50)) { 1944 String database = this.database; 1946 1947 if (catalog != null) { 1948 if (!catalog.equals("")) { 1949 database = catalog; 1950 } 1951 } 1952 1953 fkresults = extractForeignKeyFromCreateTable(this.conn, 1954 this, database, table); 1955 } else { 1956 String databasePart = ""; 1957 1958 if (catalog != null) { 1959 if (!catalog.equals("")) { 1960 databasePart = " FROM " + catalog; 1961 } 1962 } else { 1963 databasePart = " FROM " + this.database; 1964 } 1965 1966 stmt = this.conn.createStatement(); 1967 1968 if (stmt.getMaxRows() != 0) { 1969 stmt.setMaxRows(0); 1970 } 1971 1972 fkresults = stmt.executeQuery("show table status " 1973 + databasePart + " like '" + table + "'"); 1974 } 1975 1976 1979 ArrayList tuples = new ArrayList (); 1980 1981 while (fkresults.next()) { 1982 String tableType = fkresults.getString("Type"); 1983 1984 if ((tableType != null) 1985 && (tableType.equalsIgnoreCase("innodb") 1986 || tableType.equalsIgnoreCase(SUPPORTS_FK))) { 1987 String comment = fkresults.getString("Comment").trim(); 1988 1989 if (comment != null) { 1990 StringTokenizer commentTokens = new StringTokenizer (comment, 1991 ";", false); 1992 1993 if (commentTokens.hasMoreTokens()) { 1994 commentTokens.nextToken(); 1996 while (commentTokens.hasMoreTokens()) { 1997 String keys = commentTokens.nextToken(); 1998 getImportKeyResults(catalog, table, keys, 1999 tuples); 2000 } 2001 } 2002 } 2003 } 2004 } 2005 2006 if (Driver.TRACE) { 2007 StringBuffer rows = new StringBuffer (); 2008 rows.append("\n"); 2009 2010 for (int i = 0; i < tuples.size(); i++) { 2011 byte[][] b = (byte[][]) tuples.get(i); 2012 rows.append("[Row] "); 2013 2014 boolean firstTime = true; 2015 2016 for (int j = 0; j < b.length; j++) { 2017 if (!firstTime) { 2018 rows.append(", "); 2019 } else { 2020 firstTime = false; 2021 } 2022 2023 if (b[j] == null) { 2024 rows.append("null"); 2025 } else { 2026 rows.append(new String (b[j])); 2027 } 2028 } 2029 2030 rows.append("\n"); 2031 } 2032 2033 Debug.returnValue(this, "getImportedKeys", rows.toString()); 2034 } 2035 2036 return buildResultSet(fields, tuples); 2037 } finally { 2038 if (fkresults != null) { 2039 try { 2040 fkresults.close(); 2041 } catch (SQLException sqlEx) { 2042 AssertionFailedException.shouldNotHappen(sqlEx); 2043 } 2044 2045 fkresults = null; 2046 } 2047 2048 if (stmt != null) { 2049 try { 2050 stmt.close(); 2051 } catch (Exception ex) { 2052 AssertionFailedException.shouldNotHappen(ex); 2053 } 2054 2055 stmt = null; 2056 } 2057 } 2058 } else { 2059 return buildResultSet(fields, new ArrayList ()); 2060 } 2061 } 2062 2063 2155 public java.sql.ResultSet getIndexInfo(String catalog, String schema, 2156 String table, boolean unique, boolean approximate) 2157 throws java.sql.SQLException { 2158 2170 String databasePart = ""; 2171 2172 if (catalog != null) { 2173 if (!catalog.equals("")) { 2174 databasePart = " FROM " + this.quotedId + catalog 2175 + this.quotedId; 2176 } 2177 } else { 2178 databasePart = " FROM " + this.quotedId + this.database 2179 + this.quotedId; 2180 } 2181 2182 Statement stmt = null; 2183 ResultSet results = null; 2184 2185 try { 2186 stmt = this.conn.createStatement(); 2187 2188 if (stmt.getMaxRows() != 0) { 2189 stmt.setMaxRows(0); 2190 } 2191 2192 StringBuffer queryBuf = new StringBuffer ("SHOW INDEX FROM "); 2193 queryBuf.append(this.quotedId); 2194 queryBuf.append(table); 2195 queryBuf.append(this.quotedId); 2196 queryBuf.append(databasePart); 2197 2198 results = stmt.executeQuery(queryBuf.toString()); 2199 2200 Field[] fields = new Field[13]; 2201 fields[0] = new Field("", "TABLE_CAT", Types.CHAR, 255); 2202 fields[1] = new Field("", "TABLE_SCHEM", Types.CHAR, 0); 2203 fields[2] = new Field("", "TABLE_NAME", Types.CHAR, 255); 2204 fields[3] = new Field("", "NON_UNIQUE", Types.CHAR, 3); 2205 fields[4] = new Field("", "INDEX_QUALIFIER", Types.CHAR, 1); 2206 fields[5] = new Field("", "INDEX_NAME", Types.CHAR, 32); 2207 fields[6] = new Field("", "TYPE", Types.CHAR, 32); 2208 fields[7] = new Field("", "ORDINAL_POSITION", Types.SMALLINT, 5); 2209 fields[8] = new Field("", "COLUMN_NAME", Types.CHAR, 32); 2210 fields[9] = new Field("", "ASC_OR_DESC", Types.CHAR, 1); 2211 fields[10] = new Field("", "CARDINALITY", Types.INTEGER, 10); 2212 fields[11] = new Field("", "PAGES", Types.INTEGER, 10); 2213 fields[12] = new Field("", "FILTER_CONDITION", Types.CHAR, 32); 2214 2215 byte[] connectionCatalogAsBytes; 2216 2217 if (catalog == null) { 2218 connectionCatalogAsBytes = s2b(this.conn.getCatalog()); 2219 } else { 2220 connectionCatalogAsBytes = s2b(catalog); 2221 } 2222 2223 ArrayList rows = new ArrayList (); 2224 2225 while (results.next()) { 2226 byte[][] row = new byte[14][]; 2227 row[0] = connectionCatalogAsBytes; 2228 row[1] = null; 2229 row[2] = results.getBytes("Table"); 2230 row[3] = ((results.getInt("Non_unique") != 0) ? s2b("true") 2231 : s2b("false")); 2232 row[4] = new byte[0]; 2233 row[5] = results.getBytes("Key_name"); 2234 row[6] = Integer.toString(java.sql.DatabaseMetaData.tableIndexOther) 2235 .getBytes(); 2236 row[7] = results.getBytes("Seq_in_index"); 2237 row[8] = results.getBytes("Column_name"); 2238 row[9] = results.getBytes("Collation"); 2239 row[10] = results.getBytes("Cardinality"); 2240 row[11] = s2b("0"); 2241 row[12] = null; 2242 rows.add(row); 2243 } 2244 2245 java.sql.ResultSet indexInfo = buildResultSet(fields, rows); 2246 2247 return indexInfo; 2248 } finally { 2249 if (results != null) { 2250 try { 2251 results.close(); 2252 } catch (Exception ex) { 2253 ; 2254 } 2255 2256 results = null; 2257 } 2258 2259 if (stmt != null) { 2260 try { 2261 stmt.close(); 2262 } catch (Exception ex) { 2263 ; 2264 } 2265 2266 stmt = null; 2267 } 2268 } 2269 } 2270 2271 2274 public int getJDBCMajorVersion() throws SQLException { 2275 return 3; 2276 } 2277 2278 2281 public int getJDBCMinorVersion() throws SQLException { 2282 return 0; 2283 } 2284 2285 2291 2298 public int getMaxBinaryLiteralLength() throws java.sql.SQLException { 2299 return 16777208; 2300 } 2301 2302 2309 public int getMaxCatalogNameLength() throws java.sql.SQLException { 2310 return 32; 2311 } 2312 2313 2320 public int getMaxCharLiteralLength() throws java.sql.SQLException { 2321 return 16777208; 2322 } 2323 2324 2331 public int getMaxColumnNameLength() throws java.sql.SQLException { 2332 return 64; 2333 } 2334 2335 2342 public int getMaxColumnsInGroupBy() throws java.sql.SQLException { 2343 return 64; 2344 } 2345 2346 2353 public int getMaxColumnsInIndex() throws java.sql.SQLException { 2354 return 16; 2355 } 2356 2357 2364 public int getMaxColumnsInOrderBy() throws java.sql.SQLException { 2365 return 64; 2366 } 2367 2368 2375 public int getMaxColumnsInSelect() throws java.sql.SQLException { 2376 return 256; 2377 } 2378 2379 2386 public int getMaxColumnsInTable() throws java.sql.SQLException { 2387 return 512; 2388 } 2389 2390 2397 public int getMaxConnections() throws java.sql.SQLException { 2398 return 0; 2399 } 2400 2401 2408 public int getMaxCursorNameLength() throws java.sql.SQLException { 2409 return 64; 2410 } 2411 2412 2419 public int getMaxIndexLength() throws java.sql.SQLException { 2420 return 256; 2421 } 2422 2423 2430 public int getMaxProcedureNameLength() throws java.sql.SQLException { 2431 return 0; 2432 } 2433 2434 2441 public int getMaxRowSize() throws java.sql.SQLException { 2442 return Integer.MAX_VALUE - 8; } 2444 2445 2452 public int getMaxSchemaNameLength() throws java.sql.SQLException { 2453 return 0; 2454 } 2455 2456 2463 public int getMaxStatementLength() throws java.sql.SQLException { 2464 return MysqlIO.getMaxBuf() - 4; } 2466 2467 2475 public int getMaxStatements() throws java.sql.SQLException { 2476 return 0; 2477 } 2478 2479 2486 public int getMaxTableNameLength() throws java.sql.SQLException { 2487 return 64; 2488 } 2489 2490 2497 public int getMaxTablesInSelect() throws java.sql.SQLException { 2498 return 256; 2499 } 2500 2501 2508 public int getMaxUserNameLength() throws java.sql.SQLException { 2509 return 16; 2510 } 2511 2512 2519 public String getNumericFunctions() throws java.sql.SQLException { 2520 return "ABS,ACOS,ASIN,ATAN,ATAN2,BIT_COUNT,CEILING,COS," 2521 + "COT,DEGREES,EXP,FLOOR,LOG,LOG10,MAX,MIN,MOD,PI,POW," 2522 + "POWER,RADIANS,RAND,ROUND,SIN,SQRT,TAN,TRUNCATE"; 2523 } 2524 2525 2562 public java.sql.ResultSet getPrimaryKeys(String catalog, String schema, 2563 String table) throws java.sql.SQLException { 2564 Field[] fields = new Field[6]; 2565 fields[0] = new Field("", "TABLE_CAT", Types.CHAR, 255); 2566 fields[1] = new Field("", "TABLE_SCHEM", Types.CHAR, 0); 2567 fields[2] = new Field("", "TABLE_NAME", Types.CHAR, 255); 2568 fields[3] = new Field("", "COLUMN_NAME", Types.CHAR, 32); 2569 fields[4] = new Field("", "KEY_SEQ", Types.SMALLINT, 5); 2570 fields[5] = new Field("", "PK_NAME", Types.CHAR, 32); 2571 2572 String dbSub = ""; 2573 2574 if (catalog != null) { 2575 if (!catalog.equals("")) { 2576 dbSub = " FROM " + this.quotedId + catalog + this.quotedId; 2577 } 2578 } else { 2579 dbSub = " FROM " + this.quotedId + this.database + this.quotedId; 2580 } 2581 2582 if (table == null) { 2583 throw new java.sql.SQLException ("Table not specified.", SQLError.SQL_STATE_ILLEGAL_ARGUMENT); 2584 } 2585 2586 Statement stmt = null; 2587 ResultSet rs = null; 2588 2589 try { 2590 stmt = this.conn.createStatement(); 2591 2592 if (stmt.getMaxRows() != 0) { 2593 stmt.setMaxRows(0); 2594 } 2595 2596 StringBuffer queryBuf = new StringBuffer ("SHOW KEYS FROM "); 2597 queryBuf.append(this.quotedId); 2598 queryBuf.append(table); 2599 queryBuf.append(this.quotedId); 2600 queryBuf.append(dbSub); 2601 2602 rs = stmt.executeQuery(queryBuf.toString()); 2603 2604 byte[] connectionCatalogAsBytes; 2605 2606 if (catalog == null) { 2607 connectionCatalogAsBytes = s2b(this.conn.getCatalog()); 2608 } else { 2609 connectionCatalogAsBytes = s2b(catalog); 2610 } 2611 2612 ArrayList tuples = new ArrayList (); 2613 TreeMap sortMap = new TreeMap (); 2614 2615 while (rs.next()) { 2616 String keyType = rs.getString("Key_name"); 2617 2618 if (keyType != null) { 2619 if (keyType.equalsIgnoreCase("PRIMARY") 2620 || keyType.equalsIgnoreCase("PRI")) { 2621 byte[][] tuple = new byte[6][]; 2622 tuple[0] = connectionCatalogAsBytes; 2623 tuple[1] = null; 2624 tuple[2] = s2b(table); 2625 2626 String columnName = rs.getString("Column_name"); 2627 tuple[3] = s2b(columnName); 2628 tuple[4] = s2b(rs.getString("Seq_in_index")); 2629 tuple[5] = s2b(keyType); 2630 sortMap.put(columnName, tuple); 2631 } 2632 } 2633 } 2634 2635 Iterator sortedIterator = sortMap.values().iterator(); 2637 2638 while (sortedIterator.hasNext()) { 2639 tuples.add(sortedIterator.next()); 2640 } 2641 2642 return buildResultSet(fields, tuples); 2643 } finally { 2644 if (rs != null) { 2645 try { 2646 rs.close(); 2647 } catch (Exception ex) { 2648 ; 2649 } 2650 2651 rs = null; 2652 } 2653 2654 if (stmt != null) { 2655 try { 2656 stmt.close(); 2657 } catch (Exception ex) { 2658 ; 2659 } 2660 2661 stmt = null; 2662 } 2663 } 2664 } 2665 2666 2779 public java.sql.ResultSet getProcedureColumns(String catalog, 2780 String schemaPattern, String procedureNamePattern, 2781 String columnNamePattern) throws java.sql.SQLException { 2782 Field[] fields = new Field[14]; 2783 fields[0] = new Field("", "TABLE_CAT", Types.CHAR, 0); 2784 fields[1] = new Field("", "PROCEDURE_CAT", Types.CHAR, 0); 2785 fields[2] = new Field("", "PROCEDURE_SCHEM", Types.CHAR, 0); 2786 fields[3] = new Field("", "PROCEDURE_NAME", Types.CHAR, 0); 2787 fields[4] = new Field("", "COLUMN_NAME", Types.CHAR, 0); 2788 fields[5] = new Field("", "COLUMN_TYPE", Types.CHAR, 0); 2789 fields[6] = new Field("", "DATA_TYPE", Types.SMALLINT, 0); 2790 fields[7] = new Field("", "TYPE_NAME", Types.CHAR, 0); 2791 fields[8] = new Field("", "PRECISION", Types.INTEGER, 0); 2792 fields[9] = new Field("", "LENGTH", Types.INTEGER, 0); 2793 fields[10] = new Field("", "SCALE", Types.SMALLINT, 0); 2794 fields[11] = new Field("", "RADIX", Types.SMALLINT, 0); 2795 fields[12] = new Field("", "NULLABLE", Types.SMALLINT, 0); 2796 fields[13] = new Field("", "REMARKS", Types.CHAR, 0); 2797 2798 return buildResultSet(fields, new ArrayList ()); 2799 } 2800 2801 2808 public String getProcedureTerm() throws java.sql.SQLException { 2809 return ""; 2810 } 2811 2812 2876 public java.sql.ResultSet getProcedures(String catalog, 2877 String schemaPattern, String procedureNamePattern) 2878 throws java.sql.SQLException { 2879 Field[] fields = new Field[8]; 2880 fields[0] = new Field("", "PROCEDURE_CAT", Types.CHAR, 0); 2881 fields[1] = new Field("", "PROCEDURE_SCHEM", Types.CHAR, 0); 2882 fields[2] = new Field("", "PROCEDURE_NAME", Types.CHAR, 0); 2883 fields[3] = new Field("", "resTABLE_CAT", Types.CHAR, 0); 2884 fields[4] = new Field("", "resTABLE_CAT", Types.CHAR, 0); 2885 fields[5] = new Field("", "resTABLE_CAT", Types.CHAR, 0); 2886 fields[6] = new Field("", "REMARKS", Types.CHAR, 0); 2887 fields[7] = new Field("", "PROCEDURE_TYPE", Types.SMALLINT, 0); 2888 2889 return buildResultSet(fields, new ArrayList ()); 2890 } 2891 2892 2899 public boolean isReadOnly() throws java.sql.SQLException { 2900 return false; 2901 } 2902 2903 2906 public int getResultSetHoldability() throws SQLException { 2907 return ResultSet.CLOSE_CURSORS_AT_COMMIT; 2908 } 2909 2910 2918 public String getSQLKeywords() throws java.sql.SQLException { 2919 return "AUTO_INCREMENT,BINARY,BLOB,ENUM,INFILE,LOAD,MEDIUMINT,OPTION,OUTFILE,REPLACE,SET,TEXT,UNSIGNED,ZEROFILL"; 2920 } 2921 2922 2925 public int getSQLStateType() throws SQLException { 2926 return 0; 2927 } 2928 2929 2936 public String getSchemaTerm() throws java.sql.SQLException { 2937 return ""; 2938 } 2939 2940 2959 public java.sql.ResultSet getSchemas() throws java.sql.SQLException { 2960 Field[] fields = new Field[1]; 2961 fields[0] = new Field("", "TABLE_SCHEM", java.sql.Types.CHAR, 0); 2962 2963 ArrayList tuples = new ArrayList (); 2964 java.sql.ResultSet results = buildResultSet(fields, tuples); 2965 2966 return results; 2967 } 2968 2969 2985 public String getSearchStringEscape() throws java.sql.SQLException { 2986 return "\\"; 2987 } 2988 2989 2996 public String getStringFunctions() throws java.sql.SQLException { 2997 return "ASCII,BIN,BIT_LENGTH,CHAR,CHARACTER_LENGTH,CHAR_LENGTH,CONCAT," 2998 + "CONCAT_WS,CONV,ELT,EXPORT_SET,FIELD,FIND_IN_SET,HEX,INSERT," 2999 + "INSTR,LCASE,LEFT,LENGTH,LOAD_FILE,LOCATE,LOCATE,LOWER,LPAD," 3000 + "LTRIM,MAKE_SET,MATCH,MID,OCT,OCTET_LENGTH,ORD,POSITION," 3001 + "QUOTE,REPEAT,REPLACE,REVERSE,RIGHT,RPAD,RTRIM,SOUNDEX," 3002 + "SPACE,STRCMP,SUBSTRING,SUBSTRING,SUBSTRING,SUBSTRING," 3003 + "SUBSTRING_INDEX,TRIM,UCASE,UPPER"; 3004 } 3005 3006 3009 public java.sql.ResultSet getSuperTables(String arg0, String arg1, 3010 String arg2) throws SQLException { 3011 Field[] fields = new Field[4]; 3012 fields[0] = new Field("", "TABLE_CAT", Types.CHAR, 32); 3013 fields[1] = new Field("", "TABLE_SCHEM", Types.CHAR, 32); 3014 fields[2] = new Field("", "TABLE_NAME", Types.CHAR, 32); 3015 fields[3] = new Field("", "SUPERTABLE_NAME", Types.CHAR, 32); 3016 3017 return buildResultSet(fields, new ArrayList ()); 3018 } 3019 3020 3023 public java.sql.ResultSet getSuperTypes(String arg0, String arg1, 3024 String arg2) throws SQLException { 3025 Field[] fields = new Field[6]; 3026 fields[0] = new Field("", "TABLE_CAT", Types.CHAR, 32); 3027 fields[1] = new Field("", "TABLE_SCHEM", Types.CHAR, 32); 3028 fields[2] = new Field("", "TYPE_NAME", Types.CHAR, 32); 3029 fields[3] = new Field("", "SUPERTYPE_CAT", Types.CHAR, 32); 3030 fields[4] = new Field("", "SUPERTYPE_SCHEM", Types.CHAR, 32); 3031 fields[5] = new Field("", "SUPERTYPE_NAME", Types.CHAR, 32); 3032 3033 return buildResultSet(fields, new ArrayList ()); 3034 } 3035 3036 3043 public String getSystemFunctions() throws java.sql.SQLException { 3044 return "DATABASE,USER,SYSTEM_USER,SESSION_USER,PASSWORD,ENCRYPT,LAST_INSERT_ID,VERSION"; 3045 } 3046 3047 3100 public java.sql.ResultSet getTablePrivileges(String catalog, 3101 String schemaPattern, String tableNamePattern) 3102 throws java.sql.SQLException { 3103 Field[] fields = new Field[7]; 3104 fields[0] = new Field("", "TABLE_CAT", Types.CHAR, 64); 3105 fields[1] = new Field("", "TABLE_SCHEM", Types.CHAR, 1); 3106 fields[2] = new Field("", "TABLE_NAME", Types.CHAR, 64); 3107 fields[3] = new Field("", "GRANTOR", Types.CHAR, 77); 3108 fields[4] = new Field("", "GRANTEE", Types.CHAR, 77); 3109 fields[5] = new Field("", "PRIVILEGE", Types.CHAR, 64); 3110 fields[6] = new Field("", "IS_GRANTABLE", Types.CHAR, 3); 3111 3112 StringBuffer grantQuery = new StringBuffer ( 3113 "SELECT host,db,table_name,grantor,user,table_priv from mysql.tables_priv "); 3114 grantQuery.append(" WHERE "); 3115 3116 if ((catalog != null) && (catalog.length() != 0)) { 3117 grantQuery.append(" db='"); 3118 grantQuery.append(catalog); 3119 grantQuery.append("' AND "); 3120 } 3121 3122 grantQuery.append("table_name like '"); 3123 grantQuery.append(tableNamePattern); 3124 grantQuery.append("'"); 3125 3126 ResultSet results = null; 3127 ArrayList grantRows = new ArrayList (); 3128 Statement stmt = null; 3129 3130 try { 3131 stmt = this.conn.createStatement(); 3132 3133 if (stmt.getMaxRows() != 0) { 3134 stmt.setMaxRows(0); 3135 } 3136 3137 results = stmt.executeQuery(grantQuery.toString()); 3138 3139 while (results.next()) { 3140 String host = results.getString(1); 3141 String database = results.getString(2); 3142 String table = results.getString(3); 3143 String grantor = results.getString(4); 3144 String user = results.getString(5); 3145 3146 if ((user == null) || (user.length() == 0)) { 3147 user = "%"; 3148 } 3149 3150 StringBuffer fullUser = new StringBuffer (user); 3151 3152 if ((host != null) && this.conn.useHostsInPrivileges()) { 3153 fullUser.append("@"); 3154 fullUser.append(host); 3155 } 3156 3157 String allPrivileges = results.getString(6); 3158 3159 if (allPrivileges != null) { 3160 allPrivileges = allPrivileges.toUpperCase(); 3161 3162 StringTokenizer st = new StringTokenizer (allPrivileges, ","); 3163 3164 while (st.hasMoreTokens()) { 3165 String privilege = st.nextToken().trim(); 3166 3167 java.sql.ResultSet columnResults = null; 3169 3170 try { 3171 columnResults = getColumns(catalog, schemaPattern, 3172 table, "%"); 3173 3174 while (columnResults.next()) { 3175 byte[][] tuple = new byte[8][]; 3176 tuple[0] = s2b(database); 3177 tuple[1] = null; 3178 tuple[2] = s2b(table); 3179 3180 if (grantor != null) { 3181 tuple[3] = s2b(grantor); 3182 } else { 3183 tuple[3] = null; 3184 } 3185 3186 tuple[4] = s2b(fullUser.toString()); 3187 tuple[5] = s2b(privilege); 3188 tuple[6] = null; 3189 grantRows.add(tuple); 3190 } 3191 } finally { 3192 if (columnResults != null) { 3193 try { 3194 columnResults.close(); 3195 } catch (Exception ex) { 3196 ; 3197 } 3198 } 3199 } 3200 } 3201 } 3202 } 3203 } finally { 3204 if (results != null) { 3205 try { 3206 results.close(); 3207 } catch (Exception ex) { 3208 ; 3209 } 3210 3211 results = null; 3212 } 3213 3214 if (stmt != null) { 3215 try { 3216 stmt.close(); 3217 } catch (Exception ex) { 3218 ; 3219 } 3220 3221 stmt = null; 3222 } 3223 } 3224 3225 return buildResultSet(fields, grantRows); 3226 } 3227 3228 3249 public java.sql.ResultSet getTableTypes() throws java.sql.SQLException { 3250 ArrayList tuples = new ArrayList (); 3251 Field[] fields = new Field[1]; 3252 fields[0] = new Field("", "TABLE_TYPE", Types.VARCHAR, 5); 3253 3254 byte[][] tableTypeRow = new byte[1][]; 3255 tableTypeRow[0] = TABLE_AS_BYTES; 3256 tuples.add(tableTypeRow); 3257 3258 byte[][] tempTypeRow = new byte[1][]; 3259 tempTypeRow[0] = s2b("LOCAL TEMPORARY"); 3260 tuples.add(tempTypeRow); 3261 3262 return buildResultSet(fields, tuples); 3263 } 3264 3265 3314 public java.sql.ResultSet getTables(String catalog, String schemaPattern, 3315 String tableNamePattern, String [] types) throws java.sql.SQLException { 3316 String databasePart = ""; 3317 3318 if (catalog != null) { 3319 if (!catalog.equals("")) { 3320 databasePart = " FROM " + this.quotedId + catalog 3321 + this.quotedId; 3322 } 3323 } else { 3324 databasePart = " FROM " + this.quotedId + this.database 3325 + this.quotedId; 3326 } 3327 3328 if (tableNamePattern == null) { 3329 tableNamePattern = "%"; 3330 } 3331 3332 Statement stmt = null; 3333 ResultSet results = null; 3334 3335 try { 3336 stmt = this.conn.createStatement(); 3337 3338 if (stmt.getMaxRows() != 0) { 3339 stmt.setMaxRows(0); 3340 } 3341 3342 results = stmt.executeQuery("SHOW TABLES " + databasePart 3343 + " LIKE '" + tableNamePattern + "'"); 3344 3345 Field[] fields = new Field[5]; 3346 fields[0] = new Field("", "TABLE_CAT", java.sql.Types.VARCHAR, 3347 (catalog == null) ? 0 : catalog.length()); 3348 fields[1] = new Field("", "TABLE_SCHEM", java.sql.Types.VARCHAR, 0); 3349 fields[2] = new Field("", "TABLE_NAME", java.sql.Types.VARCHAR, 255); 3350 fields[3] = new Field("", "TABLE_TYPE", java.sql.Types.VARCHAR, 5); 3351 fields[4] = new Field("", "REMARKS", java.sql.Types.VARCHAR, 0); 3352 3353 ArrayList tuples = new ArrayList (); 3354 byte[][] row = null; 3355 3356 byte[] connectionCatalogAsBytes = null; 3357 3358 if (catalog == null) { 3359 connectionCatalogAsBytes = s2b(this.conn.getCatalog()); 3360 } else { 3361 connectionCatalogAsBytes = s2b(catalog); 3362 } 3363 3364 while (results.next()) { 3365 row = new byte[5][]; 3366 row[0] = connectionCatalogAsBytes; 3367 row[1] = null; 3368 row[2] = results.getBytes(1); 3369 row[3] = TABLE_AS_BYTES; 3370 row[4] = new byte[0]; 3371 tuples.add(row); 3372 } 3373 3374 java.sql.ResultSet tables = buildResultSet(fields, tuples); 3375 3376 return tables; 3377 } finally { 3378 if (results != null) { 3379 try { 3380 results.close(); 3381 } catch (Exception ex) { 3382 ; 3383 } 3384 3385 results = null; 3386 } 3387 3388 if (stmt != null) { 3389 try { 3390 stmt.close(); 3391 } catch (Exception ex) { 3392 ; 3393 } 3394 3395 stmt = null; 3396 } 3397 } 3398 } 3399 3400 3407 public String getTimeDateFunctions() throws java.sql.SQLException { 3408 return "DAYOFWEEK,WEEKDAY,DAYOFMONTH,DAYOFYEAR,MONTH,DAYNAME," 3409 + "MONTHNAME,QUARTER,WEEK,YEAR,HOUR,MINUTE,SECOND,PERIOD_ADD," 3410 + "PERIOD_DIFF,TO_DAYS,FROM_DAYS,DATE_FORMAT,TIME_FORMAT," 3411 + "CURDATE,CURRENT_DATE,CURTIME,CURRENT_TIME,NOW,SYSDATE," 3412 + "CURRENT_TIMESTAMP,UNIX_TIMESTAMP,FROM_UNIXTIME," 3413 + "SEC_TO_TIME,TIME_TO_SEC"; 3414 } 3415 3416 3520 3624 public java.sql.ResultSet getTypeInfo() throws java.sql.SQLException { 3625 Field[] fields = new Field[18]; 3626 fields[0] = new Field("", "TYPE_NAME", Types.CHAR, 32); 3627 fields[1] = new Field("", "DATA_TYPE", Types.SMALLINT, 5); 3628 fields[2] = new Field("", "PRECISION", Types.INTEGER, 10); 3629 fields[3] = new Field("", "LITERAL_PREFIX", Types.CHAR, 4); 3630 fields[4] = new Field("", "LITERAL_SUFFIX", Types.CHAR, 4); 3631 fields[5] = new Field("", "CREATE_PARAMS", Types.CHAR, 32); 3632 fields[6] = new Field("", "NULLABLE", Types.SMALLINT, 5); 3633 fields[7] = new Field("", "CASE_SENSITIVE", Types.CHAR, 3); 3634 fields[8] = new Field("", "SEARCHABLE", Types.SMALLINT, 3); 3635 fields[9] = new Field("", "UNSIGNED_ATTRIBUTE", Types.CHAR, 3); 3636 fields[10] = new Field("", "FIXED_PREC_SCALE", Types.CHAR, 3); 3637 fields[11] = new Field("", "AUTO_INCREMENT", Types.CHAR, 3); 3638 fields[12] = new Field("", "LOCAL_TYPE_NAME", Types.CHAR, 32); 3639 fields[13] = new Field("", "MINIMUM_SCALE", Types.SMALLINT, 5); 3640 fields[14] = new Field("", "MAXIMUM_SCALE", Types.SMALLINT, 5); 3641 fields[15] = new Field("", "SQL_DATA_TYPE", Types.INTEGER, 10); 3642 fields[16] = new Field("", "SQL_DATETIME_SUB", Types.INTEGER, 10); 3643 fields[17] = new Field("", "NUM_PREC_RADIX", Types.INTEGER, 10); 3644 3645 byte[][] rowVal = null; 3646 ArrayList tuples = new ArrayList (); 3647 3648 3653 3657 rowVal = new byte[18][]; 3658 rowVal[0] = s2b("BIT"); 3659 rowVal[1] = Integer.toString(java.sql.Types.BIT).getBytes(); 3660 3661 rowVal[2] = s2b("1"); rowVal[3] = s2b(""); rowVal[4] = s2b(""); rowVal[5] = s2b(""); rowVal[6] = Integer.toString(java.sql.DatabaseMetaData.typeNullable) 3667 .getBytes(); 3668 3669 rowVal[7] = s2b("true"); rowVal[8] = Integer.toString(java.sql.DatabaseMetaData.typeSearchable) 3672 .getBytes(); 3673 3674 rowVal[9] = s2b("false"); rowVal[10] = s2b("false"); rowVal[11] = s2b("false"); rowVal[12] = s2b("BIT"); rowVal[13] = s2b("0"); rowVal[14] = s2b("0"); rowVal[15] = s2b("0"); rowVal[16] = s2b("0"); rowVal[17] = s2b("10"); tuples.add(rowVal); 3685 3686 3690 rowVal = new byte[18][]; 3691 rowVal[0] = s2b("BOOL"); 3692 rowVal[1] = Integer.toString(java.sql.Types.BIT).getBytes(); 3693 3694 rowVal[2] = s2b("1"); rowVal[3] = s2b(""); rowVal[4] = s2b(""); rowVal[5] = s2b(""); rowVal[6] = Integer.toString(java.sql.DatabaseMetaData.typeNullable) 3700 .getBytes(); 3701 3702 rowVal[7] = s2b("true"); rowVal[8] = Integer.toString(java.sql.DatabaseMetaData.typeSearchable) 3705 .getBytes(); 3706 3707 rowVal[9] = s2b("false"); rowVal[10] = s2b("false"); rowVal[11] = s2b("false"); rowVal[12] = s2b("BOOL"); rowVal[13] = s2b("0"); rowVal[14] = s2b("0"); rowVal[15] = s2b("0"); rowVal[16] = s2b("0"); rowVal[17] = s2b("10"); tuples.add(rowVal); 3718 3719 3723 rowVal = new byte[18][]; 3724 rowVal[0] = s2b("TINYINT"); 3725 rowVal[1] = Integer.toString(java.sql.Types.TINYINT).getBytes(); 3726 3727 rowVal[2] = s2b("3"); rowVal[3] = s2b(""); rowVal[4] = s2b(""); rowVal[5] = s2b("[(M)] [UNSIGNED] [ZEROFILL]"); rowVal[6] = Integer.toString(java.sql.DatabaseMetaData.typeNullable) 3733 .getBytes(); 3734 3735 rowVal[7] = s2b("false"); rowVal[8] = Integer.toString(java.sql.DatabaseMetaData.typeSearchable) 3738 .getBytes(); 3739 3740 rowVal[9] = s2b("true"); rowVal[10] = s2b("false"); rowVal[11] = s2b("true"); rowVal[12] = s2b("TINYINT"); rowVal[13] = s2b("0"); rowVal[14] = s2b("0"); rowVal[15] = s2b("0"); rowVal[16] = s2b("0"); rowVal[17] = s2b("10"); tuples.add(rowVal); 3751 3752 3756 rowVal = new byte[18][]; 3757 rowVal[0] = s2b("BIGINT"); 3758 rowVal[1] = Integer.toString(java.sql.Types.BIGINT).getBytes(); 3759 3760 rowVal[2] = s2b("19"); rowVal[3] = s2b(""); rowVal[4] = s2b(""); rowVal[5] = s2b("[(M)] [UNSIGNED] [ZEROFILL]"); rowVal[6] = Integer.toString(java.sql.DatabaseMetaData.typeNullable) 3766 .getBytes(); 3767 3768 rowVal[7] = s2b("false"); rowVal[8] = Integer.toString(java.sql.DatabaseMetaData.typeSearchable) 3771 .getBytes(); 3772 3773 rowVal[9] = s2b("true"); rowVal[10] = s2b("false"); rowVal[11] = s2b("true"); rowVal[12] = s2b("BIGINT"); rowVal[13] = s2b("0"); rowVal[14] = s2b("0"); rowVal[15] = s2b("0"); rowVal[16] = s2b("0"); rowVal[17] = s2b("10"); tuples.add(rowVal); 3784 3785 3789 rowVal = new byte[18][]; 3790 rowVal[0] = s2b("LONG VARBINARY"); 3791 rowVal[1] = Integer.toString(java.sql.Types.LONGVARBINARY).getBytes(); 3792 3793 rowVal[2] = s2b("16777215"); rowVal[3] = s2b("'"); rowVal[4] = s2b("'"); rowVal[5] = s2b(""); rowVal[6] = Integer.toString(java.sql.DatabaseMetaData.typeNullable) 3799 .getBytes(); 3800 3801 rowVal[7] = s2b("true"); rowVal[8] = Integer.toString(java.sql.DatabaseMetaData.typeSearchable) 3804 .getBytes(); 3805 3806 rowVal[9] = s2b("false"); rowVal[10] = s2b("false"); rowVal[11] = s2b("false"); rowVal[12] = s2b("LONG VARBINARY"); rowVal[13] = s2b("0"); rowVal[14] = s2b("0"); rowVal[15] = s2b("0"); rowVal[16] = s2b("0"); rowVal[17] = s2b("10"); tuples.add(rowVal); 3817 3818 3822 rowVal = new byte[18][]; 3823 rowVal[0] = s2b("MEDIUMBLOB"); 3824 rowVal[1] = Integer.toString(java.sql.Types.LONGVARBINARY).getBytes(); 3825 3826 rowVal[2] = s2b("16777215"); rowVal[3] = s2b("'"); rowVal[4] = s2b("'"); rowVal[5] = s2b(""); rowVal[6] = Integer.toString(java.sql.DatabaseMetaData.typeNullable) 3832 .getBytes(); 3833 3834 rowVal[7] = s2b("true"); rowVal[8] = Integer.toString(java.sql.DatabaseMetaData.typeSearchable) 3837 .getBytes(); 3838 3839 rowVal[9] = s2b("false"); rowVal[10] = s2b("false"); rowVal[11] = s2b("false"); rowVal[12] = s2b("MEDIUMBLOB"); rowVal[13] = s2b("0"); rowVal[14] = s2b("0"); rowVal[15] = s2b("0"); rowVal[16] = s2b("0"); rowVal[17] = s2b("10"); tuples.add(rowVal); 3850 3851 3855 rowVal = new byte[18][]; 3856 rowVal[0] = s2b("LONGBLOB"); 3857 rowVal[1] = Integer.toString(java.sql.Types.LONGVARBINARY).getBytes(); 3858 3859 rowVal[2] = Integer.toString(Integer.MAX_VALUE).getBytes(); 3861 3862 rowVal[3] = s2b("'"); rowVal[4] = s2b("'"); rowVal[5] = s2b(""); rowVal[6] = Integer.toString(java.sql.DatabaseMetaData.typeNullable) 3867 .getBytes(); 3868 3869 rowVal[7] = s2b("true"); rowVal[8] = Integer.toString(java.sql.DatabaseMetaData.typeSearchable) 3872 .getBytes(); 3873 3874 rowVal[9] = s2b("false"); rowVal[10] = s2b("false"); rowVal[11] = s2b("false"); rowVal[12] = s2b("LONGBLOB"); rowVal[13] = s2b("0"); rowVal[14] = s2b("0"); rowVal[15] = s2b("0"); rowVal[16] = s2b("0"); rowVal[17] = s2b("10"); tuples.add(rowVal); 3885 3886 3890 rowVal = new byte[18][]; 3891 rowVal[0] = s2b("BLOB"); 3892 rowVal[1] = Integer.toString(java.sql.Types.LONGVARBINARY).getBytes(); 3893 3894 rowVal[2] = s2b("65535"); rowVal[3] = s2b("'"); rowVal[4] = s2b("'"); rowVal[5] = s2b(""); rowVal[6] = Integer.toString(java.sql.DatabaseMetaData.typeNullable) 3900 .getBytes(); 3901 3902 rowVal[7] = s2b("true"); rowVal[8] = Integer.toString(java.sql.DatabaseMetaData.typeSearchable) 3905 .getBytes(); 3906 3907 rowVal[9] = s2b("false"); rowVal[10] = s2b("false"); rowVal[11] = s2b("false"); rowVal[12] = s2b("BLOB"); rowVal[13] = s2b("0"); rowVal[14] = s2b("0"); rowVal[15] = s2b("0"); rowVal[16] = s2b("0"); rowVal[17] = s2b("10"); tuples.add(rowVal); 3918 3919 3923 rowVal = new byte[18][]; 3924 rowVal[0] = s2b("TINYBLOB"); 3925 rowVal[1] = Integer.toString(java.sql.Types.LONGVARBINARY).getBytes(); 3926 3927 rowVal[2] = s2b("255"); rowVal[3] = s2b("'"); rowVal[4] = s2b("'"); rowVal[5] = s2b(""); rowVal[6] = Integer.toString(java.sql.DatabaseMetaData.typeNullable) 3933 .getBytes(); 3934 3935 rowVal[7] = s2b("true"); rowVal[8] = Integer.toString(java.sql.DatabaseMetaData.typeSearchable) 3938 .getBytes(); 3939 3940 rowVal[9] = s2b("false"); rowVal[10] = s2b("false"); rowVal[11] = s2b("false"); rowVal[12] = s2b("TINYBLOB"); rowVal[13] = s2b("0"); rowVal[14] = s2b("0"); rowVal[15] = s2b("0"); rowVal[16] = s2b("0"); rowVal[17] = s2b("10"); tuples.add(rowVal); 3951 3952 3956 rowVal = new byte[18][]; 3957 rowVal[0] = s2b("VARBINARY"); 3958 rowVal[1] = Integer.toString(java.sql.Types.VARBINARY).getBytes(); 3959 3960 rowVal[2] = s2b("255"); rowVal[3] = s2b("'"); rowVal[4] = s2b("'"); rowVal[5] = s2b("(M)"); rowVal[6] = Integer.toString(java.sql.DatabaseMetaData.typeNullable) 3966 .getBytes(); 3967 3968 rowVal[7] = s2b("true"); rowVal[8] = Integer.toString(java.sql.DatabaseMetaData.typeSearchable) 3971 .getBytes(); 3972 3973 rowVal[9] = s2b("false"); rowVal[10] = s2b("false"); rowVal[11] = s2b("false"); rowVal[12] = s2b("VARBINARY"); rowVal[13] = s2b("0"); rowVal[14] = s2b("0"); rowVal[15] = s2b("0"); rowVal[16] = s2b("0"); rowVal[17] = s2b("10"); tuples.add(rowVal); 3984 3985 3989 rowVal = new byte[18][]; 3990 rowVal[0] = s2b("BINARY"); 3991 rowVal[1] = Integer.toString(java.sql.Types.BINARY).getBytes(); 3992 3993 rowVal[2] = s2b("255"); rowVal[3] = s2b("'"); rowVal[4] = s2b("'"); rowVal[5] = s2b("(M)"); rowVal[6] = Integer.toString(java.sql.DatabaseMetaData.typeNullable) 3999 .getBytes(); 4000 4001 rowVal[7] = s2b("true"); rowVal[8] = Integer.toString(java.sql.DatabaseMetaData.typeSearchable) 4004 .getBytes(); 4005 4006 rowVal[9] = s2b("false"); rowVal[10] = s2b("false"); rowVal[11] = s2b("false"); rowVal[12] = s2b("BINARY"); rowVal[13] = s2b("0"); rowVal[14] = s2b("0"); rowVal[15] = s2b("0"); rowVal[16] = s2b("0"); rowVal[17] = s2b("10"); tuples.add(rowVal); 4017 4018 4022 rowVal = new byte[18][]; 4023 rowVal[0] = s2b("LONG VARCHAR"); 4024 rowVal[1] = Integer.toString(java.sql.Types.LONGVARCHAR).getBytes(); 4025 4026 rowVal[2] = s2b("16777215"); rowVal[3] = s2b("'"); rowVal[4] = s2b("'"); rowVal[5] = s2b(""); rowVal[6] = Integer.toString(java.sql.DatabaseMetaData.typeNullable) 4032 .getBytes(); 4033 4034 rowVal[7] = s2b("false"); rowVal[8] = Integer.toString(java.sql.DatabaseMetaData.typeSearchable) 4037 .getBytes(); 4038 4039 rowVal[9] = s2b("false"); rowVal[10] = s2b("false"); rowVal[11] = s2b("false"); rowVal[12] = s2b("LONG VARCHAR"); rowVal[13] = s2b("0"); rowVal[14] = s2b("0"); rowVal[15] = s2b("0"); rowVal[16] = s2b("0"); rowVal[17] = s2b("10"); tuples.add(rowVal); 4050 4051 4055 rowVal = new byte[18][]; 4056 rowVal[0] = s2b("MEDIUMTEXT"); 4057 rowVal[1] = Integer.toString(java.sql.Types.LONGVARCHAR).getBytes(); 4058 4059 rowVal[2] = s2b("16777215"); rowVal[3] = s2b("'"); rowVal[4] = s2b("'"); rowVal[5] = s2b(""); rowVal[6] = Integer.toString(java.sql.DatabaseMetaData.typeNullable) 4065 .getBytes(); 4066 4067 rowVal[7] = s2b("false"); rowVal[8] = Integer.toString(java.sql.DatabaseMetaData.typeSearchable) 4070 .getBytes(); 4071 4072 rowVal[9] = s2b("false"); rowVal[10] = s2b("false"); rowVal[11] = s2b("false"); rowVal[12] = s2b("MEDIUMTEXT"); rowVal[13] = s2b("0"); rowVal[14] = s2b("0"); rowVal[15] = s2b("0"); rowVal[16] = s2b("0"); rowVal[17] = s2b("10"); tuples.add(rowVal); 4083 4084 4088 rowVal = new byte[18][]; 4089 rowVal[0] = s2b("LONGTEXT"); 4090 rowVal[1] = Integer.toString(java.sql.Types.LONGVARCHAR).getBytes(); 4091 4092 rowVal[2] = Integer.toString(Integer.MAX_VALUE).getBytes(); 4094 4095 rowVal[3] = s2b("'"); rowVal[4] = s2b("'"); rowVal[5] = s2b(""); rowVal[6] = Integer.toString(java.sql.DatabaseMetaData.typeNullable) 4100 .getBytes(); 4101 4102 rowVal[7] = s2b("false"); rowVal[8] = Integer.toString(java.sql.DatabaseMetaData.typeSearchable) 4105 .getBytes(); 4106 4107 rowVal[9] = s2b("false"); rowVal[10] = s2b("false"); rowVal[11] = s2b("false"); rowVal[12] = s2b("LONGTEXT"); rowVal[13] = s2b("0"); rowVal[14] = s2b("0"); rowVal[15] = s2b("0"); rowVal[16] = s2b("0"); rowVal[17] = s2b("10"); tuples.add(rowVal); 4118 4119 4123 rowVal = new byte[18][]; 4124 rowVal[0] = s2b("TEXT"); 4125 rowVal[1] = Integer.toString(java.sql.Types.LONGVARCHAR).getBytes(); 4126 4127 rowVal[2] = s2b("65535"); rowVal[3] = s2b("'"); rowVal[4] = s2b("'"); rowVal[5] = s2b(""); rowVal[6] = Integer.toString(java.sql.DatabaseMetaData.typeNullable) 4133 .getBytes(); 4134 4135 rowVal[7] = s2b("false"); rowVal[8] = Integer.toString(java.sql.DatabaseMetaData.typeSearchable) 4138 .getBytes(); 4139 4140 rowVal[9] = s2b("false"); rowVal[10] = s2b("false"); rowVal[11] = s2b("false"); rowVal[12] = s2b("TEXT"); rowVal[13] = s2b("0"); rowVal[14] = s2b("0"); rowVal[15] = s2b("0"); rowVal[16] = s2b("0"); rowVal[17] = s2b("10"); tuples.add(rowVal); 4151 4152 4156 rowVal = new byte[18][]; 4157 rowVal[0] = s2b("TINYTEXT"); 4158 rowVal[1] = Integer.toString(java.sql.Types.LONGVARCHAR).getBytes(); 4159 4160 rowVal[2] = s2b("255"); rowVal[3] = s2b("'"); rowVal[4] = s2b("'"); rowVal[5] = s2b(""); rowVal[6] = Integer.toString(java.sql.DatabaseMetaData.typeNullable) 4166 .getBytes(); 4167 4168 rowVal[7] = s2b("false"); rowVal[8] = Integer.toString(java.sql.DatabaseMetaData.typeSearchable) 4171 .getBytes(); 4172 4173 rowVal[9] = s2b("false"); rowVal[10] = s2b("false"); rowVal[11] = s2b("false"); rowVal[12] = s2b("TINYTEXT"); rowVal[13] = s2b("0"); rowVal[14] = s2b("0"); rowVal[15] = s2b("0"); rowVal[16] = s2b("0"); rowVal[17] = s2b("10"); tuples.add(rowVal); 4184 4185 4189 rowVal = new byte[18][]; 4190 rowVal[0] = s2b("CHAR"); 4191 rowVal[1] = Integer.toString(java.sql.Types.CHAR).getBytes(); 4192 4193 rowVal[2] = s2b("255"); rowVal[3] = s2b("'"); rowVal[4] = s2b("'"); rowVal[5] = s2b("(M)"); rowVal[6] = Integer.toString(java.sql.DatabaseMetaData.typeNullable) 4199 .getBytes(); 4200 4201 rowVal[7] = s2b("false"); rowVal[8] = Integer.toString(java.sql.DatabaseMetaData.typeSearchable) 4204 .getBytes(); 4205 4206 rowVal[9] = s2b("false"); rowVal[10] = s2b("false"); rowVal[11] = s2b("false"); rowVal[12] = s2b("CHAR"); rowVal[13] = s2b("0"); rowVal[14] = s2b("0"); rowVal[15] = s2b("0"); rowVal[16] = s2b("0"); rowVal[17] = s2b("10"); tuples.add(rowVal); 4217 4218 4222 rowVal = new byte[18][]; 4223 rowVal[0] = s2b("NUMERIC"); 4224 rowVal[1] = Integer.toString(java.sql.Types.NUMERIC).getBytes(); 4225 4226 rowVal[2] = s2b("17"); rowVal[3] = s2b(""); rowVal[4] = s2b(""); rowVal[5] = s2b("[(M[,D])] [ZEROFILL]"); rowVal[6] = Integer.toString(java.sql.DatabaseMetaData.typeNullable) 4232 .getBytes(); 4233 4234 rowVal[7] = s2b("false"); rowVal[8] = Integer.toString(java.sql.DatabaseMetaData.typeSearchable) 4237 .getBytes(); 4238 4239 rowVal[9] = s2b("false"); rowVal[10] = s2b("false"); rowVal[11] = s2b("true"); rowVal[12] = s2b("NUMERIC"); rowVal[13] = s2b("308"); rowVal[14] = s2b("308"); rowVal[15] = s2b("0"); rowVal[16] = s2b("0"); rowVal[17] = s2b("10"); tuples.add(rowVal); 4250 4251 4255 rowVal = new byte[18][]; 4256 rowVal[0] = s2b("DECIMAL"); 4257 rowVal[1] = Integer.toString(java.sql.Types.DECIMAL).getBytes(); 4258 4259 rowVal[2] = s2b("17"); rowVal[3] = s2b(""); rowVal[4] = s2b(""); rowVal[5] = s2b("[(M[,D])] [ZEROFILL]"); rowVal[6] = Integer.toString(java.sql.DatabaseMetaData.typeNullable) 4265 .getBytes(); 4266 4267 rowVal[7] = s2b("false"); rowVal[8] = Integer.toString(java.sql.DatabaseMetaData.typeSearchable) 4270 .getBytes(); 4271 4272 rowVal[9] = s2b("false"); rowVal[10] = s2b("false"); rowVal[11] = s2b("true"); rowVal[12] = s2b("DECIMAL"); rowVal[13] = s2b("-308"); rowVal[14] = s2b("308"); rowVal[15] = s2b("0"); rowVal[16] = s2b("0"); rowVal[17] = s2b("10"); tuples.add(rowVal); 4283 4284 4288 rowVal = new byte[18][]; 4289 rowVal[0] = s2b("INTEGER"); 4290 rowVal[1] = Integer.toString(java.sql.Types.INTEGER).getBytes(); 4291 4292 rowVal[2] = s2b("10"); rowVal[3] = s2b(""); rowVal[4] = s2b(""); rowVal[5] = s2b("[(M)] [UNSIGNED] [ZEROFILL]"); rowVal[6] = Integer.toString(java.sql.DatabaseMetaData.typeNullable) 4298 .getBytes(); 4299 4300 rowVal[7] = s2b("false"); rowVal[8] = Integer.toString(java.sql.DatabaseMetaData.typeSearchable) 4303 .getBytes(); 4304 4305 rowVal[9] = s2b("true"); rowVal[10] = s2b("false"); rowVal[11] = s2b("true"); rowVal[12] = s2b("INTEGER"); rowVal[13] = s2b("0"); rowVal[14] = s2b("0"); rowVal[15] = s2b("0"); rowVal[16] = s2b("0"); rowVal[17] = s2b("10"); tuples.add(rowVal); 4316 4317 4321 rowVal = new byte[18][]; 4322 rowVal[0] = s2b("INT"); 4323 rowVal[1] = Integer.toString(java.sql.Types.INTEGER).getBytes(); 4324 4325 rowVal[2] = s2b("10"); rowVal[3] = s2b(""); rowVal[4] = s2b(""); rowVal[5] = s2b("[(M)] [UNSIGNED] [ZEROFILL]"); rowVal[6] = Integer.toString(java.sql.DatabaseMetaData.typeNullable) 4331 .getBytes(); 4332 4333 rowVal[7] = s2b("false"); rowVal[8] = Integer.toString(java.sql.DatabaseMetaData.typeSearchable) 4336 .getBytes(); 4337 4338 rowVal[9] = s2b("true"); rowVal[10] = s2b("false"); rowVal[11] = s2b("true"); rowVal[12] = s2b("INT"); rowVal[13] = s2b("0"); rowVal[14] = s2b("0"); rowVal[15] = s2b("0"); rowVal[16] = s2b("0"); rowVal[17] = s2b("10"); tuples.add(rowVal); 4349 4350 4354 rowVal = new byte[18][]; 4355 rowVal[0] = s2b("MEDIUMINT"); 4356 rowVal[1] = Integer.toString(java.sql.Types.INTEGER).getBytes(); 4357 4358 rowVal[2] = s2b("7"); rowVal[3] = s2b(""); rowVal[4] = s2b(""); rowVal[5] = s2b("[(M)] [UNSIGNED] [ZEROFILL]"); rowVal[6] = Integer.toString(java.sql.DatabaseMetaData.typeNullable) 4364 .getBytes(); 4365 4366 rowVal[7] = s2b("false"); rowVal[8] = Integer.toString(java.sql.DatabaseMetaData.typeSearchable) 4369 .getBytes(); 4370 4371 rowVal[9] = s2b("true"); rowVal[10] = s2b("false"); rowVal[11] = s2b("true"); rowVal[12] = s2b("MEDIUMINT"); rowVal[13] = s2b("0"); rowVal[14] = s2b("0"); rowVal[15] = s2b("0"); rowVal[16] = s2b("0"); rowVal[17] = s2b("10"); tuples.add(rowVal); 4382 4383 4387 rowVal = new byte[18][]; 4388 rowVal[0] = s2b("SMALLINT"); 4389 rowVal[1] = Integer.toString(java.sql.Types.SMALLINT).getBytes(); 4390 4391 rowVal[2] = s2b("5"); rowVal[3] = s2b(""); rowVal[4] = s2b(""); rowVal[5] = s2b("[(M)] [UNSIGNED] [ZEROFILL]"); rowVal[6] = Integer.toString(java.sql.DatabaseMetaData.typeNullable) 4397 .getBytes(); 4398 4399 rowVal[7] = s2b("false"); rowVal[8] = Integer.toString(java.sql.DatabaseMetaData.typeSearchable) 4402 .getBytes(); 4403 4404 rowVal[9] = s2b("true"); rowVal[10] = s2b("false"); rowVal[11] = s2b("true"); rowVal[12] = s2b("SMALLINT"); rowVal[13] = s2b("0"); rowVal[14] = s2b("0"); rowVal[15] = s2b("0"); rowVal[16] = s2b("0"); rowVal[17] = s2b("10"); tuples.add(rowVal); 4415 4416 4420 rowVal = new byte[18][]; 4421 rowVal[0] = s2b("DOUBLE"); 4422 rowVal[1] = Integer.toString(java.sql.Types.FLOAT).getBytes(); 4423 4424 rowVal[2] = s2b("17"); rowVal[3] = s2b(""); rowVal[4] = s2b(""); rowVal[5] = s2b("[(M,D)] [ZEROFILL]"); rowVal[6] = Integer.toString(java.sql.DatabaseMetaData.typeNullable) 4430 .getBytes(); 4431 4432 rowVal[7] = s2b("false"); rowVal[8] = Integer.toString(java.sql.DatabaseMetaData.typeSearchable) 4435 .getBytes(); 4436 4437 rowVal[9] = s2b("false"); rowVal[10] = s2b("false"); rowVal[11] = s2b("true"); rowVal[12] = s2b("DOUBLE"); rowVal[13] = s2b("-308"); rowVal[14] = s2b("308"); rowVal[15] = s2b("0"); rowVal[16] = s2b("0"); rowVal[17] = s2b("10"); tuples.add(rowVal); 4448 4449 4453 rowVal = new byte[18][]; 4454 rowVal[0] = s2b("FLOAT"); 4455 rowVal[1] = Integer.toString(java.sql.Types.REAL).getBytes(); 4456 4457 rowVal[2] = s2b("10"); rowVal[3] = s2b(""); rowVal[4] = s2b(""); rowVal[5] = s2b("[(M,D)] [ZEROFILL]"); rowVal[6] = Integer.toString(java.sql.DatabaseMetaData.typeNullable) 4463 .getBytes(); 4464 4465 rowVal[7] = s2b("false"); rowVal[8] = Integer.toString(java.sql.DatabaseMetaData.typeSearchable) 4468 .getBytes(); 4469 4470 rowVal[9] = s2b("false"); rowVal[10] = s2b("false"); rowVal[11] = s2b("true"); rowVal[12] = s2b("FLOAT"); rowVal[13] = s2b("-38"); rowVal[14] = s2b("38"); rowVal[15] = s2b("0"); rowVal[16] = s2b("0"); rowVal[17] = s2b("10"); tuples.add(rowVal); 4481 4482 4486 rowVal = new byte[18][]; 4487 rowVal[0] = s2b("DOUBLE"); 4488 rowVal[1] = Integer.toString(java.sql.Types.DOUBLE).getBytes(); 4489 4490 rowVal[2] = s2b("17"); rowVal[3] = s2b(""); rowVal[4] = s2b(""); rowVal[5] = s2b("[(M,D)] [ZEROFILL]"); rowVal[6] = Integer.toString(java.sql.DatabaseMetaData.typeNullable) 4496 .getBytes(); 4497 4498 rowVal[7] = s2b("false"); rowVal[8] = Integer.toString(java.sql.DatabaseMetaData.typeSearchable) 4501 .getBytes(); 4502 4503 rowVal[9] = s2b("false"); rowVal[10] = s2b("false"); rowVal[11] = s2b("true"); rowVal[12] = s2b("DOUBLE"); rowVal[13] = s2b("-308"); rowVal[14] = s2b("308"); rowVal[15] = s2b("0"); rowVal[16] = s2b("0"); rowVal[17] = s2b("10"); tuples.add(rowVal); 4514 4515 4519 rowVal = new byte[18][]; 4520 rowVal[0] = s2b("DOUBLE PRECISION"); 4521 rowVal[1] = Integer.toString(java.sql.Types.DOUBLE).getBytes(); 4522 4523 rowVal[2] = s2b("17"); rowVal[3] = s2b(""); rowVal[4] = s2b(""); rowVal[5] = s2b("[(M,D)] [ZEROFILL]"); rowVal[6] = Integer.toString(java.sql.DatabaseMetaData.typeNullable) 4529 .getBytes(); 4530 4531 rowVal[7] = s2b("false"); rowVal[8] = Integer.toString(java.sql.DatabaseMetaData.typeSearchable) 4534 .getBytes(); 4535 4536 rowVal[9] = s2b("false"); rowVal[10] = s2b("false"); rowVal[11] = s2b("true"); rowVal[12] = s2b("DOUBLE PRECISION"); rowVal[13] = s2b("-308"); rowVal[14] = s2b("308"); rowVal[15] = s2b("0"); rowVal[16] = s2b("0"); rowVal[17] = s2b("10"); tuples.add(rowVal); 4547 4548 4552 rowVal = new byte[18][]; 4553 rowVal[0] = s2b("REAL"); 4554 rowVal[1] = Integer.toString(java.sql.Types.DOUBLE).getBytes(); 4555 4556 rowVal[2] = s2b("17"); rowVal[3] = s2b(""); rowVal[4] = s2b(""); rowVal[5] = s2b("[(M,D)] [ZEROFILL]"); rowVal[6] = Integer.toString(java.sql.DatabaseMetaData.typeNullable) 4562 .getBytes(); 4563 4564 rowVal[7] = s2b("false"); rowVal[8] = Integer.toString(java.sql.DatabaseMetaData.typeSearchable) 4567 .getBytes(); 4568 4569 rowVal[9] = s2b("false"); rowVal[10] = s2b("false"); rowVal[11] = s2b("true"); rowVal[12] = s2b("REAL"); rowVal[13] = s2b("-308"); rowVal[14] = s2b("308"); rowVal[15] = s2b("0"); rowVal[16] = s2b("0"); rowVal[17] = s2b("10"); tuples.add(rowVal); 4580 4581 4585 rowVal = new byte[18][]; 4586 rowVal[0] = s2b("VARCHAR"); 4587 rowVal[1] = Integer.toString(java.sql.Types.VARCHAR).getBytes(); 4588 4589 rowVal[2] = s2b("255"); rowVal[3] = s2b("'"); rowVal[4] = s2b("'"); rowVal[5] = s2b("(M)"); rowVal[6] = Integer.toString(java.sql.DatabaseMetaData.typeNullable) 4595 .getBytes(); 4596 4597 rowVal[7] = s2b("false"); rowVal[8] = Integer.toString(java.sql.DatabaseMetaData.typeSearchable) 4600 .getBytes(); 4601 4602 rowVal[9] = s2b("false"); rowVal[10] = s2b("false"); rowVal[11] = s2b("false"); rowVal[12] = s2b("VARCHAR"); rowVal[13] = s2b("0"); rowVal[14] = s2b("0"); rowVal[15] = s2b("0"); rowVal[16] = s2b("0"); rowVal[17] = s2b("10"); tuples.add(rowVal); 4613 4614 4618 rowVal = new byte[18][]; 4619 rowVal[0] = s2b("ENUM"); 4620 rowVal[1] = Integer.toString(java.sql.Types.VARCHAR).getBytes(); 4621 4622 rowVal[2] = s2b("65535"); rowVal[3] = s2b("'"); rowVal[4] = s2b("'"); rowVal[5] = s2b(""); rowVal[6] = Integer.toString(java.sql.DatabaseMetaData.typeNullable) 4628 .getBytes(); 4629 4630 rowVal[7] = s2b("false"); rowVal[8] = Integer.toString(java.sql.DatabaseMetaData.typeSearchable) 4633 .getBytes(); 4634 4635 rowVal[9] = s2b("false"); rowVal[10] = s2b("false"); rowVal[11] = s2b("false"); rowVal[12] = s2b("ENUM"); rowVal[13] = s2b("0"); rowVal[14] = s2b("0"); rowVal[15] = s2b("0"); rowVal[16] = s2b("0"); rowVal[17] = s2b("10"); tuples.add(rowVal); 4646 4647 4651 rowVal = new byte[18][]; 4652 rowVal[0] = s2b("SET"); 4653 rowVal[1] = Integer.toString(java.sql.Types.VARCHAR).getBytes(); 4654 4655 rowVal[2] = s2b("64"); rowVal[3] = s2b("'"); rowVal[4] = s2b("'"); rowVal[5] = s2b(""); rowVal[6] = Integer.toString(java.sql.DatabaseMetaData.typeNullable) 4661 .getBytes(); 4662 4663 rowVal[7] = s2b("false"); rowVal[8] = Integer.toString(java.sql.DatabaseMetaData.typeSearchable) 4666 .getBytes(); 4667 4668 rowVal[9] = s2b("false"); rowVal[10] = s2b("false"); rowVal[11] = s2b("false"); rowVal[12] = s2b("SET"); rowVal[13] = s2b("0"); rowVal[14] = s2b("0"); rowVal[15] = s2b("0"); rowVal[16] = s2b("0"); rowVal[17] = s2b("10"); tuples.add(rowVal); 4679 4680 4684 rowVal = new byte[18][]; 4685 rowVal[0] = s2b("DATE"); 4686 rowVal[1] = Integer.toString(java.sql.Types.DATE).getBytes(); 4687 4688 rowVal[2] = s2b("0"); rowVal[3] = s2b("'"); rowVal[4] = s2b("'"); rowVal[5] = s2b(""); rowVal[6] = Integer.toString(java.sql.DatabaseMetaData.typeNullable) 4694 .getBytes(); 4695 4696 rowVal[7] = s2b("false"); rowVal[8] = Integer.toString(java.sql.DatabaseMetaData.typeSearchable) 4699 .getBytes(); 4700 4701 rowVal[9] = s2b("false"); rowVal[10] = s2b("false"); rowVal[11] = s2b("false"); rowVal[12] = s2b("DATE"); rowVal[13] = s2b("0"); rowVal[14] = s2b("0"); rowVal[15] = s2b("0"); rowVal[16] = s2b("0"); rowVal[17] = s2b("10"); tuples.add(rowVal); 4712 4713 4717 rowVal = new byte[18][]; 4718 rowVal[0] = s2b("TIME"); 4719 rowVal[1] = Integer.toString(java.sql.Types.TIME).getBytes(); 4720 4721 rowVal[2] = s2b("0"); rowVal[3] = s2b("'"); rowVal[4] = s2b("'"); rowVal[5] = s2b(""); rowVal[6] = Integer.toString(java.sql.DatabaseMetaData.typeNullable) 4727 .getBytes(); 4728 4729 rowVal[7] = s2b("false"); rowVal[8] = Integer.toString(java.sql.DatabaseMetaData.typeSearchable) 4732 .getBytes(); 4733 4734 rowVal[9] = s2b("false"); rowVal[10] = s2b("false"); rowVal[11] = s2b("false"); rowVal[12] = s2b("TIME"); rowVal[13] = s2b("0"); rowVal[14] = s2b("0"); rowVal[15] = s2b("0"); rowVal[16] = s2b("0"); rowVal[17] = s2b("10"); tuples.add(rowVal); 4745 4746 4750 rowVal = new byte[18][]; 4751 rowVal[0] = s2b("DATETIME"); 4752 rowVal[1] = Integer.toString(java.sql.Types.TIMESTAMP).getBytes(); 4753 4754 rowVal[2] = s2b("0"); rowVal[3] = s2b("'"); rowVal[4] = s2b("'"); rowVal[5] = s2b(""); rowVal[6] = Integer.toString(java.sql.DatabaseMetaData.typeNullable) 4760 .getBytes(); 4761 4762 rowVal[7] = s2b("false"); rowVal[8] = Integer.toString(java.sql.DatabaseMetaData.typeSearchable) 4765 .getBytes(); 4766 4767 rowVal[9] = s2b("false"); rowVal[10] = s2b("false"); rowVal[11] = s2b("false"); rowVal[12] = s2b("DATETIME"); rowVal[13] = s2b("0"); rowVal[14] = s2b("0"); rowVal[15] = s2b("0"); rowVal[16] = s2b("0"); rowVal[17] = s2b("10"); tuples.add(rowVal); 4778 4779 4783 rowVal = new byte[18][]; 4784 rowVal[0] = s2b("TIMESTAMP"); 4785 rowVal[1] = Integer.toString(java.sql.Types.TIMESTAMP).getBytes(); 4786 4787 rowVal[2] = s2b("0"); rowVal[3] = s2b("'"); rowVal[4] = s2b("'"); rowVal[5] = s2b("[(M)]"); rowVal[6] = Integer.toString(java.sql.DatabaseMetaData.typeNullable) 4793 .getBytes(); 4794 4795 rowVal[7] = s2b("false"); rowVal[8] = Integer.toString(java.sql.DatabaseMetaData.typeSearchable) 4798 .getBytes(); 4799 4800 rowVal[9] = s2b("false"); rowVal[10] = s2b("false"); rowVal[11] = s2b("false"); rowVal[12] = s2b("TIMESTAMP"); rowVal[13] = s2b("0"); rowVal[14] = s2b("0"); rowVal[15] = s2b("0"); rowVal[16] = s2b("0"); rowVal[17] = s2b("10"); tuples.add(rowVal); 4811 4812 return buildResultSet(fields, tuples); 4813 } 4814 4815 4871 public java.sql.ResultSet getUDTs(String catalog, String schemaPattern, 4872 String typeNamePattern, int[] types) throws SQLException { 4873 Field[] fields = new Field[6]; 4874 fields[0] = new Field("", "TYPE_CAT", Types.VARCHAR, 32); 4875 fields[1] = new Field("", "TYPE_SCHEM", Types.VARCHAR, 32); 4876 fields[2] = new Field("", "TYPE_NAME", Types.VARCHAR, 32); 4877 fields[3] = new Field("", "CLASS_NAME", Types.VARCHAR, 32); 4878 fields[4] = new Field("", "DATA_TYPE", Types.VARCHAR, 32); 4879 fields[5] = new Field("", "REMARKS", Types.VARCHAR, 32); 4880 4881 ArrayList tuples = new ArrayList (); 4882 4883 return buildResultSet(fields, tuples); 4884 } 4885 4886 4893 public String getURL() throws java.sql.SQLException { 4894 return this.conn.getURL(); 4895 } 4896 4897 4904 public String getUserName() throws java.sql.SQLException { 4905 if (this.conn.useHostsInPrivileges()) { 4906 Statement stmt = null; 4907 ResultSet rs = null; 4908 4909 try { 4910 stmt = this.conn.createStatement(); 4911 4912 if (stmt.getMaxRows() != 0) { 4913 stmt.setMaxRows(0); 4914 } 4915 4916 rs = stmt.executeQuery("SELECT USER()"); 4917 rs.next(); 4918 4919 return rs.getString(1); 4920 } finally { 4921 if (rs != null) { 4922 try { 4923 rs.close(); 4924 } catch (Exception ex) { 4925 AssertionFailedException.shouldNotHappen(ex); 4926 } 4927 4928 rs = null; 4929 } 4930 4931 if (stmt != null) { 4932 try { 4933 stmt.close(); 4934 } catch (Exception ex) { 4935 AssertionFailedException.shouldNotHappen(ex); 4936 } 4937 4938 stmt = null; 4939 } 4940 } 4941 } else { 4942 return this.conn.getUser(); 4943 } 4944 } 4945 4946 5003 public java.sql.ResultSet getVersionColumns(String catalog, String schema, 5004 String table) throws java.sql.SQLException { 5005 Field[] fields = new Field[8]; 5006 fields[0] = new Field("", "SCOPE", Types.SMALLINT, 5); 5007 fields[1] = new Field("", "COLUMN_NAME", Types.CHAR, 32); 5008 fields[2] = new Field("", "DATA_TYPE", Types.SMALLINT, 5); 5009 fields[3] = new Field("", "TYPE_NAME", Types.CHAR, 16); 5010 fields[4] = new Field("", "COLUMN_SIZE", Types.CHAR, 16); 5011 fields[5] = new Field("", "BUFFER_LENGTH", Types.CHAR, 16); 5012 fields[6] = new Field("", "DECIMAL_DIGITS", Types.CHAR, 16); 5013 fields[7] = new Field("", "PSEUDO_COLUMN", Types.SMALLINT, 5); 5014 5015 return buildResultSet(fields, new ArrayList ()); 5016 5017 } 5019 5020 5028 public boolean allProceduresAreCallable() throws java.sql.SQLException { 5029 return false; 5030 } 5031 5032 5039 public boolean allTablesAreSelectable() throws java.sql.SQLException { 5040 return false; 5041 } 5042 5043 5051 public boolean dataDefinitionCausesTransactionCommit() 5052 throws java.sql.SQLException { 5053 return true; 5054 } 5055 5056 5063 public boolean dataDefinitionIgnoredInTransactions() 5064 throws java.sql.SQLException { 5065 return false; 5066 } 5067 5068 5079 public boolean deletesAreDetected(int type) throws SQLException { 5080 return false; 5081 } 5082 5083 5090 public boolean doesMaxRowSizeIncludeBlobs() throws java.sql.SQLException { 5091 return true; 5092 } 5093 5094 5105 public List extractForeignKeyForTable(ArrayList rows, 5106 java.sql.ResultSet rs, String catalog) throws SQLException { 5107 byte[][] row = new byte[3][]; 5108 row[0] = rs.getBytes(1); 5109 row[1] = s2b(SUPPORTS_FK); 5110 5111 String createTableString = rs.getString(2); 5112 StringTokenizer lineTokenizer = new StringTokenizer (createTableString, 5113 "\n"); 5114 StringBuffer commentBuf = new StringBuffer ("comment; "); 5115 boolean firstTime = true; 5116 5117 while (lineTokenizer.hasMoreTokens()) { 5118 String line = lineTokenizer.nextToken().trim(); 5119 5120 String constraintName = null; 5121 5122 if (StringUtils.startsWithIgnoreCase(line, "CONSTRAINT")) { 5123 boolean usingBackTicks = true; 5124 int beginPos = line.indexOf("`"); 5125 5126 if (beginPos == -1) { 5127 beginPos = line.indexOf("\""); 5128 usingBackTicks = false; 5129 } 5130 5131 if (beginPos != -1) { 5132 int endPos = -1; 5133 5134 if (usingBackTicks) { 5135 endPos = line.indexOf("`", beginPos + 1); 5136 } else { 5137 endPos = line.indexOf("\"", beginPos + 1); 5138 } 5139 5140 if (endPos != -1) { 5141 constraintName = line.substring(beginPos + 1, endPos); 5142 line = line.substring(endPos + 1, line.length()).trim(); 5143 } 5144 } 5145 } 5146 5147 if (line.startsWith("FOREIGN KEY")) { 5148 if (line.endsWith(",")) { 5149 line = line.substring(0, line.length() - 1); 5150 } 5151 5152 int lineLength = line.length(); 5154 StringBuffer lineBuf = new StringBuffer (lineLength); 5155 5156 for (int i = 0; i < lineLength; i++) { 5157 char c = line.charAt(i); 5158 5159 if (c != '`') { 5160 lineBuf.append(c); 5161 } 5162 } 5163 5164 line = lineBuf.toString(); 5165 5166 StringTokenizer keyTokens = new StringTokenizer (line, "()", 5167 false); 5168 keyTokens.nextToken(); 5170 String localColumnNamesString = keyTokens.nextToken(); 5171 String referCatalogTableString = keyTokens.nextToken(); 5172 5173 StringTokenizer referSchemaTable = new StringTokenizer (referCatalogTableString 5174 .trim(), " ."); 5175 String referColumnNamesString = keyTokens.nextToken(); 5176 referSchemaTable.nextToken(); 5178 int numTokensLeft = referSchemaTable.countTokens(); 5179 5180 String referCatalog = null; 5181 String referTable = null; 5182 5183 if (numTokensLeft == 2) { 5184 referCatalog = referSchemaTable.nextToken(); 5186 referTable = referSchemaTable.nextToken(); 5187 } else { 5188 referTable = referSchemaTable.nextToken(); 5189 referCatalog = catalog; 5190 } 5191 5192 if (!firstTime) { 5193 commentBuf.append("; "); 5194 } else { 5195 firstTime = false; 5196 } 5197 5198 if (constraintName != null) { 5199 commentBuf.append(constraintName); 5200 } else { 5201 commentBuf.append("not_available"); 5202 } 5203 5204 commentBuf.append("("); 5205 commentBuf.append(localColumnNamesString); 5206 commentBuf.append(") REFER "); 5207 commentBuf.append(referCatalog); 5208 commentBuf.append("/"); 5209 commentBuf.append(referTable); 5210 commentBuf.append("("); 5211 commentBuf.append(referColumnNamesString); 5212 commentBuf.append(")"); 5213 5214 int lastParenIndex = line.lastIndexOf(")"); 5215 5216 if (lastParenIndex != (line.length() - 1)) { 5217 String cascadeOptions = cascadeOptions = line.substring(lastParenIndex 5218 + 1); 5219 commentBuf.append(" "); 5220 commentBuf.append(cascadeOptions); 5221 } 5222 } 5223 } 5224 5225 row[2] = s2b(commentBuf.toString()); 5226 rows.add(row); 5227 5228 return rows; 5229 } 5230 5231 5244 public ResultSet extractForeignKeyFromCreateTable( 5245 java.sql.Connection conn, java.sql.DatabaseMetaData metadata, 5246 String catalog, String tableName) throws SQLException { 5247 ArrayList tableList = new ArrayList (); 5248 java.sql.ResultSet rs = null; 5249 java.sql.Statement stmt = null; 5250 5251 if (tableName != null) { 5252 tableList.add(tableName); 5253 } else { 5254 try { 5255 rs = metadata.getTables(catalog, "", "%", 5256 new String [] { "TABLE" }); 5257 5258 while (rs.next()) { 5259 tableList.add(rs.getString("TABLE_NAME")); 5260 } 5261 } finally { 5262 if (rs != null) { 5263 rs.close(); 5264 } 5265 5266 rs = null; 5267 } 5268 } 5269 5270 ArrayList rows = new ArrayList (); 5271 Field[] fields = new Field[3]; 5272 fields[0] = new Field("", "Name", Types.CHAR, Integer.MAX_VALUE); 5273 fields[1] = new Field("", "Type", Types.CHAR, 255); 5274 fields[2] = new Field("", "Comment", Types.CHAR, Integer.MAX_VALUE); 5275 5276 int numTables = tableList.size(); 5277 5278 try { 5279 stmt = conn.createStatement(); 5280 5281 if (stmt.getMaxRows() != 0) { 5282 stmt.setMaxRows(0); 5283 } 5284 5285 for (int i = 0; i < numTables; i++) { 5286 String tableToExtract = (String ) tableList.get(i); 5287 5288 String query = new StringBuffer ("SHOW CREATE TABLE ").append( 5289 "`").append(catalog).append("`.`").append(tableToExtract) 5290 .append("`") 5291 .toString(); 5292 rs = stmt.executeQuery(query); 5293 5294 while (rs.next()) { 5295 extractForeignKeyForTable(rows, rs, catalog); 5296 } 5297 } 5298 } finally { 5299 if (rs != null) { 5300 rs.close(); 5301 } 5302 5303 rs = null; 5304 5305 if (stmt != null) { 5306 stmt.close(); 5307 } 5308 5309 stmt = null; 5310 } 5311 5312 return buildResultSet(fields, rows); 5313 } 5314 5315 5325 public boolean insertsAreDetected(int type) throws SQLException { 5326 return false; 5327 } 5328 5329 5332 public boolean locatorsUpdateCopy() throws SQLException { 5333 return true; 5334 } 5335 5336 5344 public boolean nullPlusNonNullIsNull() throws java.sql.SQLException { 5345 return true; 5346 } 5347 5348 5355 public boolean nullsAreSortedAtEnd() throws java.sql.SQLException { 5356 return false; 5357 } 5358 5359 5366 public boolean nullsAreSortedAtStart() throws java.sql.SQLException { 5367 if (this.conn.getIO().versionMeetsMinimum(4, 0, 2) 5368 && !this.conn.getIO().versionMeetsMinimum(4, 0, 11)) { 5369 return true; 5370 } else { 5371 return false; 5372 } 5373 } 5374 5375 5382 public boolean nullsAreSortedHigh() throws java.sql.SQLException { 5383 return false; 5384 } 5385 5386 5393 public boolean nullsAreSortedLow() throws java.sql.SQLException { 5394 return !nullsAreSortedHigh(); 5395 } 5396 5397 5406 public boolean othersDeletesAreVisible(int type) throws SQLException { 5407 return false; 5408 } 5409 5410 5419 public boolean othersInsertsAreVisible(int type) throws SQLException { 5420 return false; 5421 } 5422 5423 5432 public boolean othersUpdatesAreVisible(int type) throws SQLException { 5433 return false; 5434 } 5435 5436 5445 public boolean ownDeletesAreVisible(int type) throws SQLException { 5446 return false; 5447 } 5448 5449 5458 public boolean ownInsertsAreVisible(int type) throws SQLException { 5459 return false; 5460 } 5461 5462 5471 public boolean ownUpdatesAreVisible(int type) throws SQLException { 5472 return false; 5473 } 5474 5475 5483 public boolean storesLowerCaseIdentifiers() throws java.sql.SQLException { 5484 return false; 5485 } 5486 5487 5495 public boolean storesLowerCaseQuotedIdentifiers() 5496 throws java.sql.SQLException { 5497 return false; 5498 } 5499 5500 5508 public boolean storesMixedCaseIdentifiers() throws java.sql.SQLException { 5509 return true; 5510 } 5511 5512 5520 public boolean storesMixedCaseQuotedIdentifiers() 5521 throws java.sql.SQLException { 5522 return false; 5523 } 5524 5525 5533 public boolean storesUpperCaseIdentifiers() throws java.sql.SQLException { 5534 return false; 5535 } 5536 5537 5545 public boolean storesUpperCaseQuotedIdentifiers() 5546 throws java.sql.SQLException { 5547 return false; 5548 } 5549 5550 5558 public boolean supportsANSI92EntryLevelSQL() throws java.sql.SQLException { 5559 return true; 5560 } 5561 5562 5569 public boolean supportsANSI92FullSQL() throws java.sql.SQLException { 5570 return false; 5571 } 5572 5573 5580 public boolean supportsANSI92IntermediateSQL() throws java.sql.SQLException { 5581 return false; 5582 } 5583 5584 5591 public boolean supportsAlterTableWithAddColumn() 5592 throws java.sql.SQLException { 5593 return true; 5594 } 5595 5596 5603 public boolean supportsAlterTableWithDropColumn() 5604 throws java.sql.SQLException { 5605 return true; 5606 } 5607 5608 5616 public boolean supportsBatchUpdates() throws SQLException { 5617 return true; 5618 } 5619 5620 5627 public boolean supportsCatalogsInDataManipulation() 5628 throws java.sql.SQLException { 5629 return this.conn.getIO().versionMeetsMinimum(3, 3, 22); 5631 } 5632 5633 5640 public boolean supportsCatalogsInIndexDefinitions() 5641 throws java.sql.SQLException { 5642 return false; 5643 } 5644 5645 5652 public boolean supportsCatalogsInPrivilegeDefinitions() 5653 throws java.sql.SQLException { 5654 return false; 5655 } 5656 5657 5664 public boolean supportsCatalogsInProcedureCalls() 5665 throws java.sql.SQLException { 5666 return false; 5667 } 5668 5669 5676 public boolean supportsCatalogsInTableDefinitions() 5677 throws java.sql.SQLException { 5678 return false; 5679 } 5680 5681 5694 public boolean supportsColumnAliasing() throws java.sql.SQLException { 5695 return true; 5696 } 5697 5698 5705 public boolean supportsConvert() throws java.sql.SQLException { 5706 return true; 5707 } 5708 5709 5721 public boolean supportsConvert(int fromType, int toType) 5722 throws java.sql.SQLException { 5723 switch (fromType) { 5724 5727 case java.sql.Types.CHAR: 5728 case java.sql.Types.VARCHAR: 5729 case java.sql.Types.LONGVARCHAR: 5730 case java.sql.Types.BINARY: 5731 case java.sql.Types.VARBINARY: 5732 case java.sql.Types.LONGVARBINARY: 5733 5734 switch (toType) { 5735 case java.sql.Types.DECIMAL: 5736 case java.sql.Types.NUMERIC: 5737 case java.sql.Types.REAL: 5738 case java.sql.Types.TINYINT: 5739 case java.sql.Types.SMALLINT: 5740 case java.sql.Types.INTEGER: 5741 case java.sql.Types.BIGINT: 5742 case java.sql.Types.FLOAT: 5743 case java.sql.Types.DOUBLE: 5744 case java.sql.Types.CHAR: 5745 case java.sql.Types.VARCHAR: 5746 case java.sql.Types.LONGVARCHAR: 5747 case java.sql.Types.BINARY: 5748 case java.sql.Types.VARBINARY: 5749 case java.sql.Types.LONGVARBINARY: 5750 case java.sql.Types.OTHER: 5751 case java.sql.Types.DATE: 5752 case java.sql.Types.TIME: 5753 case java.sql.Types.TIMESTAMP: 5754 return true; 5755 5756 default: 5757 return false; 5758 } 5759 5760 5763 case java.sql.Types.BIT: 5764 return false; 5765 5766 5769 case java.sql.Types.DECIMAL: 5770 case java.sql.Types.NUMERIC: 5771 case java.sql.Types.REAL: 5772 case java.sql.Types.TINYINT: 5773 case java.sql.Types.SMALLINT: 5774 case java.sql.Types.INTEGER: 5775 case java.sql.Types.BIGINT: 5776 case java.sql.Types.FLOAT: 5777 case java.sql.Types.DOUBLE: 5778 5779 switch (toType) { 5780 case java.sql.Types.DECIMAL: 5781 case java.sql.Types.NUMERIC: 5782 case java.sql.Types.REAL: 5783 case java.sql.Types.TINYINT: 5784 case java.sql.Types.SMALLINT: 5785 case java.sql.Types.INTEGER: 5786 case java.sql.Types.BIGINT: 5787 case java.sql.Types.FLOAT: 5788 case java.sql.Types.DOUBLE: 5789 case java.sql.Types.CHAR: 5790 case java.sql.Types.VARCHAR: 5791 case java.sql.Types.LONGVARCHAR: 5792 case java.sql.Types.BINARY: 5793 case java.sql.Types.VARBINARY: 5794 case java.sql.Types.LONGVARBINARY: 5795 return true; 5796 5797 default: 5798 return false; 5799 } 5800 5801 5802 case java.sql.Types.NULL: 5803 return false; 5804 5805 5808 case java.sql.Types.OTHER: 5809 5810 switch (toType) { 5811 case java.sql.Types.CHAR: 5812 case java.sql.Types.VARCHAR: 5813 case java.sql.Types.LONGVARCHAR: 5814 case java.sql.Types.BINARY: 5815 case java.sql.Types.VARBINARY: 5816 case java.sql.Types.LONGVARBINARY: 5817 return true; 5818 5819 default: 5820 return false; 5821 } 5822 5823 5824 case java.sql.Types.DATE: 5825 5826 switch (toType) { 5827 case java.sql.Types.CHAR: 5828 case java.sql.Types.VARCHAR: 5829 case java.sql.Types.LONGVARCHAR: 5830 case java.sql.Types.BINARY: 5831 case java.sql.Types.VARBINARY: 5832 case java.sql.Types.LONGVARBINARY: 5833 return true; 5834 5835 default: 5836 return false; 5837 } 5838 5839 5840 case java.sql.Types.TIME: 5841 5842 switch (toType) { 5843 case java.sql.Types.CHAR: 5844 case java.sql.Types.VARCHAR: 5845 case java.sql.Types.LONGVARCHAR: 5846 case java.sql.Types.BINARY: 5847 case java.sql.Types.VARBINARY: 5848 case java.sql.Types.LONGVARBINARY: 5849 return true; 5850 5851 default: 5852 return false; 5853 } 5854 5855 5858 case java.sql.Types.TIMESTAMP: 5859 5860 switch (toType) { 5861 case java.sql.Types.CHAR: 5862 case java.sql.Types.VARCHAR: 5863 case java.sql.Types.LONGVARCHAR: 5864 case java.sql.Types.BINARY: 5865 case java.sql.Types.VARBINARY: 5866 case java.sql.Types.LONGVARBINARY: 5867 case java.sql.Types.TIME: 5868 case java.sql.Types.DATE: 5869 return true; 5870 5871 default: 5872 return false; 5873 } 5874 5875 5876 default: 5877 return false; } 5879 } 5880 5881 5888 public boolean supportsCoreSQLGrammar() throws java.sql.SQLException { 5889 return true; 5890 } 5891 5892 5900 public boolean supportsCorrelatedSubqueries() throws java.sql.SQLException { 5901 return false; 5902 } 5903 5904 5912 public boolean supportsDataDefinitionAndDataManipulationTransactions() 5913 throws java.sql.SQLException { 5914 return false; 5915 } 5916 5917 5924 public boolean supportsDataManipulationTransactionsOnly() 5925 throws java.sql.SQLException { 5926 return false; 5927 } 5928 5929 5938 public boolean supportsDifferentTableCorrelationNames() 5939 throws java.sql.SQLException { 5940 return true; 5941 } 5942 5943 5950 public boolean supportsExpressionsInOrderBy() throws java.sql.SQLException { 5951 return true; 5952 } 5953 5954 5961 public boolean supportsExtendedSQLGrammar() throws java.sql.SQLException { 5962 return false; 5963 } 5964 5965 5972 public boolean supportsFullOuterJoins() throws java.sql.SQLException { 5973 return false; 5974 } 5975 5976 5981 public boolean supportsGetGeneratedKeys() { 5982 return true; 5983 } 5984 5985 5992 public boolean supportsGroupBy() throws java.sql.SQLException { 5993 return true; 5994 } 5995 5996 6004 public boolean supportsGroupByBeyondSelect() throws java.sql.SQLException { 6005 return true; 6006 } 6007 6008 6015 public boolean supportsGroupByUnrelated() throws java.sql.SQLException { 6016 return false; 6017 } 6018 6019 6026 public boolean supportsIntegrityEnhancementFacility() 6027 throws java.sql.SQLException { 6028 return false; 6029 } 6030 6031 6039 public boolean supportsLikeEscapeClause() throws java.sql.SQLException { 6040 return true; 6041 } 6042 6043 6051 public boolean supportsLimitedOuterJoins() throws java.sql.SQLException { 6052 return true; 6053 } 6054 6055 6063 public boolean supportsMinimumSQLGrammar() throws java.sql.SQLException { 6064 return true; 6065 } 6066 6067 6074 public boolean supportsMixedCaseIdentifiers() throws java.sql.SQLException { 6075 return false; 6076 } 6077 6078 6086 public boolean supportsMixedCaseQuotedIdentifiers() 6087 throws java.sql.SQLException { 6088 return false; 6089 } 6090 6091 6094 public boolean supportsMultipleOpenResults() throws SQLException { 6095 return false; 6096 } 6097 6098 6105 public boolean supportsMultipleResultSets() throws java.sql.SQLException { 6106 return false; 6107 } 6108 6109 6117 public boolean supportsMultipleTransactions() throws java.sql.SQLException { 6118 return true; 6119 } 6120 6121 6124 public boolean supportsNamedParameters() throws SQLException { 6125 return false; 6126 } 6127 6128 6136 public boolean supportsNonNullableColumns() throws java.sql.SQLException { 6137 return true; 6138 } 6139 6140 6149 public boolean supportsOpenCursorsAcrossCommit() 6150 throws java.sql.SQLException { 6151 return false; 6152 } 6153 6154 6163 public boolean supportsOpenCursorsAcrossRollback() 6164 throws java.sql.SQLException { 6165 return false; 6166 } 6167 6168 6177 public boolean supportsOpenStatementsAcrossCommit() 6178 throws java.sql.SQLException { 6179 return false; 6180 } 6181 6182 6191 public boolean supportsOpenStatementsAcrossRollback() 6192 throws java.sql.SQLException { 6193 return false; 6194 } 6195 6196 6203 public boolean supportsOrderByUnrelated() throws java.sql.SQLException { 6204 return false; 6205 } 6206 6207 6214 public boolean supportsOuterJoins() throws java.sql.SQLException { 6215 return true; 6216 } 6217 6218 6225 public boolean supportsPositionedDelete() throws java.sql.SQLException { 6226 return false; 6227 } 6228 6229 6236 public boolean supportsPositionedUpdate() throws java.sql.SQLException { 6237 return false; 6238 } 6239 6240 6253 public boolean supportsResultSetConcurrency(int type, int concurrency) 6254 throws SQLException { 6255 return ((type == ResultSet.TYPE_SCROLL_INSENSITIVE) 6256 && ((concurrency == ResultSet.CONCUR_READ_ONLY) 6257 || (concurrency == ResultSet.CONCUR_UPDATABLE))); 6258 } 6259 6260 6263 public boolean supportsResultSetHoldability(int holdability) 6264 throws SQLException { 6265 return (holdability == ResultSet.HOLD_CURSORS_OVER_COMMIT); 6266 } 6267 6268 6279 public boolean supportsResultSetType(int type) throws SQLException { 6280 return (type == ResultSet.TYPE_SCROLL_INSENSITIVE); 6281 } 6282 6283 6286 public boolean supportsSavepoints() throws SQLException { 6287 return false; 6288 } 6289 6290 6297 public boolean supportsSchemasInDataManipulation() 6298 throws java.sql.SQLException { 6299 return false; 6300 } 6301 6302 6309 public boolean supportsSchemasInIndexDefinitions() 6310 throws java.sql.SQLException { 6311 return false; 6312 } 6313 6314 6321 public boolean supportsSchemasInPrivilegeDefinitions() 6322 throws java.sql.SQLException { 6323 return false; 6324 } 6325 6326 6333 public boolean supportsSchemasInProcedureCalls() 6334 throws java.sql.SQLException { 6335 return false; 6336 } 6337 6338 6345 public boolean supportsSchemasInTableDefinitions() 6346 throws java.sql.SQLException { 6347 return false; 6348 } 6349 6350 6357 public boolean supportsSelectForUpdate() throws java.sql.SQLException { 6358 return false; 6359 } 6360 6361 6364 public boolean supportsStatementPooling() throws SQLException { 6365 return false; 6366 } 6367 6368 6376 public boolean supportsStoredProcedures() throws java.sql.SQLException { 6377 return false; 6378 } 6379 6380 6388 public boolean supportsSubqueriesInComparisons() 6389 throws java.sql.SQLException { 6390 return this.conn.getIO().versionMeetsMinimum(4, 1, 0); 6391 } 6392 6393 6401 public boolean supportsSubqueriesInExists() throws java.sql.SQLException { 6402 return this.conn.getIO().versionMeetsMinimum(4, 1, 0); 6403 } 6404 6405 6413 public boolean supportsSubqueriesInIns() throws java.sql.SQLException { 6414 return this.conn.getIO().versionMeetsMinimum(4, 1, 0); 6415 } 6416 6417 6425 public boolean supportsSubqueriesInQuantifieds() 6426 throws java.sql.SQLException { 6427 return this.conn.getIO().versionMeetsMinimum(4, 1, 0); 6428 } 6429 6430 6438 public boolean supportsTableCorrelationNames() throws java.sql.SQLException { 6439 return true; 6440 } 6441 6442 6453 public boolean supportsTransactionIsolationLevel(int level) 6454 throws java.sql.SQLException { 6455 if (this.conn.supportsIsolationLevel()) { 6456 switch (level) { 6457 case java.sql.Connection.TRANSACTION_READ_COMMITTED: 6458 case java.sql.Connection.TRANSACTION_READ_UNCOMMITTED: 6459 case java.sql.Connection.TRANSACTION_REPEATABLE_READ: 6460 case java.sql.Connection.TRANSACTION_SERIALIZABLE: 6461 return true; 6462 6463 default: 6464 return false; 6465 } 6466 } else { 6467 return false; 6468 } 6469 } 6470 6471 6479 public boolean supportsTransactions() throws java.sql.SQLException { 6480 return this.conn.supportsTransactions(); 6481 } 6482 6483 6490 public boolean supportsUnion() throws java.sql.SQLException { 6491 return this.conn.getIO().versionMeetsMinimum(4, 0, 0); 6492 } 6493 6494 6501 public boolean supportsUnionAll() throws java.sql.SQLException { 6502 return this.conn.getIO().versionMeetsMinimum(4, 0, 0); 6503 } 6504 6505 6515 public boolean updatesAreDetected(int type) throws SQLException { 6516 return false; 6517 } 6518 6519 6526 public boolean usesLocalFilePerTable() throws java.sql.SQLException { 6527 return false; 6528 } 6529 6530 6537 public boolean usesLocalFiles() throws java.sql.SQLException { 6538 return false; 6539 } 6540 6541 6549 private int getCascadeDeleteOption(String cascadeOptions) { 6550 int onDeletePos = cascadeOptions.indexOf("ON DELETE"); 6551 6552 if (onDeletePos != -1) { 6553 String deleteOptions = cascadeOptions.substring(onDeletePos, 6554 cascadeOptions.length()); 6555 6556 if (deleteOptions.startsWith("ON DELETE CASCADE")) { 6557 return DatabaseMetaData.importedKeyCascade; 6558 } else if (deleteOptions.startsWith("ON DELETE SET NULL")) { 6559 return DatabaseMetaData.importedKeySetNull; 6560 } else if (deleteOptions.startsWith("ON DELETE RESTRICT")) { 6561 return DatabaseMetaData.importedKeyRestrict; 6562 } else if (deleteOptions.startsWith("ON DELETE NO ACTION")) { 6563 return DatabaseMetaData.importedKeyNoAction; 6564 } 6565 } 6566 6567 return DatabaseMetaData.importedKeyNoAction; 6568 } 6569 6570 6578 private int getCascadeUpdateOption(String cascadeOptions) { 6579 int onUpdatePos = cascadeOptions.indexOf("ON UPDATE"); 6580 6581 if (onUpdatePos != -1) { 6582 String updateOptions = cascadeOptions.substring(onUpdatePos, 6583 cascadeOptions.length()); 6584 6585 if (updateOptions.startsWith("ON UPDATE CASCADE")) { 6586 return DatabaseMetaData.importedKeyCascade; 6587 } else if (updateOptions.startsWith("ON UPDATE SET NULL")) { 6588 return DatabaseMetaData.importedKeySetNull; 6589 } else if (updateOptions.startsWith("ON UPDATE RESTRICT")) { 6590 return DatabaseMetaData.importedKeyRestrict; 6591 } else if (updateOptions.startsWith("ON UPDATE NO ACTION")) { 6592 return DatabaseMetaData.importedKeyNoAction; 6593 } 6594 } 6595 6596 return DatabaseMetaData.importedKeyNoAction; 6597 } 6598 6599 6613 private void getExportKeyResults(String catalog, String exportingTable, 6614 String keysComment, List tuples, String fkTableName) 6615 throws SQLException { 6616 getResultsImpl(catalog, exportingTable, keysComment, tuples, 6617 fkTableName, true); 6618 } 6619 6620 6629 private int[] getForeignKeyActions(String commentString) { 6630 int[] actions = new int[] { 6631 DatabaseMetaData.importedKeyNoAction, 6632 DatabaseMetaData.importedKeyNoAction 6633 }; 6634 6635 int lastParenIndex = commentString.lastIndexOf(")"); 6636 6637 if (lastParenIndex != (commentString.length() - 1)) { 6638 String cascadeOptions = commentString.substring(lastParenIndex + 1) 6639 .trim().toUpperCase(); 6640 6641 actions[0] = getCascadeDeleteOption(cascadeOptions); 6642 actions[1] = getCascadeUpdateOption(cascadeOptions); 6643 } 6644 6645 return actions; 6646 } 6647 6648 6661 private void getImportKeyResults(String catalog, String importingTable, 6662 String keysComment, List tuples) throws SQLException { 6663 getResultsImpl(catalog, importingTable, keysComment, tuples, null, false); 6664 } 6665 6666 private void getResultsImpl(String catalog, String table, 6667 String keysComment, List tuples, String fkTableName, boolean isExport) 6668 throws SQLException { 6669 int firstLeftParenIndex = keysComment.indexOf('('); 6676 String constraintName = keysComment.substring(0, firstLeftParenIndex) 6677 .trim(); 6678 keysComment = keysComment.substring(firstLeftParenIndex, 6679 keysComment.length()); 6680 6681 StringTokenizer keyTokens = new StringTokenizer (keysComment.trim(), 6682 "()", false); 6683 String localColumnNamesString = keyTokens.nextToken(); 6684 StringTokenizer localColumnNames = new StringTokenizer (localColumnNamesString, 6685 " ,"); 6686 String referCatalogTableString = keyTokens.nextToken(); 6687 StringTokenizer referSchemaTable = new StringTokenizer (referCatalogTableString, 6688 " /"); 6689 String referColumnNamesString = keyTokens.nextToken(); 6690 StringTokenizer referColumnNames = new StringTokenizer (referColumnNamesString, 6691 " ,"); 6692 referSchemaTable.nextToken(); 6694 String referCatalog = referSchemaTable.nextToken(); 6695 String referTable = referSchemaTable.nextToken(); 6696 6697 if (isExport && !referTable.equals(table)) { 6698 return; 6699 } 6700 6701 if (localColumnNames.countTokens() != referColumnNames.countTokens()) { 6702 throw new SQLException ("Error parsing foriegn keys definition", 6703 SQLError.SQL_STATE_GENERAL_ERROR); 6704 } 6705 6706 int keySeqIndex = 1; 6707 6708 byte[] connectionCatalogAsBytes = null; 6709 6710 if (catalog == null) { 6711 connectionCatalogAsBytes = s2b(this.conn.getCatalog()); 6712 } else { 6713 connectionCatalogAsBytes = s2b(catalog); 6714 } 6715 6716 while (localColumnNames.hasMoreTokens()) { 6717 byte[][] tuple = new byte[14][]; 6718 String localColumnName = localColumnNames.nextToken(); 6719 String referColumnName = referColumnNames.nextToken(); 6720 tuple[FKTABLE_CAT] = connectionCatalogAsBytes; 6721 tuple[FKTABLE_SCHEM] = null; 6722 tuple[FKTABLE_NAME] = s2b((isExport) ? fkTableName : table); 6723 tuple[FKCOLUMN_NAME] = s2b(localColumnName); 6724 tuple[PKTABLE_CAT] = s2b(referCatalog); 6725 tuple[PKTABLE_SCHEM] = null; 6726 tuple[PKTABLE_NAME] = s2b((isExport) ? table : referTable); 6727 tuple[PKCOLUMN_NAME] = s2b(referColumnName); 6728 tuple[KEY_SEQ] = s2b(Integer.toString(keySeqIndex++)); 6729 6730 int[] actions = getForeignKeyActions(keysComment); 6731 6732 tuple[UPDATE_RULE] = s2b(Integer.toString(actions[1])); 6733 tuple[DELETE_RULE] = s2b(Integer.toString(actions[0])); 6734 tuple[FK_NAME] = s2b(constraintName); 6735 tuple[PK_NAME] = null; tuple[DEFERRABILITY] = s2b(Integer.toString( 6737 java.sql.DatabaseMetaData.importedKeyNotDeferrable)); 6738 tuples.add(tuple); 6739 } 6740 } 6741 6742 private String getTableNameWithCase(String table) { 6743 String tableNameWithCase = (this.conn.lowerCaseTableNames() 6744 ? table.toLowerCase() : table); 6745 6746 return tableNameWithCase; 6747 } 6748 6749 private java.sql.ResultSet buildResultSet(com.mysql.jdbc.Field[] fields, 6750 java.util.ArrayList rows) throws SQLException { 6751 int fieldsLength = fields.length; 6752 6753 for (int i = 0; i < fieldsLength; i++) { 6754 fields[i].setConnection(this.conn); 6755 } 6756 6757 return new com.mysql.jdbc.ResultSet(this.conn.getCatalog(), fields, 6758 new RowDataStatic(rows), this.conn); 6759 } 6760 6761 6769 private byte[] s2b(String s) { 6770 if ((this.conn != null) && this.conn.useUnicode()) { 6771 try { 6772 String encoding = this.conn.getEncoding(); 6773 6774 if (encoding == null) { 6775 return s.getBytes(); 6776 } else { 6777 SingleByteCharsetConverter converter = this.conn.getCharsetConverter(encoding); 6778 6779 if (converter != null) { 6780 return converter.toBytes(s); 6781 } else { 6782 return s.getBytes(encoding); 6783 } 6784 } 6785 } catch (java.io.UnsupportedEncodingException E) { 6786 return s.getBytes(); 6787 } 6788 } else { 6789 return s.getBytes(); 6790 } 6791 } 6792} 6793 | Popular Tags |