From: znek Date: Fri, 21 May 2004 15:16:54 +0000 (+0000) Subject: drop/create test X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2f13b19a95b943a3b6831bca45193185c4ef7905;p=scalable-opengroupware.org drop/create test git-svn-id: http://svn.opengroupware.org/SOGo/trunk@4 d1b88da0-ebda-0310-925b-ed51d893ca5b --- diff --git a/db/tests/znek/GNUmakefile b/db/tests/znek/GNUmakefile index 4e140e57..f73eab26 100644 --- a/db/tests/znek/GNUmakefile +++ b/db/tests/znek/GNUmakefile @@ -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 index 00000000..0e6cda4f --- /dev/null +++ b/db/tests/znek/connection.plist @@ -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 index 00000000..c801cfd0 --- /dev/null +++ b/db/tests/znek/inserts.eomodel @@ -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 index 00000000..87bb6ff6 --- /dev/null +++ b/db/tests/znek/inserts.m @@ -0,0 +1,139 @@ +/* + @DISCLAIMER@ +*/ +// $Id$ + +#import +#import +#import + + +#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; +}