Public Member Functions | |
InsertRequest (String sqlQuery, boolean escapeProcessing, int timeout, String lineSeparator, DatabaseSchema schema, int granularity, boolean isCaseSensitive) throws SQLException | |
InsertRequest (String sqlQuery, boolean escapeProcessing, int timeout, String lineSeparator) | |
void | parse (DatabaseSchema schema, int granularity, boolean isCaseSensitive) throws SQLException |
void | cloneParsing (AbstractRequest request) |
boolean | isInsert () |
boolean | isUpdate () |
boolean | isDelete () |
boolean | isCreate () |
boolean | isDrop () |
void | debug () |
boolean | isAlter () |
InsertRequest
is an SQL request of the following syntax:
INSERT INTO table-name [(column-name[,column-name]*)] {VALUES (constant|null[,constant|null]*)}|{SELECT query}
VALUES are ignored. * - Author:
- Emmanuel Cecchet
- Version:
- 1.0
Definition at line 48 of file InsertRequest.java.
|
Creates a new If the syntax is incorrect an exception is thrown.
Definition at line 68 of file InsertRequest.java. References org.objectweb.cjdbc.common.sql.InsertRequest.parse(). 00071 { 00072 this(sqlQuery, escapeProcessing, timeout, lineSeparator); 00073 parse(schema, granularity, isCaseSensitive); 00074 }
|
|
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 91 of file InsertRequest.java. 00093 { 00094 super(sqlQuery, escapeProcessing, timeout, lineSeparator); 00095 cacheable = RequestType.UNCACHEABLE; 00096 isParsed = false; 00097 }
|
|
Implements org.objectweb.cjdbc.common.sql.AbstractRequest. Definition at line 224 of file InsertRequest.java. References org.objectweb.cjdbc.common.sql.AbstractWriteRequest.cloneTableNameAndColumns(), and org.objectweb.cjdbc.common.sql.AbstractRequest.isParsed. 00225 { 00226 if (!request.isParsed()) 00227 return; 00228 cloneTableNameAndColumns((AbstractWriteRequest) request); 00229 isParsed = true; 00230 }
|
|
Displays some debugging information about this request. Reimplemented from org.objectweb.cjdbc.common.sql.AbstractRequest. Definition at line 280 of file InsertRequest.java. 00281 { 00282 super.debug(); 00283 if (tableName != null) 00284 System.out.println("Inserted table: " + tableName); 00285 else 00286 System.out.println("No information about inserted table"); 00287 00288 if (columns != null) 00289 { 00290 System.out.println("Inserted columns:"); 00291 for (int i = 0; i < columns.size(); i++) 00292 System.out.println(" " 00293 + ((TableColumn) columns.get(i)).getColumnName()); 00294 } 00295 else 00296 System.out.println("No information about inserted columns"); 00297 00298 System.out.println(""); 00299 }
|
|
Implements org.objectweb.cjdbc.common.sql.AbstractWriteRequest. Definition at line 304 of file InsertRequest.java. 00305 { 00306 return false; 00307 }
|
|
Implements org.objectweb.cjdbc.common.sql.AbstractWriteRequest. Definition at line 263 of file InsertRequest.java. 00264 { 00265 return false; 00266 }
|
|
Implements org.objectweb.cjdbc.common.sql.AbstractWriteRequest. Definition at line 254 of file InsertRequest.java. 00255 { 00256 return false; 00257 }
|
|
Implements org.objectweb.cjdbc.common.sql.AbstractWriteRequest. Definition at line 272 of file InsertRequest.java. 00273 { 00274 return false; 00275 }
|
|
Implements org.objectweb.cjdbc.common.sql.AbstractWriteRequest. Definition at line 236 of file InsertRequest.java. 00237 { 00238 return true; 00239 }
|
|
Implements org.objectweb.cjdbc.common.sql.AbstractWriteRequest. Definition at line 245 of file InsertRequest.java. 00246 { 00247 return false; 00248 }
|
|
Parse the query to know which table is affected. Also checks for the columns if the parsing granularity requires it.
Implements org.objectweb.cjdbc.common.sql.AbstractRequest. Definition at line 106 of file InsertRequest.java. References org.objectweb.cjdbc.common.sql.schema.DatabaseTable.getColumn(), org.objectweb.cjdbc.common.sql.schema.DatabaseTable.getColumns(), org.objectweb.cjdbc.common.sql.schema.DatabaseColumn.getName(), and org.objectweb.cjdbc.common.sql.schema.DatabaseTable.getName(). Referenced by org.objectweb.cjdbc.common.sql.InsertRequest.InsertRequest(). 00108 { 00109 if (granularity == ParsingGranularities.NO_PARSING) 00110 { 00111 isParsed = true; 00112 return; 00113 } 00114 00115 // Sanity check 00116 if (schema == null) 00117 throw new SQLException( 00118 "Unable to parse request with an undefined database schema"); 00119 00120 String originalSQL = this.trimCarriageReturn(); 00121 String sql = originalSQL.toLowerCase(); 00122 00123 // Strip 'insert into ' 00124 sql = sql.substring(7).trim().substring(5).trim(); 00125 00126 // Look for the VALUES or SELECT clause 00127 int endIdx = sql.indexOf(" values "); 00128 if (endIdx == -1) 00129 { 00130 endIdx = sql.indexOf(" values("); 00131 if (endIdx == -1) 00132 { 00133 endIdx = sql.indexOf("select "); 00134 if (endIdx == -1) 00135 throw new SQLException( 00136 "Unable to find the VALUES or SELECT keyword in this INSERT statement: '" 00137 + sqlQuery + "'"); 00138 } 00139 } 00140 00141 if (isCaseSensitive) 00142 { 00143 int shift = originalSQL.length() - sql.length(); 00144 sql = originalSQL.substring(shift, shift + endIdx).trim(); 00145 } 00146 else 00147 sql = sql.substring(0, endIdx).trim(); 00148 00149 int openParenthesisIdx = sql.indexOf("("); 00150 00151 // Get the table on which INSERT occurs 00152 String insertTable; 00153 if (openParenthesisIdx == -1) 00154 // Query like INSERT INTO table VALUES(...) 00155 insertTable = sql; 00156 else 00157 // Query of the form INSERT INTO table(column1, ...) VALUES(...) 00158 insertTable = sql.substring(0, openParenthesisIdx).trim(); 00159 00160 DatabaseTable t = schema.getTable(insertTable, isCaseSensitive); 00161 if (t == null) 00162 throw new SQLException("Unknown table '" + insertTable 00163 + "' in this INSERT statement: '" + sqlQuery + "'"); 00164 else 00165 tableName = t.getName(); 00166 00167 if ((granularity == ParsingGranularities.COLUMN) 00168 || (granularity == ParsingGranularities.COLUMN_UNIQUE)) 00169 { 00170 if (openParenthesisIdx != -1) 00171 { 00172 // Fetch the affected columns 00173 int closingParenthesisIdx = sql.indexOf(")"); 00174 if ((closingParenthesisIdx == -1) || (closingParenthesisIdx > endIdx)) 00175 { 00176 tableName = null; 00177 columns = null; 00178 throw new SQLException( 00179 "Syntax error in columns definition for this INSERT statement: '" 00180 + sqlQuery + "'"); 00181 } 00182 00183 // Column names are separated by comas 00184 StringTokenizer columnTokens = new StringTokenizer(sql.substring( 00185 openParenthesisIdx + 1, closingParenthesisIdx), ","); 00186 columns = new ArrayList(); 00187 DatabaseColumn col = null; 00188 while (columnTokens.hasMoreTokens()) 00189 { 00190 String token = columnTokens.nextToken().trim(); 00191 if ((col = t.getColumn(token)) == null) 00192 { 00193 tableName = null; 00194 columns = null; 00195 throw new SQLException("Unknown column name '" + token 00196 + "' in this INSERT statement: '" + sqlQuery + "'"); 00197 } 00198 else 00199 { 00200 columns.add(new TableColumn(tableName, col.getName())); 00201 } 00202 } 00203 } 00204 else 00205 { 00206 // All columns are affected 00207 columns = new ArrayList(); 00208 ArrayList cols = t.getColumns(); 00209 int size = cols.size(); 00210 for (int j = 0; j < size; j++) 00211 { 00212 columns.add(new TableColumn(tableName, ((DatabaseColumn) cols.get(j)) 00213 .getName())); 00214 } 00215 } 00216 } 00217 00218 isParsed = true; 00219 }
|