Bug #62491 [Ana->Wfx]: Iterating over items + dba_delete not working

From: Date: Tue, 03 Dec 2013 13:45:59 +0000
Subject: Bug #62491 [Ana->Wfx]: Iterating over items + dba_delete not working
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-183103@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=62491&edit=1

 ID:                 62491
 Updated by:         mike@php.net
 Reported by:        marc-bennewitz at arcor dot de
 Summary:            Iterating over items + dba_delete not working
-Status:             Analyzed
+Status:             Wont fix
 Type:               Bug
 Package:            DBM/DBA related
 Operating System:   openSUSE 11.3 (x86_64)
 PHP Version:        5.4.4
 Block user comment: N
 Private report:     N

 New Comment:

Yes, so the inifile handler directly operates on the file stream.


Previous Comments:
------------------------------------------------------------------------
[2013-12-03 13:13:19] mike@php.net

Two failing assumptions here:
.) Changing the set of an active iterator usually results in undefined behaviour.
.) Trying to fetch the next item after deleting the current.

So, gdbm seems to work if you fetch the next kex prior delete, but, anyway, the inifile handler
fails.

I'll have a look at the inifile handler, but am inclined to mark this report as
"Won't fix".

Changed test script:
<?php
foreach (["gdbm","db4","flatfile","inifile"] as $hnd) {
	echo "###################### $hnd ########################\n";
	$dba = dba_open(sys_get_temp_dir() . DIRECTORY_SEPARATOR . uniqid('zfcache_dba_'),
'c', $hnd);
	if (!$dba) continue;
	dba_insert('key1', 'value', $dba);
	dba_insert('test2', 'value', $dba);
	dba_insert('key3', 'value', $dba);
	dba_insert('test4', 'value', $dba);
	dba_insert('key5', 'value', $dba);

	$key = dba_firstkey($dba);
	var_dump($key);
	while ($key) {
		$key = dba_nextkey($dba);
		$key && var_dump($key);
	}

	$key = dba_firstkey($dba);
	while ($key) {
		$nxt = dba_nextkey($dba);
		
		if (substr($key, 0, 3) === 'key') {
			dba_delete($key, $dba);
		}
		$key = $nxt;
	}

	echo "\n### after delete\n";

	$key = dba_firstkey($dba);
	var_dump($key);
	while ($key) {
		$key = dba_nextkey($dba);
		$key && var_dump($key);
	}
	echo "\n\n";
}

------------------------------------------------------------------------
[2012-07-06 08:57:52] marc-bennewitz at arcor dot de

Description:
------------
With some handlers it's not possible to iterate over items if there will be items deleted
within iteration.

Test script:
---------------
// Script to delete items with specific prefix

$dba = dba_open(sys_get_temp_dir() . DIRECTORY_SEPARATOR . uniqid('zfcache_dba_'),
'c', 'qdbm');

dba_insert('key1', 'value', $dba);
dba_insert('test2', 'value', $dba);
dba_insert('key3', 'value', $dba);
dba_insert('test4', 'value', $dba);
dba_insert('key5', 'value', $dba);

$key = dba_firstkey($dba);
var_dump($key);
while ($key !== false) {
    $key = dba_nextkey($dba);
    var_dump($key);
}

echo '#############################' . PHP_EOL;

$key = dba_firstkey($dba);
while ($key !== false) {
    if (substr($key, 0, 3) === 'key') {
        var_dump($key);
        dba_delete($key, $dba);
    }
    $key = dba_nextkey($dba);
}

echo '#############################' . PHP_EOL;

$key = dba_firstkey($dba);
var_dump($key);
while ($key !== false) {
    $key = dba_nextkey($dba);
    var_dump($key);
}


Expected result:
----------------
string(4) "key1"
string(5) "test2"
string(4) "key3"
string(5) "test4"
string(4) "key5"
bool(false)
#############################
string(4) "key1"
string(4) "key3"
string(4) "key5"
#############################
string(5) "test2"
string(5) "test4"
bool(false)

Actual result:
--------------
flatfile -> correct
inifile	 -> wrong (breaks iteration after first delete)
gdbm     -> wrong (breaks iteration after first delete)
qdbm     -> correct
db4      -> correct


------------------------------------------------------------------------



-- 
Edit this bug report at https://bugs.php.net/bug.php?id=62491&edit=1


Thread (3 messages)

« previous php.bugs (#183103) next »