Skip to content
Permalink
Browse files

Fix some internal schema object type information

  • Loading branch information...
dmoagx committed Jul 22, 2018
1 parent edd1f54 commit 654e1b8a3d81d52b87935345379614edc7c48689
Showing with 77 additions and 74 deletions.
  1. +3 −3 Source/SPDatabaseStructure.m
  2. +1 −1 Source/SPNavigatorController.h
  3. +55 −52 Source/SPNavigatorController.m
  4. +18 −18 Source/SPTextView.m
@@ -239,14 +239,14 @@ - (void)queryDbStructureWithUserInfo:(NSDictionary *)userInfo
for (id aTable in [[delegate valueForKeyPath:@"tablesListInstance"] allTableNames]) {
NSDictionary *aTableDict = [NSDictionary dictionaryWithObjectsAndKeys:
aTable, @"name",
@"0", @"type",
@(SPTableTypeTable), @"type",
nil];
[tablesAndViews addObject:aTableDict];
}
for (id aView in [[delegate valueForKeyPath:@"tablesListInstance"] allViewNames]) {
NSDictionary *aViewDict = [NSDictionary dictionaryWithObjectsAndKeys:
aView, @"name",
@"1", @"type",
@(SPTableTypeView), @"type",
nil];
[tablesAndViews addObject:aViewDict];
}
@@ -365,7 +365,7 @@ - (void)queryDbStructureWithUserInfo:(NSDictionary *)userInfo
// Loop through the rows and extract the function details
for (NSArray *row in theResult) {
NSString *fname = [row objectAtIndex:0];
NSString *type = ([[row objectAtIndex:1] isEqualToString:@"FUNCTION"]) ? @"3" : @"2";
NSNumber *type = ([[row objectAtIndex:1] isEqualToString:@"FUNCTION"]) ? @(SPTableTypeFunc) : @(SPTableTypeProc);
NSString *dtd = [row objectAtIndex:2];
NSString *det = [row objectAtIndex:3];
NSString *dataaccess = [row objectAtIndex:4];
@@ -80,7 +80,7 @@
- (IBAction)syncButtonAction:(id)sender;

- (void)updateEntriesForConnection:(SPDatabaseDocument *)doc;
- (NSString*)tableInfoLabelForIndex:(NSInteger)index ofType:(NSInteger)type;
- (NSString*)tableInfoLabelForIndex:(NSInteger)index ofType:(SPTableType)type;

- (void)updateNavigator:(NSNotification *)aNotification;
#endif
@@ -48,6 +48,10 @@

static SPNavigatorController *sharedNavigatorController = nil;

@interface SPNavigatorController () <NSOutlineViewDataSource, NSOutlineViewDelegate>

@end

@implementation SPNavigatorController

#ifndef SP_CODA /* unused sort func */
@@ -681,12 +685,9 @@ - (IBAction)filterTree:(id)sender
[[[structure valueForKey:connectionID] valueForKey:db_id] setObject:[NSMutableDictionary dictionary] forKey:table_id];
}

if([[[[schemaData objectForKey:connectionID] objectForKey:db_id] objectForKey:table_id] objectForKey:@" struct_type "])
[[[[structure valueForKey:connectionID] valueForKey:db_id] valueForKey:table_id] setObject:
[[[[schemaData objectForKey:connectionID] objectForKey:db_id] objectForKey:table_id] objectForKey:@" struct_type "] forKey:@" struct_type "];
else
[[[[structure valueForKey:connectionID] valueForKey:db_id] valueForKey:table_id] setObject:
@0 forKey:@" struct_type "];
id srcType = [[[[schemaData objectForKey:connectionID] objectForKey:db_id] objectForKey:table_id] objectForKey:@" struct_type "];
NSMutableDictionary *targetDict = [[[structure valueForKey:connectionID] valueForKey:db_id] valueForKey:table_id];
[targetDict setObject:(srcType ? srcType : @(SPTableTypeTable)) forKey:@" struct_type "];

