From d1a3e8c0b2b7f661386b72bb2570f3fc95d484e0 Mon Sep 17 00:00:00 2001 From: helge Date: Sun, 20 Feb 2005 16:11:24 +0000 Subject: [PATCH] fixed gdltest git-svn-id: http://svn.opengroupware.org/SOPE/trunk@576 e4a50df8-12e2-0310-a44c-efbce7f8a7e3 --- sope-gdl1/SQLite3/ChangeLog | 2 + sope-gdl1/SQLite3/GNUmakefile | 10 +- sope-gdl1/SQLite3/GNUmakefile.preamble | 3 + sope-gdl1/SQLite3/README | 6 ++ sope-gdl1/SQLite3/SQLiteChannel.m | 33 ++++--- sope-gdl1/SQLite3/condict.plist | 2 +- sope-gdl1/SQLite3/fhs.make | 25 +++++ sope-gdl1/SQLite3/gdltest.m | 122 ++++++++++++++++--------- sope-gdl1/SQLite3/test.eomodel | 11 ++- 9 files changed, 150 insertions(+), 64 deletions(-) create mode 100644 sope-gdl1/SQLite3/fhs.make diff --git a/sope-gdl1/SQLite3/ChangeLog b/sope-gdl1/SQLite3/ChangeLog index 04c9f229..7a2b9a7c 100644 --- a/sope-gdl1/SQLite3/ChangeLog +++ b/sope-gdl1/SQLite3/ChangeLog @@ -1,5 +1,7 @@ 2005-02-20 Helge Hess + * made gdltest work again + * added work on the SQLite3 adaptor to SOPE 4.5 repository * removed some PostgreSQL stuff diff --git a/sope-gdl1/SQLite3/GNUmakefile b/sope-gdl1/SQLite3/GNUmakefile index a1e6dbaf..1d928ad4 100644 --- a/sope-gdl1/SQLite3/GNUmakefile +++ b/sope-gdl1/SQLite3/GNUmakefile @@ -22,7 +22,10 @@ # If not, write to the Free Software Foundation, # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +-include ../../config.make include $(GNUSTEP_MAKEFILES)/common.make +include ../Version +include ./Version BUNDLE_NAME = SQLite3 @@ -44,7 +47,7 @@ SQLite3_OBJC_FILES = \ SQLite3_PRINCIPAL_CLASS = SQLiteAdaptor BUNDLE_INSTALL = SQLite3 -BUNDLE_INSTALL_DIR = $(GNUSTEP_SYSTEM_ROOT)/Libraries/Adaptors +BUNDLE_INSTALL_DIR = $(GNUSTEP_INSTALLATION_DIR)/Library/GDLAdaptors-$(MAJOR_VERSION).$(MINOR_VERSION)/ # Use .gdladaptor as the bundle extension BUNDLE_EXTENSION = .gdladaptor @@ -59,5 +62,8 @@ gdltest_OBJC_FILES = gdltest.m -include GNUmakefile.preamble include $(GNUSTEP_MAKEFILES)/bundle.make -#include $(GNUSTEP_MAKEFILES)/tool.make +ifeq ($(test),yes) +include $(GNUSTEP_MAKEFILES)/tool.make +endif -include GNUmakefile.postamble +include fhs.make diff --git a/sope-gdl1/SQLite3/GNUmakefile.preamble b/sope-gdl1/SQLite3/GNUmakefile.preamble index 3d0f50b8..5a4f4cc6 100644 --- a/sope-gdl1/SQLite3/GNUmakefile.preamble +++ b/sope-gdl1/SQLite3/GNUmakefile.preamble @@ -38,3 +38,6 @@ ADDITIONAL_LIB_DIRS += \ -L/usr/local/lib \ -L/usr/lib \ +SYSTEM_LIB_DIR += \ + -L/usr/local/lib \ + -L/usr/lib diff --git a/sope-gdl1/SQLite3/README b/sope-gdl1/SQLite3/README index 4031916d..6563b139 100644 --- a/sope-gdl1/SQLite3/README +++ b/sope-gdl1/SQLite3/README @@ -33,6 +33,12 @@ Configure the Adaptor (below does not work yet for SQLite3!) SQLiteDebugEnabled +Setup gdltest Database +====================== +sqlite3 Test.sqldb +sqlite> CREATE TABLE my_table ( pkey INT PRIMARY KEY ); + + Sequential execution ==================== diff --git a/sope-gdl1/SQLite3/SQLiteChannel.m b/sope-gdl1/SQLite3/SQLiteChannel.m index 37d66b56..47649fa0 100644 --- a/sope-gdl1/SQLite3/SQLiteChannel.m +++ b/sope-gdl1/SQLite3/SQLiteChannel.m @@ -98,6 +98,20 @@ static int openConnectionCount = 0; return (self->_connection != NULL) ? YES : NO; } +- (int)maxOpenConnectionCount { + static int MaxOpenConnectionCount = -1; + + if (MaxOpenConnectionCount == -1) { + MaxOpenConnectionCount = + [[NSUserDefaults standardUserDefaults] + integerForKey:@"SQLiteMaxOpenConnectionCount"]; + if (MaxOpenConnectionCount == 0) { + MaxOpenConnectionCount = 15; + } + } + return MaxOpenConnectionCount; +} + - (BOOL)openChannel { SQLiteAdaptor *adaptor; int rc; @@ -117,21 +131,10 @@ static int openConnectionCount = 0; openConnectionCount); #endif { - static int MaxOpenConnectionCount = -1; - - if (MaxOpenConnectionCount == -1) { - MaxOpenConnectionCount = - [[NSUserDefaults standardUserDefaults] - integerForKey:@"SQLiteMaxOpenConnectionCount"]; - if (MaxOpenConnectionCount == 0) { - MaxOpenConnectionCount = 15; - } - } - if (openConnectionCount > MaxOpenConnectionCount) { - [SQLiteCouldNotOpenChannelException raise: - @"NoMoreConnections" - format: - @"cannot open a additional connection !"]; + if (openConnectionCount > [self maxOpenConnectionCount]) { + [SQLiteCouldNotOpenChannelException + raise:@"NoMoreConnections" + format:@"cannot open a additional connection !"]; return NO; } } diff --git a/sope-gdl1/SQLite3/condict.plist b/sope-gdl1/SQLite3/condict.plist index fef398e4..250e134f 100644 --- a/sope-gdl1/SQLite3/condict.plist +++ b/sope-gdl1/SQLite3/condict.plist @@ -1,3 +1,3 @@ { - databaseName = "hhtest1"; + databaseName = "Test.sqldb"; } diff --git a/sope-gdl1/SQLite3/fhs.make b/sope-gdl1/SQLite3/fhs.make new file mode 100644 index 00000000..6c5bd960 --- /dev/null +++ b/sope-gdl1/SQLite3/fhs.make @@ -0,0 +1,25 @@ +# postprocessing + +# FHS support (this is a hack and is going to be done by gstep-make!) + +ifneq ($(FHS_INSTALL_ROOT),) + +FHS_LIB_DIR=$(FHS_INSTALL_ROOT)/lib/ +FHS_DB_DIR=$(FHS_LIB_DIR)sope-$(SOPE_MAJOR_VERSION).$(SOPE_MINOR_VERSION)/dbadaptors/ + +fhs-db-dirs :: + $(MKDIRS) $(FHS_DB_DIR) + +move-bundles-to-fhs :: fhs-db-dirs + @echo "moving bundles $(BUNDLE_INSTALL_DIR) to $(FHS_DB_DIR) .." + for i in $(BUNDLE_NAME); do \ + j="$(FHS_DB_DIR)/$${i}$(BUNDLE_EXTENSION)"; \ + if test -d $$j; then rm -r $$j; fi; \ + mv "$(BUNDLE_INSTALL_DIR)/$${i}$(BUNDLE_EXTENSION)" $$j; \ + done + +move-to-fhs :: move-bundles-to-fhs + +after-install :: move-to-fhs + +endif diff --git a/sope-gdl1/SQLite3/gdltest.m b/sope-gdl1/SQLite3/gdltest.m index 6a21fe8b..cad5fdb8 100644 --- a/sope-gdl1/SQLite3/gdltest.m +++ b/sope-gdl1/SQLite3/gdltest.m @@ -1,54 +1,45 @@ -// +/* + SQLiteValues.h + + Copyright (C) 1999-2005 MDlink online service center GmbH and Helge Hess + + Author: Helge Hess (helge@mdlink.de) + + This file is part of the SQLite Adaptor Library + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; see the file COPYING.LIB. + If not, write to the Free Software Foundation, + 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ #import #import #include -int main(int argc, char **argv, char **env) { - EOModel *m = nil; - EOAdaptor *a; +static void runtestInOpenChannel(EOAdaptorChannel *ch) { EOAdaptorContext *ctx; - EOAdaptorChannel *ch; - NSDictionary *conDict; - NSString *expr; - - [NSProcessInfo initializeWithArguments:argv count:argc environment:env]; + EOModel *m; + NSString *expr; - NS_DURING { - - conDict = [NSDictionary dictionaryWithContentsOfFile:@"condict.plist"]; - NSLog(@"condict is %@", conDict); - - if ((a = [EOAdaptor adaptorWithName:@"SQLite3"]) == nil) { - NSLog(@"found no SQLite3 adaptor .."); - exit(1); - } - - NSLog(@"got adaptor %@", a); - [a setConnectionDictionary:conDict]; - NSLog(@"got adaptor with condict %@", a); - - ctx = [a createAdaptorContext]; - ch = [ctx createAdaptorChannel]; + ctx = [ch adaptorContext]; + m = [[ctx adaptor] model]; -#if 1 - m = AUTORELEASE([[EOModel alloc] initWithContentsOfFile:@"test.eomodel"]); - if (m) { - [a setModel:m]; - [a setConnectionDictionary:conDict]; - } -#endif - expr = [[NSUserDefaults standardUserDefaults] stringForKey:@"sql"]; - NSLog(@"opening channel .."); - - [ch setDebugEnabled:YES]; - - if ([ch openChannel]) { - NSLog(@"channel is open"); + NSLog(@"channel is open"); - if ([ctx beginTransaction]) { + if ([ctx beginTransaction]) { NSLog(@"began tx .."); /* do something */ @@ -75,7 +66,7 @@ int main(int argc, char **argv, char **env) { #endif /* fetch some doof records */ - e = [m entityNamed:@"Doof"]; + e = [m entityNamed:@"MyEntity"]; NSLog(@"entity: %@", e); if (e == nil) exit(1); @@ -150,6 +141,46 @@ int main(int argc, char **argv, char **env) { else NSLog(@" commit failed."); } +} + +static void runtest(void) { + EOModel *m = nil; + EOAdaptor *a; + EOAdaptorContext *ctx; + EOAdaptorChannel *ch; + NSDictionary *conDict; + + NS_DURING { + + conDict = [NSDictionary dictionaryWithContentsOfFile:@"condict.plist"]; + NSLog(@"condict is %@", conDict); + + if ((a = [EOAdaptor adaptorWithName:@"SQLite3"]) == nil) { + NSLog(@"found no SQLite3 adaptor .."); + exit(1); + } + + NSLog(@"got adaptor %@", a); + [a setConnectionDictionary:conDict]; + NSLog(@"got adaptor with condict %@", a); + + ctx = [a createAdaptorContext]; + ch = [ctx createAdaptorChannel]; + +#if 1 + m = AUTORELEASE([[EOModel alloc] initWithContentsOfFile:@"test.eomodel"]); + if (m) { + [a setModel:m]; + [a setConnectionDictionary:conDict]; + } +#endif + + NSLog(@"opening channel .."); + + [ch setDebugEnabled:YES]; + + if ([ch openChannel]) { + runtestInOpenChannel(ch); NSLog(@"closing channel .."); [ch closeChannel]; @@ -160,6 +191,15 @@ int main(int argc, char **argv, char **env) { abort(); } NS_ENDHANDLER; +} + +int main(int argc, char **argv, char **env) { + NSAutoreleasePool *pool; + + pool = [[NSAutoreleasePool alloc] init]; + [NSProcessInfo initializeWithArguments:argv count:argc environment:env]; + runtest(); + [pool release]; return 0; } diff --git a/sope-gdl1/SQLite3/test.eomodel b/sope-gdl1/SQLite3/test.eomodel index 99d8716b..9079abad 100644 --- a/sope-gdl1/SQLite3/test.eomodel +++ b/sope-gdl1/SQLite3/test.eomodel @@ -4,13 +4,14 @@ adaptorName = SQLite3; entities = ( - { - name = Doof; - externalName = doof; + { /* CREATE TABLE my_table ( pkey INT PRIMARY KEY ); */ + name = MyEntity; + externalName = my_table; + className = EOGenericRecord; - primaryKeyAttributes = ( pkey ); + primaryKeyAttributes = ( pkey ); attributesUsedForLocking = ( pkey ); - classProperties = ( pkey ); + classProperties = ( pkey ); attributes = ( { valueClassName = NSNumber; -- 2.39.5