-// $Id: NSCalendarDate+SQLiteVal.m,v 1.1 2004/06/14 14:27:44 helge Exp $
+/*
+ NSCalendarDate+SQLiteVal.m
+
+ Copyright (C) 2003-2005 SKYRIX Software AG
+
+ Author: Helge Hess (helge.hess@skyrix.com)
+
+ This file is part of the SQLite Adaptor Library
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this library; see the file COPYING.LIB.
+ If not, write to the Free Software Foundation,
+ 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+*/
+
#import <Foundation/NSString.h>
#include "SQLiteChannel.h"
#include "common.h"
+#if COCOA_Foundation_LIBRARY || NeXT_Foundation_LIBRARY
+@interface NSCalendarDate(UsedPrivates)
+- (id)initWithTimeIntervalSince1970:(NSTimeInterval)_tv;
+@end
+#endif
+
static NSString *SQLITE3_DATETIME_FORMAT = @"%b %d %Y %I:%M:%S:000%p";
@implementation NSCalendarDate(SQLiteValues)
static NSTimeZone *gmt01 = nil;
static NSTimeZone *gmt02 = nil;
-+ (id)valueFromCString:(const char *)_cstr length:(int)_length
- sqlite3Type:(NSString *)_type
- attribute:(EOAttribute *)_attribute
- adaptorChannel:(SQLiteChannel *)_channel
-{
- static unsigned char buf[28]; // reused buffer
+- (id)initWithSQLiteData:(const void *)_value length:(int)_length {
+ static unsigned char buf[28]; // reused buffer, THREAD
+ const char *_cstr = _value;
unsigned char *p;
NSTimeZone *attrTZ;
NSCalendarDate *date;
return nil;
if (_length != 22 && _length != 25) {
- NSLog(@"ERROR(%s): unexpected string '%s' for date type '%@', returning now"
+ NSLog(@"ERROR(%s): unexpected date string '%s', returning now"
@" (expected format: '2001-07-26 14:00:00+02')",
- __PRETTY_FUNCTION__,
- _cstr, _type);
+ __PRETTY_FUNCTION__, _cstr);
return [NSCalendarDate date];
}
strncpy(buf, _cstr, 25);
}
}
- if (NSCalDateClass == Nil) NSCalDateClass = [[NSCalendarDate class] retain];
+ if (NSCalDateClass == Nil) NSCalDateClass = [NSCalendarDate class];
date = [NSCalDateClass dateWithYear:year month:month day:day
hour:hour minute:min second:sec
timeZone:attrTZ];
return date;
}
-+ (id)valueFromBytes:(const void *)_bytes length:(int)_length
- sqlite3Type:(NSString *)_type
- attribute:(EOAttribute *)_attribute
- adaptorChannel:(SQLiteChannel *)_channel
-{
- return [self notImplemented:_cmd];
+- (id)initWithSQLiteDouble:(double)_value {
+ return [self initWithTimeIntervalSince1970:_value];
}
+- (id)initWithSQLiteInt:(int)_value {
+ return [self initWithSQLiteDouble:_value];
+}
+
+- (id)initWithSQLiteText:(const unsigned char *)_value {
+ return [self initWithSQLiteData:_value length:strlen(_value)];
+}
+
+/* generating value */
- (NSString *)stringValueForSQLite3Type:(NSString *)_type
attribute:(EOAttribute *)_attribute