Recently I need use sqlite to store Hierarchical data .After lots of search. I choose nested set model instead of adjacent list.because almost 90% read .only 10% query will be update delete or create. I follow the example here
and it works fine now. I add new node. delete node.read it out. but I find that all those articles have't dealt with update method? how could I move a category into another category. below is my database structure
id name left_node right_node
1 name1 1 2
all the pages don't mention the update method which I really need. Another problem is
public function delete_node($pleft, $pright){
$width = $pright-$pleft+1;
$delete_sql = "delete from categories where left_node between $pleft and $pright";
$update_sql1 = "update categories set right_node = right_node-$width where right_node > $pright";
$update_sql2 = "update categories set left_node = left_node-$width where left_node> $pright";
//
$this->db->trans_start();
//
$this->db->query($delete_sql);
//
$this->db->query($update_sql1);
$this->db->query($update_sql2);
$this->db->trans_complete();
//
return $this->db->trans_status();
}
this my delete method, and I find it needs 30ms to finish.Is that normal?
Aucun commentaire:
Enregistrer un commentaire