4 Copyright (C) 2003-2005 SKYRIX Software AG
6 Author: Helge Hess (helge.hess@skyrix.com)
8 This file is part of the SQLite Adaptor Library
10 This library is free software; you can redistribute it and/or
11 modify it under the terms of the GNU Library General Public
12 License as published by the Free Software Foundation; either
13 version 2 of the License, or (at your option) any later version.
15 This library is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 Library General Public License for more details.
20 You should have received a copy of the GNU Library General Public
21 License along with this library; see the file COPYING.LIB.
22 If not, write to the Free Software Foundation,
23 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26 #import <Foundation/NSString.h>
27 #include "SQLiteChannel.h"
30 @implementation NSNumber(SQLiteValues)
32 - (id)initWithSQLiteInt:(int)_value {
33 return [self initWithInt:_value];
35 - (id)initWithSQLiteDouble:(double)_value {
36 return [self initWithDouble:_value];
38 - (id)initWithSQLiteText:(const unsigned char *)_value {
39 return index(_value, '.') != NULL
40 ? [self initWithDouble:atof(_value)]
41 : [self initWithInt:atoi(_value)];
44 - (id)initWithSQLiteData:(const void *)_value length:(int)_length {
46 case 1: return [self initWithUnsignedChar:*(char *)_value];
47 case 2: return [self initWithShort:*(short *)_value];
48 case 4: return [self initWithInt:*(int *)_value];
49 case 8: return [self initWithDouble:*(double *)_value];
56 - (NSString *)stringValueForSQLite3Type:(NSString *)_type
57 attribute:(EOAttribute *)_attribute
59 // TODO: can we avoid the lowercaseString?
63 if ((len = [_type length]) == 0)
64 return [self stringValue];
66 return [self stringValue];
68 c1 = [_type characterAtIndex:0];
71 if (![[_type lowercaseString] hasPrefix:@"bool"])
73 return [self boolValue] ? @"true" : @"false";
76 if (![[_type lowercaseString] hasPrefix:@"money"])
78 return [@"$" stringByAppendingString:[self stringValue]];
84 static NSMutableString *ms = nil; // reuse mstring, THREAD
86 _type = [_type lowercaseString];
87 if (!([_type hasPrefix:@"char"] ||
88 [_type hasPrefix:@"varchar"] ||
89 [_type hasPrefix:@"text"]))
92 // TODO: can we get this faster?!
93 if (ms == nil) ms = [[NSMutableString alloc] initWithCapacity:256];
95 [ms appendString:[self stringValue]];
96 [ms appendString:@"'"];
97 return [[ms copy] autorelease];
100 return [self stringValue];
103 @end /* NSNumber(SQLiteValues) */