KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > mckoi > database > interpret > Set


1 /**
2  * com.mckoi.database.interpret.Set 14 Sep 2001
3  *
4  * Mckoi SQL Database ( http://www.mckoi.com/database )
5  * Copyright (C) 2000, 2001, 2002 Diehl and Associates, Inc.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * Version 2 as published by the Free Software Foundation.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License Version 2 for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * Version 2 along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19  *
20  * Change Log:
21  *
22  *
23  */

24
25 package com.mckoi.database.interpret;
26
27 import java.util.ArrayList JavaDoc;
28 import java.util.List JavaDoc;
29 import java.math.BigDecimal JavaDoc;
30 import com.mckoi.database.*;
31
32 /**
33  * The SQL SET statement. Sets properties within the current local database
34  * connection such as auto-commit mode.
35  *
36  * @author Tobias Downer
37  */

38
39 public class Set extends Statement {
40
41   /**
42    * The type of set this is.
43    */

44   String JavaDoc type;
45
46   /**
47    * The variable name of this set statement.
48    */

49   String JavaDoc var_name;
50
51   /**
52    * The Expression that is the value to assign the variable to
53    * (if applicable).
54    */

55   Expression exp;
56
57   /**
58    * The value to assign the value to (if applicable).
59    */

60   String JavaDoc value;
61
62
63
64   // ---------- Implemented from Statement ----------
65

66   public void prepare() throws DatabaseException {
67     type = (String JavaDoc) cmd.getObject("type");
68     var_name = (String JavaDoc) cmd.getObject("var_name");
69     exp = (Expression) cmd.getObject("exp");
70     value = (String JavaDoc) cmd.getObject("value");
71   }
72
73   public Table evaluate() throws DatabaseException {
74
75     DatabaseQueryContext context = new DatabaseQueryContext(database);
76
77     String JavaDoc com = type.toLowerCase();
78
79     if (com.equals("varset")) {
80       database.setVar(var_name, exp);
81     }
82     else if (com.equals("isolationset")) {
83       value = value.toLowerCase();
84       database.setTransactionIsolation(value);
85     }
86     else if (com.equals("autocommit")) {
87       value = value.toLowerCase();
88       if (value.equals("on") ||
89           value.equals("1")) {
90         database.setAutoCommit(true);
91       }
92       else if (value.equals("off") ||
93                value.equals("0")) {
94         database.setAutoCommit(false);
95       }
96       else {
97         throw new DatabaseException("Unrecognised value for SET AUTO COMMIT");
98       }
99     }
100     else if (com.equals("schema")) {
101       // It's particularly important that this is done during exclusive
102
// lock because SELECT requires the schema name doesn't change in
103
// mid-process.
104

105       // Change the connection to the schema
106
database.setDefaultSchema(value);
107
108     }
109     else {
110       throw new DatabaseException("Unrecognised set command.");
111     }
112
113     return FunctionTable.resultTable(context, 0);
114
115   }
116
117
118 }
119
Popular Tags