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.8.2.4 -r1.8.2.5 --- openacs-4/packages/acs-core-docs/www/db-api.html 7 Apr 2003 16:59:25 -0000 1.8.2.4 +++ openacs-4/packages/acs-core-docs/www/db-api.html 15 Apr 2003 17:03:01 -0000 1.8.2.5 @@ -1,17 +1,17 @@ -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

+

Overview

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. Our goal is to develop a coherent API for database access which makes this even easier.

More detailed information about the DB api is available at Database Access API. -

The Old Way

+

The Old Way

Here's a typical block of code from an OpenACS 3.x dynamic page:

 set tcl_var "foo"
@@ -45,18 +45,18 @@
     

Writing code like this had the following annoyances: -

  • +

    • It was repetitive, tedious and error prone to write the same type of loops over and over again. -

    • +

    • Using Tcl variable interpolation in a literal string, to pass values from the page to the database, is error prone, relatively inefficient, and a good way to compromise the security of a web site. -

    • +

    • Magic like set_variables_after_query made code confusing. -

    • +

    • The scope of transactions is not clear from reading the code. -

    • +

    • Passing handles around explicitly made it easy to use them in bad ways, like holding a handle for too long while returning data to a user's browser. @@ -66,7 +66,7 @@ Introduced in ACS 3.4, the new Database API is meant to save developers from the above tedium and provide a more structured syntax for specifying database operations, including transactions. -

    The New Way

    +

    The New Way

    Here is how you would code up the example above using the new API.

     set count 0 
    @@ -113,7 +113,7 @@
     	    from a Tcl variable to the database, which we'll cover next.
     	  

-

Bind Variables

+

Bind Variables

Bind variables are placeholders for literal values in an SQL query being sent to the server. Take the example query above: in the old way, data was generally passed to Oracle directly, via Tcl string @@ -235,7 +235,7 @@ Finally, the DB API has several different styles for passing bind variable values to queries. In general, use the style presented here because it is the most convenient. -

Usage

Every db_* command accepting a SQL command as an argument +

Usage

Every db_* command accepting a SQL command as an argument supports bind variables. You can either

  • Specify the -bind switch to provide a set with bind variable values, or @@ -302,7 +302,7 @@ # of "administrator" } -

Nulls and Bind Variables

+

Nulls and Bind Variables

When processing a DML statement, Oracle coerces empty strings into null. (This coercion does not occur in the WHERE clause of a query, i.e. @@ -350,7 +350,7 @@ # # sets the values for both the "bar" and "baz" columns to null -

Sequence Pooling

+

Sequence Pooling

The database library can transparently maintain pools of sequence values, so that each request for a new sequence value (using db_nextval) does not incur a roundtrip to the server. For instance, this functionality is @@ -381,7 +381,7 @@ yourservername /acs/database] configuration section.) -

Basic API

+

Basic API

The Database API has several functions that wrap familiar parts of the AOLserver database API.

@@ -400,8 +400,8 @@ db_dml "abort" "abort transaction". -

db_multirow
-db_multirow [ -local ] [ -append ] [ -extend column_list ] \
+	  

db_multirow
+db_multirow [ -local ] [ -append ] [ -extend column_list ] \
     var-name statement-name sql \
     [ -bind bind_set_id | -bind bind_value_list ] \
     code_block [ if_no_rows if_no_rows_block ]
@@ -737,4 +737,4 @@
 
 	  

($Id$)

-

View comments on this page at openacs.org
+

View comments on this page at openacs.org