]> err.no Git - scalable-opengroupware.org/commitdiff
drop/create test
authorznek <znek@d1b88da0-ebda-0310-925b-ed51d893ca5b>
Fri, 21 May 2004 15:16:54 +0000 (15:16 +0000)
committerznek <znek@d1b88da0-ebda-0310-925b-ed51d893ca5b>
Fri, 21 May 2004 15:16:54 +0000 (15:16 +0000)
git-svn-id: http://svn.opengroupware.org/SOGo/trunk@4 d1b88da0-ebda-0310-925b-ed51d893ca5b

db/tests/znek/GNUmakefile
db/tests/znek/connection.plist [new file with mode: 0644]
db/tests/znek/inserts.eomodel [new file with mode: 0644]
db/tests/znek/inserts.m [new file with mode: 0644]

index 4e140e57f58255444e77bbef2da950439f289bd9..f73eab261cda1b247b8992c37e56edeea3f9544e 100644 (file)
@@ -5,7 +5,8 @@ include $(GNUSTEP_MAKEFILES)/common.make
 TOOL_NAME = \
        ldapPersonExporter \
        findLongestEMailAddress \
-       personalFolderInfoInserts
+       personalFolderInfoInserts \
+        adaptorChannelInserts
 
 ldapPersonExporter_OBJC_FILES = lpe.m
 ldapPersonExporter_TOOL_LIBS += -lNGLdap
@@ -14,6 +15,10 @@ findLongestEMailAddress_OBJC_FILES = lmail.m
 
 personalFolderInfoInserts_OBJC_FILES = pfinserts.m
 
+adaptorChannelInserts_OBJC_FILES = inserts.m
+adaptorChannelInserts_TOOL_LIBS += -lGDLAccess
+
+
 -include GNUmakefile.preamble
 include $(GNUSTEP_MAKEFILES)/tool.make
 -include GNUmakefile.postamble
