Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prefix columns with table in SELECT clause #299

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions Incremental Store/EncryptedStore.m
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ - (id)executeRequest:(NSPersistentStoreRequest *)request
// return fetched dictionaries
if (type == NSDictionaryResultType && [[fetchRequest propertiesToFetch] count] > 0) {
NSArray * propertiesToFetch = [fetchRequest propertiesToFetch];
NSString * propertiesToFetchString = [self columnsClauseWithProperties:propertiesToFetch];
NSString * propertiesToFetchString = [self columnsClauseWithProperties:propertiesToFetch fromTable:table];

// TODO: Need a test case to reach here, or remove it entirely
// NOTE - this now supports joins but in a limited fashion. It will successfully
Expand Down Expand Up @@ -3235,11 +3235,11 @@ - (BOOL) maybeAddJoinStatementsForKey: (NSString *) key
}


- (NSString *)expressionDescriptionTypeString:(NSExpressionDescription *)expressionDescription {
- (NSString *)expressionDescriptionTypeString:(NSExpressionDescription *)expressionDescription fromTable:(NSString *)table {

switch (expressionDescription.expressionResultType) {
case NSObjectIDAttributeType:
return @"__objectID";
return [NSString stringWithFormat:@"%@.__objectID", table];
break;

/* NSUndefinedAttributeType
Expand All @@ -3262,20 +3262,20 @@ - (NSString *)expressionDescriptionTypeString:(NSExpressionDescription *)express
}
}

- (NSString *)columnsClauseWithProperties:(NSArray *)properties {
- (NSString *)columnsClauseWithProperties:(NSArray *)properties fromTable:(NSString *)table {
NSMutableArray *columns = [NSMutableArray arrayWithCapacity:[properties count]];

[properties enumerateObjectsUsingBlock:^(NSPropertyDescription *prop, NSUInteger idx, BOOL *stop) {
if ([prop isKindOfClass:[NSRelationshipDescription class]]) {
if (![(NSRelationshipDescription *)prop isToMany]) {
[columns addObject:[self foreignKeyColumnForRelationship:(NSRelationshipDescription *)prop]];
[columns addObject:[NSString stringWithFormat:@"%@.%@", table, [self foreignKeyColumnForRelationship:(NSRelationshipDescription *)prop]]];
}
} else if ([prop isKindOfClass:[NSExpressionDescription class]]) {
NSExpressionDescription *expression = (NSExpressionDescription*) prop;
NSString *column = [self expressionDescriptionTypeString:expression];
NSString *column = [self expressionDescriptionTypeString:expression fromTable:table];
[columns addObject:column];
} else {
[columns addObject:[NSString stringWithFormat:@"%@",prop.name]];
[columns addObject:[NSString stringWithFormat:@"%@.%@", table, prop.name]];
}
}];

Expand Down