Changeset 282
- Timestamp:
- 02/11/08 12:15:56 (1 year ago)
- Files:
-
- lex/trunk/dist/com.qwirx.db.jar (modified) (previous)
- lex/trunk/src/com/qwirx/db/sql/SqlChange.java (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
lex/trunk/src/com/qwirx/db/sql/SqlChange.java
r280 r282 45 45 private static final Logger m_LOG = Logger.getLogger(SqlChange.class); 46 46 private String m_PrimaryKeyField = "ID"; 47 private String changeQuery = null; 47 48 48 49 public SqlChange(String username, String database, … … 206 207 { 207 208 throw new DatabaseException("Failed to capture new values " + 208 "of rows. You may not have an ID column in the table.", e); 209 "of rows. You may not have an ID column in the table.", e, 210 sb.toString()); 209 211 } 210 212 else … … 212 214 throw new DatabaseException("Failed to capture old values " + 213 215 "of rows. You may have an error in your conditions: " + 214 conditions, e );216 conditions, e, sb.toString()); 215 217 } 216 218 } … … 331 333 } 332 334 333 this.conditions = newConditions.toString(); 335 String newCond = newConditions.toString(); 336 if (newCond.length() > 0) 337 { 338 this.conditions = newCond; 339 } 340 else if (type != SqlChange.DELETE) 341 { 342 throw new DatabaseException("No records created or updated", 343 changeQuery); 344 } 334 345 } 335 346 catch (SQLException e) … … 391 402 if (type == INSERT) 392 403 { 393 try 394 { 395 PreparedStatement stmt = prepareAndLogError( 396 "SELECT LAST_INSERT_ID()"); 397 ResultSet rs = executeQueryAndLogError(stmt); 398 rs.next(); 399 insertedRowId = rs.getInt(1); 400 rs.close(); 401 stmt.close(); 402 } 403 catch (SQLException e) 404 { 405 throw new DatabaseException("Failed to get the ID " + 406 "of the last inserted row", e); 407 } 408 404 if (fields.containsKey("ID")) 405 { 406 insertedRowId = Integer.parseInt(fields.get("ID").toString()); 407 } 408 else 409 { 410 try 411 { 412 PreparedStatement stmt = prepareAndLogError( 413 "SELECT LAST_INSERT_ID()"); 414 ResultSet rs = executeQueryAndLogError(stmt); 415 rs.next(); 416 insertedRowId = rs.getInt(1); 417 rs.close(); 418 stmt.close(); 419 } 420 catch (SQLException e) 421 { 422 throw new DatabaseException("Failed to get the ID " + 423 "of the last inserted row", e); 424 } 425 } 426 409 427 conditions = m_PrimaryKeyField + " = " + insertedRowId; 410 428 … … 518 536 try 519 537 { 520 PreparedStatement stmt = prepareAndLogError(sb.toString()); 538 changeQuery = sb.toString(); 539 PreparedStatement stmt = prepareAndLogError(changeQuery); 521 540 522 541 if (type == INSERT || type == UPDATE) … … 549 568 catch (SQLException e) 550 569 { 570 changeQuery = null; 551 571 throw new DatabaseException("Failed to execute " + 552 572 "the requested operation. Please check your field names " + … … 558 578 captureNewValues(); 559 579 } 560 580 581 changeQuery = null; 582 561 583 try 562 584 {
