]> granicus.if.org Git - php/commitdiff
- dba_[p]open accepts now a new parameter, which kind of database to create
authorJouni Ahto <jah@php.net>
Tue, 27 Jun 2000 21:36:26 +0000 (21:36 +0000)
committerJouni Ahto <jah@php.net>
Tue, 27 Jun 2000 21:36:26 +0000 (21:36 +0000)
  (DBA_BTREE or DBA_HASH), if the handler is either 'db2' or 'db3' and
  mode 'c' or 'n'. It is ignored if mode is 'c' and the db already exists.
# Asked on the list 4 1/2 hours ago if anyone's got to say something to this,
# no response, so I'm assuming it's ok. And yes, I did test this.

NEWS
ext/dba/dba.c
ext/dba/dba_db2.c
ext/dba/dba_db3.c
ext/dba/php_dba.h

diff --git a/NEWS b/NEWS
index d9f922e920116c9112509bc8c85253682dc0ce2d..d372addc6ad31fde5ae7c6cd363a2dc51fa4d439 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -2,6 +2,10 @@ PHP 4.0                                                                    NEWS
 |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
 
 28 Jun 2000, Version 4.0.1
+- Added a new (fifth) parameter to dba_[p]open(), which kind of database to
+  create (DBA_BTREE or DBA_HASH), if the handler is either 'db2' or 'db3' and 
+  mode 'c' or 'n'. It is ignored if mode is 'c' and the db already exists.
+  (Jouni)
 - Fixed a bug in opendir(), which prevented readdir() from working properly if
   the $dir argument wasn't explicitly specified (Zeev)
 - Made --enable-discard-path work again. (Andi) 
index b84de998c94b57ad77b2257b7b5a6c2136fe006a..934b801e7e70bdea301615c8484c57f10947a3cc 100644 (file)
@@ -191,6 +191,9 @@ static PHP_MINIT_FUNCTION(dba)
        zend_hash_init(&ht_keys, 0, NULL, NULL, 1);
        GLOBAL(le_db) = register_list_destructors(dba_close, NULL);
        GLOBAL(le_pdb) = register_list_destructors(NULL, dba_close);
+       REGISTER_LONG_CONSTANT("DBA_BTREE", DBA_BTREE, CONST_CS | CONST_PERSISTENT);
+       REGISTER_LONG_CONSTANT("DBA_HASH", DBA_HASH, CONST_CS | CONST_PERSISTENT);
+       REGISTER_LONG_CONSTANT("DBA_RECNO", DBA_RECNO, CONST_CS | CONST_PERSISTENT);
        return SUCCESS;
 }
 
index de68974358bf0a933f607b5063663f29b2e4a478..67eb366c60cf4bf0f7aa8add897140321527e7f4 100644 (file)
@@ -76,6 +76,21 @@ DBA_OPEN_FUNC(db2)
                filemode = (*info->argv[0])->value.lval;
        }
 
+       if(info->argc > 1
+          && ((info->mode == DBA_CREAT && type != DB_UNKNOWN)
+              || info->mode == DBA_TRUNC)) {
+               convert_to_long_ex(info->argv[1]);
+               switch ((*info->argv[1])->value.lval) {
+                       case DBA_HASH:
+                               type = DB_HASH;
+                               break;
+                       case DBA_BTREE:
+                       default:
+                               type = DB_BTREE;
+                               break;
+               }
+       }
+
        if(!db_open(info->path, type, gmode, filemode, NULL, NULL, &dbp)) {
                info->dbf = malloc(sizeof(dba_db2_data));
                memset(info->dbf, 0, sizeof(dba_db2_data));
index ae1405705df71c3881e8078c5360b5572621a235..809c5408ebee541b99c6b8ff6951dca58c8adb1f 100644 (file)
@@ -76,6 +76,21 @@ DBA_OPEN_FUNC(db3)
                filemode = (*info->argv[0])->value.lval;
        }
 
+       if(info->argc > 1
+          && ((info->mode == DBA_CREAT && type != DB_UNKNOWN)
+              || info->mode == DBA_TRUNC)) {
+               convert_to_long_ex(info->argv[1]);
+               switch ((*info->argv[1])->value.lval) {
+                       case DBA_HASH:
+                               type = DB_HASH;
+                               break;
+                       case DBA_BTREE:
+                       default:
+                               type = DB_BTREE;
+                               break;
+               }
+       }
+
        if (db_create(&dbp, NULL, 0) == 0 &&
                        dbp->open(dbp, info->path, NULL, type, gmode, filemode) == 0) {
                dba_db3_data *data;
index a504e972d11357f7a0de31340ca1ccde417af036..0eeb38c027ff47daf966c69cc5b2e78f58eb7b27 100644 (file)
@@ -41,6 +41,12 @@ typedef enum {
        DBA_CREAT
 } dba_mode_t;
 
+typedef enum { 
+       DBA_BTREE = 1,
+       DBA_HASH,
+       DBA_RECNO
+} dba_type_t;
+
 typedef struct dba_info {
        /* public */
        void *dbf;               /* ptr to private data or whatever */