1 24 25 package org.objectweb.cjdbc.common.sql; 26 27 import java.io.IOException ; 28 import java.io.Serializable ; 29 import java.sql.SQLException ; 30 31 import org.objectweb.cjdbc.common.sql.schema.DatabaseSchema; 32 import org.objectweb.cjdbc.common.sql.schema.DatabaseTable; 33 import org.objectweb.cjdbc.common.stream.CJDBCInputStream; 34 35 46 public class DropRequest extends AbstractWriteRequest implements Serializable 47 { 48 private static final long serialVersionUID = 7362381853446232926L; 49 50 68 public DropRequest(String sqlQuery, boolean escapeProcessing, int timeout, 69 String lineSeparator, DatabaseSchema schema, int granularity, 70 boolean isCaseSensitive) throws SQLException 71 { 72 this(sqlQuery, escapeProcessing, timeout, lineSeparator); 73 parse(schema, granularity, isCaseSensitive); 74 } 75 76 91 public DropRequest(String sqlQuery, boolean escapeProcessing, int timeout, 92 String lineSeparator) 93 { 94 super(sqlQuery, escapeProcessing, timeout, lineSeparator, RequestType.DROP); 95 } 96 97 100 public DropRequest(CJDBCInputStream in) throws IOException 101 { 102 super(in, RequestType.DROP); 103 } 104 105 109 public void parse(DatabaseSchema schema, int granularity, 110 boolean isCaseSensitive) throws SQLException 111 { 112 if (granularity == ParsingGranularities.NO_PARSING) 113 { 114 isParsed = true; 115 return; 116 } 117 118 String originalSQL = this.trimCarriageReturnAndTabs(); 119 String dropTable = originalSQL.toLowerCase(); 120 121 int tableIdx = dropTable.indexOf("table"); 123 if (tableIdx < 0) 124 throw new SQLException ("TABLE not found in this DROP statement: '" 125 + sqlQuery + "'"); 126 127 if (isCaseSensitive) 128 dropTable = originalSQL.substring(tableIdx + 5).trim(); 129 else 130 dropTable = dropTable.substring(tableIdx + 5).trim(); 131 132 if (schema == null) 133 tableName = dropTable; 134 else 135 { 136 DatabaseTable t = schema.getTable(dropTable, isCaseSensitive); 138 if (t == null) 139 throw new SQLException ("Unknown table '" + dropTable 140 + "' in this DROP statement '" + sqlQuery + "'"); 141 else 142 tableName = t.getName(); 143 } 144 isParsed = true; 145 } 146 147 150 public void cloneParsing(AbstractRequest request) 151 { 152 if (!request.isParsed()) 153 return; 154 cloneTableNameAndColumns((AbstractWriteRequest) request); 155 isParsed = true; 156 } 157 158 161 public boolean needsMacroProcessing() 162 { 163 return false; 164 } 165 166 169 public boolean returnsResultSet() 170 { 171 return false; 172 } 173 174 177 public void debug() 178 { 179 super.debug(); 180 if (tableName != null) 181 System.out.println("Dropped table '" + tableName + "'"); 182 else 183 System.out.println("No information about dropped table"); 184 185 System.out.println(); 186 } 187 } | Popular Tags |