if([a count] > 3) {
NSString *field_id = [NSString stringWithFormat:@"%@%@%@", table_id,SPUniqueSchemaDelimiter,[a objectAtIndex:3]];
@@ -860,7 +861,7 @@ - (BOOL)outlineView:(id)outlineView isItemExpandable:(id)item
{
if([item isKindOfClass:NSDictionaryClass]) {
// Suppress expanding for PROCEDUREs and FUNCTIONs
if([[item objectForKey:@" struct_type "] intValue] > 1) {
if((SPTableType)[[item objectForKey:@" struct_type "] intValue] > SPTableTypeView) {
return NO;
}
return YES;
@@ -920,20 +921,21 @@ - (id)outlineView:(id)outlineView objectValueForTableColumn:(NSTableColumn *)tab

if ([parentObject isKindOfClass:NSDictionaryClass]) {
if([item isKindOfClass:NSDictionaryClass]) {
if([item objectForKey:@" struct_type "]) {
switch([[item objectForKey:@" struct_type "] intValue]) {
case 0:
[[tableColumn dataCell] setImage:tableIcon];
break;
case 1:
[[tableColumn dataCell] setImage:viewIcon];
break;
case 2:
[[tableColumn dataCell] setImage:procedureIcon];
break;
case 3:
[[tableColumn dataCell] setImage:functionIcon];
break;
NSNumber *type = [item objectForKey:@" struct_type "];
if(type) {
switch((SPTableType)[type intValue]) {
case SPTableTypeTable:
[[tableColumn dataCell] setImage:tableIcon];
break;
case SPTableTypeView:
[[tableColumn dataCell] setImage:viewIcon];
break;
case SPTableTypeProc:
[[tableColumn dataCell] setImage:procedureIcon];
break;
case SPTableTypeFunc:
[[tableColumn dataCell] setImage:functionIcon];
break;
}
} else {
[[tableColumn dataCell] setImage:databaseIcon];
@@ -1066,15 +1068,15 @@ - (void)outlineViewSelectionDidChange:(NSNotification *)aNotification
NSString *item = NSArrayObjectAtIndex(selectedItem, i);
if([item isNSNull] || ![item length]) continue;
[infoArray addObject:[NSString stringWithFormat:@"%@: %@",
[self tableInfoLabelForIndex:i ofType:0],
[self tableInfoLabelForIndex:i ofType:SPTableTypeTable],
[item stringByReplacingOccurrencesOfString:@"," withString:@", "]]];
}
}

// check if selected item is a PROCEDURE or FUNCTION
else if([selectedItem isKindOfClass:NSDictionaryClass] && [selectedItem objectForKey:@" struct_type "] && [[selectedItem objectForKey:@" struct_type "] intValue] > 1) {
else if([selectedItem isKindOfClass:NSDictionaryClass] && [selectedItem objectForKey:@" struct_type "] && (SPTableType)[[selectedItem objectForKey:@" struct_type "] intValue] > SPTableTypeView) {
NSInteger i = 0;
NSInteger type = [[selectedItem objectForKey:@" struct_type "] intValue];
SPTableType type = (SPTableType)[[selectedItem objectForKey:@" struct_type "] intValue];
NSArray *keys = [selectedItem allKeys];
NSInteger keyIndex = 0;
if(keys && [keys count] == 2) {
@@ -1212,57 +1214,58 @@ - (void)tableView:(NSTableView*)tableView didClickTableColumn:(NSTableColumn *)t
#pragma mark -
#pragma mark others

- (NSString*)tableInfoLabelForIndex:(NSInteger)anIndex ofType:(NSInteger)type
- (NSString*)tableInfoLabelForIndex:(NSInteger)anIndex ofType:(SPTableType)type
{

if(type == 0 || type == 1) // TABLE / VIEW
switch(anIndex) {
if(type == SPTableTypeTable || type == SPTableTypeView) {
switch (anIndex) {
case 0:
return NSLocalizedString(@"Type", @"type label (Navigator)");
return NSLocalizedString(@"Type", @"type label (Navigator)");
case 1:
return NSLocalizedString(@"Default", @"default label");
return NSLocalizedString(@"Default", @"default label");
case 2:
return NSLocalizedString(@"Is Nullable", @"is nullable label (Navigator)");
return NSLocalizedString(@"Is Nullable", @"is nullable label (Navigator)");
case 3:
return NSLocalizedString(@"Encoding", @"encoding label (Navigator)");
return NSLocalizedString(@"Encoding", @"encoding label (Navigator)");
case 4:
return NSLocalizedString(@"Collation", @"collation label (Navigator)");
return NSLocalizedString(@"Collation", @"collation label (Navigator)");
case 5:
return NSLocalizedString(@"Key", @"key label (Navigator)");
return NSLocalizedString(@"Key", @"key label (Navigator)");
case 6:
return NSLocalizedString(@"Extra", @"extra label (Navigator)");
return NSLocalizedString(@"Extra", @"extra label (Navigator)");
case 7:
return NSLocalizedString(@"Privileges", @"privileges label (Navigator)");
return NSLocalizedString(@"Privileges", @"privileges label (Navigator)");
case 8:
return NSLocalizedString(@"Comment", @"comment label");
return NSLocalizedString(@"Comment", @"comment label");
}

if(type == 2) // PROCEDURE
switch(anIndex) {
}
else if(type == SPTableTypeProc) {
switch (anIndex) {
case 0:
return NSLocalizedString(@"DTD Identifier",@"dtd identifier label (Navigator)");
return NSLocalizedString(@"DTD Identifier", @"dtd identifier label (Navigator)");
case 1:
return NSLocalizedString(@"SQL Data Access",@"sql data access label (Navigator)");
return NSLocalizedString(@"SQL Data Access", @"sql data access label (Navigator)");
case 2:
return NSLocalizedString(@"Is Deterministic",@"is deterministic label (Navigator)");
return NSLocalizedString(@"Is Deterministic", @"is deterministic label (Navigator)");
case 3:
return NSLocalizedString(@"Execution Privilege", @"execution privilege label (Navigator)");
return NSLocalizedString(@"Execution Privilege", @"execution privilege label (Navigator)");
case 4:
return NSLocalizedString(@"Definer",@"definer label (Navigator)");
return NSLocalizedString(@"Definer", @"definer label (Navigator)");
}
if(type == 3) // FUNCTION
switch(anIndex) {
}
else if(type == SPTableTypeFunc) {
switch (anIndex) {
case 0:
return NSLocalizedString(@"Return Type", @"return type label (Navigator)");
return NSLocalizedString(@"Return Type", @"return type label (Navigator)");
case 1:
return NSLocalizedString(@"SQL Data Access",@"sql data access label (Navigator)");
return NSLocalizedString(@"SQL Data Access", @"sql data access label (Navigator)");
case 2:
return NSLocalizedString(@"Is Deterministic",@"is deterministic label (Navigator)");
return NSLocalizedString(@"Is Deterministic", @"is deterministic label (Navigator)");
case 3:
return NSLocalizedString(@"Execution Privilege", @"execution privilege label (Navigator)");
return NSLocalizedString(@"Execution Privilege", @"execution privilege label (Navigator)");
case 4:
return NSLocalizedString(@"Definer",@"definer label (Navigator)");
return NSLocalizedString(@"Definer", @"definer label (Navigator)");
}
}
return @"";
}
#endif
@@ -517,24 +517,24 @@ - (NSArray *)suggestionsForSQLCompletionWith:(NSString *)currentWord dictMode:(B
NSDictionary *theTable = [[dbs objectForKey:db] objectForKey:table];
NSString *tablepath = [table substringFromIndex:[table rangeOfString:SPUniqueSchemaDelimiter].location];
NSArray *allFields = [theTable allKeys];
NSInteger structtype = [[theTable objectForKey:@" struct_type "] intValue];
SPTableType structtype = (SPTableType)[[theTable objectForKey:@" struct_type "] intValue];
BOOL breakFlag = NO;
if(!aTableNameExists)
switch(structtype) {
case 0:
[possibleCompletions addObject:[NSDictionary dictionaryWithObjectsAndKeys:[[table componentsSeparatedByString:SPUniqueSchemaDelimiter] lastObject], @"display", @"table-small-square", @"image", tablepath, @"path", @"", @"isRef", nil]];
break;
case 1:
[possibleCompletions addObject:[NSDictionary dictionaryWithObjectsAndKeys:[[table componentsSeparatedByString:SPUniqueSchemaDelimiter] lastObject], @"display", @"table-view-small-square", @"image", tablepath, @"path", @"", @"isRef", nil]];
break;
case 2:
[possibleCompletions addObject:[NSDictionary dictionaryWithObjectsAndKeys:[[table componentsSeparatedByString:SPUniqueSchemaDelimiter] lastObject], @"display", @"proc-small", @"image", tablepath, @"path", @"", @"isRef", nil]];
breakFlag = YES;
break;
case 3:
[possibleCompletions addObject:[NSDictionary dictionaryWithObjectsAndKeys:[[table componentsSeparatedByString:SPUniqueSchemaDelimiter] lastObject], @"display", @"func-small", @"image", tablepath, @"path", @"", @"isRef", nil]];
breakFlag = YES;
break;
case SPTableTypeTable:
[possibleCompletions addObject:[NSDictionary dictionaryWithObjectsAndKeys:[[table componentsSeparatedByString:SPUniqueSchemaDelimiter] lastObject], @"display", @"table-small-square", @"image", tablepath, @"path", @"", @"isRef", nil]];
break;
case SPTableTypeView:
[possibleCompletions addObject:[NSDictionary dictionaryWithObjectsAndKeys:[[table componentsSeparatedByString:SPUniqueSchemaDelimiter] lastObject], @"display", @"table-view-small-square", @"image", tablepath, @"path", @"", @"isRef", nil]];
break;
case SPTableTypeProc:
[possibleCompletions addObject:[NSDictionary dictionaryWithObjectsAndKeys:[[table componentsSeparatedByString:SPUniqueSchemaDelimiter] lastObject], @"display", @"proc-small", @"image", tablepath, @"path", @"", @"isRef", nil]];
breakFlag = YES;
break;
case SPTableTypeFunc:
[possibleCompletions addObject:[NSDictionary dictionaryWithObjectsAndKeys:[[table componentsSeparatedByString:SPUniqueSchemaDelimiter] lastObject], @"display", @"func-small", @"image", tablepath, @"path", @"", @"isRef", nil]];
breakFlag = YES;
break;
}
if(!breakFlag) {
NSArray *sortedFields = [allFields sortedArrayUsingDescriptors:@[desc]];
@@ -1443,12 +1443,12 @@ - (void)showCompletionListFor:(NSString*)kind atRange:(NSRange)aRange fuzzySearc
// [desc release];
// for(id table in sortedTables) {
// NSDictionary * theTable = [[dbs objectForKey:currentDb] objectForKey:table];
// NSInteger structtype = [[theTable objectForKey:@" struct_type "] intValue];
// SPTableType structtype = (SPTableType)[[theTable objectForKey:@" struct_type "] intValue];
// switch(structtype) {
// case 0:
// case SPTableTypeTable:
// [possibleCompletions addObject:[NSDictionary dictionaryWithObjectsAndKeys:table, @"display", @"table-small-square", @"image", currentDb, @"path", @"", @"isRef", nil]];
// break;
// case 1:
// case SPTableTypeView:
// [possibleCompletions addObject:[NSDictionary dictionaryWithObjectsAndKeys:table, @"display", @"table-view-small-square", @"image", currentDb, @"path", @"", @"isRef", nil]];
// break;
// }

0 comments on commit 654e1b8

Please sign in to comment.
You can’t perform that action at this time.