Changeset 161

Show
Ignore:
Timestamp:
11/19/07 08:23:20 (1 year ago)
Author:
chris
Message:

Fix tracking of date value changes to/from 0000-00-00.

Fix cases where an UPDATE would change the found set of records.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • lex/trunk/src/com/qwirx/db/sql/SqlChange.java

    r153 r161  
    1313import java.sql.SQLException; 
    1414import java.sql.Types; 
     15import java.util.ArrayList; 
    1516import java.util.HashMap; 
    1617import java.util.Iterator; 
     18import java.util.List; 
    1719import java.util.Map; 
    1820 
     
    5052        } 
    5153 
    52         final static class Type { 
     54        final static class Type 
     55        { 
    5356                private String name; 
    5457                private Type(String name) { this.name = name; } 
     
    149152                } 
    150153                 
    151                 String destColName = storeAsNewValue ? "New_Value" : "Old_Value"; 
     154                String destColName = storeAsNewValue ? "New_Value" : "Old_Value"; 
    152155 
    153156                try 
     
    167170 
    168171                PreparedStatement cvs = prepareAndLogError(query); 
     172                List changedRowIds = new ArrayList(); 
    169173                 
    170174                        while (rs.next()) 
    171175                        { 
    172176                            int uniqueId = rs.getInt("ID"); 
     177                            changedRowIds.add(Integer.valueOf(uniqueId)); 
    173178 
    174179                            int logRowEntryId; 
     
    190195                                // FIXME date 0000-00-00 in a MySQL database causes 
    191196                                // an exception when we call getString() on it 
     197                                 
    192198                                try 
    193199                                { 
     
    199205                                        "can not be represented as java.sql.Date")) 
    200206                                    { 
    201                                         // do nothing 
     207                                        curValue = "0000-00-00"; 
    202208                                    } 
    203209                                    else 
     
    224230                        rs.close(); 
    225231                        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(); 
    226250        } 
    227251        catch (SQLException e) 
     
    265289        { 
    266290                if (type != UPDATE && type != DELETE) 
     291                { 
    267292                        throw new AssertionError("this method can only be used "+ 
    268293                                        "when the command type is UPDATE or DELETE"); 
     294                } 
    269295                 
    270296                captureValues(true, false);