|
|
|
| только начал изучать mysql, так что не судите строго. простейший скрипт по созданию процедуры добавления узла в дерево. куча ошибок, просто. помогите, пожалуйста.
drop procedure if exists add_comment;
create procedure add_comment (p_rgt integer, p_level integer)
begin
update comments
set lft_id = lft_id+2, rgt_id = rgt_id+2
where (lft_id > p_rgt);
update comments
set rgt_id = rgt_id+2
where ((rgt_id >= p_rgt)&&(lft_id < p_rgt));
if ((p_rgt = 0)&&(p_level = 0)) then
-- comment_id? record_id?
insert into comments(comment_id, level_num, active,
frozen, pic_id, subject, body_post, user_id, user_login,
user_name, user_node_id, created_datetime, ip_xff,
record_id, parent_id, lft_id, rgt_id, rep_original_id,
rep_node_id, replicator_user_id, disallow_replicate)
values(300, 1, 0, 2, 0, 0, 0, 0, 0, 0, 0, NOW(), 0, 76,
0, 1, p_rgt, 0, 0, 0, 0);
else
insert into comments(comment_id, level_num, active,
frozen, pic_id, subject, body_post, user_id, user_login,
user_name, user_node_id, created_datetime, ip_xff,
record_id, parent_id, lft_id, rgt_id, rep_original_id,
rep_node_id, replicator_user_id, disallow_replicate)
values(300, p_level+1, 0, 2, 0, 0, 0, 0, 0, 0, 0, NOW(),
0, 76, 0, p_rgt, p_rgt+1, 0, 0, 0, 0);
end if;
end;
|
| |
|
|
|
|
|
|
|
для: Spaniard
(01.09.2008 в 23:08)
| | а что за ошибки? можно поподробнее? когда возникают? | |
|
|
|
|
|
|
|
для: ronin80
(02.09.2008 в 08:57)
| |
1 drop procedure if exists add_comment;
2
3 create procedure add_comment (p_rgt integer, p_level integer)
4 begin
5
6 update comments
7 set lft_id = lft_id+2, rgt_id = rgt_id+2
8 where (lft_id > p_rgt);
9
10 update comments
11 set rgt_id = rgt_id+2
12 where ((rgt_id >= p_rgt)&&(lft_id < p_rgt));
13
14 if ((p_rgt = 0)&&(p_level = 0)) then
15 -- comment_id? record_id?
16 insert into comments(comment_id, level_num, active,
frozen, pic_id, subject, body_post, user_id, user_login,
user_name, user_node_id, created_datetime, ip_xff,
record_id, parent_id, lft_id, rgt_id, rep_original_id,
rep_node_id, replicator_user_id, disallow_replicate)
17 values(300, 1, 0, 2, 0, 0, 0, 0, 0, 0, 0, NOW(), 0, 76,
0, 1, p_rgt, 0, 0, 0, 0);
18 else
19 insert into comments(comment_id, level_num, active,
frozen, pic_id, subject, body_post, user_id, user_login,
user_name, user_node_id, created_datetime, ip_xff,
record_id, parent_id, lft_id, rgt_id, rep_original_id,
rep_node_id, replicator_user_id, disallow_replicate)
20 values(300, p_level+1, 0, 2, 0, 0, 0, 0, 0, 0, 0, NOW(),
0, 76, 0, p_rgt, p_rgt+1, 0, 0, 0, 0);
21 end if;
22
23 end;
|
Script line: 3 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'update comments
set lft_id = lft_id+2, rgt_id = rgt_id+2
where (lft_id > ' at line 4
Script line: 10 Unknown column 'p_rgt' in 'where clause'
Script line: 14 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'if ((p_rgt = 0)&&(p_level = 0)) then
-- comment_id? record_id?
insert into' at line 1
Script line: 18 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'else
insert into comments(comment_id, level_num, active, frozen, pic_id, su' at line 1
Script line: 21 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'end if' at line 1
Script line: 23 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'end' at line 1
|
:( | |
|
|
|
|
|
|
|
для: Spaniard
(02.09.2008 в 13:22)
| | во-первых, перед выполнением необходимо указать в начале (и в конце) скрипта delimiter // чтобы сервер не распознавал знаки ; как сигнал к выполнению, соответственно в строке 23 надо указать end// чтобы скрипт выполнился
во-вторых, необходимо указать типы параметров процедуры in, out, inout
в-третьих, не помню можно ли так комменты отмечать, но я обычно использую /**/ - для комментирования блока текста, # - для комментирования строки
а потом будет видно есть где ещё косяки или нет :) | |
|
|
|
|
|
|
|
для: ronin80
(02.09.2008 в 13:39)
| | сделал все, как вы посоветовали - дело было в delimiter. теперь осталась только одна ошибка:
Script line: 3 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ';
drop procedure if exists add_comment;
create procedure add_comment (in p' at line 1
|
| |
|
|
|
|
|
|
|
для: Spaniard
(02.09.2008 в 14:05)
| | надо так
delimiter //
drop procedure if exists add_comment//
create procedure add_comment (in p' at line 1 ...
а у вас ; там где надо выполнить удаление процедуры | |
|
|
|
|
|
|
|
для: ronin80
(02.09.2008 в 14:09)
| | все, теперь работает! огромное вам спасибо!
только не очень понятно, почему нужен delimiter// ... // для удаления процедуры и не нужен для создания? | |
|
|
|
|
|
|
|
для: Spaniard
(02.09.2008 в 14:25)
| | принцип такой:
указываете delimiter "какойто_знак", соответственно сервер не будет учитывать ; как команда к выполнению а будет воспринимать указанный вами "какойто_знак", соответственно если вам нужно будет выполнить какую то команду нужно будет в конце указывать не ; как обычно а указанный вами "какойто_знак"
вот и получается следующая конструкция:
delimter //
drop procedure if exists procedure_name // /*здесь выполнение команды*/
create procedure procedure_name ()
begin
/*здесь тело процедуры со знаками ;*/
end// /*здесь выполнение команды*/
delimter;
в вашем случае "какойто_знак" это двойной слэш (можно другой знак) | |
|
|
|
|
|
|
|
для: ronin80
(02.09.2008 в 14:33)
| | понятно. еще раз, большое вам спасибо. | |
|
|
|
|