propertylist/IPropertylist: removed obsolete loadTextDB_top()
[metux-java.git] / dbobjects / QueryGenerator.java
blobfa816b4b2f0f8c9ec64a1bfc932253989ffc8296
2 package org.de.metux.dbObjects;
4 import java.util.*;
6 public class QueryGenerator
8 static String InsertQuery(String tablename, DataList data)
10 String fields = null;
11 String values = null;
13 data.enumReset();
14 while (data.enumScan())
16 if (fields==null)
17 fields += new String(data.walkName);
18 else
19 fields += ", " + data.walkName;
21 if (values==null)
22 values += data.walkValue.toSQL();
23 else
24 values += ", " + data.walkValue.toSQL();
27 if ((fields==null)||(values==null))
28 return 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;
37 search.enumReset();
38 while (search.enumScan())
40 if (q_search==null)
41 q_search = search.walkName+"="+search.walkValue.toSQL();
42 else
43 q_search += " AND "+search.walkName+"="+search.walkValue.toSQL();
46 /* generate SET ... clause */
47 String q_newdata = null;
48 newdata.enumReset();
49 while (newdata.enumScan())
51 if (q_newdata==null)
52 q_newdata = newdata.walkName+"="+newdata.walkValue.toSQL();
53 else
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;
63 newdata.enumReset();
64 while (newdata.enumScan())
66 if (q_newdata==null)
67 q_newdata = newdata.walkName+"="+newdata.walkValue.toSQL();
68 else
69 q_newdata += ", "+newdata.walkName+"="+newdata.walkValue.toSQL();
71 return "UPDATE "+tablename+" SET "+q_newdata+" WHERE "+oidField+"="+oidValue.toSQL();