Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 30 Jan 2002 17:35:27 -0500
From:      The Anarcat <anarcat@anarcat.dyndns.org>
To:        Alexander Langer <alex@big.endian.de>
Cc:        Libh <freebsd-libh@freebsd.org>
Subject:   Re: making Database::create the "default" Database tclh command and Exceptions
Message-ID:  <20020130223527.GA712@shall.anarcat.dyndns.org>
In-Reply-To: <20020130232718.E60912@fump.kawo2.rwth-aachen.de>
References:  <20020130214652.GA441@shall.anarcat.dyndns.org> <20020130232718.E60912@fump.kawo2.rwth-aachen.de>

next in thread | previous in thread | raw e-mail | index | archive | help

--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<Database> open( const string& /* aBasedir */ );
+     static Pointer<Database> open( bool, /* create */ , const string& /* =
aBasedir */ );
      static Pointer<Database> create( const string& /* aBasedir */ );
      static Pointer<Database> import_db( const string& aBasedir, const str=
ing& aFilename ) { Pointer<Database> 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> Database::open( const string& aBasedir =3D
+Pointer<Database> 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> 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




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20020130223527.GA712>