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" 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 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]) + "\""; 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

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 uses to customize the display strings of the pick list.

Like the Static Select 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 VJS) copy, compile, and add the resulting Crossware Application to an enterprise server.

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

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