4 Copyright (C) 1999-2005 MDlink online service center GmbH and Helge Hess
6 Author: Helge Hess (helge@mdlink.de)
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 "SQLiteValues.h"
29 @implementation SQLiteDataTypeMappingException
31 - (id)initWithObject:(id)_obj
32 forAttribute:(EOAttribute *)_attr
33 andSQLite3Type:(NSString *)_dt
34 inChannel:(SQLiteChannel *)_channel;
37 NSString *typeName = nil;
43 typeName = [NSString stringWithFormat:@"Oid[%i]", _dt];
45 r = [NSString stringWithFormat:
46 @"mapping between %@<Class:%@> and "
47 @"SQLite type %@ is not supported",
49 NSStringFromClass([_obj class]),
51 ui = [NSDictionary dictionaryWithObjectsAndKeys:
57 [self setName:@"DataTypeMappingNotSupported"];
60 [self setUserInfo:ui];
64 @end /* SQLiteDataTypeMappingException */
66 @implementation NSNull(SQLiteValues)
68 - (NSString *)stringValueForSQLite3Type:(NSString *)_type
69 attribute:(EOAttribute *)_attribute
74 @end /* NSNull(SQLiteValues) */
76 @implementation NSObject(SQLiteValues)
78 - (id)initWithSQLiteInt:(int)_value {
79 if ([self respondsToSelector:@selector(initWithInt:)])
80 return [(NSNumber *)self initWithInt:_value];
82 if ([self respondsToSelector:@selector(initWithDouble:)])
83 return [(NSNumber *)self initWithDouble:_value];
85 if ([self respondsToSelector:@selector(initWithString:)]) {
89 sprintf(buf, "%i", _value);
90 s = [[NSString alloc] initWithCString:buf];
91 self = [(NSString *)self initWithString:s];
100 - (id)initWithSQLiteDouble:(double)_value {
101 if ([self respondsToSelector:@selector(initWithDouble:)])
102 return [(NSNumber *)self initWithDouble:_value];
108 - (id)initWithSQLiteText:(const unsigned char *)_value {
109 if ([self respondsToSelector:@selector(initWithString:)]) {
112 s = [[NSString alloc] initWithUTF8String:_value];
113 self = [(NSString *)self initWithString:s];
122 - (id)initWithSQLiteData:(const void *)_data length:(int)_length {
123 if ([self respondsToSelector:@selector(initWithBytes:length:)])
124 return [(NSData *)self initWithBytes:_data length:_length];
126 if ([self respondsToSelector:@selector(initWithData:)]) {
129 d = [[NSData alloc] initWithBytes:_data length:_length];
130 self = [(NSData *)self initWithData:d];
139 @end /* NSObject(SQLiteValues) */
141 void __link_SQLiteValues() {
142 // used to force linking of object file
143 __link_SQLiteValues();