2005-02-24 Helge Hess <helge.hess@opengroupware.org>
+ * NSString+SQLiteVal.m, NSCalendarDate+SQLiteVal.m: improved SQL value
+ generation (v4.5.14)
+
* v4.5.13
* NSString+SQLiteVal.m: fixed a warning on MacOSX
NSTimeZone *serverTimeZone;
NSString *format;
NSString *val;
+ unsigned len;
+ unichar c1;
+
+ if ((len = [_type length]) == 0)
+ c1 = 0;
+ else
+ c1 = [_type characterAtIndex:0];
+
+ if (c1 == 'i' || c1 == 'I') { // INTEGER
+ char buf[64];
+ sprintf(buf, "%d", ((unsigned int)[self timeIntervalSince1970]));
+ return [NSString stringWithCString:buf];
+ }
+ if (c1 == 'r' || c1 == 'R') { // REAL
+ char buf[64]; // TODO: check format
+ sprintf(buf, "%f", [self timeIntervalSince1970]);
+ return [NSString stringWithCString:buf];
+ }
if ((serverTimeZone = [_attribute serverTimeZone]) == nil ) {
if (DefServerTimezone == nil) {
return self;
}
+/* generate SQL value */
+
- (NSString *)stringValueForSQLite3Type:(NSString *)_type
attribute:(EOAttribute *)_attribute
{
c1 = [_type characterAtIndex:0];
switch (c1) {
- case 'c': case 'C':
- case 'v': case 'V':
- case 't': case 'T': {
+ case 'c': case 'C': // char
+ case 'v': case 'V': // varchar
+ case 't': case 'T': { // text
NSString *s;
id expr;
[expr release];
return [s autorelease];
}
- case 'm': case 'M': {
- if (len < 5) {
- if ([[_type lowercaseString] hasPrefix:@"money"])
- return [@"$" stringByAppendingString:self];
- }
- break;
+ case 'i': case 'I': { // int
+ unsigned char buf[128];
+ sprintf(buf, "%i", [self intValue]);
+ return [NSString stringWithCString:buf];
}
+ default:
+ NSLog(@"WARNING(%s): return string as is for type %@",
+ __PRETTY_FUNCTION__, _type);
+ break;
}
return self;
}