I agree that xotcl is amazing (brilliant work, Gustaf!), but it also precipitates situations that appear to be "a riddle inside a mystery wrapped in an enigma" (as Churchill once said).
To wit: with the latest xotcl-note package (0.6) with an oacs-5-2 install (xotcl-core 0.38), when adding a first ever note, this server error results:
Database operation "0or1row" failed (exception NSDB, "Query was not a statement returning rows.")
ERROR: null value in column "name" violates not-null constraint
CONTEXT: SQL statement "insert into cr_items ( item_id, name, content_type, parent_id, storage_type ) values ( $1 , $2 , $3 , $4 , $5 )"
PL/pgSQL function "content_item__new" line 89 at SQL statement
PL/pgSQL function "content_item__new" line 20 at assignment
SQL:
select content_item__new(NULL,-100,null,null,null,'506',null,null,
'content_item','::CrNote','Test Title',
'Test description',NULL,
NULL,'{Test content } text/html','text')
while executing
"ns_pg_bind 0or1row nsdb0 {
select content_item__new(:name,-100,null,null,null,:creation_user,null,null,
'content_item',:object_type,:title,
..."
("uplevel" body line 1)
invoked from within
"uplevel $ulevel [list ns_pg_bind $type $db $sql]"
("postgresql" arm line 2)
invoked from within
"switch $driverkey {
oracle {
return [uplevel $ulevel [list ns_ora $type $db $sql] $args]
}
..."
invoked from within
"db_exec 0or1row $db $full_statement_name $sql"
invoked from within
"if {[regexp -nocase -- {^\s*select} $test_sql match]} {
....etc etc etc
Obviously the attribute "name" isn't getting defined so the CR barfs, but where is the problem? Alternatives:
- Maybe name needs to be included in the "fields" set in the ::Generic::Form constructor in /packages/xotcl-note/www/edit.tcl?
- Does this constructor need some param that feeds into the new_data block of ad_form (which ::Generic::Form wraps, I think)? How do you setup on_submit, new_data, and other ad_form-type blocks with ::Generic::Form?
- Maybe there's a bug in ::Generic::Form itself such that "name" isn't getting initialized from "title" or something else?
- Maybe there's a bug in the CR itself? That's virtually impossible since the CR seems to work fine elsewhere, but how can you tell from the available error info?
- And is this a problem in the xotcl code, the tcl code, the plpgsql code, or the sql? Again it's almost certainly just a bug in the xotcl, but in a more complex case it would be very hard to tell, eh?
- Or is it something else?
Anyway, in the Old Days where add.tcl set up the form, add-2.tcl processed the form for errors etc, and add-3.tcl stuffed the database -- and all SQL was inline -- it was easy to tell exactly and immediately where problems occurred. Now we wrap things in the CR, ad_form, ::Generic::Form, plus a few callbacks to keep you looking in the rear view mirror while you drive, and it's, well, confusing.
When things work well, the kind of code streamlining and simplification that xotcl etc can produce are astounding. But in the time I've spent so far trying to figure out why this simple illustration package won't create a new note, I could have coded from a blank page an entire old-style package. That subtracts a bit from the efficiencies. I'll catch on eventually, though.