switched to create the PreparedStatementCreatorFactory using a list of SqlParameters to preserve type names (SPR-7699)

This commit is contained in:
Thomas Risberg
2011-02-09 13:58:30 +00:00
parent 91debc3a35
commit 939da34869
3 changed files with 48 additions and 10 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2008 the original author or authors.
* Copyright 2002-2011 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -99,6 +99,22 @@ public class NamedParameterUtilsTests {
.buildSqlTypeArray(NamedParameterUtils.parseSqlStatement("xxx :a :b :c xx :a :b"), namedParams)[4]);
}
@Test
public void convertTypeMapToSqlParameterList() {
MapSqlParameterSource namedParams = new MapSqlParameterSource();
namedParams.addValue("a", "a", 1).addValue("b", "b", 2).addValue("c", "c", 3, "SQL_TYPE");
assertSame(3, NamedParameterUtils
.buildSqlParameterList(NamedParameterUtils.parseSqlStatement("xxx :a :b :c"), namedParams).size());
assertSame(5, NamedParameterUtils
.buildSqlParameterList(NamedParameterUtils.parseSqlStatement("xxx :a :b :c xx :a :b"), namedParams).size());
assertSame(5, NamedParameterUtils
.buildSqlParameterList(NamedParameterUtils.parseSqlStatement("xxx :a :a :a xx :a :a"), namedParams).size());
assertEquals(2, NamedParameterUtils
.buildSqlParameterList(NamedParameterUtils.parseSqlStatement("xxx :a :b :c xx :a :b"), namedParams).get(4).getSqlType());
assertEquals("SQL_TYPE", NamedParameterUtils
.buildSqlParameterList(NamedParameterUtils.parseSqlStatement("xxx :a :b :c"), namedParams).get(2).getTypeName());
}
@Test(expected = InvalidDataAccessApiUsageException.class)
public void buildValueArrayWithMissingParameterValue() throws Exception {
String sql = "select count(0) from foo where id = :id";