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 "SQLiteValues.h"
27
#include "SQLiteChannel.h"
28
#import <Foundation/NSData.h>
31
@implementation NSData(SQLiteValues)
33
- (id)initWithSQLiteInt:(int)_value {
34
return [self initWithBytes:&_value length:sizeof(int)];
36
- (id)initWithSQLiteDouble:(double)_value {
37
return [self initWithBytes:&_value length:sizeof(double)];
39
- (id)initWithSQLiteText:(const unsigned char *)_value {
40
return [self initWithBytes:_value length:strlen((char *)_value)];
42
- (id)initWithSQLiteData:(const void *)_value length:(int)_length {
43
return [self initWithBytes:_value length:_length];
46
- (NSString *)stringValueForSQLite3Type:(NSString *)_type
47
attribute:(EOAttribute *)_attribute
50
// TODO: this method looks slow
51
static NSStringEncoding enc = 0;
56
if ((len = [self length]) == 0)
60
enc = [NSString defaultCStringEncoding];
61
NSLog(@"Note: SQLite adaptor using '%@' encoding for data=>string "
63
[NSString localizedNameOfStringEncoding:enc]);
66
str = [[NSString alloc] initWithData:self encoding:enc];
68
if (((len = [_type length]) == 0) || (len != 4 && len != 5 && len != 7))
69
return [str autorelease];
71
c1 = [_type characterAtIndex:0];
77
t = [_type lowercaseString];
78
if ([t hasPrefix:@"char"] ||
79
[t hasPrefix:@"varchar"] ||
80
[t hasPrefix:@"money"] ||
81
[t hasPrefix:@"text"]) {
82
t = [[str stringValueForSQLite3Type:_type
83
attribute:_attribute] retain];
85
return [t autorelease];
89
return [str autorelease];;
92
@end /* NSData(SQLiteValues) */