function writeln(str) { write(str + "\n") } writeln("
") 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]) + "\""; sWhereCondition = params.filterCol + " = \' " + unescape(request[params.filterCol]) + "\' "; sSQL = addWhereCondition( sSQL, sWhereCondition ); } if ( (params.sortCol != null) && (params.sortCol != "") ) { sOrdering = params.sortCol; if ( "Descending" == 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 (this.connection == null) { this.connection = pool.connection(pool.id, pool.timeout) //} cursorObj = this.connection.cursor(sSQL, false) //request.connection = null; } } 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) ) { if ( (server.httpdlwVersion.indexOf("1.0") == -1) ) { this.connection.release() } } // netscape_peas_DBSelect function displayErrMsgs(db) { write("Error: Unable to connect to database. Check that your username and password are correct") write("and that you have specified the correct name for the database server, database name, and type.") write("

Major Error Message: " + db.majorErrorMessage() ) write("

Minor Error Message: " + db.minorErrorMessage() ) write("

Major Error Code: " + db.majorErrorCode() ) write("

Minor Error Code: " + db.minorErrorCode() ) } function netscape_peas_DBPool(params) { if (params.dbName == null) params.dbName = "" if (params.password == null) params.password = "" if (params.dbType.indexOf("ODBC") != -1) params.dbType = "ODBC" if (params.dbType == "Personal Oracle Lite") //use ODBC to connect to POLite params.dbType = "ODBC" project.dbType = params.dbType project.dbServer = params.dbServer project.userName = params.userName project.password = params.password project.dbName = params.dbName this.timeout = params.timeout this.id = params.id // ----------------- Server 3.0 ---------------------- if (server.httpdlwVersion.indexOf("3.0") != -1) { if (project[params.id] == null) { //Create db pool if it doesn't already exist pool = new DbPool(params.dbType, params.dbServer, params.userName, params.password, params.dbName, params.maxConnections, params.transactionMode) project[params.id] = pool } else { pool = project[params.id] } if ( !pool.connected() ) displayErrMsgs(pool) else return pool // ----------------- Server 2.0 ---------------------- } else { dbObj = new Object() with (params) { database.connect(dbType, dbServer, userName, password, dbName) } if ( !database.connected() ) displayErrMsgs(database) else return dbObj } } // netscape_peas_DBPool

DBSelect Component

This page illustrates the DBSelect JavaScript component. This component is visible both on the server and on the client, and results in an HTML <SELECT> tag. The component must be placed within an HTML <FORM> tag.

Its properties are server side properties, including the DBPool object which defines the database, a table property for specifying the table, and column names for both the display and value lists. If specified, the "Text Expression" property defines an expression (evaluated in the context of the "cursor" object), which can be used to customize the display strings of the pick list.

Like the JavaScript Select List component, this JSObject can be easily connected to other components (with tools like Visual JavaScript VJS), since it publishes its value property as a bound property. In the example below it has been wired to a standard HTML Text field.

To run this example one must manually (or with the help of Visual JavaScript) copy, compile, and add the resulting Web Application to an enterprise server.

//automatically generated script _param_ = new Object(); _param_.dbType = "INFORMIX"; _param_.userName = "informix"; _param_.maxConnections = 2; _param_.transactionMode = "rollback"; _param_.timeout = 30; _param_.password = "informix"; _param_.dbServer = "ol_chip"; _param_.dbName = "lw_video"; _param_.id = "DBPool1"; DBPool1 = new netscape_peas_DBPool(_param_);

Name and City: //automatically generated script _param_ = new Object(); _param_.maxRows = 100; _param_.sortCol = "id"; _param_.size = 5; _param_.dbpool = "DBPool1"; _param_.textExpr = "name + \" of \" + city"; _param_.table = "customer"; _param_.valueColumn = "ID"; _param_.textColumn = ""; _param_.defaultValue = ""; _param_.sortAscending = ""; _param_.filterCol = ""; _param_.multiple = false; _param_.id = "DBSelect1"; DBSelect1 = new netscape_peas_DBSelect(_param_);

ID:

The above HTML text field is easily connected to the DBSelect component with Visual JavaScript. The text field shows the current "value" of the DBSelect component. The DBSelect component's current value also will be passed on the URL in a form submission.