|
52 | 52 | import com.mysql.cj.result.Field; |
53 | 53 | import com.mysql.cj.result.Row; |
54 | 54 | import com.mysql.cj.util.SearchMode; |
| 55 | +import com.mysql.cj.util.StringInspector; |
55 | 56 | import com.mysql.cj.util.StringUtils; |
56 | 57 |
|
57 | 58 | /** |
@@ -921,52 +922,52 @@ private List<Row> extractStoredRoutineColumnsTypeInfo(String dbName, String rout |
921 | 922 | boolean isOutParam = false; |
922 | 923 | boolean isInParam = false; |
923 | 924 |
|
924 | | - // Bug#52167, tokenizer will break if declaration contains special characters like '\n'. |
925 | | - declaration = declaration.replaceAll("[\\t\\n\\x0B\\f\\r]", " "); |
926 | | - StringTokenizer declarationTok = new StringTokenizer(declaration, " "); |
927 | | - if (declarationTok.hasMoreTokens()) { |
928 | | - String possibleParamName = declarationTok.nextToken(); |
| 925 | + boolean noBackslashEscapes = getSession().getServerSession().isNoBackslashEscapesSet(); |
| 926 | + StringInspector strInspector = new StringInspector(declaration, openingDelimiters, closingDelimiters, "", |
| 927 | + noBackslashEscapes ? SearchMode.__MRK_COM_MYM_HNT_WS : SearchMode.__BSE_MRK_COM_MYM_HNT_WS); |
| 928 | + |
| 929 | + int endPos = strInspector.indexOfNextWsChar(); |
| 930 | + int startPos = 0; |
| 931 | + if (endPos != -1) { |
| 932 | + String possibleParamName = declaration.substring(startPos, endPos); |
| 933 | + boolean firstStringWasParamType = false; |
929 | 934 | if (possibleParamName.equalsIgnoreCase("OUT")) { |
930 | 935 | isOutParam = true; |
931 | 936 | isInParam = false; |
932 | | - if (declarationTok.hasMoreTokens()) { |
933 | | - paramName = declarationTok.nextToken(); |
934 | | - } else { |
935 | | - throw SQLError.createSQLException(Messages.getString("DatabaseMetaData.6"), MysqlErrorNumbers.SQLSTATE_CONNJ_GENERAL_ERROR, |
936 | | - getExceptionInterceptor()); |
937 | | - } |
| 937 | + firstStringWasParamType = true; |
938 | 938 | } else if (possibleParamName.equalsIgnoreCase("INOUT")) { |
939 | 939 | isOutParam = true; |
940 | 940 | isInParam = true; |
941 | | - if (declarationTok.hasMoreTokens()) { |
942 | | - paramName = declarationTok.nextToken(); |
943 | | - } else { |
944 | | - throw SQLError.createSQLException(Messages.getString("DatabaseMetaData.6"), MysqlErrorNumbers.SQLSTATE_CONNJ_GENERAL_ERROR, |
945 | | - getExceptionInterceptor()); |
946 | | - } |
| 941 | + firstStringWasParamType = true; |
947 | 942 | } else if (possibleParamName.equalsIgnoreCase("IN")) { |
948 | 943 | isOutParam = false; |
949 | 944 | isInParam = true; |
950 | | - if (declarationTok.hasMoreTokens()) { |
951 | | - paramName = declarationTok.nextToken(); |
952 | | - } else { |
953 | | - throw SQLError.createSQLException(Messages.getString("DatabaseMetaData.6"), MysqlErrorNumbers.SQLSTATE_CONNJ_GENERAL_ERROR, |
954 | | - getExceptionInterceptor()); |
955 | | - } |
| 945 | + firstStringWasParamType = true; |
956 | 946 | } else { |
957 | 947 | isOutParam = false; |
958 | 948 | isInParam = true; |
959 | 949 | paramName = possibleParamName; |
960 | 950 | } |
961 | 951 |
|
962 | | - TypeDescriptor typeDesc = null; |
963 | | - if (declarationTok.hasMoreTokens()) { |
964 | | - StringBuilder typeInfo = new StringBuilder(declarationTok.nextToken()); |
965 | | - while (declarationTok.hasMoreTokens()) { |
966 | | - typeInfo.append(" "); |
967 | | - typeInfo.append(declarationTok.nextToken()); |
| 952 | + if (firstStringWasParamType) { |
| 953 | + while (Character.isWhitespace(strInspector.getChar())) { |
| 954 | + strInspector.incrementPosition(); |
| 955 | + } |
| 956 | + startPos = strInspector.getPosition(); |
| 957 | + endPos = strInspector.indexOfNextWsChar(); |
| 958 | + if (endPos != -1) { |
| 959 | + paramName = declaration.substring(startPos, endPos); |
| 960 | + } else { |
| 961 | + throw SQLError.createSQLException(Messages.getString("DatabaseMetaData.6"), MysqlErrorNumbers.SQLSTATE_CONNJ_GENERAL_ERROR, |
| 962 | + getExceptionInterceptor()); |
968 | 963 | } |
969 | | - typeDesc = new TypeDescriptor(typeInfo.toString(), "YES"); |
| 964 | + } |
| 965 | + |
| 966 | + TypeDescriptor typeDesc = null; |
| 967 | + if (strInspector.getPosition() != declaration.length()) { |
| 968 | + startPos = strInspector.indexOfNextNonWsChar(); |
| 969 | + endPos = declaration.length(); |
| 970 | + typeDesc = new TypeDescriptor(declaration.substring(startPos, endPos), "YES"); |
970 | 971 | } else { |
971 | 972 | throw SQLError.createSQLException(Messages.getString("DatabaseMetaData.7"), MysqlErrorNumbers.SQLSTATE_CONNJ_GENERAL_ERROR, |
972 | 973 | getExceptionInterceptor()); |
|
0 commit comments