You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by "makssent (via GitHub)" <gi...@apache.org> on 2026/10/29 13:18:20 UTC
[I] Firebird Proxy describes CHAR columns and parameters as VARCHAR [shardingsphere]
makssent opened a new issue, #40396:
URL: https://github.com/apache/shardingsphere/issues/40396
### Before reporting a bug
- [x] I have searched open and closed [GitHub issues](https://github.com/apache/shardingsphere/issues).
- [x] I have read the [ShardingSphere documentation](https://shardingsphere.apache.org/document/current/en/overview).
### ShardingSphere version
master, commit [ab8624a369dac2a9a84762a24e1f078a57ee75e6](https://github.com/apache/shardingsphere/commit/ab8624a369dac2a9a84762a24e1f078a57ee75e6)
### ShardingSphere project
ShardingSphere-Proxy
### Expected behavior
The proxy should describe `CHAR(4)` columns and associated parameters as `CHAR(4)`, as the Firebird server does.
### Actual behavior
The proxy describes the `CHAR(4)` column and its associated parameters as `VARCHAR(4)`.
| Steps | Firebird server | Proxy |
| --- | --- | --- |
| Describe the parameters of an INSERT | `INTEGER(10)`, `CHAR(4)` | `INTEGER(10)`, `VARCHAR(4)` |
| Insert a row with ID = 5601 and CH = 'ab' | One row inserted | One row inserted |
| Describe the parameters of an UPDATE | `CHAR(4)`, `INTEGER(10)` | `VARCHAR(4)`, `INTEGER(10)` |
| Update CH to 'cd' for ID = 5601 | One row updated | One row updated |
| Describe the parameter and columns of a SELECT filtered by CH | Parameter `CHAR(4)`; column CH `CHAR(4)` | Parameter `VARCHAR(4)`; column CH `VARCHAR(4)` |
| Describe the columns of a SELECT filtered by ID | Column CH `CHAR(4)` | Column CH `VARCHAR(4)` |
| Read the updated row in both SELECT statements | ID = 5601, CH = 'cd ' | ID = 5601, CH = 'cd ' |
Applications inspecting the result or parameter metadata receive a different type through the proxy.
### Reason analysis
The Firebird server obtains the SQL type from the descriptor and writes it in the response ([`dsql.cpp`](https://github.com/FirebirdSQL/firebird/blob/v5.0.4/src/dsql/dsql.cpp#L1168-L1183), [`isc_info_sql_type`](https://github.com/FirebirdSQL/firebird/blob/v5.0.4/src/dsql/dsql.cpp#L1202-L1204)).
The proxy chooses the type to write from the JDBC type in [`FirebirdReturnColumnPacket#write`](https://github.com/apache/shardingsphere/blob/ab8624a369dac2a9a84762a24e1f078a57ee75e6/database/protocol/dialect/firebird/src/main/java/org/apache/shardingsphere/database/protocol/firebird/packet/command/query/statement/prepare/FirebirdReturnColumnPacket.java#L57-L66).
[`FirebirdBinaryColumnType`](https://github.com/apache/shardingsphere/blob/ab8624a369dac2a9a84762a24e1f078a57ee75e6/database/protocol/dialect/firebird/src/main/java/org/apache/shardingsphere/database/protocol/firebird/packet/command/query/FirebirdBinaryColumnType.java#L89-L91) maps JDBC `CHAR` to `VARYING`, as it does for `VARCHAR`.
### Steps to reproduce
#### Environment
- Firebird server 5.0.
- Client: Jaybird 6.0.7.
#### Steps
1. Create the table on the Firebird server:
```sql
CREATE TABLE T_CH (ID INTEGER NOT NULL PRIMARY KEY, CH CHAR(4));
```
2. Start ShardingSphere-Proxy with this configuration:
```yaml
# global.yaml
authority:
users:
- user: root@%
password: root
privilege:
type: ALL_PERMITTED
props:
proxy-frontend-database-protocol-type: Firebird
```
```yaml
# database-firebird.yaml
databaseName: firebird_db
dataSources:
ds_0:
url: jdbc:firebirdsql://<host>/<database file>?encoding=UTF8
username: <user>
password: <password>
rules:
- !SINGLE
tables:
- "*.*"
```
3. Run the example directly against the Firebird server and through the proxy, then compare its output. Set the connection environment variables for each target. The example deletes rows with IDs from 5600 to 5609 before and after the test.
### Example code
```java
import java.sql.*;
import java.util.*;
public class DescribeCharExample {
// Set the URL and credentials for the Firebird server or the proxy before running.
private static final String URL = System.getenv("JDBC_URL");
private static final String USER = System.getenv("DB_USER");
private static final String PASSWORD = System.getenv("DB_PASSWORD");
public static void main(String[] args) throws Exception {
try (Connection connection = DriverManager.getConnection(URL, USER, PASSWORD)) {
describeChar(connection);
}
}
// The server prints CHAR(4); the proxy prints VARCHAR(4) for CH.
private static void describeChar(Connection connection) throws SQLException {
try (Statement statement = connection.createStatement()) {
statement.executeUpdate("DELETE FROM T_CH WHERE ID BETWEEN 5600 AND 5609");
}
run(connection, "INSERT INTO T_CH (ID, CH) VALUES (?, ?)", 5601, "ab");
run(connection, "UPDATE T_CH SET CH = ? WHERE ID = ?", "cd", 5601);
run(connection, "SELECT ID, CH FROM T_CH WHERE CH = ? ORDER BY ID", "cd");
run(connection, "SELECT ID, CH FROM T_CH WHERE ID BETWEEN 5600 AND 5609 ORDER BY ID");
try (Statement statement = connection.createStatement()) {
statement.executeUpdate("DELETE FROM T_CH WHERE ID BETWEEN 5600 AND 5609");
}
}
private static void run(Connection connection, String sql, Object... values) throws SQLException {
try (PreparedStatement statement = connection.prepareStatement(sql)) {
ParameterMetaData parameters = statement.getParameterMetaData();
List<String> types = new ArrayList<>();
for (int i = 1; i <= parameters.getParameterCount(); i++) {
types.add(parameters.getParameterTypeName(i) + "(" + parameters.getPrecision(i) + ")");
}
System.out.println(sql + ": parameters " + types);
for (int i = 0; i < values.length; i++) {
statement.setObject(i + 1, values[i]);
}
if (statement.execute()) {
try (ResultSet rows = statement.getResultSet()) {
ResultSetMetaData columns = rows.getMetaData();
List<String> description = new ArrayList<>();
for (int i = 1; i <= columns.getColumnCount(); i++) {
description.add(columns.getColumnLabel(i) + " " + columns.getColumnTypeName(i) + "(" + columns.getPrecision(i) + ")");
}
System.out.println("columns " + description);
while (rows.next()) {
System.out.println("row [" + rows.getInt(1) + ", '" + rows.getString(2) + "']");
}
}
} else {
System.out.println("updated " + statement.getUpdateCount());
}
}
}
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org