ah\\, coucou\\; test!
Monotone-Parent: 59d4ff7e6c2fe24e74adbe4891af30ece4f5e858 Monotone-Revision: c05e0091913ed81140571dab045abdaf56a77ef8 Monotone-Author: wsourdeau@inverse.ca Monotone-Date: 2011-11-14T05:01:26 Monotone-Branch: ca.inverse.sogo
This commit is contained in:
parent
a137e1679e
commit
531ed59298
|
@ -1,3 +1,9 @@
|
||||||
|
2011-11-14 Wolfgang Sourdeau <wsourdeau@inverse.ca>
|
||||||
|
|
||||||
|
* GCSFolder.m
|
||||||
|
(_generateUpdateStatementForRow:adaptor:fields:tableName:whereColumn:isEqualTo:andColumn:isEqualTo:):
|
||||||
|
same as below.
|
||||||
|
|
||||||
2011-10-21 Francis Lachapelle <flachapelle@inverse.ca>
|
2011-10-21 Francis Lachapelle <flachapelle@inverse.ca>
|
||||||
|
|
||||||
* GCSFolder.m
|
* GCSFolder.m
|
||||||
|
|
|
@ -602,40 +602,48 @@ static GCSStringFormatter *stringFormatter = nil;
|
||||||
|
|
||||||
- (NSString *)_formatRowValue:(id)_value {
|
- (NSString *)_formatRowValue:(id)_value {
|
||||||
|
|
||||||
if (![_value isNotNull])
|
|
||||||
return @"NULL";
|
|
||||||
|
|
||||||
if ([_value isKindOfClass:NSStringClass])
|
|
||||||
return [stringFormatter stringByFormattingString:_value];
|
|
||||||
|
|
||||||
if ([_value isKindOfClass:NSNumberClass]) {
|
|
||||||
#if GNUSTEP_BASE_LIBRARY
|
|
||||||
_value = [_value stringValue];
|
|
||||||
return ([(NSString *)_value hasPrefix:@"Y"] ||
|
|
||||||
[(NSString *)_value hasPrefix:@"N"])
|
|
||||||
? (id)([_value boolValue] ? @"1" : @"0")
|
|
||||||
: _value;
|
|
||||||
#endif
|
|
||||||
return [_value stringValue];
|
|
||||||
}
|
|
||||||
|
|
||||||
if ([_value isKindOfClass:NSCalendarDateClass]) {
|
if ([_value isKindOfClass:NSCalendarDateClass]) {
|
||||||
/* be smart ... convert to timestamp. Note: we loose precision. */
|
/* be smart ... convert to timestamp. Note: we loose precision. */
|
||||||
char buf[256];
|
char buf[256];
|
||||||
snprintf(buf, sizeof(buf), "%i", (int)[_value timeIntervalSince1970]);
|
snprintf(buf, sizeof(buf), "%i", (int)[_value timeIntervalSince1970]);
|
||||||
return [NSString stringWithCString:buf];
|
return [NSString stringWithCString:buf];
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
[self errorWithFormat:@"cannot handle value class: %@", [_value class]];
|
return _value;
|
||||||
return nil;
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSString *)_generateInsertStatementForRow:(NSDictionary *)_row
|
- (NSString *) _sqlTypeForColumn: (NSString *) _field withFieldInfos: (NSArray *) _fields
|
||||||
tableName:(NSString *)_table
|
{
|
||||||
|
NSString *sqlType;
|
||||||
|
NSEnumerator *fields;
|
||||||
|
GCSFieldInfo *fieldInfo;
|
||||||
|
|
||||||
|
sqlType = nil;
|
||||||
|
fields = [_fields objectEnumerator];
|
||||||
|
while ((fieldInfo = [fields nextObject]))
|
||||||
|
{
|
||||||
|
if ([[fieldInfo columnName] caseInsensitiveCompare: _field] == NSOrderedSame)
|
||||||
|
{
|
||||||
|
sqlType = [fieldInfo sqlType];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return sqlType;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (NSString *) _generateInsertStatementForRow:(NSDictionary *)_row
|
||||||
|
adaptor:(EOAdaptor *)_adaptor
|
||||||
|
fields:(NSArray *)_fields
|
||||||
|
tableName:(NSString *)_table
|
||||||
{
|
{
|
||||||
// TODO: move to NSDictionary category?
|
// TODO: move to NSDictionary category?
|
||||||
NSMutableString *sql;
|
NSMutableString *sql;
|
||||||
|
NSString *fieldName, *sqlType;
|
||||||
NSArray *keys;
|
NSArray *keys;
|
||||||
|
EOAttribute *attribute;
|
||||||
|
id value;
|
||||||
unsigned i, count;
|
unsigned i, count;
|
||||||
|
|
||||||
if (_row == nil || _table == nil)
|
if (_row == nil || _table == nil)
|
||||||
|
@ -656,12 +664,25 @@ static GCSStringFormatter *stringFormatter = nil;
|
||||||
[sql appendString:@") VALUES ("];
|
[sql appendString:@") VALUES ("];
|
||||||
|
|
||||||
for (i = 0, count = [keys count]; i < count; i++) {
|
for (i = 0, count = [keys count]; i < count; i++) {
|
||||||
id value;
|
fieldName = [keys objectAtIndex:i];
|
||||||
|
sqlType = [self _sqlTypeForColumn: fieldName withFieldInfos: _fields];
|
||||||
|
|
||||||
if (i != 0) [sql appendString:@", "];
|
if (sqlType)
|
||||||
value = [_row objectForKey:[keys objectAtIndex:i]];
|
{
|
||||||
value = [self _formatRowValue:value];
|
value = [self _formatRowValue: [_row objectForKey: fieldName]];
|
||||||
[sql appendString:value];
|
attribute = AUTORELEASE([[EOAttribute alloc] init]);
|
||||||
|
[attribute setName: fieldName];
|
||||||
|
[attribute setColumnName: fieldName];
|
||||||
|
[attribute setExternalType: sqlType];
|
||||||
|
|
||||||
|
if (i != 0) [sql appendString:@", "];
|
||||||
|
[sql appendString:[_adaptor formatValue: value forAttribute: attribute]];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
[self errorWithFormat:@"%s: no type found for column name %@",
|
||||||
|
__PRETTY_FUNCTION__, fieldName];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[sql appendString:@")"];
|
[sql appendString:@")"];
|
||||||
|
@ -699,7 +720,7 @@ static GCSStringFormatter *stringFormatter = nil;
|
||||||
|
|
||||||
if (sqlType)
|
if (sqlType)
|
||||||
{
|
{
|
||||||
value = [_row objectForKey: fieldName];
|
value = [self _formatRowValue: [_row objectForKey: fieldName]];
|
||||||
attribute = AUTORELEASE([[EOAttribute alloc] init]);
|
attribute = AUTORELEASE([[EOAttribute alloc] init]);
|
||||||
[attribute setName: fieldName];
|
[attribute setName: fieldName];
|
||||||
[attribute setColumnName: fieldName];
|
[attribute setColumnName: fieldName];
|
||||||
|
@ -717,41 +738,32 @@ static GCSStringFormatter *stringFormatter = nil;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sqlType = [self _sqlTypeForColumn: _colname withFieldInfos: _fields];
|
||||||
|
attribute = AUTORELEASE([[EOAttribute alloc] init]);
|
||||||
|
[attribute setName: _colname];
|
||||||
|
[attribute setColumnName: _colname];
|
||||||
|
[attribute setExternalType: sqlType];
|
||||||
[sql appendString:@" WHERE "];
|
[sql appendString:@" WHERE "];
|
||||||
[sql appendString:_colname];
|
[sql appendString:_colname];
|
||||||
[sql appendString:@" = "];
|
[sql appendString:@" = "];
|
||||||
[sql appendString:[self _formatRowValue:_value]];
|
[sql appendString:[_adaptor formatValue: [self _formatRowValue:_value] forAttribute: attribute]];
|
||||||
|
|
||||||
if (_colname2 != nil) {
|
if (_colname2 != nil) {
|
||||||
[sql appendString:@" AND "];
|
[sql appendString:@" AND "];
|
||||||
|
|
||||||
|
sqlType = [self _sqlTypeForColumn: _colname2 withFieldInfos: _fields];
|
||||||
|
attribute = AUTORELEASE([[EOAttribute alloc] init]);
|
||||||
|
[attribute setName: _colname2];
|
||||||
|
[attribute setColumnName: _colname2];
|
||||||
|
[attribute setExternalType: sqlType];
|
||||||
[sql appendString:_colname2];
|
[sql appendString:_colname2];
|
||||||
[sql appendString:@" = "];
|
[sql appendString:@" = "];
|
||||||
[sql appendString:[self _formatRowValue:_value2]];
|
[sql appendString:[_adaptor formatValue: [self _formatRowValue:_value2] forAttribute: attribute]];
|
||||||
}
|
}
|
||||||
|
|
||||||
return sql;
|
return sql;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSString *) _sqlTypeForColumn: (NSString *) _field withFieldInfos: (NSArray *) _fields
|
|
||||||
{
|
|
||||||
NSString *sqlType;
|
|
||||||
NSEnumerator *fields;
|
|
||||||
GCSFieldInfo *fieldInfo;
|
|
||||||
|
|
||||||
sqlType = nil;
|
|
||||||
fields = [_fields objectEnumerator];
|
|
||||||
while ((fieldInfo = [fields nextObject]))
|
|
||||||
{
|
|
||||||
if ([[fieldInfo columnName] caseInsensitiveCompare: _field] == NSOrderedSame)
|
|
||||||
{
|
|
||||||
sqlType = [fieldInfo sqlType];
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return sqlType;
|
|
||||||
}
|
|
||||||
|
|
||||||
- (EOEntity *) _entityWithName: (NSString *) _name
|
- (EOEntity *) _entityWithName: (NSString *) _name
|
||||||
{
|
{
|
||||||
EOAttribute *attribute;
|
EOAttribute *attribute;
|
||||||
|
@ -976,6 +988,8 @@ static GCSStringFormatter *stringFormatter = nil;
|
||||||
? [quickChannel insertRowX: quickRow forEntity: quickTableEntity]
|
? [quickChannel insertRowX: quickRow forEntity: quickTableEntity]
|
||||||
: [quickChannel
|
: [quickChannel
|
||||||
evaluateExpressionX: [self _generateInsertStatementForRow: quickRow
|
evaluateExpressionX: [self _generateInsertStatementForRow: quickRow
|
||||||
|
adaptor: [[quickChannel adaptorContext] adaptor]
|
||||||
|
fields: [folderInfo quickFields]
|
||||||
tableName: [self quickTableName]]]);
|
tableName: [self quickTableName]]]);
|
||||||
|
|
||||||
if (!error)
|
if (!error)
|
||||||
|
@ -983,6 +997,8 @@ static GCSStringFormatter *stringFormatter = nil;
|
||||||
? [storeChannel insertRowX: contentRow forEntity: storeTableEntity]
|
? [storeChannel insertRowX: contentRow forEntity: storeTableEntity]
|
||||||
: [storeChannel
|
: [storeChannel
|
||||||
evaluateExpressionX: [self _generateInsertStatementForRow: contentRow
|
evaluateExpressionX: [self _generateInsertStatementForRow: contentRow
|
||||||
|
adaptor: [[storeChannel adaptorContext] adaptor]
|
||||||
|
fields: [folderInfo fields]
|
||||||
tableName: [self storeTableName]]]);
|
tableName: [self storeTableName]]]);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
Loading…
Reference in a new issue