apache/shardingsphere · error · UnsupportedPreparedStatementException
1295
1295
Error message
This command is not supported in the prepared statement protocol yet
What it means
Error "This command is not supported in the prepared statement protocol yet" thrown in apache/shardingsphere.
Source
Thrown at proxy/frontend/dialect/mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/binary/prepare/MySQLComStmtPrepareExecutor.java:100
failedIfContainsMultiStatements();
MetaDataContexts metaDataContexts = ProxyContext.getInstance().getContextManager().getMetaDataContexts();
SQLParserRule sqlParserRule = metaDataContexts.getMetaData().getGlobalRuleMetaData().getSingleRule(SQLParserRule.class);
SQLStatement sqlStatement = sqlParserRule.getSQLParserEngine(databaseType).parse(packet.getSQL(), true);
ShardingSpherePreconditions.checkState(MySQLComStmtPrepareChecker.isAllowedStatement(sqlStatement), UnsupportedPreparedStatementException::new);
SQLStatementContext sqlStatementContext = new SQLBindEngine(ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData(),
connectionSession.getCurrentDatabaseName(), packet.getHintValueContext()).bind(sqlStatement);
int statementId = MySQLStatementIdGenerator.getInstance().nextStatementId(connectionSession.getConnectionId());
MySQLServerPreparedStatement serverPreparedStatement = new MySQLServerPreparedStatement(packet.getSQL(), sqlStatementContext, packet.getHintValueContext());
connectionSession.getServerPreparedStatementRegistry().addPreparedStatement(statementId, serverPreparedStatement);
return createPackets(sqlStatementContext, statementId, serverPreparedStatement);
}
private void failedIfContainsMultiStatements() {
// TODO Multi statements should be identified by SQL Parser instead of checking if sql contains ";".
if (connectionSession.getAttributeMap().hasAttr(MySQLConstants.OPTION_MULTI_STATEMENTS_ATTRIBUTE_KEY)
&& MySQLComSetOptionPacket.MYSQL_OPTION_MULTI_STATEMENTS_ON == connectionSession.getAttributeMap().attr(MySQLConstants.OPTION_MULTI_STATEMENTS_ATTRIBUTE_KEY).get()
&& packet.getSQL().contains(";")) {
throw new UnsupportedPreparedStatementException();
}
}
private Collection<DatabasePacket> createPackets(final SQLStatementContext sqlStatementContext, final int statementId, final MySQLServerPreparedStatement serverPreparedStatement) {
Collection<Projection> projections = getProjections(sqlStatementContext);
Collection<DatabasePacket> result = new ArrayList<>(sqlStatementContext.getSqlStatement().getParameterCount() + projections.size() + 3);
int parameterCount = sqlStatementContext.getSqlStatement().getParameterCount();
ShardingSpherePreconditions.checkState(parameterCount <= MAX_PARAMETER_COUNT, TooManyPlaceholdersException::new);
result.add(new MySQLComStmtPrepareOKPacket(statementId, projections.size(), parameterCount, 0));
int characterSet = connectionSession.getAttributeMap().attr(MySQLConstants.CHARACTER_SET_ATTRIBUTE_KEY).get().getId();
int statusFlags = ServerStatusFlagCalculator.calculateFor(connectionSession, true);
if (parameterCount > 0) {
result.addAll(createParameterColumnDefinition41Packets(sqlStatementContext, characterSet, serverPreparedStatement));
result.add(new MySQLEofPacket(statusFlags));
}
if (!projections.isEmpty() && sqlStatementContext instanceof SelectStatementContext) {
result.addAll(createProjectionColumnDefinition41Packets((SelectStatementContext) sqlStatementContext, characterSet, serverPreparedStatement));
result.add(new MySQLEofPacket(statusFlags));View on GitHub (pinned to e952770a21)
Solutions
- Use statements that are supported in the prepared statement protocol.
- Fall back to text protocol (COM_QUERY) for unsupported statement types.
- Check the ShardingSphere documentation for the list of statements supported by COM_STMT_PREPARE.
When it happens
Trigger: COM_STMT_PREPARE is used for a statement type the proxy cannot prepare.
Common situations: Preparing unsupported SQL (certain DDL or administrative statements) through the MySQL binary protocol.
AI-assisted analysis of apache/shardingsphere@e952770a21 (2026-08-14).
Data as JSON: /api/errors/1ba1ea2620be8a0c.
Report an issue: GitHub.