On Thursday, May 10, 2001, at 09:48 AM, Eric Dobbs wrote:
> I am working on some example code to implement the above which I
> will send soon for comparison and discussion.
Attached is a tarball of some example code. A few notes:
I've spent more time writing and verifying test cases than I have
in writing comments. The present example supports fairly complex
SELECT queries. INSERT, UPDATE, and DELETE are incomplete. And
it requires a patch to TableColumn.java which I include in the
body of this message below. I've chosen to put this stuff in
package org.apache.turbine.util.db.query;
The most interesting test case is as follows:
Query q = new Query(Query.SELECT)
.addSelectColumn(column1)
.addSelectColumn(column2)
.addSelectColumn(column3)
.addSelectColumn(column4)
.where(column1,column3,Query.EQUAL)
.and(column2,"'foo%'",Query.LIKE)
.and(new Query()
.where(column4,new Integer(1),Query.EQUAL)
.or(column4,new Integer(6),Query.EQUAL)
.or(column4,new Integer(15),Query.EQUAL))
.orderBy(column2,Query.ASC);
which produces this output (linewrapped here for readability):
SELECT
TABLE1.COLUMN1,
TABLE1.COLUMN2,
TABLE2.COLUMN1,
TABLE2.COLUMN2
FROM
TABLE1,
TABLE2
WHERE
(TABLE1.COLUMN1=TABLE2.COLUMN1
AND TABLE1.COLUMN2 LIKE 'foo%'
AND (TABLE2.COLUMN2=1
OR TABLE2.COLUMN2=6
OR TABLE2.COLUMN2=15))
ORDER BY
TABLE1.COLUMN2 ASC
On Thursday, May 10, 2001, at 06:03 PM, Daniel Rall wrote:
> For your suggested model, preferable would be:
>
> Query q = new Insert()
> .setColumn(tableColumn1,value1)
Excellent suggestion. Thank you. I'll try to implement that
soon and post another tarball.
-Eric
ps. here's the patch I promised. I need the getters in a
couple places, and I think I need the empty constructor for
my TableColumnOrder subclass.
Index: TableColumn.java
===================================================================
RCS file: /home/cvspublic/jakarta-
turbine/src/java/org/apache/turbine/util/db/TableColumn.java,v
retrieving revision 1.2
diff -u -r1.2 TableColumn.java
--- TableColumn.java 2001/03/06 06:14:01 1.2
+++ TableColumn.java 2001/05/11 00:34:49
@@ -76,13 +76,30 @@
* The concatenation of the table name and column name separated
with a
* dot.
*/
- private String tableColumn;
+ protected String tableColumn;
+ public TableColumn()
+ {
+ //empty
+ }
+
public TableColumn(String tableName, String columnName)
{
this.tableName = tableName;
this.columnName = columnName;
this.tableColumn = (tableName + '.' + columnName);
+ }
+
+ /** return the table name as a String */
+ public String getTable()
+ {
+ return this.tableName;
+ }
+
+ /** return the column name as a String */
+ public String getColumn()
+ {
+ return this.columnName;
}
/**
query.tar.gz