Skip to content
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

Fix issues with apostrophe being passed in table name + Improvements in SQLServerParameterMetadata #780

Merged
merged 21 commits into from
Sep 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
01e4a82
Fix issues with apostrophe being passed in table names
cheenamalhotra Aug 8, 2018
1b3a91f
Make Util API generic for all objects
cheenamalhotra Aug 8, 2018
d500c22
Fix FMTONLY call with old SQL Servers
cheenamalhotra Aug 9, 2018
b2e04ff
Fix Apostrophe issues in more places
cheenamalhotra Aug 10, 2018
2bcd2c1
Fix SQLServerParameterMetadata Class objects + added missing null che…
cheenamalhotra Aug 14, 2018
f40c668
Reformat code changes
cheenamalhotra Aug 14, 2018
348f1a3
Fix regressions with APIs
cheenamalhotra Aug 24, 2018
c286256
Close SQLServerStatement and ResultSet and add support for parameter …
cheenamalhotra Aug 28, 2018
c07fe88
Merge branch 'ms-dev' into issue775
cheenamalhotra Aug 28, 2018
ef6058a
Fix for Paramter metadata type fetch
cheenamalhotra Aug 28, 2018
3f6ee84
Minor fixes in code
cheenamalhotra Aug 28, 2018
d1b2349
Add SS_TYPE_SCHEMA_NAME to metadata
cheenamalhotra Aug 28, 2018
7131f1c
Add apostrophe & ParameterMetaData test case.
cheenamalhotra Aug 28, 2018
6bed2cc
Add another column type to test precision/scale APIs
cheenamalhotra Aug 28, 2018
bccc6df
Remove apostrophe from column Name - rename test
cheenamalhotra Aug 28, 2018
092b88d
Add null check to other parsing method too.
cheenamalhotra Sep 19, 2018
1ac7371
Reflect comments
cheenamalhotra Sep 19, 2018
8f3d4c8
Remove obselete comment
cheenamalhotra Sep 19, 2018
e9b7806
Update branch to latest dev changes
cheenamalhotra Sep 21, 2018
8118d6c
Fix conflict issues
cheenamalhotra Sep 22, 2018
5c687ed
Code formatted
cheenamalhotra Sep 22, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1728,8 +1728,8 @@ private void getDestinationMetadata() throws SQLServerException {
ResultSet.CONCUR_READ_ONLY, connection.getHoldability(), stmtColumnEncriptionSetting);

// Get destination metadata
rs = stmt.executeQueryInternal(
"sp_executesql N'SET FMTONLY ON SELECT * FROM " + destinationTableName + " '");
rs = stmt.executeQueryInternal("sp_executesql N'SET FMTONLY ON SELECT * FROM "
+ Util.escapeSingleQuotes(destinationTableName) + " '");
}

destColumnCount = rs.getMetaData().getColumnCount();
Expand All @@ -1740,11 +1740,11 @@ private void getDestinationMetadata() throws SQLServerException {
// SQL server prior to 2016 does not support encryption_type
rsMoreMetaData = ((SQLServerStatement) connection.createStatement())
.executeQueryInternal("select collation_name from sys.columns where " + "object_id=OBJECT_ID('"
+ destinationTableName + "') " + "order by column_id ASC");
+ Util.escapeSingleQuotes(destinationTableName) + "') " + "order by column_id ASC");
} else {
rsMoreMetaData = ((SQLServerStatement) connection.createStatement())
.executeQueryInternal("select collation_name, encryption_type from sys.columns where "
+ "object_id=OBJECT_ID('" + destinationTableName + "') " + "order by column_id ASC");
rsMoreMetaData = ((SQLServerStatement) connection.createStatement()).executeQueryInternal(
"select collation_name, encryption_type from sys.columns where " + "object_id=OBJECT_ID('"
+ Util.escapeSingleQuotes(destinationTableName) + "') " + "order by column_id ASC");
}
for (int i = 1; i <= destColumnCount; ++i) {
if (rsMoreMetaData.next()) {
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -1970,8 +1970,9 @@ public int[] executeBatch() throws SQLServerException, BatchUpdateException, SQL
try (SQLServerStatement stmt = (SQLServerStatement) connection.createStatement(
ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, connection.getHoldability(),
stmtColumnEncriptionSetting);
SQLServerResultSet rs = stmt.executeQueryInternal(
"sp_executesql N'SET FMTONLY ON SELECT * FROM " + tableName + " '");) {
SQLServerResultSet rs = stmt
.executeQueryInternal("sp_executesql N'SET FMTONLY ON SELECT * FROM "
+ Util.escapeSingleQuotes(tableName) + " '");) {
if (null != columnList && columnList.size() > 0) {
if (columnList.size() != valueList.size()) {
throw new IllegalArgumentException(
Expand Down Expand Up @@ -2123,8 +2124,9 @@ public long[] executeLargeBatch() throws SQLServerException, BatchUpdateExceptio
try (SQLServerStatement stmt = (SQLServerStatement) connection.createStatement(
ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, connection.getHoldability(),
stmtColumnEncriptionSetting);
SQLServerResultSet rs = stmt.executeQueryInternal(
"sp_executesql N'SET FMTONLY ON SELECT * FROM " + tableName + " '");) {
SQLServerResultSet rs = stmt
lilgreenbird marked this conversation as resolved.
Show resolved Hide resolved
.executeQueryInternal("sp_executesql N'SET FMTONLY ON SELECT * FROM "
+ Util.escapeSingleQuotes(tableName) + " '");) {
if (null != columnList && columnList.size() > 0) {
if (columnList.size() != valueList.size()) {
throw new IllegalArgumentException(
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/com/microsoft/sqlserver/jdbc/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -981,6 +981,17 @@ static synchronized boolean checkIfNeedNewAccessToken(SQLServerConnection connec
static boolean use43Wrapper() {
return use43Wrapper;
}

/**
* Escapes single quotes (') in object name to convert and pass it as String safely.
*
* @param name
* Object name to be passed as String
* @return Converted object name
*/
static String escapeSingleQuotes(String name) {
return name.replace("'", "''");
}
}


Expand Down
Loading