4
** Copyright (c) 2007 Inverse groupe conseil inc. and Ludovic Marcotte
6
** Author: Ludovic Marcotte <ludovic@inverse.ca>
8
** This program is free software; you can redistribute it and/or modify
9
** it under the terms of the GNU General Public License as published by
10
** the Free Software Foundation; either version 2 of the License, or
11
** (at your option) any later version.
13
** This program is distributed in the hope that it will be useful,
14
** but WITHOUT ANY WARRANTY; without even the implied warranty of
15
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
** GNU General Public License for more details.
18
** You should have received a copy of the GNU General Public License
19
** along with this program; if not, write to the Free Software
20
** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23
#import <Foundation/Foundation.h>
24
#import <GDLAccess/GDLAccess.h>
29
void evaluate(EOAdaptorChannel *c, NSString *s)
31
NSLog(@"Evaluating:\t%@",s);
32
if ([c evaluateExpression: s] && [c isFetchInProgress])
37
attributes = [c describeResults];
38
NSLog(@"attributes = %@", [attributes description]);
40
while ((record = [c fetchAttributes: attributes withZone: NULL]))
42
NSLog(@"record = %@", record);
50
void insert(EOAdaptorChannel *channel, EOEntity *entity, NSMutableDictionary *row)
52
[row setObject: @"foo" forKey: @"c_name"];
53
[row setObject: @"barrr" forKey: @"c_content"];
54
[row setObject: [NSNumber numberWithInt: 1] forKey: @"c_creationdate"];
55
[row setObject: [NSNumber numberWithInt: 2] forKey: @"c_lastmodified"];
56
[row setObject: [NSNumber numberWithInt: 0] forKey: @"c_version"];
58
[channel insertRow: row forEntity: entity];
64
void update(EOAdaptorChannel *channel, EOEntity *entity, NSMutableDictionary *row)
66
EOSQLQualifier *qualifier;
68
qualifier = [[EOSQLQualifier alloc] initWithEntity: entity
69
qualifierFormat: @"%A = 'foo'", @"c_name"];
71
[row setObject: @"bazzzzzzzzzzz" forKey: @"c_content"];
72
[row setObject: [NSNumber numberWithInt: 2] forKey: @"c_creationdate"];
73
[row setObject: [NSNumber numberWithInt: 3] forKey: @"c_lastmodified"];
74
[row setObject: [NSNumber numberWithInt: 1] forKey: @"c_version"];
76
[channel updateRow: row describedByQualifier: qualifier];
82
int main (int argc, char **argv, char **env)
84
NSAutoreleasePool *pool;
86
EOAdaptorChannel *channel;
87
NSMutableDictionary *row;
88
EOAdaptorContext *ctx;
91
EOAttribute *attribute;
93
pool = [[NSAutoreleasePool alloc] init];
94
[NSProcessInfo initializeWithArguments: argv count: argc environment: env];
96
adaptor = [EOAdaptor adaptorWithName: @"Oracle8"];
97
[adaptor setConnectionDictionary: [NSDictionary dictionaryWithContentsOfFile: @"condict.plist"]];
98
ctx = [adaptor createAdaptorContext];
99
channel = [ctx createAdaptorChannel];
101
[channel openChannel];
102
[ctx beginTransaction];
104
//evaluate(channel, @"SELECT * FROM all_tables");
105
evaluate(channel, @"SELECT COUNT(*) FROM all_tables");
106
evaluate(channel, @"SELECT 1 FROM dual");
107
evaluate(channel, @"SELECT sysdate FROM dual");
109
evaluate(channel, @"DROP table otest_demo");
110
evaluate(channel, @"CREATE TABLE otest_demo (\nc_name VARCHAR2 (256) NOT NULL,\n c_content CLOB NOT NULL,\n c_creationdate INTEGER NOT NULL,\n c_lastmodified INTEGER NOT NULL,\n c_version INTEGER NOT NULL,\n c_deleted INTEGER DEFAULT 0 NOT NULL\n)");
112
evaluate(channel, @"DELETE FROM otest_demo where c_name = 'foo'");
114
entity = [[EOEntity alloc] init];
115
[entity setName: @"otest_demo"];
116
[entity setExternalName: @"otest_demo"]; // table name
118
attribute = AUTORELEASE([[EOAttribute alloc] init]);
119
[attribute setName: @"c_name"];
120
[attribute setColumnName: @"c_name"];
121
[entity addAttribute: attribute];
123
row = [[NSMutableDictionary alloc] init];
125
insert(channel, entity, row);
126
evaluate(channel, @"SELECT * FROM otest_demo where c_name = 'foo'");
127
update(channel, entity, row);
128
evaluate(channel, @"SELECT * FROM otest_demo where c_name = 'foo'");
133
[ctx commitTransaction];
134
[channel closeChannel];