001: /**
002: * com.mckoi.database.interpret.Set 14 Sep 2001
003: *
004: * Mckoi SQL Database ( http://www.mckoi.com/database )
005: * Copyright (C) 2000, 2001, 2002 Diehl and Associates, Inc.
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License
009: * Version 2 as published by the Free Software Foundation.
010: *
011: * This program is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014: * GNU General Public License Version 2 for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * Version 2 along with this program; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
019: *
020: * Change Log:
021: *
022: *
023: */package com.mckoi.database.interpret;
024:
025: import java.util.ArrayList;
026: import java.util.List;
027: import java.math.BigDecimal;
028: import com.mckoi.database.*;
029:
030: /**
031: * The SQL SET statement. Sets properties within the current local database
032: * connection such as auto-commit mode.
033: *
034: * @author Tobias Downer
035: */
036:
037: public class Set extends Statement {
038:
039: /**
040: * The type of set this is.
041: */
042: String type;
043:
044: /**
045: * The variable name of this set statement.
046: */
047: String var_name;
048:
049: /**
050: * The Expression that is the value to assign the variable to
051: * (if applicable).
052: */
053: Expression exp;
054:
055: /**
056: * The value to assign the value to (if applicable).
057: */
058: String value;
059:
060: // ---------- Implemented from Statement ----------
061:
062: public void prepare() throws DatabaseException {
063: type = (String) cmd.getObject("type");
064: var_name = (String) cmd.getObject("var_name");
065: exp = (Expression) cmd.getObject("exp");
066: value = (String) cmd.getObject("value");
067: }
068:
069: public Table evaluate() throws DatabaseException {
070:
071: DatabaseQueryContext context = new DatabaseQueryContext(
072: database);
073:
074: String com = type.toLowerCase();
075:
076: if (com.equals("varset")) {
077: database.setVar(var_name, exp);
078: } else if (com.equals("isolationset")) {
079: value = value.toLowerCase();
080: database.setTransactionIsolation(value);
081: } else if (com.equals("autocommit")) {
082: value = value.toLowerCase();
083: if (value.equals("on") || value.equals("1")) {
084: database.setAutoCommit(true);
085: } else if (value.equals("off") || value.equals("0")) {
086: database.setAutoCommit(false);
087: } else {
088: throw new DatabaseException(
089: "Unrecognised value for SET AUTO COMMIT");
090: }
091: } else if (com.equals("schema")) {
092: // It's particularly important that this is done during exclusive
093: // lock because SELECT requires the schema name doesn't change in
094: // mid-process.
095:
096: // Change the connection to the schema
097: database.setDefaultSchema(value);
098:
099: } else {
100: throw new DatabaseException("Unrecognised set command.");
101: }
102:
103: return FunctionTable.resultTable(context, 0);
104:
105: }
106:
107: }
|