diff --git a/db/tests/znek/connection.plist b/db/tests/znek/connection.plist
new file mode 100644 (file)
index 0000000..0e6cda4
--- /dev/null
@@ -0,0 +1,7 @@
+{
+  hostName     = "agenor-db";
+  userName     = "agenor";
+  password     = "";
+  databaseName = "SOGo1";
+  port         = 5432;
+}
diff --git a/db/tests/znek/inserts.eomodel b/db/tests/znek/inserts.eomodel
new file mode 100644 (file)
index 0000000..c801cfd
--- /dev/null
@@ -0,0 +1,66 @@
+{
+/*
+  CREATE TABLE SOGo_test (
+    c_id        INT PRIMARY KEY,
+    c_dir       VARCHAR(255) NOT NULL,
+    c_cn        VARCHAR(40) NOT NULL,
+    c_mailto    VARCHAR(120) NOT NULL,
+  );
+*/
+
+    EOModelVersion   = 1;
+    adaptorClassName = PostgreSQLAdaptor;
+    adaptorName      = PostgreSQL;
+
+    entities = (
+      {
+        name         = Test;
+        externalName = SOGo_test;
+        className    = EOGenericRecord;
+        primaryKeyAttributes = ( pkey );
+        attributesUsedForLocking    = ( pkey,
+                                        dir,
+                                        cn,
+                                        mailto
+         );
+        classProperties             = ( pkey,
+                                        dir,
+                                        cn,
+                                        mailto
+         );
+        attributes = (
+                {
+                    columnName      = "c_id";
+                    name            = "pkey";
+                    valueClassName  = "NSNumber";
+                    valueType       = i;
+                    externalType    = INT;
+                },
+                {
+                    columnName      = "c_dir";
+                    name            = "dir";
+                    valueClassName  = "NSString";
+                    externalType    = "VARCHAR(255)";
+                    allowsNull      = N;
+                    width           = 255;
+                },
+                {
+                    columnName      = "c_cn";
+                    name            = "cn";
+                    valueClassName  = "NSString";
+                    externalType    = "VARCHAR(40)";
+                    allowsNull      = N;
+                    width           = 40;
+                },
+                {
+                    columnName      = "c_mailto";
+                    name            = "mailto";
+                    valueClassName  = "NSString";
+                    externalType    = "VARCHAR(120)";
+                    allowsNull      = N;
+                    width           = 120;
+                }
+        );
+      }
+    );
+}
diff --git a/db/tests/znek/inserts.m b/db/tests/znek/inserts.m
new file mode 100644 (file)
index 0000000..87bb6ff
--- /dev/null
@@ -0,0 +1,139 @@
+/*
+  @DISCLAIMER@
+*/
+// $Id$
+
+#import <Foundation/Foundation.h>
+#import <EOAccess/EOAccess.h>
+#import <NGExtensions/NGExtensions.h>
+
+
+#define DEBUG 0
+
+
+#define ALL_RECORDS @"/home/znek/all-BALI.plist"
+
+
+int main(int argc, char **argv, char **env) {
+    NSAutoreleasePool *pool;
+    EOModel          *m = nil;
+    EOAdaptor        *a;
+    EOAdaptorContext *ctx;
+    EOAdaptorChannel *ch;
+    NSDictionary     *conDict;
+    
+    pool = [[NSAutoreleasePool alloc] init];
+#if LIB_FOUNDATION_LIBRARY
+    [NSProcessInfo initializeWithArguments:argv count:argc environment:env];
+#endif
+
+    conDict = [NSDictionary dictionaryWithContentsOfFile:@"connection.plist"];
+    NSLog(@"condict is %@", conDict);
+    
+    if ((a = [EOAdaptor adaptorWithName:@"PostgreSQL72"]) == nil) {
+        NSLog(@"found no PostgreSQL adaptor ..");
+        exit(1);
+    }
+    
+    NSLog(@"got adaptor %@", a);
+    [a setConnectionDictionary:conDict];
+    NSLog(@"got adaptor with condict %@", a);
+    
+    ctx = [a   createAdaptorContext];
+    ch  = [ctx createAdaptorChannel];
+    
+    m = [[EOModel alloc] initWithContentsOfFile:@"inserts.eomodel"];
+    if (m) {
+        [a setModel:m];
+        [a setConnectionDictionary:conDict];
+    }
+    
+    
+    NSLog(@"opening channel ..");
+    
+    [ch setDebugEnabled:YES];
+    
+    if ([ch openChannel]) {
+        NSLog(@"channel is open");
+
+#if 0
+        if ([ctx beginTransaction]) {
+            NSLog(@"began tx ..");
+#endif            
+            /* do something */
+            {
+                NSAutoreleasePool *lpool = [[NSAutoreleasePool alloc] init];
+                EOEntity *e;
+                EOSQLQualifier *q;
+                NSArray *attrs;
+                NSString *expr;
+
+#if 0
+                NS_DURING
+
+                if([ctx beginTransaction]) {
+                    expr = @"DROP TABLE SOGo_test";
+
+                    if([ch evaluateExpression:expr]) {
+                        attrs = [ch describeResults];
+                        NSLog(@"results: %@", attrs);
+
+
+                        if([ctx commitTransaction]) {
+                            NSLog(@"DROP'ed table - committed.");
+                        } else {
+                            NSLog(@"couldn't commit DROP TABLE!");
+                        }
+                    }
+                }
+               NS_HANDLER
+
+                    NSLog(@"DROP table aborted - %@", [localException reason]);
+                    NSLog(@"a");
+
+               NS_ENDHANDLER
+#endif
+
+                NS_DURING
+
+                if([ctx beginTransaction]) {
+                    expr = @"CREATE TABLE SOGo_test (c_id INT PRIMARY KEY, c_dir       VARCHAR(255) NOT NULL, c_cn VARCHAR(40) NOT NULL, c_mailto    VARCHAR(120) NOT NULL);";
+                    if([ch evaluateExpression:expr]) {
+                        if([ctx commitTransaction]) {
+                            NSLog(@"CREATE TABLE - committed");
+                        } else {
+                            NSLog(@"couldn't commit CREATE TABLE!");
+                        }
+                    }
+                }
+                
+                NS_HANDLER
+
+                   fprintf(stderr, "exception: %s\n", [[localException description] cString]);
+                   abort();
+
+                NS_ENDHANDLER;
+
+                [lpool release];
+            }
+#if 0
+            NSLog(@"committing tx ..");
+            if ([ctx commitTransaction])
+                NSLog(@"  could commit.");
+            else
+                NSLog(@"  commit failed.");
+       }
+#endif
+        
+        NSLog(@"closing channel ..");
+        [ch closeChannel];
+    }
+
+    
+    [m release];
+    [pool release];
+
+    exit(0);
+    return 0;
+}