Index: openacs-4/packages/acs-content-repository/sql/postgresql/content-create.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-content-repository/sql/postgresql/content-create.sql,v diff -u -r1.13 -r1.14 --- openacs-4/packages/acs-content-repository/sql/postgresql/content-create.sql 30 Apr 2001 01:34:58 -0000 1.13 +++ openacs-4/packages/acs-content-repository/sql/postgresql/content-create.sql 1 May 2001 04:37:49 -0000 1.14 @@ -407,7 +407,31 @@ create trigger cr_revisions_lob_trig before delete or update or insert on cr_revisions for each row execute procedure on_lob_ref(); +create function cr_check_revision_storage_tr () returns opaque as ' +declare + v_storage_type cr_items.storage_type%TYPE; +begin + select storage_type into v_storage_type + from cr_items + where item_id = new.item_id; + if (v_storage_type <> new.storage_type) or + (v_storage_type = ''lob'' and new.lob is null) or + ((v_storage_type = ''text'' or v_storage_type = ''file'') and + new.content is null) then + + raise EXCEPTION ''Invalid storage type: % for revision_id = %'', new.storage_type, new.revision_id; + + end if; + + return new; + +end;' language 'plpgsql'; + +create trigger cr_check_revision_storage_tr before update or insert +on cr_revisions for each row execute procedure cr_check_revision_storage_tr (); + + create index cr_revisions_by_mime_type on cr_revisions(mime_type); create index cr_revisions_title_idx on cr_revisions(title); -- create index cr_revisions_lower_title_idx on cr_revisions(lower(title)); Index: openacs-4/packages/acs-content-repository/tcl/content-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-content-repository/tcl/content-procs.tcl,v diff -u -r1.1 -r1.2 --- openacs-4/packages/acs-content-repository/tcl/content-procs.tcl 30 Apr 2001 05:33:14 -0000 1.1 +++ openacs-4/packages/acs-content-repository/tcl/content-procs.tcl 1 May 2001 04:37:49 -0000 1.2 @@ -38,8 +38,6 @@ append path "/" } - ns_log Notice "path = $path, revision_id = $revision_id" - set content_file "${path}${revision_id}" set ifp [open $client_filename r] set ofp [open [cr_fs_path]$content_file w] @@ -50,3 +48,14 @@ return $content_file } + +proc cr_create_content_lob { client_filename } { + + set lob_id [db_string new_lob_id "select empty_lob()"] + + db_with_handle db { + ns_pg blob_dml_file $db $lob_id $client_filename + } + + return $lob_id +} Index: openacs-4/packages/acs-subsite/www/shared/portrait-bits-postgresql.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-subsite/www/shared/Attic/portrait-bits-postgresql.xql,v diff -u -r1.1 -r1.2 --- openacs-4/packages/acs-subsite/www/shared/portrait-bits-postgresql.xql 30 Apr 2001 05:33:14 -0000 1.1 +++ openacs-4/packages/acs-subsite/www/shared/portrait-bits-postgresql.xql 1 May 2001 04:37:49 -0000 1.2 @@ -5,9 +5,9 @@ - select content + select '[cr_fs_path]' || content from cr_revisions - where revision_id = $revision_id + where revision_id = :revision_id Index: openacs-4/packages/acs-subsite/www/user/portrait/upload-2.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-subsite/www/user/portrait/Attic/upload-2.xql,v diff -u -r1.1 -r1.2 --- openacs-4/packages/acs-subsite/www/user/portrait/upload-2.xql 30 Apr 2001 05:33:14 -0000 1.1 +++ openacs-4/packages/acs-subsite/www/user/portrait/upload-2.xql 1 May 2001 04:37:49 -0000 1.2 @@ -38,7 +38,7 @@ update images set width = :original_width, height = :original_height - where image_id = :revision_id" + where image_id = :revision_id Index: openacs-4/packages/acs-tcl/tcl/00-database-procs-postgresql.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-tcl/tcl/Attic/00-database-procs-postgresql.tcl,v diff -u -r1.6 -r1.7 --- openacs-4/packages/acs-tcl/tcl/00-database-procs-postgresql.tcl 30 Apr 2001 05:33:14 -0000 1.6 +++ openacs-4/packages/acs-tcl/tcl/00-database-procs-postgresql.tcl 1 May 2001 04:37:49 -0000 1.7 @@ -80,7 +80,6 @@ set function_name "__exec_${unique_id}_${fname}" - # insert tcl variable values (Openacs - Dan) if {![string equal $sql $pre_sql]} { set sql [uplevel 2 [list subst -nobackslashes $sql]] @@ -112,19 +111,14 @@ [DoubleApos $proc_sql] ' language 'plpgsql'" - ns_log Notice "proc_sql = $proc_sql" set ret_val [ns_db 0or1row $db "select $function_name ()"] - ns_log Notice "anon func selected" # drop the anonymous function (OpenACS - Dan) ns_db dml $db "drop function $function_name ()" - ns_log Notice "anon func dropped $ret_val" + return $ret_val } error] - # error in the plsql anonymous function - try and drop it. - ns_log Notice "errno = $errno" - global errorInfo errorCode set errinfo $errorInfo set errcode $errorCode @@ -290,19 +284,19 @@ ad_arg_parser { bind } $args db_with_handle db { - db_exec write_blob $db $statement_name $sql + db_exec_lob write_blob $db $statement_name $sql } } ad_proc db_blob_get_file { statement_name sql args } { ad_arg_parser { bind file args } $args db_with_handle db { - db_exec_lob $db $statement_name $sql $file + db_exec_lob blob_select_file $db $statement_name $sql $file } } -ad_proc -private db_exec_lob { db statement_name pre_sql file } { +ad_proc -private db_exec_lob { type db statement_name pre_sql { file "" } } { A helper procedure to execute a SQL statement, potentially binding depending on the value of the $bind variable in the calling environment @@ -318,13 +312,13 @@ # Query Dispatcher (OpenACS - ben) set sql [db_qd_replace_sql $statement_name $pre_sql] - ns_log Notice "POST-QD: the SQL is $sql" - # insert tcl variable values (Openacs - Dan) if {![string equal $sql $pre_sql]} { set sql [uplevel 2 [list subst -nobackslashes $sql]] } + ns_log Notice "POST-QD: the SQL is $sql" + # create a function definition statement for the inline code # binding is emulated in tcl. (OpenACS - Dan) @@ -346,11 +340,37 @@ set lob_sql [uplevel 2 [list db_bind_var_substitution $sql]] } - # get the lob id + # get the content set selection [ns_db 1row $db $lob_sql] - set lob_id [ns_set value $selection 0] + set val [ns_set value $selection 0] - ns_pg blob_select file $db $lob_id $file + switch $type { + + blob_select_file { + if {[regexp {^[0-9]+$} $val match]} { + ns_pg blob_select_file $db $val $file + } else { + error "lob id is not an integer" + } + } + + write_blob { + + # this is an ugly hack, but it allows content to be written + # to the connection if it is stored as a lob or if it is + # stored in the content-repository as a file. (DanW - Openacs) + if {[file exists [cr_fs_path]$val]} { + set ofp [open [cr_fs_path]$val r] + ns_writefp $ofp + close $ofp + } elseif {[regexp {^[0-9]+$} $val match]} { + ns_pg blob_write $db $val + } else { + error "file: [cr_fs_path]$val doesn't exist" + } + } + } + return } error]