Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
The error message I get is:#$dbh->do("create table terms (id INTEGER not NULL, # term TEXT,tree TEXT, parent_id INTEGER,left_id # int,right_id int,PRIMARY KEY (id))" # # ); #$dbh->do(qq| INSERT INTO terms VALUES (1,"ANATOMY BODY REGIONS","A01" +,"1","1","8")|); #$dbh->do(qq| INSERT INTO terms VALUES (2,"ABDOMEN","A01.047","1","2", +"")|); #$dbh->do(qq| INSERT INTO terms VALUES (3,"AXILA","A01.133","1","","") +|); #$dbh->do(qq| INSERT INTO terms VALUES (4,"EXTREMITIES","A01.378","1", +"","")|); #$dbh->do(qq| INSERT INTO terms VALUES (5,"ARM","A01.378.209","4",""," +")|); #$dbh->do(qq| INSERT INTO terms VALUES (6,"ELBOW","A01.378.209.235","5 +","","")|); #$dbh->do(qq| INSERT INTO terms VALUES (7,"HAND","A01.378.209.455","5" +,"","")|); #$dbh->do(qq| INSERT INTO terms VALUES (8,"FINGERS","A01.378.209.455.4 +30","7","","")|); my $result= $dbh->prepare("SELECT id FROM terms WHERE parent_id = ?"); my $left = $dbh->prepare("UPDATE terms SET left_id=? WHERE id = ?"); my $right= $dbh->prepare("UPDATE terms SET left_id=? WHERE id = ?"); my $root =1; my $counter = 1; rebuild_tree($root); sub rebuild_tree{ my $idy = shift; $left->execute($ctr++,$idy); $result->execute($idy); while (my $idy = $result->fetchrow_hashref()) { $idy = $i->{id}; rebuild_tree($idy); } $right->execute($ctr++,$idy); }#end of sub
When I put all the prepare statements in the rebuild_tree sub, the results are not right. Anything wrong with the recursive method or is it a problem with my scoping? Any help would be much appreciated. I am trying to build a nested set database to access some hierarchical data. I am using MySQL as my back-end database.DBD::mysql::st fetchrow_hashref failed: fetch() without execute() at s +et_depth1. pl line 67. DBD::mysql::st fetchrow_hashref failed: fetch() without execute() at s +et_depth1. pl line 67.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Hierarchical Tree Traversal
by jZed (Prior) on Jul 15, 2004 at 18:04 UTC | |
by Raad (Acolyte) on Jul 15, 2004 at 19:31 UTC | |
by Hero Zzyzzx (Curate) on Jul 16, 2004 at 00:23 UTC | |
by Anonymous Monk on Jul 16, 2004 at 01:53 UTC | |
by Raad (Acolyte) on Jul 15, 2004 at 19:50 UTC | |
by eric256 (Parson) on Jul 15, 2004 at 20:05 UTC |