Public Member Functions | |
DeleteRequest (String sqlQuery, boolean escapeProcessing, int timeout, String lineSeparator, DatabaseSchema schema, int granularity, boolean isCaseSensitive) throws SQLException | |
DeleteRequest (String sqlQuery, boolean escapeProcessing, int timeout, String lineSeparator) | |
void | parse (DatabaseSchema schema, int granularity, boolean isCaseSensitive) throws SQLException |
void | cloneParsing (AbstractRequest request) |
ArrayList | getValues () |
boolean | isUnique () |
boolean | isInsert () |
boolean | isUpdate () |
boolean | isDelete () |
boolean | isCreate () |
boolean | isDrop () |
void | debug () |
boolean | isAlter () |
Protected Attributes | |
ArrayList | whereValues |
DeleteRequest
is an SQL request with the following syntax:
DELETE [table1] FROM table1,table2,table3,... WHERE search-condition or DELETE t WHERE search-condition
Note that DELETE from multiple tables are not supported but this is not part of the SQL standard.
Definition at line 54 of file DeleteRequest.java.
|
Creates a new If the syntax is incorrect an exception is thrown.
Definition at line 95 of file DeleteRequest.java. References org.objectweb.cjdbc.common.sql.DeleteRequest.parse(). 00098 { 00099 this(sqlQuery, escapeProcessing, timeout, lineSeparator); 00100 parse(schema, granularity, isCaseSensitive); 00101 }
|
|
Creates a new The request is not parsed but it can be done later by a call to parse(DatabaseSchema, int, boolean).
Definition at line 118 of file DeleteRequest.java. 00120 { 00121 super(sqlQuery, escapeProcessing, timeout, lineSeparator); 00122 cacheable = RequestType.UNCACHEABLE; 00123 isParsed = false; 00124 isUnique = false; 00125 }
|
|
Implements org.objectweb.cjdbc.common.sql.AbstractRequest. Definition at line 263 of file DeleteRequest.java. References org.objectweb.cjdbc.common.sql.AbstractWriteRequest.cloneTableNameAndColumns(), and org.objectweb.cjdbc.common.sql.AbstractRequest.isParsed. 00264 { 00265 if (!request.isParsed()) 00266 return; 00267 cloneTableNameAndColumns((AbstractWriteRequest) request); 00268 isParsed = true; 00269 }
|
|
Displays some debugging information about this request. Reimplemented from org.objectweb.cjdbc.common.sql.AbstractRequest. Definition at line 435 of file DeleteRequest.java. 00436 { 00437 super.debug(); 00438 System.out.println("Is unique: " + isUnique); 00439 if (tableName != null) 00440 System.out.println("Deleted table: " + tableName); 00441 else 00442 System.out.println("No information about deleted table"); 00443 00444 if (columns != null) 00445 { 00446 System.out.println("Columns columns:"); 00447 for (int i = 0; i < columns.size(); i++) 00448 System.out.println(" " 00449 + ((TableColumn) columns.get(i)).getColumnName()); 00450 } 00451 else 00452 System.out.println("No information about updated columns"); 00453 00454 System.out.println(); 00455 }
|
|
Returns an
Definition at line 372 of file DeleteRequest.java. 00373 {
00374 return whereValues;
00375 }
|
|
Implements org.objectweb.cjdbc.common.sql.AbstractWriteRequest. Definition at line 460 of file DeleteRequest.java. 00461 { 00462 return false; 00463 }
|
|
Implements org.objectweb.cjdbc.common.sql.AbstractWriteRequest. Definition at line 418 of file DeleteRequest.java. 00419 { 00420 return false; 00421 }
|
|
Implements org.objectweb.cjdbc.common.sql.AbstractWriteRequest. Definition at line 409 of file DeleteRequest.java. 00410 { 00411 return true; 00412 }
|
|
Implements org.objectweb.cjdbc.common.sql.AbstractWriteRequest. Definition at line 427 of file DeleteRequest.java. 00428 { 00429 return false; 00430 }
|
|
Implements org.objectweb.cjdbc.common.sql.AbstractWriteRequest. Definition at line 391 of file DeleteRequest.java. 00392 { 00393 return false; 00394 }
|
|
Returns
Definition at line 382 of file DeleteRequest.java. 00383 {
00384 return isUnique;
00385 }
|
|
Implements org.objectweb.cjdbc.common.sql.AbstractWriteRequest. Definition at line 400 of file DeleteRequest.java. 00401 { 00402 return false; 00403 }
|
|
Parses the SQL request and extracts the selected columns and tables given the An exception is thrown when the parsing fails. Warning, this method does not check the validity of the request. In particular, invalid request could be parsed without throwing an exception. However, valid SQL request should never throw an exception.
Implements org.objectweb.cjdbc.common.sql.AbstractRequest. Definition at line 142 of file DeleteRequest.java. References org.objectweb.cjdbc.common.sql.DeleteRequest.whereValues. Referenced by org.objectweb.cjdbc.common.sql.DeleteRequest.DeleteRequest(). 00144 { 00145 if (granularity == ParsingGranularities.NO_PARSING) 00146 { 00147 isParsed = true; 00148 return; 00149 } 00150 00151 // Sanity check 00152 if (schema == null) 00153 throw new SQLException( 00154 "Unable to parse request with an undefined database schema"); 00155 00156 String originalSQL = this.trimCarriageReturn(); 00157 String sql = originalSQL.toLowerCase(); 00158 00159 int fromIdx = sql.indexOf("from "); 00160 if (fromIdx == -1) 00161 { 00162 // For queries like: DELETE t WHERE ... used by Oracle 00163 fromIdx = 6; // 6 = "delete".length() 00164 } 00165 else 00166 { 00167 // Syntax is usually DELETE FROM t WHERE ... but it can be 00168 // DELETE t1 FROM t1,t2,.... WHERE ... 00169 // If there is something between DELETE and FROM, tableName will use this 00170 // name but the FROM clause will have all tables. 00171 String tableBetweenDeleteAndFrom; 00172 if (isCaseSensitive) 00173 tableBetweenDeleteAndFrom = originalSQL.substring(6, fromIdx).trim(); 00174 else 00175 tableBetweenDeleteAndFrom = sql.substring(6, fromIdx).trim(); 00176 if (tableBetweenDeleteAndFrom.length() == 0) 00177 tableName = null; 00178 else 00179 tableName = tableBetweenDeleteAndFrom; 00180 fromIdx += 5; // 5 = "from".length() 00181 } 00182 00183 sql = sql.substring(fromIdx).trim(); 00184 00185 // Look for the WHERE clause 00186 int whereIdx = sql.indexOf("where "); 00187 00188 if (isCaseSensitive) 00189 sql = originalSQL.substring(originalSQL.length() - sql.length()); 00190 if (tableName == null) 00191 { // It was not a DELETE t1 FROM xxx type of query 00192 if (whereIdx == -1) 00193 tableName = sql; 00194 else 00195 tableName = sql.substring(0, whereIdx).trim(); 00196 } 00197 00198 // Get the table on which DELETE occurs 00199 DatabaseTable t = schema.getTable(tableName, isCaseSensitive); 00200 if (t == null) 00201 throw new SQLException("Unknown table '" + tableName 00202 + "' in this DELETE statement: " + sqlQuery + "'"); 00203 00204 try 00205 { 00206 switch (granularity) 00207 { 00208 case ParsingGranularities.NO_PARSING : 00209 return; 00210 case ParsingGranularities.TABLE : 00211 break; 00212 case ParsingGranularities.COLUMN : 00213 from = getFromTables(tableName, schema); 00214 columns = getWhereColumns(sql.substring(whereIdx + 6).trim(), from); 00215 00216 if (from != null) 00217 { 00218 // Convert 'from' to an ArrayList of String objects instead of 00219 // AliasedTables objects 00220 int size = from.size(); 00221 ArrayList unaliased = new ArrayList(size); 00222 for (int i = 0; i < size; i++) 00223 unaliased.add(((AliasedDatabaseTable) from.get(i)).getTable() 00224 .getName()); 00225 from = unaliased; 00226 } 00227 break; 00228 case ParsingGranularities.COLUMN_UNIQUE : 00229 from = getFromTables(tableName, schema); 00230 columns = getWhereColumns(sql.substring(whereIdx + 6).trim(), from); 00231 00232 if (from != null) 00233 { 00234 // Convert 'from' to an ArrayList of String objects instead of 00235 // AliasedTables objects 00236 int size = from.size(); 00237 ArrayList unaliased = new ArrayList(size); 00238 for (int i = 0; i < size; i++) 00239 unaliased.add(((AliasedDatabaseTable) from.get(i)).getTable() 00240 .getName()); 00241 from = unaliased; 00242 } 00243 break; 00244 default : 00245 throw new SQLException("Unsupported parsing granularity: '" 00246 + granularity + "'"); 00247 } 00248 } 00249 catch (SQLException e) 00250 { 00251 from = null; 00252 columns = null; 00253 whereValues = null; 00254 throw e; 00255 } 00256 00257 isParsed = true; 00258 }
|
|
The
Definition at line 75 of file DeleteRequest.java. Referenced by org.objectweb.cjdbc.common.sql.DeleteRequest.parse(). |