#1193 - For RawSql ignore the Postgres cast double colon like ::text

This commit is contained in:
rob bygrave
2017-11-02 00:03:38 +13:00
parent 66fe278e3f
commit 10eb2bc21f
4 changed files with 89 additions and 4 deletions
@@ -160,4 +160,26 @@ public class TestRawSqlColumnParsing extends TestCase {
}
public void test_doubleColon() {
ColumnMapping columnMapping = DRawSqlColumnsParser.parse("a,MD5(id::text) as b,c");
Map<String, Column> mapping = columnMapping.mapping();
Column c = mapping.get("a");
assertEquals("a", c.getDbColumn());
assertEquals(0, c.getIndexPos());
assertEquals("a", c.getPropertyName());
c = mapping.get("b");
assertEquals("MD5(id::text)", c.getDbColumn());
assertEquals(1, c.getIndexPos());
assertEquals("b", c.getPropertyName());
c = mapping.get("c");
assertEquals("c", c.getDbColumn());
assertEquals(2, c.getIndexPos());
assertEquals("c", c.getPropertyName());
}
}
@@ -1,12 +1,24 @@
package io.ebeaninternal.server.rawsql;
import io.ebean.BaseTestCase;
import io.ebean.Ebean;
import io.ebean.RawSql;
import io.ebeaninternal.server.rawsql.SpiRawSql.Sql;
import io.ebean.RawSqlBuilder;
import junit.framework.TestCase;
import io.ebean.annotation.ForPlatform;
import io.ebean.annotation.Platform;
import io.ebeaninternal.server.rawsql.SpiRawSql.Sql;
import org.junit.Test;
import org.tests.model.basic.Customer;
import org.tests.model.basic.ResetBasicData;
public class TestRawSqlParsing extends TestCase {
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertTrue;
public class TestRawSqlParsing extends BaseTestCase {
@Test
public void test() {
String sql
@@ -24,6 +36,25 @@ public class TestRawSqlParsing extends TestCase {
String s = rs.toString();
assertTrue(s, s.contains("[order_id, sum"));
}
@Test
@ForPlatform(Platform.POSTGRES)
public void testDoubleColon() {
ResetBasicData.reset();
String sql = "select id, name from o_customer where name=:name and MD5(id::text) BETWEEN '00000000000000000000000000000000' AND 'ffffffffffffffffffffffffffffffff'";
RawSql rawSql = RawSqlBuilder
.parse(sql)
.create();
List<Customer> list = Ebean.createQuery(Customer.class)
.setRawSql(rawSql)
.setParameter("name", "Rob")
.findList();
assertThat(list).isNotEmpty();
}
}
@@ -32,4 +32,19 @@ public class BindParamsParserTest {
assertEquals("delete from foo where id in (?,?,?,?)", sql1);
}
@Test
public void findNameStart() {
assertEquals(5, BindParamsParser.findNameStart("some :name = ?", 0));
}
@Test
public void findNameStart_doubleColon() {
assertEquals(-1, BindParamsParser.findNameStart("some ::name = ?", 0));
}
@Test
public void findNameStart_doubleColonSkip() {
assertEquals(10, BindParamsParser.findNameStart("some ::na :a = ?", 0));
}
}