Index: openacs-4/packages/acs-core-docs/www/db-api.html =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-core-docs/www/db-api.html,v diff -u -r1.50 -r1.51 --- openacs-4/packages/acs-core-docs/www/db-api.html 27 Oct 2014 16:39:17 -0000 1.50 +++ openacs-4/packages/acs-core-docs/www/db-api.html 7 Aug 2017 23:47:49 -0000 1.51 @@ -1,5 +1,5 @@ -The OpenACS Database Access API

The OpenACS Database Access API

+The OpenACS Database Access API

The OpenACS Database Access API

By Pete Su and Jon Salz. Modified by Roberto Mello.

Overview

One of OpenACS's great strengths is that code written for it is @@ -103,8 +103,8 @@ What the DB API (in conjuntion with the database drivers implemented for aolserver) do is send the SQL statement to the server for parsing, then bind values to the - variables and sends those values along seperately as a second - step. This seperate binding step is where the term + variables and sends those values along separately as a second + step. This separate binding step is where the term bind variable comes from.

This split has several advantages. First, type checking happens @@ -299,7 +299,7 @@

 db_abort_transaction
 	  

Aborts all levels of a transaction. That is if this is called within - several nested transactions, all of them are terminated. Use this insetead of + several nested transactions, all of them are terminated. Use this instead of db_dml "abort" "abort transaction". @@ -526,11 +526,11 @@ insert. Only one of -blobs, -clobs, -blob_files, and -clob_files may be provided.

Example:

 
-db_dml insert_photos "
+db_dml insert_photos {
         insert photos(photo_id, image, thumbnail_image)
         values(photo_id_seq.nextval, empty_blob(), empty_blob())
         returning image, thumbnail_image into :1, :2
-    "  -blob_files [list "/var/tmp/the_photo" "/var/tmp/the_thumbnail"] 
+    }  -blob_files [list "/var/tmp/the_photo" "/var/tmp/the_thumbnail"] 
 
 	  

This inserts a new row into the photos table, with the contents @@ -549,7 +549,7 @@ db_write_blob statement-name sql [ -bind bind_set_id | -bind bind_value_list ] db_blob_get_file statement-name sql [ -bind bind_set_id | -bind bind_value_list ] -

Analagous to ns_ora write_clob/write_blob/blob_get_file. +

Analogous to ns_ora write_clob/write_blob/blob_get_file.

db_release_unused_handles
@@ -567,8 +567,8 @@
 
 proc replace_the_foo { col } {
     db_transaction {
-        db_dml "delete from foo"
-        db_dml "insert into foo(col) values($col)"
+        db_dml delete {delete from foo}
+        db_dml insert {insert into foo(col) values(:col)}
     }
 }
 
@@ -582,7 +582,7 @@
 db_transaction {
     replace_the_foo 14
     print_the_foo ; # Writes out "foo is 14"
-    db_dml "insert into some_other_table(col) values(999)"
+    db_dml insert_foo {insert into some_other_table(col) values(999)}
     ...
     db_abort_transaction
 } on_error {
@@ -638,10 +638,9 @@
 
 # Clean out the foo table
 #
-db_dml unused "delete from foo"
+db_dml unused {delete from foo}
+db_dml unused {insert into foo(baz) values(:baz)}
 
-db_dml unused "insert into foo(baz) values('$baz')"
-
 set n_rows [db_string unused "select count(*) from foo where baz is null"]
 #
 # $n_rows is 1; in effect, the "baz is null" criterion is matching
@@ -653,7 +652,7 @@
 	    null by writing: 
 	  

 
-db_dml foo_insert "insert into foo(baz) values(:1)" {[db_nullify_empty_string $baz]}
+db_dml foo_insert {insert into foo(baz) values(:1)} {[db_nullify_empty_string $baz]}
 
 	  

($Id$)

@@ -689,4 +688,4 @@ db_flush_cache -cache_key_pattern page_${page_id}_* -

View comments on this page at openacs.org
+