]> source.dussan.org Git - jackcess.git/commitdiff
add some more query read tests
authorJames Ahlborn <jtahlborn@yahoo.com>
Thu, 28 May 2009 14:30:33 +0000 (14:30 +0000)
committerJames Ahlborn <jtahlborn@yahoo.com>
Thu, 28 May 2009 14:30:33 +0000 (14:30 +0000)
git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@394 f203690c-595d-4dc9-a70b-905162fa7fd2

src/java/com/healthmarketscience/jackcess/query/Query.java
src/java/com/healthmarketscience/jackcess/query/UnionQuery.java
test/data/queryTest.mdb
test/src/java/com/healthmarketscience/jackcess/query/QueryTest.java

index 08f6f484b23d068e046716fa4f78f0b849111185..acc0954f620ee9732f57632b5fc2a5a093234453 100644 (file)
@@ -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);
index 05f0c51aa4fad6f972222a0c02a6e42895cefee2..3534a7081ab714c56f25778ac9e7d91999e3fc0a 100644 (file)
@@ -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);
+  }
+
 }
index 5bb6b28d70adb933073c1232297387dd0c1bb0bb..456071001b0dbd14164337f28e78856e20a4b4b9 100755 (executable)
Binary files a/test/data/queryTest.mdb and b/test/data/queryTest.mdb differ
index 5d243074b03ed9fb76b21342a31a67576777dec0..d1f8eac77511ec55793c6509ec9c34c58844c774 100644 (file)
@@ -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();
   }