2 package org
.de
.metux
.dbObjects
;
6 public class QueryGenerator
8 static String
InsertQuery(String tablename
, DataList data
)
14 while (data
.enumScan())
17 fields
+= new String(data
.walkName
);
19 fields
+= ", " + data
.walkName
;
22 values
+= data
.walkValue
.toSQL();
24 values
+= ", " + data
.walkValue
.toSQL();
27 if ((fields
==null)||(values
==null))
30 return "INSERT INTO "+tablename
+" ( "+fields
+" ) VALUES ( "+values
+" );";
33 static String
UpdateQueryAND(String tablename
, DataList search
, DataList newdata
)
35 /* generate WHERE clause */
36 String q_search
= null;
38 while (search
.enumScan())
41 q_search
= search
.walkName
+"="+search
.walkValue
.toSQL();
43 q_search
+= " AND "+search
.walkName
+"="+search
.walkValue
.toSQL();
46 /* generate SET ... clause */
47 String q_newdata
= null;
49 while (newdata
.enumScan())
52 q_newdata
= newdata
.walkName
+"="+newdata
.walkValue
.toSQL();
54 q_newdata
+= ", "+newdata
.walkName
+"="+newdata
.walkValue
.toSQL();
56 return "UPDATE "+tablename
+" SET "+q_newdata
+" WHERE "+q_search
;
59 static String
UpdateQueryAND(String tablename
, String oidField
, Data oidValue
, DataList newdata
)
61 /* generate SET ... clause */
62 String q_newdata
= null;
64 while (newdata
.enumScan())
67 q_newdata
= newdata
.walkName
+"="+newdata
.walkValue
.toSQL();
69 q_newdata
+= ", "+newdata
.walkName
+"="+newdata
.walkValue
.toSQL();
71 return "UPDATE "+tablename
+" SET "+q_newdata
+" WHERE "+oidField
+"="+oidValue
.toSQL();