microdb icon indicating copy to clipboard operation
microdb copied to clipboard

Deleting a record corrupts the index

Open Joker-vD opened this issue 9 years ago • 5 comments

<?php

include "MicroDB/Database.php";
include "MicroDB/Event.php";
include "MicroDB/Cache.php";
include "MicroDB/Index.php";

$db = new \MicroDB\Database('data/bug_index');
$id_idx = new \MicroDB\Index($db, 'id_idx', 'id');

$id1 = $db->create(array('id' => 42, 'data' => 'Item #1'));
$id2 = $db->create(array('id' => 42, 'data' => 'Item #2'));

$db->delete($id1);
$db->delete($id2);

$id = $id_idx->first(42);

var_dump($id);
?>

Expected output: NULL Actual output: int(2)

Joker-vD avatar Mar 09 '16 12:03 Joker-vD

@rickerd would you mind looking into this?

morris avatar Mar 09 '16 22:03 morris

Im currently working on a AngularJS application with jcrop that i need to fix. If i have time ill do it, maybe you'll have it solved faster than me.

UPDATE: I looked into it but don't have an answer for the bug.

rickerd avatar Mar 09 '16 22:03 rickerd

Well, I'd say the immediate problem is with https://github.com/morris/microdb/blob/master/src/MicroDB/Index.php#L227 https://github.com/morris/microdb/blob/master/src/MicroDB/Index.php#L254 because the docs for array_splice() explicitly state

Note that numeric keys in input are not preserved.

However, given that in 2 years nobody has ever bothered to use the index-related functionality of this DBMS, I doubt it is worth any time or efforts to investigate this issue any further.

Joker-vD avatar Mar 17 '16 13:03 Joker-vD

Thanks for the information! :+1:

Why do you think its not worth any time? I think there can be a fix. If you can contribute to the project i'll appreciate it.

rickerd avatar Mar 17 '16 14:03 rickerd

how much speed this microdb?

sirmagid avatar Feb 09 '18 20:02 sirmagid