Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 1.17.0
- Fix prepared statements to use 1-based indexes, See #117


# :construction: 1.6
- Fixing exceptions in metadata class.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ String createSqlQuery() throws SQLException {
log.error("Not enough parameters to replace placeholders in query.");
throw new SQLException("Not enough parameters");
}
Object parameter = parameters.get(parameterIndex++);
Object parameter = parameters.get(++parameterIndex);
sqlQuery = sqlQuery.replaceFirst("\\?", parameter == null ? "null" : parameter.toString());
}
return sqlQuery;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@ public void init() {

@Test
public void testWildCardReplacementForPreparedStatement() throws SQLException {
preparedStatement.setString(0, "Angella");
preparedStatement.setInt(1, 1000);
preparedStatement.setString(1, "Angella");
preparedStatement.setInt(2, 1000);
String sql = preparedStatement.createSqlQuery();
Assert.assertEquals(sql, "select FirstName__c, BirthDate__c, YearlyIncome__c from Individual__dlm where FirstName__c = 'Angella' and YearlyIncome__c > 1000");
}

@Test
public void testSqlWithoutEnoughParameters() throws SQLException {
preparedStatement.setString(0, "Angella");
preparedStatement.setString(1, "Angella");
exceptionRule.expect(SQLException.class);
exceptionRule.expectMessage("Not enough parameters");
preparedStatement.createSqlQuery();
Expand All @@ -67,7 +67,7 @@ public void testSqlWithDateParameter() throws SQLException {
Date date = new Date(System.currentTimeMillis());
preparedStatement = new QueryServicePreparedStatement(connection, "select FirstName__c, BirthDate__c from Individual__dlm where BirthDate__c > ?", ResultSet.TYPE_FORWARD_ONLY,
ResultSet.CONCUR_READ_ONLY);
preparedStatement.setDate(0, date);
preparedStatement.setDate(1, date);
String sql = preparedStatement.createSqlQuery();
Assert.assertEquals(sql, "select FirstName__c, BirthDate__c from Individual__dlm where BirthDate__c > " + date.toString());
}
Expand Down