beautypg.com

Chapter 8: the database api, How database api functions work – Adobe Dreamweaver API Reference CS5 User Manual

Page 59

background image

54

Last updated 8/27/2013

Chapter 8: The database API

Functions in the database API let you manage database connections and access information that is stored in databases.
The database API is divided by two distinct purposes: managing database connections and accessing database
connections.

Database API functions are used at design time when users are building web applications, not at runtime when the web
application is deployed.

You can use these functions in any extension. In fact, the Adobe® Dreamweaver® CS5 server behavior, data format, and
data sources APIs all use these database functions.

How database API functions work

The following example shows how the server behavior function,

getDynamicBindings()

, is defined for Recordset.js.

This example uses the

MMDB.getColumnAndTypeList()

function:

function getDynamicBindings(ss)

{

var serverModel = dw.getDocumentDOM().serverModel.getServerName();
var bindingsAndTypeArray = new Array();
var connName=ss.connectionName;
var statement = ss.source;
var rsName= ss.rsName;

// remove SQL comments
statement = statement.replace(/\/\*[\S\s]*?\*\//g, " ");
var bIsSimple = ParseSimpleSQL(statement);
statement = stripCFIFSimple(statement);

if (bIsSimple) {
statement = RemoveWhereClause(statement,false);
} else {
var pa = new Array();

if (ss.ParamArray != null) {
for (var i = 0; i < ss.ParamArray.length; i++) {

pa[i] = new Array();
pa[i][0] = ss.ParamArray[i].name;
pa[i][1] = ss.ParamArray[i].value;

}
}


var statement = replaceParamsWithVals(statement, pa, serverModel);

}

bindingsAndTypeArray = MMDB.getColumnAndTypeList(connName, statement);
return bindingsAndTypeArray;

}