/*
* DBSelect.jsb 1.0 97/08/28
*
* Copyright (c) 1997 Netscape Communications Corporation
*
* Netscape grants you a non-exclusive, royalty free, license to use,
* modify and redistribute this software in source and binary code form,
* provided that i) this copyright notice and license appear on all copies of
* the software; and ii) Licensee does not utilize the software in a manner
* which is disparaging to Netscape.
*
* This software is provided "AS IS," without a warranty of any kind.
* See the CDK License Agreement for additional terms and conditions.
*/
// client properties
function writeln(str) {
write(str + "\n")
}
writeln("")
/**
* This is the main constructor,
* which instantiates our object.
*/
function addWhereCondition( sql, sCondition ) {
sql = sql.toUpperCase()
var sInsert
i = sql.indexOf( "WHERE" )
if ( i != -1 ) {
// where clause exists
sInsert = sCondition + " AND";
i = i + 6;
} else {
// no where... need to add it also
sInsert = "WHERE " + sCondition;
i = sql.indexOf( "GROUP BY" );
if ( i == -1 ) {
i = sql.indexOf( "HAVING" );
if ( i == -1 ) {
i = sql.indexOf( "ORDER BY" );
}
}
if ( i == -1 ) {
// it goes at end
return sql + " " + sInsert;
}
}
return sql.substring( 0, i ) + sInsert + " " + sql.substring( i, sql.length );
}
function addOrdering( sql, sOrdering ) {
sql = sql.toUpperCase()
var sInsert
i = sql.indexOf( "ORDER BY" )
if ( i != -1 ) {
// order by clause exists
sInsert = sOrdering + ",";
i = i + 9;
} else {
// need to add order by. Isert at end.
sInsert = "ORDER BY " + sOrdering;
return sql + " " + sInsert;
}
return sql.substring( 0, i ) + sInsert + " " + sql.substring( i, sql.length )
}
function netscape_peas_DBSelect(params) {
sSQL = "select * from " + params.table;
if ( (params.filterCol != null) && (params.filterCol != "") ) {
sWhereCondition = params.filterCol + " = \"" + unescape(request[params.filterCol]) + "\"";
sSQL = addWhereCondition( sSQL, sWhereCondition );
}
if ( (params.sortCol != null) && (params.sortCol != "") ) {
sOrdering = params.sortCol;
if ( false == params.sortAscending ) {
sOrdering += " DESC";
}
sSQL = addOrdering( sSQL, sOrdering );
}
if (server.httpdlwVersion.indexOf("3.0") != -1) { //--- Server 3.0 ---
if (params.dbpool == null) {
debug("Cursor's DBPool property is null - using generic database object.")
cursorObj = database.cursor(sSQL, false)
} else {
pool = project[params.dbpool]
if (request.connection == null) {
request.connection = pool.connection(pool.id, pool.timeout)
}
cursorObj = request.connection.cursor(sSQL, false)
}
} else { //---Server 2.0---
cursorObj = database.cursor(sSQL, params.updatable)
}
// Prop assignments common to both server versions
//cursorObj.cursorName = params.id
cursorObj.maxRows = params.maxRows;
// now generate the client object
if ( ""==params.valueColumn ) {
params.valueColumn = null;
}
if ( ""==params.textColumn ) {
params.textColumn = null;
}
if ( ""==params.textExpr ) {
params.textExpr = null;
}
writeln( "" );
cursorObj.close()
if ( (params.release) && (server.httpdlwVersion.indexOf("1.0") == -1) ) {
request.connection.release()
}
} // netscape_peas_DBSelect
/**
* This listener declarator makes it possible to
* wire listeners to our object
*/