提交 6dc3587d authored 作者: Thomas Mueller's avatar Thomas Mueller

Issue 119: JaQu creates wrong WHERE condition on some inputs.

上级 07c5a909
...@@ -18,7 +18,8 @@ Change Log ...@@ -18,7 +18,8 @@ Change Log
<h1>Change Log</h1> <h1>Change Log</h1>
<h2>Next Version (unreleased)</h2> <h2>Next Version (unreleased)</h2>
<ul><li>SELECT COUNT(*) FROM SYSTEM_RANGE(...) returned the wrong result. Fixed. <ul><li>Issue 119: JaQu creates wrong WHERE condition on some inputs.
</li><li>SELECT COUNT(*) FROM SYSTEM_RANGE(...) returned the wrong result. Fixed.
</li><li>The Recover tool now also processes the log files, however applying those changes </li><li>The Recover tool now also processes the log files, however applying those changes
is still a manual process. is still a manual process.
</li><li>New sample application that shows how to pass data to a trigger. </li><li>New sample application that shows how to pass data to a trigger.
......
...@@ -60,6 +60,7 @@ import org.h2.test.db.TestTransaction; ...@@ -60,6 +60,7 @@ import org.h2.test.db.TestTransaction;
import org.h2.test.db.TestTriggersConstraints; import org.h2.test.db.TestTriggersConstraints;
import org.h2.test.db.TestTwoPhaseCommit; import org.h2.test.db.TestTwoPhaseCommit;
import org.h2.test.db.TestView; import org.h2.test.db.TestView;
import org.h2.test.jaqu.AliasMapTest;
import org.h2.test.jaqu.SamplesTest; import org.h2.test.jaqu.SamplesTest;
import org.h2.test.jdbc.TestBatchUpdates; import org.h2.test.jdbc.TestBatchUpdates;
import org.h2.test.jdbc.TestCallableStatement; import org.h2.test.jdbc.TestCallableStatement;
...@@ -521,6 +522,7 @@ kill -9 `jps -l | grep "org.h2.test." | cut -d " " -f 1` ...@@ -521,6 +522,7 @@ kill -9 `jps -l | grep "org.h2.test." | cut -d " " -f 1`
new TestView().runTest(this); new TestView().runTest(this);
// jaqu // jaqu
new AliasMapTest().runTest(this);
new SamplesTest().runTest(this); new SamplesTest().runTest(this);
// jdbc // jdbc
......
/*
* Copyright 2004-2009 H2 Group. Multiple-Licensed under the H2 License,
* Version 1.0, and under the Eclipse Public License, Version 1.0
* (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package org.h2.test.jaqu;
import java.util.List;
import org.h2.jaqu.Db;
import org.h2.test.TestBase;
/**
* Tests that columns (p.unitsInStock) are not compared by value with the value
* (9), but by reference (using an identity hash map).
* See http://code.google.com/p/h2database/issues/detail?id=119
*
* @author d moebius at scoop slash gmbh dot de
*/
public class AliasMapTest extends TestBase {
/**
* This method is called when executing this application from the command
* line.
*
* @param args the command line parameters
*/
public static void main(String[] args) throws Exception {
new AliasMapTest().test();
}
public void test() throws Exception {
Db db = Db.open("jdbc:h2:mem:", "sa", "sa");
db.insertAll(Product.getList());
Product p = new Product();
List<Product> products = db
.from(p)
.where(p.unitsInStock).is(9)
.orderBy(p.productId).select();
assertEquals("[]", products.toString());
}
}
...@@ -27,6 +27,7 @@ import org.h2.test.TestBase; ...@@ -27,6 +27,7 @@ import org.h2.test.TestBase;
* no more SQL injection.</p> * no more SQL injection.</p>
*/ */
public class SamplesTest extends TestBase { public class SamplesTest extends TestBase {
/** /**
* This object represents a database (actually a connection to the database). * This object represents a database (actually a connection to the database).
*/ */
...@@ -141,7 +142,6 @@ public class SamplesTest extends TestBase { ...@@ -141,7 +142,6 @@ public class SamplesTest extends TestBase {
expensiveInStockProducts.toString()); expensiveInStockProducts.toString());
} }
private void testWhereSimple4() { private void testWhereSimple4() {
// var waCustomers = // var waCustomers =
......
...@@ -11,12 +11,10 @@ import java.lang.reflect.Field; ...@@ -11,12 +11,10 @@ import java.lang.reflect.Field;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.IdentityHashMap;
import java.util.List; import java.util.List;
import org.h2.jaqu.util.ClassReader; import org.h2.jaqu.util.ClassReader;
import org.h2.jaqu.util.Utils; import org.h2.jaqu.util.Utils;
//## Java 1.5 end ##
/** /**
* This class represents a query. * This class represents a query.
...@@ -30,7 +28,7 @@ public class Query<T> { ...@@ -30,7 +28,7 @@ public class Query<T> {
private SelectTable<T> from; private SelectTable<T> from;
private ArrayList<Token> conditions = Utils.newArrayList(); private ArrayList<Token> conditions = Utils.newArrayList();
private ArrayList<SelectTable< ? >> joins = Utils.newArrayList(); private ArrayList<SelectTable< ? >> joins = Utils.newArrayList();
private final HashMap<Object, SelectColumn<T>> aliasMap = Utils.newHashMap(); private final IdentityHashMap<Object, SelectColumn<T>> aliasMap = Utils.newIdentityHashMap();
private ArrayList<OrderExpression<T>> orderByList = Utils.newArrayList(); private ArrayList<OrderExpression<T>> orderByList = Utils.newArrayList();
private Object[] groupByExpressions; private Object[] groupByExpressions;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论