Permalink
Browse files

Remove quotes from everywhere else in testdb.ddl except for a couple …

…of targeted places, and fix an issue with quoting in orderBy() on QueryResult
  • Loading branch information...
1 parent b77da05 commit 8b73cfc27213acc9b223c01efa653aac074f73a5 @akeefer-guidewire akeefer-guidewire committed Feb 8, 2012
@@ -16,6 +16,7 @@ uses java.lang.System
uses tosa.dbmd.PreparedStatementParameterImpl
uses java.sql.Types
uses java.util.NoSuchElementException
+uses tosa.api.IDBColumn
/**
* Created by IntelliJ IDEA.
@@ -195,7 +196,8 @@ public class QueryResultImpl<T> implements QueryResult<T> {
return _sql
} else {
// TODO - AHK - Quoting
- return "\"" + _sortColumn.PropertyInfo["ColumnName"] + "\"" + (_direction == ASC ? " ASC" : " DESC")
+ var column = _sortColumn.PropertyInfo["Column"] as IDBColumn
+ return column.PossiblyQuotedName + (_direction == ASC ? " ASC" : " DESC")
}
}
}
@@ -7,6 +7,7 @@
import gw.lang.reflect.PropertyInfoBase;
import gw.lang.reflect.TypeSystem;
import tosa.CachedDBObject;
+import tosa.api.IDBColumn;
import tosa.api.IDBObject;
import tosa.dbmd.DBColumnImpl;
import tosa.db.execution.QueryExecutor;
@@ -90,6 +91,10 @@ public String getColumnName() {
return _column.getName();
}
+ public IDBColumn getColumn() {
+ return _column;
+ }
+
private class DBPropertyAccessor implements IPropertyAccessor {
@Override
public void setValue(Object ctx, Object value) {
View
@@ -1,42 +1,42 @@
CREATE TABLE Bar(
- "id" BIGINT PRIMARY KEY AUTO_INCREMENT,
+ id BIGINT PRIMARY KEY AUTO_INCREMENT,
Date DATE,
Misc VARCHAR(50)
);
-CREATE TABLE "SortPage"(
- "id" BIGINT PRIMARY KEY AUTO_INCREMENT,
- "Number" INT
+CREATE TABLE SortPage(
+ id BIGINT PRIMARY KEY AUTO_INCREMENT,
+ Number INT
);
CREATE TABLE ForOrderByTests (
- "id" BIGINT PRIMARY KEY AUTO_INCREMENT,
+ id BIGINT PRIMARY KEY AUTO_INCREMENT,
Number INT,
Date DATE,
Str VARCHAR(50),
Str2 VARCHAR(50)
);
CREATE TABLE ForGroupByTests (
- "id" BIGINT PRIMARY KEY AUTO_INCREMENT,
+ id BIGINT PRIMARY KEY AUTO_INCREMENT,
Number INT,
Date DATE,
Str VARCHAR(50),
Str2 VARCHAR(50)
);
CREATE TABLE ForNumericTests (
- "id" BIGINT PRIMARY KEY AUTO_INCREMENT,
+ id BIGINT PRIMARY KEY AUTO_INCREMENT,
Number INT
);
-CREATE TABLE "Foo"(
- "id" BIGINT PRIMARY KEY AUTO_INCREMENT,
- "FirstName" VARCHAR(50),
- "LastName" VARCHAR(50),
- "Bar_id" BIGINT,
- "Address" TEXT,
- "Named_SortPage_id" BIGINT
+CREATE TABLE Foo(
+ id BIGINT PRIMARY KEY AUTO_INCREMENT,
+ FirstName VARCHAR(50),
+ LastName VARCHAR(50),
+ Bar_id BIGINT,
+ Address TEXT,
+ Named_SortPage_id BIGINT
);
CREATE TABLE "Baz"(
@@ -49,13 +49,13 @@ CREATE TABLE "join_Foo_Baz"(
"Baz_id" BIGINT
);
-CREATE TABLE "Relatives_join_Bar_Baz"(
- "Bar_id" BIGINT,
- "Baz_id" BIGINT
+CREATE TABLE Relatives_join_Bar_Baz(
+ Bar_id BIGINT,
+ Baz_id BIGINT
);
-CREATE TABLE "SelfJoins_join_Baz_Baz"(
- "id" BIGINT PRIMARY KEY AUTO_INCREMENT,
- "Baz_src_id" BIGINT,
- "Baz_dest_id" BIGINT
+CREATE TABLE SelfJoins_join_Baz_Baz(
+ id BIGINT PRIMARY KEY AUTO_INCREMENT,
+ Baz_src_id BIGINT,
+ Baz_dest_id BIGINT
);
@@ -486,9 +486,9 @@ public void testRemoveWillNullOutCachedFkObjectOnElement() {
private int countMatchesInDB(IDBObject foo, IDBObject bar) {
String sql = SimpleSqlBuilder.substitute("SELECT count(*) as count FROM ${fooTable} WHERE ${idColumn} = ${fooId} AND ${barColumn} = ${barId}",
"fooTable", foo.getDBTable(),
- "idColumn", "\"id\"",
+ "idColumn", "id",
"fooId", foo.getId(),
- "barColumn", "\"Bar_id\"",
+ "barColumn", "Bar_id",
"barId", bar.getId());
return new QueryExecutorImpl(getDB()).count("", sql);
}
@@ -156,7 +156,7 @@ class DBTypeInfoSelectTest {
var foo2 = new Foo(){:Bar = bar2, :FirstName = "Alice"}
foo2.update()
- var result = Bar.select("SELECT * FROM Bar INNER JOIN \"Foo\" ON \"Foo\".\"Bar_id\" = Bar.\"id\" WHERE \"Foo\".\"FirstName\" = :arg", {"arg" -> "Bob"})
+ var result = Bar.select("SELECT * FROM Bar INNER JOIN Foo ON Foo.Bar_id = Bar.id WHERE Foo.FirstName = :arg", {"arg" -> "Bob"})
Assert.assertEquals(1, result.Count)
assertMatch(bar, result.get(0))
}
@@ -166,7 +166,7 @@ class DBTypeInfoSelectTest {
var foo = createFoo("Bob", "Bob")
var foo2 = createFoo("Bob", "Other")
- var result = Foo.select("SELECT * FROM \"Foo\" WHERE \"FirstName\" = :arg AND \"LastName\" = :arg", {"arg" -> "Bob"})
+ var result = Foo.select("SELECT * FROM Foo WHERE FirstName = :arg AND LastName = :arg", {"arg" -> "Bob"})
Assert.assertEquals(1, result.Count)
assertMatch(foo, result.get(0))
}
@@ -176,7 +176,7 @@ class DBTypeInfoSelectTest {
var foo = createFoo("Bob", "Bob")
var foo2 = createFoo("Bob", "Other")
- var result = Foo.select("SELECT * FROM \"Foo\" WHERE \"FirstName\" = :arg AND \"LastName\" = :arg", {"arg" -> "Bob", "arg2" -> "Other", "arg3" -> "Hrm"})
+ var result = Foo.select("SELECT * FROM Foo WHERE FirstName = :arg AND LastName = :arg", {"arg" -> "Bob", "arg2" -> "Other", "arg3" -> "Hrm"})
Assert.assertEquals(1, result.Count)
assertMatch(foo, result.get(0))
}
@@ -186,7 +186,7 @@ class DBTypeInfoSelectTest {
var foo = createFoo("Bob", "Bob")
var foo2 = createFoo("Bob", "Other")
- var result = Foo.select("SELECT * FROM \"Foo\" WHERE \"FirstName\" = ':arg' AND \"LastName\" = ':arg'")
+ var result = Foo.select("SELECT * FROM Foo WHERE FirstName = ':arg' AND LastName = ':arg'")
Assert.assertEquals(0, result.Count)
}
@@ -196,7 +196,7 @@ class DBTypeInfoSelectTest {
var foo2 = createFoo("Bob", "Other")
try {
- var result = Foo.select("SELECT * FROM \"Foo\" WHERE \"FirstName\" = :arg AND \"LastName\" = :arg", {"arrg" -> "Bob"})
+ var result = Foo.select("SELECT * FROM Foo WHERE FirstName = :arg AND LastName = :arg", {"arrg" -> "Bob"})
Assert.fail("Expected an IllegalArgumentException")
} catch (e : IllegalArgumentException) {
Assert.assertEquals("No value for the token arg was found in the map", e.Message)
@@ -208,16 +208,16 @@ class DBTypeInfoSelectTest {
var foo = createFoo("Bob", "Bob")
var foo2 = createFoo("Bob", "Other")
- var result = Foo.select("SELECT * FROM \"Foo\" WHERE \"FirstName\" = '\\:arg' AND \"LastName\" = :arg", {"arg" -> "Bob"})
+ var result = Foo.select("SELECT * FROM Foo WHERE FirstName = '\\:arg' AND LastName = :arg", {"arg" -> "Bob"})
Assert.assertEquals(0, result.Count)
}
@Test
function testSelectWithStringNotStartingWithSelectStartFromThrowsIllegalArgumentException() {
try {
- Foo.select("SELECT id FROM \"Foo\" WHERE \"FirstName\" = 'Bob'")
+ Foo.select("SELECT id FROM Foo WHERE FirstName = 'Bob'")
} catch (e : IllegalArgumentException) {
- Assert.assertEquals("The select(String, Map) method must always be called with 'SELECT * FROM' as the start of the statement. The sql passed in was SELECT id FROM \"Foo\" WHERE \"FirstName\" = 'Bob'", e.Message)
+ Assert.assertEquals("The select(String, Map) method must always be called with 'SELECT * FROM' as the start of the statement. The sql passed in was SELECT id FROM Foo WHERE FirstName = 'Bob'", e.Message)
}
}
@@ -226,7 +226,7 @@ class DBTypeInfoSelectTest {
var foo = createFoo("Bob", "Bob")
var foo2 = createFoo("Bob", "Other")
- var result = Foo.select("Select * From \"Foo\" WHERE \"FirstName\" = :arg AND \"LastName\" = :arg", {"arg" -> "Bob", "arg2" -> "Other", "arg3" -> "Hrm"})
+ var result = Foo.select("Select * From Foo WHERE FirstName = :arg AND LastName = :arg", {"arg" -> "Bob", "arg2" -> "Other", "arg3" -> "Hrm"})
assertMatch(foo, result.get(0))
}
@@ -320,7 +320,7 @@ class DBTypeInfoSelectTest {
var foo = createFoo("Bob", "Bob")
var foo2 = createFoo("Bob", "Other")
- var result = Foo.selectWhere("\"FirstName\" = :arg AND \"LastName\" = :arg", {"arg" -> "Bob"})
+ var result = Foo.selectWhere("FirstName = :arg AND LastName = :arg", {"arg" -> "Bob"})
Assert.assertEquals(1, result.Count)
assertMatch(foo, result.get(0))
}
@@ -330,7 +330,7 @@ class DBTypeInfoSelectTest {
var foo = createFoo("Bob", "Bob")
var foo2 = createFoo("Bob", "Other")
- var result = Foo.selectWhere("\"FirstName\" = :arg AND \"LastName\" = :arg", {"arg" -> "Bob", "arg2" -> "Other", "arg3" -> "Hrm"})
+ var result = Foo.selectWhere("FirstName = :arg AND LastName = :arg", {"arg" -> "Bob", "arg2" -> "Other", "arg3" -> "Hrm"})
Assert.assertEquals(1, result.Count)
assertMatch(foo, result.get(0))
}
@@ -340,7 +340,7 @@ class DBTypeInfoSelectTest {
var foo = createFoo("Bob", "Bob")
var foo2 = createFoo("Bob", "Other")
- var result = Foo.selectWhere("\"FirstName\" = ':arg' AND \"LastName\" = ':arg'")
+ var result = Foo.selectWhere("FirstName = ':arg' AND LastName = ':arg'")
Assert.assertEquals(0, result.Count)
}
@@ -350,7 +350,7 @@ class DBTypeInfoSelectTest {
var foo2 = createFoo("Bob", "Other")
try {
- var result = Foo.selectWhere("\"FirstName\" = :arg AND \"LastName\" = :arg", {"arrg" -> "Bob"})
+ var result = Foo.selectWhere("FirstName = :arg AND LastName = :arg", {"arrg" -> "Bob"})
Assert.fail("Expected an IllegalArgumentException")
} catch (e : IllegalArgumentException) {
Assert.assertEquals("No value for the token arg was found in the map", e.Message)
@@ -362,20 +362,20 @@ class DBTypeInfoSelectTest {
var foo = createFoo("Bob", "Bob")
var foo2 = createFoo("Bob", "Other")
- var result = Foo.selectWhere("\"FirstName\" = '\\:arg' AND \"LastName\" = :arg", {"arg" -> "Bob"})
+ var result = Foo.selectWhere("FirstName = '\\:arg' AND LastName = :arg", {"arg" -> "Bob"})
Assert.assertEquals(0, result.Count)
}
@Test
function testSelectWhereStartingWithSelectThrowsIllegalArgumentException() {
- assertException(\ -> Foo.selectWhere("SELECT * FROM \"Foo\" WHERE \"FirstName\" = 'Bob'"),
+ assertException(\ -> Foo.selectWhere("SELECT * FROM Foo WHERE FirstName = 'Bob'"),
IllegalArgumentException,
"The selectWhere(String, Map) method should only be called with the WHERE clause of a query. To specify the full SQL for the query, use the select(String, Map) method instead.")
}
@Test
function testSelectWhereStartingWithSelectInAlternateCaseThrowsIllegalArgumentException() {
- assertException(\ -> Foo.selectWhere("Select * from \"Foo\" WHERE \"FirstName\" = 'Bob'"),
+ assertException(\ -> Foo.selectWhere("Select * from Foo WHERE FirstName = 'Bob'"),
IllegalArgumentException,
"The selectWhere(String, Map) method should only be called with the WHERE clause of a query. To specify the full SQL for the query, use the select(String, Map) method instead.")
}
@@ -425,7 +425,7 @@ class DBTypeInfoSelectTest {
var foo2 = new Foo(){:Bar = bar2, :FirstName = "Alice"}
foo2.update()
- var result = Bar.count("SELECT count(*) as count FROM Bar INNER JOIN \"Foo\" ON \"Foo\".\"Bar_id\" = Bar.\"id\" WHERE \"Foo\".\"FirstName\" = :arg", {"arg" -> "Bob"})
+ var result = Bar.count("SELECT count(*) as count FROM Bar INNER JOIN Foo ON Foo.Bar_id = Bar.id WHERE Foo.FirstName = :arg", {"arg" -> "Bob"})
Assert.assertEquals(1, result)
}
@@ -434,7 +434,7 @@ class DBTypeInfoSelectTest {
var foo = createFoo("Bob", "Bob")
var foo2 = createFoo("Bob", "Other")
- var result = Foo.count("SELECT count(*) as count FROM \"Foo\" WHERE \"FirstName\" = :arg AND \"LastName\" = :arg", {"arg" -> "Bob"})
+ var result = Foo.count("SELECT count(*) as count FROM Foo WHERE FirstName = :arg AND LastName = :arg", {"arg" -> "Bob"})
Assert.assertEquals(1, result)
}
@@ -443,7 +443,7 @@ class DBTypeInfoSelectTest {
var foo = createFoo("Bob", "Bob")
var foo2 = createFoo("Bob", "Other")
- var result = Foo.count("SELECT count(*) as count FROM \"Foo\" WHERE \"FirstName\" = :arg AND \"LastName\" = :arg", {"arg" -> "Bob", "arg2" -> "Other", "arg3" -> "Hrm"})
+ var result = Foo.count("SELECT count(*) as count FROM Foo WHERE FirstName = :arg AND LastName = :arg", {"arg" -> "Bob", "arg2" -> "Other", "arg3" -> "Hrm"})
Assert.assertEquals(1, result)
}
@@ -452,7 +452,7 @@ class DBTypeInfoSelectTest {
var foo = createFoo("Bob", "Bob")
var foo2 = createFoo("Bob", "Other")
- var result = Foo.count("SELECT count(*) as count FROM \"Foo\" WHERE \"FirstName\" = ':arg' AND \"LastName\" = ':arg'")
+ var result = Foo.count("SELECT count(*) as count FROM Foo WHERE FirstName = ':arg' AND LastName = ':arg'")
Assert.assertEquals(0, result)
}
@@ -462,7 +462,7 @@ class DBTypeInfoSelectTest {
var foo2 = createFoo("Bob", "Other")
try {
- var result = Foo.count("SELECT count(*) as count FROM \"Foo\" WHERE \"FirstName\" = :arg AND \"LastName\" = :arg", {"arrg" -> "Bob"})
+ var result = Foo.count("SELECT count(*) as count FROM Foo WHERE FirstName = :arg AND LastName = :arg", {"arrg" -> "Bob"})
Assert.fail("Expected an IllegalArgumentException")
} catch (e : IllegalArgumentException) {
Assert.assertEquals("No value for the token arg was found in the map", e.Message)
@@ -474,16 +474,16 @@ class DBTypeInfoSelectTest {
var foo = createFoo("Bob", "Bob")
var foo2 = createFoo("Bob", "Other")
- var result = Foo.count("SELECT count(*) as count FROM \"Foo\" WHERE \"FirstName\" = '\\:arg' AND \"LastName\" = :arg", {"arg" -> "Bob"})
+ var result = Foo.count("SELECT count(*) as count FROM Foo WHERE FirstName = '\\:arg' AND LastName = :arg", {"arg" -> "Bob"})
Assert.assertEquals(0, result)
}
@Test
function testCountWithStringNotStartingWithSelectCountStarAsCountFromThrowsIllegalArgumentException() {
try {
- Foo.count("SELECT id FROM \"Foo\" WHERE \"FirstName\" = 'Bob'")
+ Foo.count("SELECT id FROM Foo WHERE FirstName = 'Bob'")
} catch (e : IllegalArgumentException) {
- Assert.assertEquals("The count(String, Map) method must always be called with 'SELECT count(*) as count FROM' as the start of the statement. The sql passed in was SELECT id FROM \"Foo\" WHERE \"FirstName\" = 'Bob'", e.Message)
+ Assert.assertEquals("The count(String, Map) method must always be called with 'SELECT count(*) as count FROM' as the start of the statement. The sql passed in was SELECT id FROM Foo WHERE FirstName = 'Bob'", e.Message)
}
}
@@ -530,7 +530,7 @@ class DBTypeInfoSelectTest {
var foo = createFoo("Bob", "Bob")
var foo2 = createFoo("Bob", "Other")
- var result = Foo.countWhere("\"FirstName\" = :arg AND \"LastName\" = :arg", {"arg" -> "Bob"})
+ var result = Foo.countWhere("FirstName = :arg AND LastName = :arg", {"arg" -> "Bob"})
Assert.assertEquals(1, result)
}
@@ -539,7 +539,7 @@ class DBTypeInfoSelectTest {
var foo = createFoo("Bob", "Bob")
var foo2 = createFoo("Bob", "Other")
- var result = Foo.countWhere("\"FirstName\" = :arg AND \"LastName\" = :arg", {"arg" -> "Bob", "arg2" -> "Other", "arg3" -> "Hrm"})
+ var result = Foo.countWhere("FirstName = :arg AND LastName = :arg", {"arg" -> "Bob", "arg2" -> "Other", "arg3" -> "Hrm"})
Assert.assertEquals(1, result)
}
@@ -548,7 +548,7 @@ class DBTypeInfoSelectTest {
var foo = createFoo("Bob", "Bob")
var foo2 = createFoo("Bob", "Other")
- var result = Foo.countWhere("\"FirstName\" = ':arg' AND \"LastName\" = ':arg'")
+ var result = Foo.countWhere("FirstName = ':arg' AND LastName = ':arg'")
Assert.assertEquals(0, result)
}
@@ -558,7 +558,7 @@ class DBTypeInfoSelectTest {
var foo2 = createFoo("Bob", "Other")
try {
- var result = Foo.countWhere("\"FirstName\" = :arg AND \"LastName\" = :arg", {"arrg" -> "Bob"})
+ var result = Foo.countWhere("FirstName = :arg AND LastName = :arg", {"arrg" -> "Bob"})
Assert.fail("Expected an IllegalArgumentException")
} catch (e : IllegalArgumentException) {
Assert.assertEquals("No value for the token arg was found in the map", e.Message)
@@ -570,20 +570,20 @@ class DBTypeInfoSelectTest {
var foo = createFoo("Bob", "Bob")
var foo2 = createFoo("Bob", "Other")
- var result = Foo.countWhere("\"FirstName\" = '\\:arg' AND \"LastName\" = :arg", {"arg" -> "Bob"})
+ var result = Foo.countWhere("FirstName = '\\:arg' AND LastName = :arg", {"arg" -> "Bob"})
Assert.assertEquals(0, result)
}
@Test
function testCountWhereWithStringStartingWithSelectThrowsIllegalArgumentException() {
- assertException(\ -> Foo.countWhere("SELECT count(*) as count FROM \"Foo\" WHERE \"FirstName\" = 'Bob'"),
+ assertException(\ -> Foo.countWhere("SELECT count(*) as count FROM Foo WHERE FirstName = 'Bob'"),
IllegalArgumentException,
"The countWhere(String, Map) method should only be called with the WHERE clause of a query. To specify the full SQL for the query, use the count(String, Map) method instead.")
}
@Test
function testCountWhereWithStringStartingWithSelectInAlternateCaseThrowsIllegalArgumentException() {
- assertException(\ -> Foo.countWhere("select count(*) as count FROM \"Foo\" WHERE \"FirstName\" = 'Bob'"),
+ assertException(\ -> Foo.countWhere("select count(*) as count FROM Foo WHERE FirstName = 'Bob'"),
IllegalArgumentException,
"The countWhere(String, Map) method should only be called with the WHERE clause of a query. To specify the full SQL for the query, use the count(String, Map) method instead.")
}
Oops, something went wrong.

0 comments on commit 8b73cfc

Please sign in to comment.