Source code: javatools/db/DbMiscExpr.java
1 /*
2 Javatools (modified version) - Some useful general classes.
3 Copyright (C) 2002-2003 Chris Bitmead (original) Antonio Petrelli (modified)
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
19 Contact me at: brenmcguire@users.sourceforge.net
20 */
21 package javatools.db;
22 import java.sql.*;
23 import java.util.*;
24
25 /**
26 * An SQL expression of the form FUNCNAME(parameter....).
27 * (Hey Chris what's the difference between this and DbFuncExpr???)
28 * @author Chris Bitmead
29 */
30 public class DbMiscExpr extends DbExpr {
31 /** See DbFuncExpr
32 */
33 String func;
34 /** See DbFuncExpr
35 */
36 Object args[];
37
38 /** See DbFuncExpr
39 * @param db See DbFuncExpr
40 * @param func See DbFuncExpr
41 */
42 public DbMiscExpr(DbDatabase db, String func) {
43 super(db);
44 this.func = func;
45 }
46
47 /** See DbFuncExpr
48 * @param db See DbFuncExpr
49 * @param func See DbFuncExpr
50 * @param arg1 See DbFuncExpr
51 */
52 public DbMiscExpr(DbDatabase db, String func, Object arg1) {
53 super(db);
54 this.func = func;
55 args = new Object[1];
56 args[0] = arg1;
57 }
58
59 /** See DbFuncExpr
60 * @param db See DbFuncExpr
61 * @param func See DbFuncExpr
62 * @param arg1 See DbFuncExpr
63 * @param arg2 See DbFuncExpr
64 */
65 public DbMiscExpr(DbDatabase db, String func, Object arg1, Object arg2) {
66 super(db);
67 this.func = func;
68 args = new Object[2];
69 args[0] = arg1;
70 args[1] = arg2;
71 }
72
73 /** See DbFuncExpr
74 * @throws DbException See DbFuncExpr
75 * @return See DbFuncExpr
76 */
77 public String getQueryString() throws DbException {
78 StringTokenizer st = new StringTokenizer(func, "?");
79 String rtn = "";
80 int c = 0;
81 while (st.hasMoreTokens()) {
82 rtn += st.nextToken();
83 if (c < args.length) {
84 rtn += getString(args[c++]);
85 }
86 }
87 return rtn;
88 }
89
90 /** See DbFuncExpr
91 * @param ps See DbFuncExpr
92 * @param i See DbFuncExpr
93 * @throws DbException See DbFuncExpr
94 * @throws SQLException See DbFuncExpr
95 * @return See DbFuncExpr
96 */
97 public int setSqlValues(PreparedStatement ps, int i) throws DbException, SQLException {
98 for (int c = 0; c < args.length; c++) {
99 i = setSqlValue(ps, i, args[c], null);
100 }
101 return i;
102 }
103
104 /** See DbFuncExpr
105 * @param coll See DbFuncExpr
106 */
107 public void usesTables(Set coll) {
108 for (int c = 0; c < args.length; c++) {
109 usesTables(coll, args[c]);
110 }
111 }
112 }