summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJames Ahlborn <jtahlborn@yahoo.com>2009-05-28 14:30:33 +0000
committerJames Ahlborn <jtahlborn@yahoo.com>2009-05-28 14:30:33 +0000
commitaeab15c5c14b3d9de43bb5f97c368694b6f7625e (patch)
tree61e3e502ee63c5bdfd6089a97801b1d3c071b7af
parentcd23b435686872ea0abd59568be5bd2bd1994858 (diff)
downloadjackcess-aeab15c5c14b3d9de43bb5f97c368694b6f7625e.tar.gz
jackcess-aeab15c5c14b3d9de43bb5f97c368694b6f7625e.zip
add some more query read tests
git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@394 f203690c-595d-4dc9-a70b-905162fa7fd2
-rw-r--r--src/java/com/healthmarketscience/jackcess/query/Query.java3
-rw-r--r--src/java/com/healthmarketscience/jackcess/query/UnionQuery.java7
-rwxr-xr-xtest/data/queryTest.mdbbin163840 -> 176128 bytes
-rw-r--r--test/src/java/com/healthmarketscience/jackcess/query/QueryTest.java35
4 files changed, 36 insertions, 9 deletions
diff --git a/src/java/com/healthmarketscience/jackcess/query/Query.java b/src/java/com/healthmarketscience/jackcess/query/Query.java
index 08f6f48..acc0954 100644
--- a/src/java/com/healthmarketscience/jackcess/query/Query.java
+++ b/src/java/com/healthmarketscience/jackcess/query/Query.java
@@ -31,7 +31,6 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
-import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
@@ -586,7 +585,7 @@ public abstract class Query
public Map<String,Object> toTableRow()
{
- Map<String,Object> tableRow = new HashMap<String,Object>();
+ Map<String,Object> tableRow = new LinkedHashMap<String,Object>();
tableRow.put(COL_ATTRIBUTE, attribute);
tableRow.put(COL_EXPRESSION, expression);
diff --git a/src/java/com/healthmarketscience/jackcess/query/UnionQuery.java b/src/java/com/healthmarketscience/jackcess/query/UnionQuery.java
index 05f0c51..3534a70 100644
--- a/src/java/com/healthmarketscience/jackcess/query/UnionQuery.java
+++ b/src/java/com/healthmarketscience/jackcess/query/UnionQuery.java
@@ -63,7 +63,7 @@ public class UnionQuery extends Query
private String getUnionString(String id) {
for(Row row : getTableRows()) {
if(id.equals(row.name2)) {
- return row.expression;
+ return cleanUnionString(row.expression);
}
}
throw new IllegalStateException(
@@ -86,4 +86,9 @@ public class UnionQuery extends Query
}
}
+ private static String cleanUnionString(String str)
+ {
+ return str.trim().replaceAll("[\r\n]+", NEWLINE);
+ }
+
}
diff --git a/test/data/queryTest.mdb b/test/data/queryTest.mdb
index 5bb6b28..4560710 100755
--- a/test/data/queryTest.mdb
+++ b/test/data/queryTest.mdb
Binary files differ
diff --git a/test/src/java/com/healthmarketscience/jackcess/query/QueryTest.java b/test/src/java/com/healthmarketscience/jackcess/query/QueryTest.java
index 5d24307..d1f8eac 100644
--- a/test/src/java/com/healthmarketscience/jackcess/query/QueryTest.java
+++ b/test/src/java/com/healthmarketscience/jackcess/query/QueryTest.java
@@ -202,7 +202,7 @@ public class QueryTest extends TestCase
Map<String,String> expectedQueries = new HashMap<String,String>();
expectedQueries.put(
"SelectQuery", multiline(
- "SELECT Table1.*, Table2.col1, Table2.col2, Table3.col3",
+ "SELECT DISTINCT Table1.*, Table2.col1, Table2.col2, Table3.col3",
"FROM (Table1 LEFT OUTER JOIN Table3 ON Table1.col1 = Table3.col1) INNER JOIN Table2 ON (Table3.col1 = Table2.col1) AND (Table3.col1 = Table2.col2)",
"WHERE (((Table2.col2)=\"foo\" Or (Table2.col2) In (\"buzz\",\"bazz\")))",
"ORDER BY Table2.col1;"));
@@ -218,24 +218,47 @@ public class QueryTest extends TestCase
"FROM Table3, Table1 INNER JOIN Table2 ON [Table1].[col1]=[Table2].[col1];"));
expectedQueries.put(
"UpdateQuery",multiline(
+ "PARAMETERS User Name Text;",
"UPDATE Table1",
- "SET Table1.col1 = \"foo\", Table1.col2 = [Table2].[col3]",
- "WHERE (([Table2].[col1] Is Not Null));"));
+ "SET Table1.col1 = \"foo\", Table1.col2 = [Table2].[col3], [[Table2]].[[col1]] = [User Name]",
+ "WHERE ((([Table2].[col1]) Is Not Null));"));
expectedQueries.put(
"MakeTableQuery",multiline(
"SELECT Max(Table2.col1) AS MaxOfcol1, Table2.col2, Table3.col2 INTO Table4",
"FROM (Table2 INNER JOIN Table1 ON Table2.col1 = Table1.col2) RIGHT OUTER JOIN Table3 ON Table1.col2 = Table3.col3",
"GROUP BY Table2.col2, Table3.col2",
"HAVING (((Max(Table2.col1))=\"buzz\") AND ((Table2.col2)<>\"blah\"));"));
+ expectedQueries.put(
+ "CrosstabQuery", multiline(
+ "TRANSFORM Count([Table2].[col2]) AS CountOfcol2",
+ "SELECT Table2_1.col1, [Table2].[col3], Avg(Table2_1.col2) AS AvgOfcol2",
+ "FROM (Table1 INNER JOIN Table2 ON [Table1].[col1]=[Table2].[col1]) INNER JOIN Table2 AS Table2_1 ON [Table2].[col1]=Table2_1.col3",
+ "WHERE ((([Table1].[col1])>\"10\") And ((Table2_1.col1) Is Not Null) And ((Avg(Table2_1.col2))>\"10\"))",
+ "GROUP BY Table2_1.col1, [Table2].[col3]",
+ "ORDER BY [Table2].[col3]",
+ "PIVOT [Table1].[col1];"));
+ expectedQueries.put(
+ "UnionQuery", multiline(
+ "Select Table1.col1, Table1.col2",
+ "where Table1.col1 = \"foo\"",
+ "UNION",
+ "Select Table2.col1, Table2.col2",
+ "UNION ALL Select Table3.col1, Table3.col2",
+ "where Table3.col3 > \"blah\";"));
+ expectedQueries.put(
+ "PassthroughQuery", multiline(
+ "ALTER TABLE Table4 DROP COLUMN col5;\0"));
+ expectedQueries.put(
+ "DataDefinitionQuery", multiline(
+ "CREATE TABLE Table5 (col1 CHAR, col2 CHAR);\0"));
Database db = DatabaseTest.open(new File("test/data/queryTest.mdb"));
- Map<String,String> foundQueries = new HashMap<String,String>();
for(Query q : db.getQueries()) {
- assertNull(foundQueries.put(q.getName(), q.toSQLString()));
+ assertEquals(expectedQueries.remove(q.getName()), q.toSQLString());
}
- assertEquals(expectedQueries, foundQueries);
+ assertTrue(expectedQueries.isEmpty());
db.close();
}