From owner-freebsd-libh Wed Jan 30 14:35:35 2002 Delivered-To: freebsd-libh@freebsd.org Received: from tomts17-srv.bellnexxia.net (tomts17.bellnexxia.net [209.226.175.71]) by hub.freebsd.org (Postfix) with ESMTP id D41DB37B402 for ; Wed, 30 Jan 2002 14:35:26 -0800 (PST) Received: from khan.anarcat.dyndns.org ([65.94.186.7]) by tomts17-srv.bellnexxia.net (InterMail vM.4.01.03.16 201-229-121-116-20010115) with ESMTP id <20020130223525.QRPG16289.tomts17-srv.bellnexxia.net@khan.anarcat.dyndns.org>; Wed, 30 Jan 2002 17:35:25 -0500 Received: from shall.anarcat.dyndns.org (shall.anarcat.dyndns.org [192.168.0.1]) by khan.anarcat.dyndns.org (Postfix) with ESMTP id 62B0E18E9; Wed, 30 Jan 2002 17:35:22 -0500 (EST) Received: by shall.anarcat.dyndns.org (Postfix, from userid 1000) id DF36920ACA; Wed, 30 Jan 2002 17:35:27 -0500 (EST) Date: Wed, 30 Jan 2002 17:35:27 -0500 From: The Anarcat To: Alexander Langer Cc: Libh Subject: Re: making Database::create the "default" Database tclh command and Exceptions Message-ID: <20020130223527.GA712@shall.anarcat.dyndns.org> Mail-Followup-To: The Anarcat , Alexander Langer , Libh References: <20020130214652.GA441@shall.anarcat.dyndns.org> <20020130232718.E60912@fump.kawo2.rwth-aachen.de> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="HlL+5n6rz5pIUxbD" Content-Disposition: inline In-Reply-To: <20020130232718.E60912@fump.kawo2.rwth-aachen.de> User-Agent: Mutt/1.3.25i Sender: owner-freebsd-libh@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG --HlL+5n6rz5pIUxbD Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed Jan 30, 2002 at 11:27:18PM +0100, Alexander Langer wrote: > Hi! >=20 > Makes sense to me. However, you should be able to turn the auto-create > behaviour off somehow, possibly by calling it with an extra parameter. Hmmm... Tricky. If we make the Database tcl command an alias to create(), then the code to handle that would end up in create(). Not good. I guess the proper way to do it would be to hack open() instead and give it the possibility to override the behavior there. On the top of my head: --- Database.hh 2002/01/30 21:58:22 1.5 +++ Database.hh 2002/01/30 22:32:00 @@ -74,7 +74,7 @@ Database( OpenFlag aOpenFlag, bool addSYSTEMpackage, const string& aBasedir ); virtual ~Database(); =20 - static Pointer open( const string& /* aBasedir */ ); + static Pointer open( bool, /* create */ , const string& /* = aBasedir */ ); static Pointer create( const string& /* aBasedir */ ); static Pointer import_db( const string& aBasedir, const str= ing& aFilename ) { Pointer db =3D new Database( ofCreate, false, = aBasedir ); db->import_db( aFilename ); return db; } =20 --- Database.cc 2002/01/21 21:44:52 1.4 +++ Database.cc 2002/01/30 22:32:29 @@ -83,7 +83,11 @@ addSYSTEMpackage &=3D mOpenFlag =3D=3D ofCreate; if ( mOpenFlag =3D=3D ofCreate ) { mOpenFlag =3D ofReadWrite; - create(); + try { + create(); + } catch (...) { + // db already created + } } =20 engine().lock(); @@ -109,10 +113,11 @@ =20 //=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =20 -Pointer Database::open( const string& aBasedir =3D +Pointer Database::open( bool create, const string& aBasedir =3D Configuration::instance()->dbPath() ) { - return new Database( ofReadWrite, false, aBasedir ); + return new Database( (create ? ofCreate : ofReadWrite ), + create, aBasedir ); } =20 Pointer Database::create( const string& aBasedir =3D But this would be yet another change in the Database interface, not sure this is a good idea. If we choose this, we might as well get rid of create(string), since it is the same as open(true, string). I have to think this over. A. --HlL+5n6rz5pIUxbD Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.6 (FreeBSD) Comment: For info see http://www.gnupg.org iEYEARECAAYFAjxYdS0ACgkQttcWHAnWiGfWJQCfYE9pHr8q8FyYC30fecf5haj2 8EoAn0n+ph//8xsQ0zhaCYTWHCib8jTS =2xv9 -----END PGP SIGNATURE----- --HlL+5n6rz5pIUxbD-- To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-libh" in the body of the message