aboutsummaryrefslogtreecommitdiffstats
path: root/Source/TableSource.m
diff options
context:
space:
mode:
authorstuconnolly <stuart02@gmail.com>2009-05-15 12:41:14 +0000
committerstuconnolly <stuart02@gmail.com>2009-05-15 12:41:14 +0000
commit74b67a8498f66488bebf52d197bcccc06cfd60ee (patch)
treebba99f68ff03c0213e77e8cae0056a17a27fe7cf /Source/TableSource.m
parent44e7c62bb12fa1d601cfbaf3ddf870a148b4f474 (diff)
downloadsequelpro-74b67a8498f66488bebf52d197bcccc06cfd60ee.tar.gz
sequelpro-74b67a8498f66488bebf52d197bcccc06cfd60ee.tar.bz2
sequelpro-74b67a8498f66488bebf52d197bcccc06cfd60ee.zip
Fix for issue #256. Don't perform field updates if nothing has changed when selecting the table cell.
Diffstat (limited to 'Source/TableSource.m')
-rw-r--r--Source/TableSource.m73
1 files changed, 47 insertions, 26 deletions
diff --git a/Source/TableSource.m b/Source/TableSource.m
index 5ba34246..a85b9d84 100644
--- a/Source/TableSource.m
+++ b/Source/TableSource.m
@@ -599,17 +599,16 @@ fetches the result as an array with a dictionary for each row in it
return NO;
}
-
+/**
+ * tries to write row to mysql-db
+ * returns YES if row written to db, otherwies NO
+ * returns YES if no row is beeing edited and nothing has to be written to db
+ */
- (BOOL)addRowToDB;
-/*
-tries to write row to mysql-db
-returns YES if row written to db, otherwies NO
-returns YES if no row is beeing edited and nothing has to be written to db
-*/
{
+ int code;
NSDictionary *theRow;
NSMutableString *queryString;
- int code;
if ( !isEditingRow || currentlyEditingRow == -1 )
return YES;
@@ -618,26 +617,50 @@ returns YES if no row is beeing edited and nothing has to be written to db
theRow = [tableFields objectAtIndex:currentlyEditingRow];
- if ( isEditingNewRow ) {
- //ADD syntax
- if ( [[theRow objectForKey:@"Length"] isEqualToString:@""] || ![theRow objectForKey:@"Length"] ) {
+ if (isEditingNewRow) {
+ // ADD syntax
+ if ([[theRow objectForKey:@"Length"] isEqualToString:@""] || ![theRow objectForKey:@"Length"]) {
+
queryString = [NSMutableString stringWithFormat:@"ALTER TABLE %@ ADD %@ %@",
- [selectedTable backtickQuotedString], [[theRow objectForKey:@"Field"] backtickQuotedString], [theRow objectForKey:@"Type"]];
- } else {
+ [selectedTable backtickQuotedString],
+ [[theRow objectForKey:@"Field"] backtickQuotedString],
+ [theRow objectForKey:@"Type"]];
+ }
+ else {
queryString = [NSMutableString stringWithFormat:@"ALTER TABLE %@ ADD %@ %@(%@)",
- [selectedTable backtickQuotedString], [[theRow objectForKey:@"Field"] backtickQuotedString], [theRow objectForKey:@"Type"],
- [theRow objectForKey:@"Length"]];
+ [selectedTable backtickQuotedString],
+ [[theRow objectForKey:@"Field"] backtickQuotedString],
+ [theRow objectForKey:@"Type"],
+ [theRow objectForKey:@"Length"]];
}
- } else {
- //CHANGE syntax
+ }
+ else {
+ // CHANGE syntax
if (([[theRow objectForKey:@"Length"] isEqualToString:@""]) || (![theRow objectForKey:@"Length"]) || ([[theRow objectForKey:@"Type"] isEqualToString:@"datetime"])) {
+
+ // If the old row and new row dictionaries are equel then the user didn't actually change anything so don't continue
+ if ([oldRow isEqualToDictionary:theRow]) {
+ return YES;
+ }
+
queryString = [NSMutableString stringWithFormat:@"ALTER TABLE %@ CHANGE %@ %@ %@",
- [selectedTable backtickQuotedString], [[oldRow objectForKey:@"Field"] backtickQuotedString], [[theRow objectForKey:@"Field"] backtickQuotedString],
- [theRow objectForKey:@"Type"]];
- } else {
+ [selectedTable backtickQuotedString],
+ [[oldRow objectForKey:@"Field"] backtickQuotedString],
+ [[theRow objectForKey:@"Field"] backtickQuotedString],
+ [theRow objectForKey:@"Type"]];
+ }
+ else {
+ // If the old row and new row dictionaries are equel then the user didn't actually change anything so don't continue
+ if ([oldRow isEqualToDictionary:theRow]) {
+ return YES;
+ }
+
queryString = [NSMutableString stringWithFormat:@"ALTER TABLE %@ CHANGE %@ %@ %@(%@)",
- [selectedTable backtickQuotedString], [[oldRow objectForKey:@"Field"] backtickQuotedString], [[theRow objectForKey:@"Field"] backtickQuotedString],
- [theRow objectForKey:@"Type"], [theRow objectForKey:@"Length"]];
+ [selectedTable backtickQuotedString],
+ [[oldRow objectForKey:@"Field"] backtickQuotedString],
+ [[theRow objectForKey:@"Field"] backtickQuotedString],
+ [theRow objectForKey:@"Type"],
+ [theRow objectForKey:@"Length"]];
}
}
@@ -690,16 +713,13 @@ returns YES if no row is beeing edited and nothing has to be written to db
if ( [chooseKeyButton indexOfSelectedItem] == 0 ) {
[queryString appendString:@" PRIMARY KEY"];
} else {
- [queryString appendString:[NSString stringWithFormat:@", ADD %@ (%@)",
- [chooseKeyButton titleOfSelectedItem], [[theRow objectForKey:@"Field"] backtickQuotedString]]];
+ [queryString appendString:[NSString stringWithFormat:@", ADD %@ (%@)", [chooseKeyButton titleOfSelectedItem], [[theRow objectForKey:@"Field"] backtickQuotedString]]];
}
}
}
-
+
[mySQLConnection queryString:queryString];
- //NSLog(queryString);
-
if ( [[mySQLConnection getLastErrorMessage] isEqualToString:@""] ) {
isEditingRow = NO;
isEditingNewRow = NO;
@@ -723,6 +743,7 @@ returns YES if no row is beeing edited and nothing has to be written to db
nil, @"addrow", [NSString stringWithFormat:NSLocalizedString(@"Couldn't change field %@.\nMySQL said: %@", @"message of panel when field cannot be changed"),
[theRow objectForKey:@"Field"], [mySQLConnection getLastErrorMessage]]);
}
+
return NO;
}
}