donjajo/php-jsondb

Does deleting all rows works correctly?

Closed this issue · 3 comments

Hello donjajo!
This library is very useful and thank you for your efforts.
I applied your library to my project and I experience one strange issue which explain in below.

Situation

When I use 'delete' action without any 'where' function, nothing happened. But, 'delete' action with 'where' function is perfectly worked. The code in issue is :

hnd_json::GetDB()->delete()->from(hnd_json::TABLE_BOOK)->trigger(); //not working
hnd_json::GetDB()->delete()->from(hnd_json::TABLE_BOOK)->where(['book_path' => $path])->trigger(); //working

/*
hnd_json::GetDB() returns my Jajo/JSONDB Object
hnd_json::TABLE_BOOK is const of json file's path
*/

You can see whole code I wrote in here

I have the snapshot of JSONDB object when it's executed until

hnd_json::GetDB()->delete()->from(hnd_json::TABLE_BOOK)

and it's like image below
snapshot

Additionally, JSONDB Object in this situation performed serveral 'select' actions..

Solution?

In my think, condition of if statement in here need to be changed ' empty( $this->where ) && empty( $this->last_indexes ) to empty( $this->where ) or flush_indexes function need to be called before every deleting all rows action. But, I didn't understand whole of your code and intentions. so, I just guess

Thank you for reading and I will look forward to your reply.

Hi,
I am unable to replicate your issue. I added a test for delete all here cac01b5 and all works fine. Kindly check and revert.

Hello, thanks for reply.
I updated test for delete all at #13.
In this test case, you can reproduce my issue's situation.

Or, Is it intended to recreate new JSONDB object per each actions?
Please check my pull request and question. Thank you.

This has been fixed here in the above commit.

Thank you!