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 #include "SQLiteChannel.h"
27 #include <NGExtensions/NSString+Ext.h>
28 #import <Foundation/NSString.h>
31 @implementation NSString(SQLiteValues)
33 static Class EOExprClass = Nil;
35 - (id)initWithSQLiteInt:(int)_value {
37 sprintf(buf, "%i", _value);
38 return [self initWithCString:buf];
40 - (id)initWithSQLiteDouble:(double)_value {
42 sprintf(buf, "%g", _value);
43 return [self initWithCString:buf];
46 - (id)initWithSQLiteText:(const unsigned char *)_value {
47 return [self initWithUTF8String:_value];
50 - (id)initWithSQLiteData:(const void *)_value length:(int)_length {
53 d = [[NSData alloc] initWithBytes:_value length:_length];
54 self = [self initWithData:d encoding:NSUTF8StringEncoding];
59 - (NSString *)stringValueForSQLite3Type:(NSString *)_type
60 attribute:(EOAttribute *)_attribute
62 // TODO: all this looks slow ...
66 if ((len = [_type length]) == 0)
69 c1 = [_type characterAtIndex:0];
80 _type = [_type lowercaseString];
82 if (!([_type hasPrefix:@"char"] ||
83 [_type hasPrefix:@"varchar"] ||
84 [_type hasPrefix:@"text"]))
87 /* TODO: creates too many autoreleased strings :-( */
89 expr = [self stringByReplacingString:@"\\" withString:@"\\\\"];
91 if (EOExprClass == Nil) EOExprClass = [EOQuotedExpression class];
92 expr = [[EOExprClass alloc] initWithExpression:expr
93 quote:@"'" escape:@"\\'"];
94 s = [[expr expressionValueForContext:nil] retain];
96 return [s autorelease];
100 if ([[_type lowercaseString] hasPrefix:@"money"])
101 return [@"$" stringByAppendingString:self];
109 @end /* NSString(SQLiteValues) */