001/** 002 * 003 * Copyright (c) 2014, the Railo Company Ltd. All rights reserved. 004 * 005 * This library is free software; you can redistribute it and/or 006 * modify it under the terms of the GNU Lesser General Public 007 * License as published by the Free Software Foundation; either 008 * version 2.1 of the License, or (at your option) any later version. 009 * 010 * This library is distributed in the hope that it will be useful, 011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 013 * Lesser General Public License for more details. 014 * 015 * You should have received a copy of the GNU Lesser General Public 016 * License along with this library. If not, see <http://www.gnu.org/licenses/>. 017 * 018 **/ 019package lucee.runtime.sql.old; 020 021import java.util.Enumeration; 022import java.util.Hashtable; 023import java.util.Vector; 024 025public final class ZUpdate implements ZStatement { 026 027 public ZUpdate(String s) 028 { 029 where_ = null; 030 columns_ = null; 031 table_ = new String(s); 032 } 033 034 public String getTable() 035 { 036 return table_; 037 } 038 039 public void addSet(Hashtable hashtable) 040 { 041 set_ = hashtable; 042 } 043 044 public Hashtable getSet() 045 { 046 return set_; 047 } 048 049 public void addColumnUpdate(String s, ZExp zexp) 050 { 051 if(set_ == null) 052 set_ = new Hashtable(); 053 set_.put(s, zexp); 054 if(columns_ == null) 055 columns_ = new Vector(); 056 columns_.addElement(s); 057 } 058 059 public ZExp getColumnUpdate(String s) 060 { 061 return (ZExp)set_.get(s); 062 } 063 064 public ZExp getColumnUpdate(int i) 065 { 066 if(--i < 0) 067 return null; 068 if(columns_ == null || i >= columns_.size()) 069 { 070 return null; 071 } 072 String s = (String)columns_.elementAt(i); 073 return (ZExp)set_.get(s); 074 075 } 076 077 public String getColumnUpdateName(int i) 078 { 079 if(--i < 0) 080 return null; 081 if(columns_ == null || i >= columns_.size()) 082 return null; 083 return (String)columns_.elementAt(i); 084 } 085 086 public int getColumnUpdateCount() 087 { 088 if(set_ == null) 089 return 0; 090 return set_.size(); 091 } 092 093 public void addWhere(ZExp zexp) 094 { 095 where_ = zexp; 096 } 097 098 public ZExp getWhere() 099 { 100 return where_; 101 } 102 103 public String toString() 104 { 105 StringBuffer stringbuffer = new StringBuffer("update " + table_); 106 stringbuffer.append(" set "); 107 Enumeration enumeration; 108 if(columns_ != null) 109 enumeration = columns_.elements(); 110 else 111 enumeration = set_.keys(); 112 for(boolean flag = true; enumeration.hasMoreElements(); flag = false) 113 { 114 String s = enumeration.nextElement().toString(); 115 if(!flag) 116 stringbuffer.append(", "); 117 stringbuffer.append(s + "=" + set_.get(s).toString()); 118 } 119 120 if(where_ != null) 121 stringbuffer.append(" where " + where_.toString()); 122 return stringbuffer.toString(); 123 } 124 125 String table_; 126 Hashtable set_; 127 ZExp where_; 128 Vector columns_; 129}