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 **/
019
020
021
022//Source File Name:   ZInsert.java
023
024package lucee.runtime.sql.old;
025
026import java.util.Vector;
027
028
029//         ZExpression, ZQuery, ZStatement, ZExp
030
031public final class ZInsert
032 implements ZStatement
033{
034
035 public ZInsert(String s)
036 {
037     columns_ = null;
038     valueSpec_ = null;
039     table_ = new String(s);
040 }
041
042 public String getTable()
043 {
044     return table_;
045 }
046
047 public Vector getColumns()
048 {
049     return columns_;
050 }
051
052 public void addColumns(Vector vector)
053 {
054     columns_ = vector;
055 }
056
057 public void addValueSpec(ZExp zexp)
058 {
059     valueSpec_ = zexp;
060 }
061
062 public Vector getValues()
063 {
064     if(!(valueSpec_ instanceof ZExpression))
065         return null;
066     return ((ZExpression)valueSpec_).getOperands();
067 }
068
069 public ZQuery getQuery()
070 {
071     if(!(valueSpec_ instanceof ZQuery))
072         return null;
073     return (ZQuery)valueSpec_;
074 }
075
076 public String toString()
077 {
078     StringBuffer stringbuffer = new StringBuffer("insert into " + table_);
079     if(columns_ != null && columns_.size() > 0)
080     {
081         stringbuffer.append("(" + columns_.elementAt(0));
082         for(int i = 1; i < columns_.size(); i++)
083             stringbuffer.append("," + columns_.elementAt(i));
084
085         stringbuffer.append(")");
086     }
087     String s = valueSpec_.toString();
088     stringbuffer.append(" ");
089     if(getValues() != null)
090         stringbuffer.append("values ");
091     if(s.startsWith("("))
092         stringbuffer.append(s);
093     else
094         stringbuffer.append(" (" + s + ")");
095     return stringbuffer.toString();
096 }
097
098 String table_;
099 Vector columns_;
100 ZExp valueSpec_;
101}