Changeset 161
- Timestamp:
- 11/19/07 08:23:20 (1 year ago)
- Files:
-
- 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
r153 r161 13 13 import java.sql.SQLException; 14 14 import java.sql.Types; 15 import java.util.ArrayList; 15 16 import java.util.HashMap; 16 17 import java.util.Iterator; 18 import java.util.List; 17 19 import java.util.Map; 18 20 … … 50 52 } 51 53 52 final static class Type { 54 final static class Type 55 { 53 56 private String name; 54 57 private Type(String name) { this.name = name; } … … 149 152 } 150 153 151 String destColName = storeAsNewValue ? "New_Value" : "Old_Value";154 String destColName = storeAsNewValue ? "New_Value" : "Old_Value"; 152 155 153 156 try … … 167 170 168 171 PreparedStatement cvs = prepareAndLogError(query); 172 List changedRowIds = new ArrayList(); 169 173 170 174 while (rs.next()) 171 175 { 172 176 int uniqueId = rs.getInt("ID"); 177 changedRowIds.add(Integer.valueOf(uniqueId)); 173 178 174 179 int logRowEntryId; … … 190 195 // FIXME date 0000-00-00 in a MySQL database causes 191 196 // an exception when we call getString() on it 197 192 198 try 193 199 { … … 199 205 "can not be represented as java.sql.Date")) 200 206 { 201 // do nothing207 curValue = "0000-00-00"; 202 208 } 203 209 else … … 224 230 rs.close(); 225 231 stmt.close(); 232 233 // an UPDATE may change the found set, but we want to record 234 // the changes to all rows that were found by the UPDATE 235 // (and the preceding SELECT), so we have to change the 236 // conditions to ensure that we find the same rows again. 237 238 StringBuffer newConditions = new StringBuffer(); 239 240 for (Iterator i = changedRowIds.iterator(); i.hasNext();) 241 { 242 newConditions.append("ID = " + i.next()); 243 if (i.hasNext()) 244 { 245 newConditions.append(" OR "); 246 } 247 } 248 249 this.conditions = newConditions.toString(); 226 250 } 227 251 catch (SQLException e) … … 265 289 { 266 290 if (type != UPDATE && type != DELETE) 291 { 267 292 throw new AssertionError("this method can only be used "+ 268 293 "when the command type is UPDATE or DELETE"); 294 } 269 295 270 296 captureValues(true, false);
