]> err.no Git - sope/blob - sope-gdl1/SQLite3/SQLiteValues.m
fixed gcc 4.0 warnings
[sope] / sope-gdl1 / SQLite3 / SQLiteValues.m
1 /* 
2    SQLiteValues.m
3
4    Copyright (C) 1999-2005 MDlink online service center GmbH and Helge Hess
5
6    Author: Helge Hess (helge@mdlink.de)
7
8    This file is part of the SQLite Adaptor Library
9
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.
14
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.
19
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.
24 */
25
26 #import "SQLiteValues.h"
27 #import "common.h"
28
29 @implementation SQLiteDataTypeMappingException
30
31 - (id)initWithObject:(id)_obj
32   forAttribute:(EOAttribute *)_attr
33   andSQLite3Type:(NSString *)_dt
34   inChannel:(SQLiteChannel *)_channel;
35 {  
36   NSDictionary *ui;
37   NSString *typeName = nil;
38   NSString *r;
39
40   typeName = _dt;
41
42   if (typeName == nil)
43     typeName = [NSString stringWithFormat:@"Oid[%i]", _dt];
44
45   r = [NSString stringWithFormat:
46                               @"mapping between %@<Class:%@> and "
47                               @"SQLite type %@ is not supported",
48                               [_obj description],
49                               NSStringFromClass([_obj class]),
50                 typeName];
51   ui = [NSDictionary dictionaryWithObjectsAndKeys:
52                                     _attr,    @"attribute",
53                                     _channel, @"channel",
54                                     _obj,     @"object",
55                      nil];
56   
57   return [self initWithName:@"DataTypeMappingNotSupported" reason:r
58                userInfo:ui];
59 }
60
61 @end /* SQLiteDataTypeMappingException */
62
63 @implementation NSNull(SQLiteValues)
64
65 - (NSString *)stringValueForSQLite3Type:(NSString *)_type
66   attribute:(EOAttribute *)_attribute
67 {
68   return @"null";
69 }
70
71 @end /* NSNull(SQLiteValues) */
72
73 @implementation NSObject(SQLiteValues)
74
75 - (id)initWithSQLiteInt:(int)_value {
76   if ([self respondsToSelector:@selector(initWithInt:)])
77     return [(NSNumber *)self initWithInt:_value];
78   
79   if ([self respondsToSelector:@selector(initWithDouble:)])
80     return [(NSNumber *)self initWithDouble:_value];
81   
82   if ([self respondsToSelector:@selector(initWithString:)]) {
83     NSString *s;
84     char buf[256];
85
86     sprintf(buf, "%i", _value);
87     s = [[NSString alloc] initWithCString:buf];
88     self = [(NSString *)self initWithString:s];
89     [s release];
90     return self;
91   }
92   
93   [self release];
94   return nil;
95 }
96
97 - (id)initWithSQLiteDouble:(double)_value {
98   if ([self respondsToSelector:@selector(initWithDouble:)])
99     return [(NSNumber *)self initWithDouble:_value];
100   
101   [self release];
102   return nil;
103 }
104
105 - (id)initWithSQLiteText:(const unsigned char *)_value {
106   if ([self respondsToSelector:@selector(initWithString:)]) {
107     NSString *s;
108     
109     s = [[NSString alloc] initWithUTF8String:(char *)_value];
110     self = [(NSString *)self initWithString:s];
111     [s release];
112     return self;
113   }
114   
115   [self release];
116   return nil;
117 }
118
119 - (id)initWithSQLiteData:(const void *)_data length:(int)_length {
120   if ([self respondsToSelector:@selector(initWithBytes:length:)])
121     return [(NSData *)self initWithBytes:_data length:_length];
122   
123   if ([self respondsToSelector:@selector(initWithData:)]) {
124     NSData *d;
125     
126     d = [[NSData alloc] initWithBytes:_data length:_length];
127     self = [(NSData *)self initWithData:d];
128     [d release];
129     return self;
130   }
131   
132   [self release];
133   return nil;
134 }
135
136 @end /* NSObject(SQLiteValues) */
137
138 void __link_SQLiteValues() {
139   // used to force linking of object file
140   __link_SQLiteValues();
141 }