~ubuntu-branches/ubuntu/saucy/sope/saucy

« back to all changes in this revision

Viewing changes to sope-gdl1/SQLite3/SQLiteAdaptor.m

  • Committer: Package Import Robot
  • Author(s): Jeroen Dekkers
  • Date: 2012-05-09 15:39:17 UTC
  • Revision ID: package-import@ubuntu.com-20120509153917-nr4jlm8mktma1yv3
Tags: upstream-1.3.14
ImportĀ upstreamĀ versionĀ 1.3.14

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* 
 
2
   SQLiteAdaptor.m
 
3
 
 
4
   Copyright (C) 2003-2005 SKYRIX Software AG
 
5
 
 
6
   Author: Helge Hess (helge.hess@skyrix.com)
 
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
#include "SQLiteAdaptor.h"
 
27
#include "SQLiteContext.h"
 
28
#include "SQLiteChannel.h"
 
29
#include "SQLiteExpression.h"
 
30
#include "SQLiteValues.h"
 
31
#include "common.h"
 
32
 
 
33
@implementation SQLiteAdaptor
 
34
 
 
35
- (NSDictionary *)connectionDictionaryForNSURL:(NSURL *)_url {
 
36
  /*
 
37
    "Database URLs"
 
38
    
 
39
    We use the schema:
 
40
      SQLite3://localhost/dbpath/foldername
 
41
  */
 
42
  NSMutableDictionary *md;
 
43
  NSString *p;
 
44
  
 
45
  if ((p = [_url path]) == nil)
 
46
    return nil;
 
47
  
 
48
  p = [p stringByDeletingLastPathComponent];
 
49
  if ([p length] == 0) p = [_url path];
 
50
  
 
51
  md = [NSMutableDictionary dictionaryWithCapacity:8];
 
52
  [md setObject:p forKey:@"databaseName"];
 
53
  return md;
 
54
}
 
55
 
 
56
- (id)initWithName:(NSString *)_name {
 
57
  if ((self = [super initWithName:_name])) {
 
58
  }
 
59
  return self;
 
60
}
 
61
 
 
62
/* NSCopying methods */
 
63
 
 
64
- (id)copyWithZone:(NSZone *)_zone {
 
65
  return [self retain];
 
66
}
 
67
 
 
68
// connections
 
69
 
 
70
- (NSString *)serverName {
 
71
  return @"localhost";
 
72
}
 
73
- (NSString *)loginName {
 
74
  return @"no-login-required";
 
75
}
 
76
- (NSString *)loginPassword {
 
77
  return @"no-pwd-required";
 
78
}
 
79
- (NSString *)databaseName {
 
80
  return [[[[self connectionDictionary]
 
81
                  objectForKey:@"databaseName"] copy] autorelease];
 
82
}
 
83
 
 
84
- (NSString *)port {
 
85
  return @"no-port-required";
 
86
}
 
87
- (NSString *)options {
 
88
  return [[[[self connectionDictionary]
 
89
                  objectForKey:@"options"] copy] autorelease];
 
90
}
 
91
 
 
92
/* sequence for primary key generation */
 
93
 
 
94
- (NSString *)primaryKeySequenceName {
 
95
  NSString *seqName;
 
96
 
 
97
  seqName =
 
98
    [[self pkeyGeneratorDictionary] objectForKey:@"primaryKeySequenceName"];
 
99
  return [[seqName copy] autorelease];
 
100
}
 
101
 
 
102
- (NSString *)newKeyExpression {
 
103
  NSString *newKeyExpr;
 
104
  
 
105
  newKeyExpr =
 
106
    [[self pkeyGeneratorDictionary] objectForKey:@"newKeyExpression"];
 
107
  return [[newKeyExpr copy] autorelease];
 
108
}
 
109
 
 
110
// formatting
 
111
 
 
112
- (NSString *)charConvertExpressionForAttributeNamed:(NSString *)_attrName {
 
113
  return _attrName;
 
114
}
 
115
 
 
116
- (id)formatValue:(id)value forAttribute:(EOAttribute *)attribute {
 
117
  NSString *result;
 
118
  
 
119
  result = [value stringValueForSQLite3Type:[attribute externalType]
 
120
                  attribute:attribute];
 
121
 
 
122
  //NSLog(@"formatting value %@ result %@", value, result);
 
123
  //NSLog(@"  value class %@ attr %@ attr type %@",
 
124
  //             [value class], attribute, [attribute externalType]);
 
125
 
 
126
  return result;
 
127
}
 
128
 
 
129
- (BOOL)attributeAllowedInDistinctSelects:(EOAttribute *)_attr {
 
130
  return YES;
 
131
}
 
132
 
 
133
/* types */
 
134
 
 
135
- (BOOL)isValidQualifierType:(NSString *)_typeName {
 
136
  return YES;
 
137
}
 
138
 
 
139
/* adaptor info */
 
140
 
 
141
- (Class)adaptorContextClass {
 
142
  return [SQLiteContext class];
 
143
}
 
144
- (Class)adaptorChannelClass {
 
145
  return [SQLiteChannel class];
 
146
}
 
147
 
 
148
- (Class)expressionClass {
 
149
  return [SQLiteExpression class];
 
150
}
 
151
 
 
152
@end /* SQLiteAdaptor */
 
153
 
 
154
void __linkSQLiteAdaptor(void) {
 
155
  extern void __link_EOAttributeSQLite();
 
156
  extern void __link_NSStringSQLite();
 
157
  extern void __link_SQLiteChannelModel();
 
158
  extern void __link_SQLiteValues();
 
159
  ;
 
160
  [SQLiteChannel    class];
 
161
  [SQLiteContext    class];
 
162
  [SQLiteException  class];
 
163
  [SQLiteExpression class];
 
164
  __link_EOAttributeSQLite();
 
165
  __link_NSStringSQLite();
 
166
  //__link_SQLiteChannelModel();
 
167
  __link_SQLiteValues();
 
168
  __linkSQLiteAdaptor();
 
169
}