<% // ============================================ // NOTE: all source code downloaded from CoverYourASP was written by // James Shaw (unless stated otherwise), and is copyright (c) 2000-2002 // by James Shaw. You can use the code for any purpose, but do not // publish or distribute the content in any way. // // See http://CoverYourASP.com/Legal.asp for up-to-date details. // ============================================ // globals var oConnection; var oRecordSet; // enums // Connection.State and Recordset.State property var adStateClosed = 0; // the object is closed. var adStateOpen = 1; // the object is open. var adStateConnecting = 2; // the object is connecting. var adStateExecuting = 4; // the object is executing a command. var adStateFetching = 8; // the rows of the object are being fetched. // Recordset.Cursor property var adOpenUnspecified = -1; // does not specify the type of cursor. var adOpenForwardOnly = 0; // (default) a forward-only cursor, i.e. you get only one pass thru the data! var adOpenKeyset = 1; // can go in any direction, and as a bonus you'll see changes other users make. EXPENSIVE! var adOpenDynamic = 2; // as Keyset, but also you can see additions/deletions other users make. EXPENSIVE! var adOpenStatic = 3; // can go in any direction, but read-only. // Recordset.LockType property var adLockUnspecified = -1; // does not specify a type of lock. var adLockReadOnly = 1; // (default) guess! var adLockPessimistic = 2; // guaranteed to work var adLockOptimistic = 3; // records locked only when you call Update. fingers crossed var adLockBatchOptimistic = 4;// required for batch update mode var adCmdUnspecified = -1; // Does not specify the command type argument. var adCmdUnknown = 8; // Default. Indicates that the type of command in the CommandText property is not known. var adCmdText = 1; // a textual definition of a command or stored procedure call. var adCmdTable = 2; // a table name whose columns are all returned by an internally generated SQL query. var adCmdStoredProc = 4; // a stored procedure name. var adCmdFile = 256; // a persisted Recordset. var adCmdTableDirect = 512; // a table name whose columns are all returned. // SchemaEnum - specifies the type of schema Recordset to be retrieved by the OpenSchema method var adSchemaTables = 20; // returns the tables // ======================================================================== // initializes database variables for first use on page - leave it to the // last possible second before calling this function // // connectString can be left null, and if it is null, db will use the // application default connection string specified in global.asa // ======================================================================== function DBInitConnection (connectString) { if ( oConnection != undefined ) return; oConnection = Server.CreateObject( 'ADODB.Connection' ); if (connectString) oConnection.Open(connectString); else oConnection.Open( Application("xsight_ConnectionString") ); oRecordSet = Server.CreateObject( 'ADODB.Recordset' ); } // ======================================================================== // tidies up after DBInitConnection // ======================================================================== function DBReleaseConnection ( ) { if ( oConnection == undefined ) return; DBReleaseRecords ( ); oRecordSet = undefined; if ( oConnection.State != adStateClosed ) oConnection.Close(); oConnection = undefined; } // ======================================================================== // executes the passed in SQL statement and returns a read-only // forward-only oRecordSet object // ======================================================================== function DBGetRecords ( sSQL ) { DBReleaseRecords ( ); oRecordSet.Open ( sSQL, oConnection, adOpenForwardOnly, adLockReadOnly ); } // ======================================================================== // tidies up after DBGetRecords // ======================================================================== function DBReleaseRecords ( ) { if ( oRecordSet != undefined && oRecordSet.State != adStateClosed ) oRecordSet.Close(); } // ======================================================================== // Counts the number of rows in a record set // ======================================================================== function DBCountRows(recSet) { var rec_count=recSet.RecordCount; if (rec_count==-1) { for (rec_count=0; !recSet.EOF; recSet.MoveNext()) rec_count++; // reset the cursor to the beginning if (recSet.CursorType > 0) { if (!recSet.BOF) recSet.MoveFirst(); } else recSet.Requery(); } return rec_count; } // ======================================================================== // OOP Encapsulation of the above // ======================================================================== function dbConnect() { this.connection=null; this.recordset=null; this.open=function(connectString) { if (this.connection) return; this.connection = Server.CreateObject( 'ADODB.Connection' ); if (connectString) this.connection.Open( connectString ); else this.connection.Open( Application("xsight_ConnectionString") ); // create a Recordset this.recordset = Server.CreateObject( 'ADODB.Recordset' ); } this.close=function() { if ( this.connection == undefined ) return; this.recordset = undefined; if ( this.connection.State != adStateClosed ) this.connection.Close(); this.connection = undefined; } this.releaseRecords=function() { if (!this.recordset) return; if (this.recordset.State != adStateClosed ) this.recordset.Close(); } this.query=function(sql) { this.releaseRecords(); if (!this.connection) this.open(); this.recordset.Open(sql,this.connection, adOpenForwardOnly, adLockReadOnly ); return this.recordset; } this.execute=function(sql) { if (!this.connection) this.open(); this.connection.execute(sql); } this.rowCount=function() { return DBCountRows(this.recordset); } } // ======================================================================== // Creates a javascript object from a record in a recordset // with properties matching the names and values if the fields // ======================================================================== function recordObject(rs) { for (i=0; i\r\n"; while (!rs.EOF) { result+="\t\r\n"; for (i=0; i"+rs.fields(i).value+"\r\n"; result+="\t\r\n"; rs.MoveNext(); } db.close(); result+=""; return result; } %>