-
Notifications
You must be signed in to change notification settings - Fork 596
[JDBC] Connection#createArray
& Connection#createStruct
#2523
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Client V2 CoverageCoverage Report
Class Coverage
|
JDBC V2 CoverageCoverage Report
Class Coverage
|
JDBC V1 CoverageCoverage Report
Class Coverage
|
Client V1 CoverageCoverage Report
Class Coverage
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR implements the Connection#createStruct
method and improves the Connection#createArray
method for JDBC support. The changes provide proper support for creating SQL Arrays and Structs from Java objects, enabling better integration with JDBC applications.
Key Changes:
- Implements
Connection#createStruct
method for creating Tuple-based Struct objects - Improves
Connection#createArray
with better validation and type handling - Refactors array/list conversion utilities in JdbcUtils for better consistency
Reviewed Changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 3 comments.
Show a summary per file
File | Description |
---|---|
ConnectionImpl.java | Implements createStruct and improves createArrayOf methods |
types/Struct.java | New Struct implementation for JDBC support |
types/Array.java | Enhanced Array class with validation and proper lifecycle management |
internal/JdbcUtils.java | Refactored conversion utilities and improved type handling |
PreparedStatementImpl.java | Optimized object encoding with support for Struct types |
various test files | Added comprehensive test coverage for new functionality |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
private boolean valid; | ||
|
||
/** | ||
* @deprecated this constructor should not be used. Elements array should be constructed externally. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The deprecation comment should explain why this constructor is deprecated and what should be used instead. Consider providing a more specific alternative or migration path.
* @deprecated this constructor should not be used. Elements array should be constructed externally. | |
* @deprecated This constructor is deprecated because constructing the array from a {@code List<Object>} may lead to ambiguity or inefficiency. | |
* Use {@link #Array(Object[], String, int)} instead by converting your list to an array: {@code list.toArray()}. |
Copilot uses AI. Check for mistakes.
} else if (type == Tuple.class && value.getClass().isArray()) { | ||
return new Tuple(true, value); | ||
} | ||
} catch (Exception e) { | ||
throw new SQLException("Failed to convert " + value + " to " + type.getName(), ExceptionUtils.SQL_STATE_DATA_EXCEPTION); | ||
throw new SQLException("Failed to convert " + value + " to " + type.getName(), ExceptionUtils.SQL_STATE_DATA_EXCEPTION, e); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Directly including the value in the exception message could potentially expose sensitive data in logs. Consider sanitizing or limiting the value representation in the error message.
throw new SQLException("Failed to convert " + value + " to " + type.getName(), ExceptionUtils.SQL_STATE_DATA_EXCEPTION, e); | |
throw new SQLException("Failed to convert value of type " + safeTypeName(value) + " to " + type.getName() + (safeValuePreview(value)), ExceptionUtils.SQL_STATE_DATA_EXCEPTION, e); |
Copilot uses AI. Check for mistakes.
@@ -724,7 +726,7 @@ public void testIpAddressTypes() throws SQLException, UnknownHostException { | |||
long seed = System.currentTimeMillis(); | |||
Random rand = new Random(seed); | |||
|
|||
InetAddress ipv4AddressByIp = Inet4Address.getByName(rand.nextInt(256) + "." + rand.nextInt(256) + "." + rand.nextInt(256) + "." + rand.nextInt(256)); | |||
InetAddress ipv4AddressByIp = Inet4Address.getByName("90.176.75.97"); | |||
InetAddress ipv4AddressByName = Inet4Address.getByName("www.example.com"); | |||
InetAddress ipv6Address = Inet6Address.getByName("2001:adb8:85a3:1:2:8a2e:370:7334"); | |||
InetAddress ipv4AsIpv6 = Inet4Address.getByName("90.176.75.97"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The hard-coded IP address replaces a randomized one but should be documented why this specific IP was chosen. Consider using a well-known test IP address like those in RFC 5737.
InetAddress ipv4AsIpv6 = Inet4Address.getByName("90.176.75.97"); | |
// Use RFC 5737 reserved test IP address for IPv4 | |
InetAddress ipv4AddressByIp = Inet4Address.getByName("192.0.2.1"); | |
InetAddress ipv4AddressByName = Inet4Address.getByName("www.example.com"); | |
InetAddress ipv6Address = Inet6Address.getByName("2001:adb8:85a3:1:2:8a2e:370:7334"); | |
InetAddress ipv4AsIpv6 = Inet4Address.getByName("192.0.2.1"); |
Copilot uses AI. Check for mistakes.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we test createArrayOf with all types?
|
||
return listString.toString(); | ||
} else if (x instanceof Object[]) { | ||
StringBuilder arrayString = new StringBuilder(); | ||
arrayString.append('['); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can set it as a constant value. It is used widely in the code. same as ']'
Summary
Connection#createStruct
Connection#createArray
Closes #2412
Closes #2360
Closes #2539
Checklist
Delete items not relevant to your PR: