aboutsummaryrefslogtreecommitdiffstats
path: root/Source/SPTableData.m
diff options
context:
space:
mode:
authorBibiko <bibiko@eva.mpg.de>2009-10-16 16:46:41 +0000
committerBibiko <bibiko@eva.mpg.de>2009-10-16 16:46:41 +0000
commit967579ef1225a134c50a686ee7caa9a3b5e293f3 (patch)
tree11470982216c5f9579c26bfa07815b73a081e0f5 /Source/SPTableData.m
parent507d0089c6bb73a01129f1e356d1e88ca53afb55 (diff)
downloadsequelpro-967579ef1225a134c50a686ee7caa9a3b5e293f3.tar.gz
sequelpro-967579ef1225a134c50a686ee7caa9a3b5e293f3.tar.bz2
sequelpro-967579ef1225a134c50a686ee7caa9a3b5e293f3.zip
• fixed SPArrayAdditions method 'componentsJoinedByCommas' to use a mutable string to avoid crashes if array has a very large number of items (malloc error due to reassigning a NSString pointer)
• added to SPTableData method - (NSArray *) primaryKeyColumnNames - returns all column names which are set as PRIMARY KEYs - return nil if no PRIMARY KEY is set • improved the deletion of rows - if current table has only one PRIMARY KEY field delete all rows via DELETE FROM table WHERE pri_key IN (…) whereby the deletion query will be splitted into 256k chunks Note: line 1790ff It has to be implemented a workaround for tables with more than one PRIMARY KEY – maybe via DELETE FROM table WHERE ( (pri_key1='…' AND pri_key2='…') OR (… AND …) OR … ) splitted in 256k chunks as well
Diffstat (limited to 'Source/SPTableData.m')
-rw-r--r--Source/SPTableData.m38
1 files changed, 38 insertions, 0 deletions
diff --git a/Source/SPTableData.m b/Source/SPTableData.m
index ec02c301..52911330 100644
--- a/Source/SPTableData.m
+++ b/Source/SPTableData.m
@@ -968,6 +968,44 @@
return [fieldDetails autorelease];
}
+/*
+ * Return the column names which are set to PRIMIARY KEY; returns nil if no PRIMARY KEY is set.
+ */
+- (NSArray *)primaryKeyColumnNames
+{
+
+ NSString *selectedTable = [tableListInstance tableName];
+ if(![selectedTable length]) return nil;
+
+ MCPResult *r;
+ NSArray *resultRow;
+ NSInteger i;
+ NSMutableArray *keyColumns = [NSMutableArray array];
+
+ r = [mySQLConnection queryString:[NSString stringWithFormat:@"SHOW COLUMNS FROM %@ WHERE `key` = 'PRI'", [selectedTable backtickQuotedString]]];
+
+ if([r numOfRows] < 1) return nil;
+
+ if (![[mySQLConnection getLastErrorMessage] isEqualToString:@""]) {
+ if ([mySQLConnection isConnected])
+ NSRunAlertPanel(@"Error", [NSString stringWithFormat:@"An error occured while retrieving the PRIAMRY KEY data:\n\n%@", [mySQLConnection getLastErrorMessage]], @"OK", nil, nil);
+ return nil;
+ }
+
+
+ for( i = 0; i < [r numOfRows]; i++ ) {
+ resultRow = [r fetchRowAsArray];
+ [keyColumns addObject:[NSArrayObjectAtIndex(resultRow, 0) description]];
+ }
+
+ if([keyColumns count])
+ return keyColumns;
+
+ return nil;
+}
+
+#pragma mark -
+
- (void) dealloc
{
[columns release];