home *** CD-ROM | disk | FTP | other *** search
Wrap
<SCRIPT runat="server" language="VBScript"> ' ***************************************************************************** ' ' include/ado.runtime5.asp ' ' Dynamic Link runtime support for Microsoft ADO. ' ' COPYRIGHT (c) 1999-2000 Adobe Systems Incorporated. All rights reserved. ' ' ----------------------------------------------------------------------------- function GetMaxPendingRows( rs ) GetMaxPendingRows = 0 if False = RuntimeDebug then on error resume next end if GetMaxPendingRows = rs.Properties( "Maximum Pending Rows" ).Value end function function testIndexColumns( index ) if False = RuntimeDebug then on error resume next end if count = index.Columns.Count if Err then testIndexColumns = false else testIndexColumns = true end if end function </SCRIPT> <SCRIPT runat="server" language="JScript"> // ***************************************************************************** // CONSTANTS // // CursorTypeEnum var adOpenForwardOnly = 0; var adOpenKeyset = 1; var adOpenDynamic = 2; var adOpenStatic = 3; var adOpenUnspecified = -1; // LockTypeEnum var adLockReadOnly = 1; var adLockPessimistic = 2; var adLockOptimistic = 3; var adLockBatchOptimistic = 4; var adLockUnspecified = -1; // DataTypeEnum var AdArray = 0x2000; var adEmpty = 0; var adSmallInt = 2; var adInterger = 3; var adSingle = 4; var adDouble = 5; var adCurrency = 6; var adDate = 7; var adBSTR = 8; var adIDispatch = 9; var adError = 10; var adBoolean = 11; var adVariant = 12; var adIUnknown = 13; var adDecimal = 14; var adTinyInt = 16; var adUnsignedTinyInt = 17; var adUnsignedSmallInt = 18; var adUnsignedInt = 19; var adBigInt = 20; var adUnsignedBigInt = 21; var adFileTime = 64; var adGUID = 72; var adBinary = 128; var adChar = 129; var adWChar = 130; var adNumeric = 131; var adUserDefined = 132; var adDBDate = 133; var adDBTime = 134; var adDBTimeStamp = 135; var adChapter = 136; var adPropVariant = 138; var adVarNumeric = 139; var adVarChar = 200; var adLongVarChar = 201; var adVarWChar = 202; var adLongVarWChar = 203; var adVarBinary = 204; var adLongVarBinary = 205; var adSchemaTables = 20; var adSchemaProviderTypes = 22; // ***************************************************************************** // CONTENT SOURCE WRAPPER: RECORDSET // // Content source wrapper for RecordSet. The primaryKey (a comma separated list // of column names) must be specified for record sets which will be updated; it // is ignored for those that are not. // // Items are accessed through the wrapper as follows: // // set results = WrapRecordSet(adoRecordSet, primaryKey) // results.MoveFirst // results.Value("SKU") function WrapRecordSet( adoRecordSet, primaryKey ) { var wrapper = new CSWRecordSet( adoRecordSet, primaryKey ); var key = Request.QueryString( "RECORD_KEY" ); if( key.Count > 0 ){ wrapper.MoveToKey( key ); } return wrapper; } // First priority: User specified primary key field // Second priority: Automatic discovery primary key for OLE DB (ODBC is not supported) // Third priority: Use all field without long text function CSWRecordSet(adoRecordSet, primaryKey) { // Method table: this.Move = CSWRecordSet_Move; this.MoveFirst = CSWRecordSet_MoveFirst; this.MoveNext = CSW_MoveNext; this.Value = CSWRecordSet_Value; this.Set = CSWRecordSet_Set; this.Key = CSWRecordSet_Key; this.MoveToKey = CSWRecordSet_MoveToKey; this.UpdateBatch = CSWRecordSet_UpdateBatch; this.AddNew = CSWRecordSet_AddNew; this.Delete = CSWRecordSet_Delete; this.Data = adoRecordSet; this.maxpending = GetMaxPendingRows( adoRecordSet ); if( primaryKey ){ // User specified primary key var temp = String( primaryKey ).split( " " ).join( "" ); this.PrimaryKey = temp.split( "," ); }else{ // Primary key is not specified >> auto detect if( RuntimeDebug ){ RuntimeDebugMessage( "No primary key is specified" ); } this.PrimaryKey = new Array; var catalog = new ActiveXObject( "ADOX.Catalog" ); catalog.ActiveConnection = adoRecordSet.ActiveConnection; var tableName = getTableNameFromSource( adoRecordSet.Source ); var table = new ActiveXObject( "ADOX.Table" ); table = catalog.Tables.Item( String( tableName )); var primaryKeyCounter = 0; var indexColumnsSupport = true; for( var k = 0; k < table.Indexes.Count; k++ ){ var index = new ActiveXObject( "ADOX.Index" ); index = table.Indexes.Item( k ); if( !index.PrimaryKey ) continue; // skip non-primary key if( testIndexColumns( index )){ // supported for( var m = 0; m < index.Columns.Count; m++ ){ var column = new ActiveXObject( "ADOX.Column" ); column = index.Columns.Item( m ); var n = 0; for( n = 0; n < table.Columns.Count; n++ ){ var column2 = new ActiveXObject( "ADOX.Column" ); column2 = table.Columns.Item( n ); if( column.Name == column2.Name ) break; } if( n < table.Columns.Count ){ var o = 0; for( o = 0; o < this.PrimaryKey.length; o++ ){ if( column.Name == this.PrimaryKey[o].Name ) break; } if( this.PrimaryKey.length <= o ){ this.PrimaryKey[primaryKeyCounter++] = column.Name; } } } }else{ // not supported indexColumnsSupport = false; break; } } if( !indexColumnsSupport ||( primaryKeyCounter == 0 )){ // failed automatic discover primary key or no primary key var knownkey = false; for( var i = 0; i < adoRecordSet.fields.count; i++ ){ var field = adoRecordSet.fields.item( i ); var attrib = field.Attributes; if(( attrib & 0x100 )&&( attrib != -1 )){ this.PrimaryKey = new Array( field.Name ); break; } if( knownkey ){ if(( attrib & 0x8000 )&&( attrib != -1 )){ this.PrimaryKey = this.PrimaryKey.concat( Array( field.Name )); } }else{ if( attrib == -1 ){ this.PrimaryKey = this.PrimaryKey.concat( Array( field.Name )); }else if( attrib & 0x8000 ){ this.PrimaryKey = new Array( field.Name ); knownkey = true; }else if( !( attrib & 0x80 )){ this.PrimaryKey = this.PrimaryKey.concat( Array( field.Name )); } } } } } this.RecordCount = 0; while( !adoRecordSet.EOF ){ this.RecordCount++; adoRecordSet.MoveNext(); } this.NewRecord = false; this.BlockSize = 0; this.MoveFirst(); } // ----------------------------------------------------------------------------- // Cursor positioning: function CSWRecordSet_Move( delta ) { if( delta > 0 ){ this.AbsolutePosition += Number( delta ); this.RECORD_INDEX = this.AbsolutePosition; this.EOF = ( this.AbsolutePosition > this.RecordCount ); this.Data.Move( delta ); } } function CSWRecordSet_MoveFirst() { this.AbsolutePosition = Number( 1 ); this.RECORD_INDEX = this.AbsolutePosition; this.EOF = ( this.AbsolutePosition > this.RecordCount ); if( this.RecordCount > 0 ){ this.Data.MoveFirst(); } } // ----------------------------------------------------------------------------- // Data access: function CSWRecordSet_Value(fieldName) { if( this.EOF ){ return ""; // new record } return this.Data.fields.item( fieldName ); } function CSWRecordSet_Set(fieldName, value) { if( String( value ).length == 0 ){ value = null; } for( var i = 0; i < this.Data.fields.count; i++ ){ if( this.Data.fields.item( i ).name.toLowerCase() == fieldName.toLowerCase() ){ if(( this.AbsolutePosition != this.LastEdit )&& this.maxpending ){ this.Data.UpdateBatch(); } this.LastEdit = this.AbsolutePosition; this.Data.fields.item( i ).value = value; break; } } } // ----------------------------------------------------------------------------- // Key-based data access: // // The primary key specification is stored as an array of column names. An // instance of a key is of the format: colName=value&colName=value.... function CSWRecordSet_Key() { if( this.EOF ){ return "$newRecord"; } var keyLengthLimit = 255 - String( Request.ServerVariables( "PATH_TRANSLATED" )).length - 50; // 50 is extra mergin included server name var fieldLengthLimit = Math.max( 4, (( keyLengthLimit / this.PrimaryKey.length ) / 6 )); // Min 4 is for "null". 6 is worst case for 2 byte char encoded. var key = ""; var keyField = ""; for( var i = 0; i < this.PrimaryKey.length; i++ ){ var keyName = this.PrimaryKey[i]; if( keyLengthLimit < ( key.length - keyName.length - fieldLengthLimit - 1 )) break; if( 0 < i ){ key += "&"; keyField += ","; } switch( this.Data.fields.item( keyName ).Type ){ case adDate: case adDBDate: case adDBTime: case adDBTimeStamp: if(( this.Data.fields.item( keyName ) == null )||( String( this.Data.fields.item( keyName )).toUpperCase() == "NULL" )){ key += escape( keyName ) + "=" + escape( "null" ); keyField += keyName; }else{ key += escape( keyName ) + "=" + escape( callVBFormatDateTime( this.Data.fields.item( keyName ))); keyField += keyName; } break; case adBSTR: case adChar: case adWChar: case adVarChar: case adLongVarChar: case adVarWChar: case adLongVarWChar: if(( this.Data.fields.item( keyName ) == null )||( String( this.Data.fields.item( keyName )).toUpperCase() == "NULL" )){ key += escape( keyName ) + "=" + escape( "null" ); keyField += keyName; }else{ key += escape( keyName ) + "=" + escape( String( this.Data.fields.item( keyName )).substr( 0, fieldLengthLimit )); keyField += keyName; } break; default: if(( this.Data.fields.item( keyName ) == null )||( String( this.Data.fields.item( keyName )).toUpperCase() == "NULL" )){ key += escape( keyName ) + "=" + escape( "null" ); keyField += keyName; }else{ key += escape( keyName ) + "=" + escape( this.Data.fields.item( keyName )); keyField += keyName; } break; } } if( RuntimeDebug ){ var testString = escape( keyField ) + "&" + key; if( keyLengthLimit < testString.length ){ RuntimeDebugMessage( "Generated key length is too long." ); } } return escape( keyField ) + "&" + key; } function CSWRecordSet_MoveToKey( key ) { if( key == "$newRecord" ){ while( !this.EOF ){ this.Move( 1 ); } }else{ this.MoveFirst(); var keys = new Array; if( key == "$queryString" ){ // this part is version 1 compatibility. var keyString = Request.QueryString( "$key" ); if( keyString.Count < 1 ) return; var rawKeys = String( unescape( keyString )).split( "&" ); for( var i = 0; i < rawKeys.length; i++ ){ var keyDelim = rawKeys[i].indexOf( "=" ); keys[i] = new Object; keys[i].name = unescape( rawKeys[i].substring( 0, keyDelim )); keys[i].value = unescape( rawKeys[i].substring( keyDelim + 1 )); } }else{ var keyName = String( key ).split( "," ); for( var i = 0; i < keyName.length; i++ ){ keys[i] = new Object; keys[i].name = keyName[i]; keys[i].value = String( Request.QueryString( keyName[i] )); } } while( !this.EOF ){ var match = true; for( var i = 0; i < this.Data.fields.count; i++ ){ var field = this.Data.fields.item( i ); var stringField = String( field ); if(( field.Type == adDate )||( field.Type == adDBDate )||( field.Type == adDBTime )||( field.Type == adDBTimeStamp )) stringField = callVBFormatDateTime( field ); for( var j = 0; match && j < keys.length; j++ ){ if(( field.Name == keys[j].name )&&( stringField.indexOf( keys[j].value ) != 0 )){ match = false; } } } if( match ){ return; } this.MoveNext(); } } } // ----------------------------------------------------------------------------- // Forms automation: function obscure( plaintext ) { var plain = "obscure_" + escape( plaintext ); if( typeof( Application( plain )) == "undefined" ) { Application( plain ) = Math.random(); Application( "obscure_" + Application( plain )) = plaintext; } return Application( plain ); } function unobscure( hash ) { return Application( "obscure_" + hash ); } function CSWRecordSet_UpdateBatch() { this.Data.UpdateBatch(); } function CSWRecordSet_Delete() { this.Data.Delete(); } function CSWRecordSet_AddNew() { this.Data.AddNew(); } function getTableNameFromSource( source ) { var tableName = ""; var tokens = source.split( " " ); for (var i = 0; i < ( tokens.length -1 ); i++) { if( tokens[i].toUpperCase() == "FROM" ){ tableName = tokens[i+1]; break; } } return tableName; } </SCRIPT>