aboutsummaryrefslogtreecommitdiffstats
path: root/Source/TableContent.m
diff options
context:
space:
mode:
authorrowanbeentje <rowan@beent.je>2009-10-03 14:06:59 +0000
committerrowanbeentje <rowan@beent.je>2009-10-03 14:06:59 +0000
commit83b3a92c9d6b973214edd303a45de9181b141145 (patch)
tree4e17055ac2e808822efd39fc4e71d01426906698 /Source/TableContent.m
parent8884c0dfce8e22893c232648a314ba4e0604caae (diff)
downloadsequelpro-83b3a92c9d6b973214edd303a45de9181b141145.tar.gz
sequelpro-83b3a92c9d6b973214edd303a45de9181b141145.tar.bz2
sequelpro-83b3a92c9d6b973214edd303a45de9181b141145.zip
- Ensure that blob and text fields which are loaded on-demand never have placeholder values written to database. This addresses the data corruption part of Issue #423.
Diffstat (limited to 'Source/TableContent.m')
-rw-r--r--Source/TableContent.m27
1 files changed, 20 insertions, 7 deletions
diff --git a/Source/TableContent.m b/Source/TableContent.m
index f5b0fa47..6537f574 100644
--- a/Source/TableContent.m
+++ b/Source/TableContent.m
@@ -1397,6 +1397,7 @@
id rowObject;
NSMutableString *rowValue = [NSMutableString string];
NSString *currentTime = [[NSDate date] descriptionWithCalendarFormat:@"%H:%M:%S" timeZone:nil locale:nil];
+ BOOL prefsLoadBlobsAsNeeded = [prefs boolForKey:@"LoadBlobsAsNeeded"];
int i;
if ( !isEditingRow || currentlyEditingRow == -1) {
@@ -1418,11 +1419,18 @@
for ( i = 0 ; i < [dataColumns count] ; i++ ) {
rowObject = [NSArrayObjectAtIndex(tableValues, currentlyEditingRow) objectAtIndex:i];
+ // Add (not loaded) placeholders directly for easy comparsion when added
+ if (prefsLoadBlobsAsNeeded && !isEditingNewRow
+ && [rowObject isEqualToString:NSLocalizedString(@"(not loaded)", @"value shown for hidden blob and text fields")])
+ {
+ [fieldValues addObject:[NSString stringWithString:rowObject]];
+ continue;
+
// Catch CURRENT_TIMESTAMP automatic updates - if the row is new and the cell value matches
// the default value, or if the cell hasn't changed, update the current timestamp.
- if ([[NSArrayObjectAtIndex(dataColumns, i) objectForKey:@"onupdatetimestamp"] intValue]
- && ( (isEditingNewRow && [rowObject isEqualTo:[NSArrayObjectAtIndex(dataColumns, i) objectForKey:@"default"]])
- || (!isEditingNewRow && [rowObject isEqualTo:NSArrayObjectAtIndex(oldRow, i)])))
+ } else if ([[NSArrayObjectAtIndex(dataColumns, i) objectForKey:@"onupdatetimestamp"] intValue]
+ && ( (isEditingNewRow && [rowObject isEqualTo:[NSArrayObjectAtIndex(dataColumns, i) objectForKey:@"default"]])
+ || (!isEditingNewRow && [rowObject isEqualTo:NSArrayObjectAtIndex(oldRow, i)])))
{
[rowValue setString:@"CURRENT_TIMESTAMP"];
@@ -1459,18 +1467,23 @@
[fieldValues addObject:[NSString stringWithString:rowValue]];
}
- // Use INSERT syntax when creating new rows
+ // Use INSERT syntax when creating new rows - no need to do (not loaded) checking, as all values have been entered
if ( isEditingNewRow ) {
queryString = [NSString stringWithFormat:@"INSERT INTO %@ (%@) VALUES (%@)",
[selectedTable backtickQuotedString], [[tableDataInstance columnNames] componentsJoinedAndBacktickQuoted], [fieldValues componentsJoinedByString:@","]];
// Use UPDATE syntax otherwise
} else {
+ BOOL firstCellOutput = NO;
queryString = [NSMutableString stringWithFormat:@"UPDATE %@ SET ", [selectedTable backtickQuotedString]];
for ( i = 0 ; i < [dataColumns count] ; i++ ) {
- if ( i > 0 ) {
- [queryString appendString:@", "];
- }
+
+ // If data column loading is deferred and the value is the not loaded string, skip this cell
+ if (prefsLoadBlobsAsNeeded && [[fieldValues objectAtIndex:i] isEqualToString:NSLocalizedString(@"(not loaded)", @"value shown for hidden blob and text fields")]) continue;
+
+ if (firstCellOutput) [queryString appendString:@", "];
+ else firstCellOutput = YES;
+
[queryString appendString:[NSString stringWithFormat:@"%@=%@",
[[NSArrayObjectAtIndex(dataColumns, i) objectForKey:@"name"] backtickQuotedString], [fieldValues objectAtIndex:i]]];
}