/**************************************************************** * This application is used by Visual JavaScript. * * DO NOT ALTER THIS CODE, or the operation of Visual JavaScript * * will be affected. See the Visual JavaScript documentation. * * * * Copyright 1997 Netscape Communications Corp. * *****************************************************************/ function writeln(str) { write(str + "\n") } function notSet( val ) { if (val == null) val = "" if (val == "" ) return true else return false } function ConnectToDB(params) { retstr = "" with ( params ) { if ( notSet(dbType) ) retstr +="

Database Type Not Specified." else retstr += "

Database Type is " + dbType if ( notSet(dbServer) ) retstr +="

Database Server Not Specified." else retstr += "

Database Server is " + dbServer if ( notSet(userName) ) retstr +="

User Name Not Specified." else retstr += "

User Name is " + userName if ( notSet(password) ) retstr +="

Password Not Specified." else retstr += "

Password is " + password if ( notSet(dbName) ) retstr +="

Database Name Not Specified." else retstr += "

Database Name is " + dbName if ( dbType.indexOf("ODBC") != -1 || dbType=="Personal Oracle Lite") database.connect("ODBC", dbServer, userName, password, dbName) else database.connect(dbType, dbServer, userName, password, dbName) } //with if (!database.connected()) { retstr+="

Error: Unable to connect to database." retstr+="
Major Error Message: " + database.majorErrorMessage() retstr+="
Minor Error Message: " + database.minorErrorMessage() retstr+="
Major Error Code: " + database.majorErrorCode() retstr+="
Minor Error Code: " + database.minorErrorCode() } else retstr = "" // If connect to DB, don't return err msg. return retstr } //ConnectToDB function datatype( val ) { if ( (dbType == "ODBC-SQL Anywhere") || (dbType == "ORACLE") || (dbType == "Personal Oracle Lite")) return val else if (dbType == "ODBC-SQL Server") return ODBCdatatype[val] else if (dbType == "SYBASE") return sybaseDatatype[val] else if (dbType == "INFORMIX") { val = val % 256 if ( val == 0 ) return "char" else if ( val == 1 ) return "smallint" else if ( val == 2 ) return "integer" else if ( val == 3 ) return "float" else if ( val == 4 ) return "smallfloat" else if ( val == 5 ) return "decimal" else if ( val == 6 ) return "serial" else if ( val == 7 ) return "date" else if ( val == 8 ) return "money" else if ( val == 10 ) return "datetime" else if ( val == 11 ) return "byte" else if ( val == 12 ) return "text" else if ( val == 13 ) return "varchar" else if ( val == 14 ) return "interval" else if ( val == 15 ) return "nchar" else if ( val == 16 ) return "nvarchar" else if ( val > 16 ) return "unknown type" } //else } // datatype function showOracleViews(obj) { if (dbType=="ORACLE") { views = database.cursor("select view_name from user_views") while (views.next()) { write("" + views[0] + "") obj[views[0]] = views[0] } views.close() } } /* * Returns object that encapsulates mapping between unique table id and table name. */ function showTables(SQL) { tables = database.cursor(SQL) write("") numTables = 0 t = new Object() // First column in cursor is assumed to be table name; second is unique table id while (tables.next()) { write("") t[tables[1]] = tables[0] numTables++ } showOracleViews(t) writeln("
Tables
" + tables[0] + "
") tables.close() return t } function nullable(val) { if ( (dbType == "ODBC-SQL Anywhere") || (dbType == "ORACLE") || (dbType == "Personal Oracle Lite") ) return ( (val=="Y") ? "nullable" : "not null" ) else if (dbType == "ODBC-SQL Server") return ( (val==8) ? "nullable" : "not null" ) else if (dbType == "INFORMIX") return ( (val > 256) ? "not null" : "nullable" ) else if (dbType == "SYBASE") return ( (val == 0) ? "not null" : "nullable" ) else return "Unknown" } function showColumns(SQL, tableID) { cols = database.cursor(SQL) write("") /* For debugging: writeln("
 sql = " + SQL + "\n no cols = " + cols.columns())
	cols.next(); writeln(cols[0])
	writeln(cols[1])
 	writeln(cols[2])
	*/

	PK = primaryKey(tableID)

	// First property of cursor is the column name, second indicates datatype, third indicates nullability
	while (cols.next()) {
		write("
") write("") write("") write("") write("") } writeln("
" + tableNames[tableID] + "
" + cols[0] + "" + datatype(cols[1]) + "" + nullable(cols[2]) + "" + isColPrimaryKey(cols[0]) + "
") cols.close() } /* * Returns "primary key" if col is primary key, null string otherwise */ function isColPrimaryKey(colName) { retVal = "" if (PK != null) { for (col in PK) { if (colName == PK[col]) retVal = "Primary Key" } } return retVal } /* * Returns an object containing a property that is name of each key column for table; null if no keys */ function primaryKey(tableID) { keyCols = null if (dbType == "SYBASE") { colNames = new Object() // Stores mapping between colid & colName colsInTable = database.cursor("SELECT colid, name FROM syscolumns WHERE id = " + tableID) while (colsInTable.next()) colNames[colsInTable.colid] = colsInTable.name key = database.cursor("SELECT keycnt, key1, key2, key3, key4, key5, key6, key7, key8 FROM syskeys WHERE type = 1 AND id = " + tableID) if (key.next()) { if (key.keycnt != 0) keyCols = new Object() for (i = 0; i < key.keycnt; i++) keyCols[i] = colNames[key[i+1]] // Each property is name of a key column } colsInTable.close() key.close() } else if (dbType == "INFORMIX") { colNames = new Object() // Stores mapping between colid & colName colsInTable = database.cursor("SELECT colno, colname FROM syscolumns where tabid = " + tableID) while (colsInTable.next()) colNames[colsInTable.colno] = colsInTable.colname key = database.cursor("SELECT * FROM sysindexes where idxtype = 'U' and tabid = " + tableID) key.next() for (i = 5; i < 21; i++) { if (keyCols == null) keyCols = new Object() if (key[i] != 0) { keyCols[i] = colNames[key[i]] // Each property is name of a key column } } key.close() colsInTable.close() } else if (dbType == "ORACLE") { key = database.cursor("SELECT constraint_name from user_constraints where constraint_type='P' or constraint_type='C' and table_name = '" + tableID + "'") key.next() keyColsCursor = database.cursor("SELECT column_name from user_cons_columns where constraint_name='" + key.constraint_name + "'") i = 0 while ( keyColsCursor.next() ){ if (keyCols == null) keyCols = new Object() keyCols[i] = keyColsCursor.column_name i++ } keyColsCursor.close() key.close() } else if (dbType == "Personal Oracle Lite") { key = database.cursor("SELECT constraint_name from all_constraints where constraint_type='P' and table_name = '" + tableID + "'") key.next() keyColsCursor = database.cursor("SELECT column_name from all_cons_columns where constraint_name='" + key.constraint_name + "'") i = 0 while ( keyColsCursor.next() ){ if (keyCols == null) keyCols = new Object() keyCols[i] = keyColsCursor.column_name i++ } keyColsCursor.close() key.close() } return keyCols } //primaryKey // ---------------- Functions for data source management ----------------- sep = "," //This is the separator character used to delimit data items in the conf file. // Helper function that parses datasource lines into object with corresponding properties function parseInfo(str) { o = new Object() o.nickName = null o.dbType = null o.dbServer = null o.dbName = null sepPosition = 0 /* ------- Does not work consistently in ES2 --------- for (prop in o) { nextSep = str.indexOf(sep, sepPosition) o[prop] = str.substring(sepPosition, nextSep) sepPosition = nextSep+1 } */ nextSep = str.indexOf(sep, sepPosition) o.nickName = str.substring(sepPosition, nextSep) sepPosition = nextSep+1 nextSep = str.indexOf(sep, sepPosition) o.dbType = str.substring(sepPosition, nextSep) sepPosition = nextSep+1 nextSep = str.indexOf(sep, sepPosition) o.dbServer = str.substring(sepPosition, nextSep) sepPosition = nextSep+1 nextSep = str.indexOf(sep, sepPosition) o.dbName = str.substring(sepPosition, nextSep) return o } // Helper function that returns a string for table cell for each property in an object function cellForProps(obj) { str = "" + obj.nickName + "" str += "" + obj.dbType + "" str += "" + obj.dbName + "" str += "" + obj.dbServer + "" return str } // Returns true if the data source is unique, false otherwise function unique(str) { retVal = true for (prop in project) { if (prop.indexOf("VJSdataSource") != -1) { if (project[prop]==str) retVal = false } } return retVal } // Adds a data source to list of known data sources // Assumes request object has props for nickName, dbType, dbName, and dbServer function addDataSource(ds) { dsStr = unescape(ds.nickName + sep + ds.dbType + sep + ds.dbName + sep + ds.dbServer + sep) project.lock() if (unique(dsStr)) { if (dsFile.open("a+")) { debug("Opened ds file to add new data source.") dsFile.writeln(dsStr) dsFile.flush() project.numVJSds = parseInt(project.numVJSds) + 1 n = "VJSdataSource" + project.numVJSds project[n] = dsStr } else write("