I have got a block of code which runs normally without, but hangs with db_transaction and I cannot imagine why. I try to get values from one table and stuff them into another table. So this is the code (sql code substituted from .xql file):
db_transaction {
db_exec_plsql create_question {
declare
v integer;
begin
v := survey_question.new (
question_id => :question_id,
section_id => :section_id,
sort_order => :sort_order,
question_text => empty_clob(),
abstract_data_type => :abstract_data_type,
presentation_type => :presentation_type,
presentation_alignment => :presentation_alignment,
presentation_options => :presentation_options,
active_p => :active_p,
required_p => :required_p,
context_id => :section_id,
creation_user => :user_id,
question_html_p => :question_html_p,
summary_type => :summary_type,
answer_description => :answer_description,
predefined_question_id => :predefined_question_id
);
end;
}
db_dml add_question_text {
update survey_questions
set question_text = :question_text
where question_id = :question_id}
# For questions where the user is selecting a canned response, insert
# the canned responses into survey_question_choices by using the predefined
# choices
if { $presentation_type == "checkbox" || $presentation_type == "radio" || $presentation_type == "select" } {
if { $abstract_data_type == "choice" } {
ns_log notice "test0"
db_foreach get_choices " select choice_id,label,numeric_value,sort_order,presentation_alignment,more_info_type from survey_predef_question_choices where question_id=:predefined_question_id" {
ns_log notice "test1"
set new_choice_id [db_nextval survey_choice_id_sequence]
db_dml add_new_choice "
insert into
survey_question_choices(choice_id,predef_choice_id,question_id,label,numeric_value,sort_order,presentation_alignment,more_info_type)
values (:new_choice_id,:choice_id,:question_id,:label,:numeric_value,:sort_order,:presentation_alignment,:more_info_type)"
ns_log notice "test2"
}
}
}
} on_error {
ns_log notice "testtest : $errmsg"
db_release_unused_handles
ad_return_error "Database Error" "$errmsg
"
ad_script_abort
}
This one should create a question from a predefined question. This works fine for normal questions but not for multiple choice questions, which use another table (question_choices). In that case the db creates the question and the question text, selects the predefined choices and hangs after the first execution of add_new_choice, see following snippet from error log:
update survey_questions
set question_text = :question_text
where question_id = :question_id
[17/Jun/2003:12:50:38][7811.688153][-conn4-] Notice: bind variable 'question_text' = 'Which Continent are you from?'
[17/Jun/2003:12:50:38][7811.688153][-conn4-] Notice: bind variable 'question_id' = '19005'
[17/Jun/2003:12:50:38][7811.688153][-conn4-] Notice: test0
[17/Jun/2003:12:50:38][7811.688153][-conn4-] Notice: SQL():
select choice_id,label,numeric_value,sort_order,presentation_alignment,more_info_type from survey_predef_question_choi\
ces where question_id=:predefined_question_id
[17/Jun/2003:12:50:38][7811.688153][-conn4-] Notice: bind variable 'predefined_question_id' = '18070'
[17/Jun/2003:12:50:38][7811.688153][-conn4-] Notice: test1
[17/Jun/2003:12:50:38][7811.688153][-conn4-] Notice: SQL(): select survey_choice_id_sequence.nextval from dual
[17/Jun/2003:12:50:38][7811.688153][-conn4-] Notice: SQL():
insert into
survey_question_choices(choice_id,predef_choice_id,question_id,label,numeric_value,sort_order,presentation_alignment,m\
ore_info_type)
values (:new_choice_id,:choice_id,:question_id,:label,:numeric_value,:sort_order,:presentation_alignment,:more_info_ty\
pe)
[17/Jun/2003:12:50:38][7811.688153][-conn4-] Notice: bind variable 'new_choice_id' = '67'
[17/Jun/2003:12:50:38][7811.688153][-conn4-] Notice: bind variable 'choice_id' = '33'
[17/Jun/2003:12:50:38][7811.688153][-conn4-] Notice: bind variable 'question_id' = '19005'
[17/Jun/2003:12:50:38][7811.688153][-conn4-] Notice: bind variable 'label' = 'Europe'
[17/Jun/2003:12:50:38][7811.688153][-conn4-] Notice: bind variable 'numeric_value' = ''
[17/Jun/2003:12:50:38][7811.688153][-conn4-] Notice: bind variable 'sort_order' = '0'
[17/Jun/2003:12:50:38][7811.688153][-conn4-] Notice: bind variable 'presentation_alignment' = 'right'
[17/Jun/2003:12:50:38][7811.688153][-conn4-] Notice: bind variable 'more_info_type' = ''
After executing this, the next time it hangs even when creating the question. Notice that "test2" is not written to the log. After this, the whole server blocks and needs to be restarted.
Without the transaction it works, and that is really strange I think. Anyone any ideas? Thanks in advance