Riverwatcher Active Content Environment

RACE Documentation:


Database Access
a. SQL Database
b. LDAP Database



SQL Database

RACE has native support for mySQL, PostgreSQL, mSQL and support for Oracle, Microsoft SQL, etc., through the proper ODBC driver.

One of the great strengths of RACE is how easy it is to access a SQL database. The database tag takes care of all the nitty-gritty details of opening and maintaining database connections and process the returned result. In RACE, you specify your SQL query in the query attribute and if your query returns any result, RACE will automatically create database variables, prefixed by # for you. The name of the database variables are the same as the column headings of the rows of data returned, e.g.:

<database name="mystuff" user="me" password="hidden" type="mysql" query="select * from Inventory where ID < 3"> <tr>   <td></td>   <td></td>   <td></td> </tr> </database>

You can think of the database as a loop. The body of the database tag will be executed for each row of data returned by the query. In the example above, assuming the table "Inventory" has the columns named ID, Description and Price, RACE automatically creates the corresponding database variables for you. If there are 5 rows returned by the query, then the body will be executed 5 times, each time, <#ID>, <#Description> and <#Price> will take on the values of the current row.

Because you can use any valid RACE variables in the query statement, therefore you can pass information dynamically to the database server to be updated, e.g.:

<database name="mystuff" user="me" password="hidden" type="mysql" query="update Inventory set Price='' where ID = ''">

Assuming the variable $id contains 5 and $newprice contains 5.99, then the above example is same as if you had issued the query "update Inventory set Price='5.99' where Id='5'".

There is a special hash variable <%database> that you can use to find out more information about the query you just performed. For example, <$database.rows> will tell you how many rows the query has returned and <$database.next> will tell you the row number of next row to be returned. You can get a complete listing of the database hash variable in the RACE reference.





LDAP Database

Light-weight Directory Access Protocol (LDAP) is the standard for directory services for many platforms including UNIX, Windows, and Mac OS X. The built-in support for LDAP in RACE makes accessing and updating a LDAP database fast and easy.

To access a LDAP database, you can use the database tag with the type attribute set to "ldap". RACE supports connecting to a LDAP via secure Transport Layer Security (TLS) when you specify the TLS attribute. By default RACE will not use TLS when connecting to the LDAP server.

<database host="localhost" type="ldap" action="compare"
dn="uid=janedoe,ou=Users,dc=soltec,dc=net" fields="{name='email' value='janedoe@soltec.net'}">
</database>


There are five allowed ldap actions: add, modify, delete, search, and compare. You can find complete specifications of these actions in the RACE Reference. In the previous example, we performed a compare operation. The compare operation is a quick and efficient way to check if an entry in the LDAP database has a certain attribute-and-value pair or pairs. will be either be true, false or empty if there is an error. If more than one pair of name and value is specified, then will be true only if all the name-and-value pairs match. Also note that by omitting the "user" attribute, RACE will attempt to bind to the LDAP server anonymously.

To add a record to the LDAP database, you need to bind to the LDAP server with a distinguished name that has write privilege. The fields attribute expects an array of hashes. This array can be specified in its textual representation or as a RACE array variable, e.g.:

<database host="localhost" type="ldap" action="add" user="cn=ldaproot,dc=soltec,dc=net" password="letmein" dn="uid=janedoe,ou=Users,dc=soltec,dc=net" fields="{name='email' values=['janedoe@soltec.net']}, {name='cn' values=['tron']}, {name='objectClass' values=['top','posixAccount']}"/>

<database host="localhost" type="ldap" action="add" user="cn=ldaproot,dc=soltec,dc=net" passsword="letmein" dn="uid=johndoe,ou=Users,dc=soltec,dc=net" fields="<@johndoerecord>"/>

To modify a LDAP record is very similar to adding a record. One difference is in the specification for fields attribute. When adding a record, you only need to specify the name and value pair in each hash but when modifying a record you need to specify the action you want to perform for each name-and-value pair. The allowed actions for each name-value pair are add, delete, and replace, e.g.:

<database host="localhost" type="ldap" action="modify"
user="cn=ldaproot,dc=soltec,dc=net" password="letmein"
dn="uid=janedoe,ou=Users,dc=soltec,dc=net" host="" fields="{name='streetAddress' value='223 N. Neil St.' action='replace'}, {name='homeDirectory' value='/home/janedoe' action='add'}, {name='loginShell' value='/bin/bash' action='delete'}"/>


The search action works almost exactly like the select query for a SQL database. Database variables are created for each entry of the returned matching records. The body of the database tag will be executed for each returned entry.

<database host="localhost" type="ldap" action="search" user="cn=ldaproot,dc=soltec,dc=net" password="letmein" dn="ou=Users,dc=soltec,dc=net" scope="onelevel"> <$database.next> <#dn> <#sn> <#objectClass><br>
</database>


RACE Documentation



 
Copyright 2009 Riverwatcher, Inc. Hosting by Riverwatcher Studios