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 -N -r1.50.2.14 -r1.50.2.15 --- openacs-4/packages/acs-core-docs/www/db-api.html 19 Nov 2016 09:21:53 -0000 1.50.2.14 +++ openacs-4/packages/acs-core-docs/www/db-api.html 6 Jan 2017 09:18:41 -0000 1.50.2.15 @@ -2,7 +2,7 @@ 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 + One of OpenACS's great strengths is that code written for it is very close to the database. It is very easy to interact with the database from anywhere within OpenACS, and we have a coherent API for database access which makes this even easier. @@ -12,7 +12,7 @@

DB API Examples

The OpenACS database API is meant to save developers from making common mistakes and to provide a more structured syntax for - specifying database operations, including transactions. Here's + specifying database operations, including transactions. Here's an example of the API.

 set count 0
@@ -134,7 +134,7 @@
 
 db_foreach my_query { select :table from some_table where :condition }
     

- SQL will not allow a literal to occur where we've put the bind + SQL will not allow a literal to occur where we've put the bind variables, so the query is syntactically incorrect. You have to remember that while the bind variable syntax looks similar to variable interpolation in Tcl, It is not the same thing at all. @@ -290,7 +290,7 @@

Note that you never have to use ns_db anymore (including ns_db gethandle)! Just start doing stuff, and (if you want) call - db_release_unused_handles when you're done as a hint to + db_release_unused_handles when you're done as a hint to release the database handle.

@@ -318,11 +318,11 @@

Each row also has a column, rownum, automatically added and set to the row number, starting with 1. Note that this will - override any column in the SQL statement named 'rownum', also if you're + override any column in the SQL statement named 'rownum', also if you're using the Oracle rownum pseudo-column.

If the -local is passed, the variables defined - by db_multirow will be set locally (useful if you're compiling dynamic templates + by db_multirow will be set locally (useful if you're compiling dynamic templates in a function or similar situations).

You may supply a code block, which will be executed for each row in @@ -338,7 +338,7 @@ useful for things like constructing a URL for the object retrieved by the query.

- If you're constructing your multirow through multiple queries with the + If you're constructing your multirow through multiple queries with the same set of columns, but with different rows, you can use the -append switch. This causes the rows returned by this query to be appended to the rows already in the multirow, instead of starting @@ -377,7 +377,7 @@ multirow foreach assets { lappend asset_id_l $asset_id } -

Technically it's equivalent to using a code block on +

Technically it's equivalent to using a code block on the end of your db_multirow.

@@ -444,7 +444,7 @@

Example:

 
 db_1row select_foo "select foo, bar from greeble where greeble_id = $greeble_id"
-# Bombs if there's no such greeble!
+# Bombs if there's no such greeble!
 # Now $foo and $bar are set.
 
 	  
@@ -487,7 +487,7 @@ db_string statement-name sql [ -default default ] [ -bind bind_set_id | -bind bind_value_list ]

Returns the first column of the result of SQL query sql. - If sql doesn't return a + If sql doesn't return a row, returns default (or throws an error if @@ -500,15 +500,15 @@

Returns a Tcl list of the values in the first column of the result of SQL query sql. - If sql doesn't + If sql doesn't return any rows, returns an empty list. Analogous to database_to_tcl_list.

db_list_of_lists
 db_list_of_lists statement-name sql [ -bind bind_set_id | -bind bind_value_list ]
 	  

Returns a Tcl list, each element of which is a list of all column values in a row of the result of SQL query sql. If - sql doesn't return any rows, returns an empty list. + sql doesn't return any rows, returns an empty list. (Analogous to database_to_tcl_list_list.)

db_dml
@@ -601,7 +601,7 @@
 	  

db_with_handle
 db_with_handle var code_block
 	  

Places a database handle into the variable var and - executes code_block. This is useful when you don't + executes code_block. This is useful when you don't want to have to use the new API (db_foreach, db_1row, etc.), but need to use database handles explicitly.

Example:

 
@@ -612,7 +612,7 @@
 }
 
 db_with_handle db {
-    # Now there's a database handle in $db.
+    # Now there's a database handle in $db.
     set selection [ns_db select $db "select foo from bar"]
     while { [ns_db getrow $db $selection] } {
         set_variables_after_query
@@ -644,7 +644,7 @@
 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
-# the empty string we just inserted (because of Oracle's coercion
+# the empty string we just inserted (because of Oracle's coercion
 # quirk)