📄 recordset.asp
字号:
this._objEventManager.fireEvent(RS_ONROWEXIT);
this._rsADO.AddNew(fieldList, fieldValues);
if (this._rsADO.LockType == 4)
this._rsADO.UpdateBatch();
this._syncBOFandEOF();
if (this._count >= 0)
++this._count;
this.fields._reset(this._rsADO);
@if (@trace_events)
thisPage._traceEvent(this.name,RS_ONROWENTER);
@end
this._objEventManager.fireEvent(RS_ONROWENTER);
return true;
}
@if (@trace_warnings)
if (!this.isOpen())
thisPage._traceWarning('Err 408: Cannot add a new record to a closed recordset.','recordset.asp',this.name + '.addImmediate()');
else if (this._rsADO.LockType == 1)
thisPage._traceWarning('Err 409: Cannot add a new record to a read-only recordset.','recordset.asp',this.name + '.addImmediate()');
else if (this._bFiringOnBeforeUpdate == true)
thisPage._traceWarning('Err 405: Calling addImmediate is not allowed during the onbeforeupdate event.','recordset.asp',this.name + '.addImmediate()');
@end
return false;
}
function _RS_deleteRecord()
{
if (this._allowUpdate && !this._isEmpty())
{
this._bAddNewImmediate = false;
@if (@trace_events)
thisPage._traceEvent(this.name,RS_ONROWEXIT);
@end
this._objEventManager.fireEvent(RS_ONROWEXIT);
this._rsADO.Delete();
if (this._rsADO.LockType == 4)
this._rsADO.UpdateBatch();
this._rsADO.moveNext();
if (this._rsADO.EOF)
this._rsADO.movePrevious();
this._syncBOFandEOF();
if (this._count >= 0)
--this._count;
this.fields._reset(this._rsADO);
@if (@trace_events)
thisPage._traceEvent(this.name,RS_ONROWENTER);
@end
this._objEventManager.fireEvent(RS_ONROWENTER);
return true;
}
else if(!this._allowUpdate)
{
@if (@trace_events)
thisPage._traceEvent(this.name,RS_ONROWENTER);
@end
this._objEventManager.fireEvent(RS_ONROWENTER);
}
@if (@trace_warnings)
if (this._isEmpty())
thisPage._traceWarning('Err 412: Cannot delete a record from a closed or empty recordset.','recordset.asp',this.name + '.deleteRecord()');
else if (this._rsADO.LockType == 1)
thisPage._traceWarning('Err 413: Cannot delete a record from a read-only recordset.','recordset.asp',this.name + '.deleteRecord()');
@end
return false;
}
function _RS_advise(strEvent,funcToCall)
{
if (this.isOpen() &&
(strEvent == RS_ONROWENTER || strEvent == RS_ONDATASETCOMPLETE || strEvent == RS_ONDATASETCHANGED))
{ // fire immediately if data is available
this._fireEvent(funcToCall);
}
return this._objEventManager.advise(strEvent,funcToCall);
}
function _RS_unadvise(strEvent,nAdviseID)
{
return this._objEventManager.unadvise(strEvent,nAdviseID);
}
function _RS_adviseDefaultHandler(strName,strEvent)
{
var nAdviseID = this._objEventManager.adviseDefaultHandler(strName,strEvent);
if (this.isOpen() && nAdviseID > 0 &&
(strEvent == RS_ONROWENTER || strEvent == RS_ONDATASETCOMPLETE || strEvent == RS_ONDATASETCHANGED))
{ // fire immediately if data is available
var funcToCall = strName + '_' + strEvent + '()';
this._fireEvent(funcToCall);
}
return nAdviseID;
}
function _RS_getRecordSource()
{ return this._rsADO; }
//function _RS_setRecordSource(rsADO) OR
function _RS_setRecordSource(strConn,strSQL)
{
if (typeof(strConn) == 'string')
{ // given a connect and SQL string
this._resetMembers(true);
this._objDBConn = Server.CreateObject('ADODB.Connection');
this._objDBConn.ConnectionString = strConn;
this._objDBConn.Open();
if (!this.setSQLText(strSQL))
return false;
}
else if (typeof(strConn) == 'object')
{ // given an ADO object
var strBook = this._bookmark;
this._objDBConn = null;
this._resetMembers(true);
this._bookmark = strBook;
this._rsADO = strConn;
}
else
{
@if (@trace_warnings)
thisPage._traceWarning('Err 427: Invalid argument [strConn]. Must provide either an ADO recordset object OR a connection string and SQL string.','recordset.asp',this.name + '.setRecordSource(strConn,[strSQL])');
@end
return false;
}
if (this._rsADO.LockType == 1)
this._allowUpdate = false;
else
this._allowUpdate = true;
if (this.isOpen())
{
this.fields = CreateFields(this._rsADO);
if (this._bookmark != 0)
this.setBookmark(this._bookmark);
else
this._syncBOFandEOF();
this._objDBConn = this._rsADO.ActiveConnection;
@if (@trace_events)
thisPage._traceEvent(this.name,RS_ONROWENTER);
@end
this._objEventManager.fireEvent(RS_ONROWENTER);
@if (@trace_events)
thisPage._traceEvent(this.name,RS_ONDATASETCHANGED);
@end
this._objEventManager.fireEvent(RS_ONDATASETCHANGED);
@if (@trace_events)
thisPage._traceEvent(this.name,RS_ONDATASETCOMPLETE);
@end
this._objEventManager.fireEvent(RS_ONDATASETCOMPLETE);
}
return true;
}
function _RS_isOpen()
{
if ((this._rsADO && this._rsADO.state != 0) || (this._bExecuted))
return true;
return false;
}
function _RS_open()
{
if (this._rsADO != null)
{
@if (@debug)
if (typeof(this._rsADO.ActiveCommand) == 'undefined')
thisPage._reportError(null,'recordset.asp',this.name + '.open()','Err 437: This version of ADO does not support the ActiveCommand property. Must have ADO 2.0 or greater installed.');
@end
if (!this.isOpen())
{
@if (@trace_events)
thisPage._traceEvent(this.name,RS_ONBEFOREOPEN);
@end
this._objEventManager.fireEvent(RS_ONBEFOREOPEN);
if (this._params != null)
{
for (var i=0; i < this._params.length; i++)
{
if (typeof(this._params[i]) != 'undefined')
this._rsADO.ActiveCommand.Parameters(Number(i)).value = this._params[i];
}
}
// force AbsolutePosition to work in server-side cursor for SQL
if (this._rsADO.CursorLocation == 2)
{
@if (@debug)
try {
@end
this._rsADO.Properties('IRowsetScroll') = true;
@if (@debug)
} catch (e) {
thisPage._reportError(e,'recordset.asp', this.name + '.open()',
'Err 439: Unable to set the IRowsetScroll property on the ADO recordset.<br>' +
'Make sure the database supports a server-side cursor OR use a client-side cursor.');
throw e;
}
@end
}
// double-check after ONBEFOREOPEN is fired
if (!this.isOpen())
{
@if (@debug)
try {
@end
this._rsADO.Open();
@if (@debug)
} catch (e) {
this._reportError(e,'open');
throw e;
}
@end
}
this._objDBConn = this._rsADO.ActiveConnection;
this.fields = CreateFields(this._rsADO);
this._bExecuted = true;
if (this._bookmark != 0)
this.setBookmark(this._bookmark);
else
this._syncBOFandEOF();
// fire initial events
@if (@trace_events)
thisPage._traceEvent(this.name,RS_ONROWENTER);
@end
this._objEventManager.fireEvent(RS_ONROWENTER);
@if (@trace_events)
thisPage._traceEvent(this.name,RS_ONDATASETCHANGED);
@end
this._objEventManager.fireEvent(RS_ONDATASETCHANGED);
@if (@trace_events)
thisPage._traceEvent(this.name,RS_ONDATASETCOMPLETE);
@end
this._objEventManager.fireEvent(RS_ONDATASETCOMPLETE);
return true;
}
@if (@trace_warnings)
thisPage._traceWarning('Err 435: Recordset is already open.','recordset.asp',this.name + '.open()');
@end
return false;
}
@if (@trace_warnings)
thisPage._traceWarning('Err 401: An ADO recordset has not been defined. Check recordset DTC properties.','recordset.asp',this.name + '.open()');
@end
return false;
}
function _RS_close()
{
if (this.isOpen())
this._rsADO.Close();
@if (@trace_warnings)
else
thisPage._traceWarning('Err 434: Recordset is already closed.','recordset.asp',this.name + '.close()');
@end
this._resetMembers(true);
return true;
}
function _RS_getConnectString()
{
if (this._rsADO != null)
return this._rsADO.ActiveConnection.ConnectionString;
return '';
}
function _RS_getSQLText()
{
if (this._rsADO != null)
return this._rsADO.ActiveCommand.CommandText;
return '';
}
function _RS_setSQLText(strSQL)
{
if (typeof(strSQL) == 'string')
{
if (!this.isOpen())
{ // recordset is not open
if (this._rsADO != null)
{ // try to use existing recordset
var objDBCmd = this._rsADO.ActiveCommand;
//adCmdUnknown = 8
objDBCmd.CommandType = 8;
objDBCmd.CommandText = strSQL;
this._strSQL = strSQL;
return true;
}
// create an ADO recordset
if (this._objDBConn != null)
{
var objDBCmd = Server.CreateObject('ADODB.Command');
//adCmdUnknown = 8
objDBCmd.CommandType = 8;
objDBCmd.CommandText = strSQL;
objDBCmd.ActiveConnection = this._objDBConn;
this._rsADO = Server.CreateObject('ADODB.Recordset');
this._rsADO.Source = objDBCmd;
this.setRecordSource(this._rsADO);
return true;
}
}
else
{ // recordset is open, set CommandText to strSQL
// strSQL must be valid for current CommandType
this._rsADO.ActiveCommand.CommandText = strSQL;
this._strSQL = strSQL;
@if (@trace_warnings)
thisPage._traceWarning('Err 436: Recordset is already open. A requery is required to execute the new SQL statement.','recordset.asp',this.name + '.setSQLText(strSQL)');
@end
return true;
}
}
@if (@trace_warnings)
thisPage._traceWarning('Err 442: Wrong argument type [strSQL]. Expect a string.','recordset.asp',this.name + '.setSQLText(strSQL)');
@end
return false;
}
function _RS_requery()
{
if (this.isOpen())
{
@if (@debug)
try {
@end
this._rsADO.Requery();
@if (@debug)
} catch (e) {
this._reportError(e,'requery');
throw e;
}
@end
@if (@trace_events)
thisPage._traceEvent(this.name,RS_ONROWEXIT);
@end
this._objEventManager.fireEvent(RS_ONROWEXIT);
this._resetMembers();
this._syncBOFandEOF();
this.fields._reset(this._rsADO);
@if (@trace_events)
thisPage._traceEvent(this.name,RS_ONROWENTER);
@end
this._objEventManager.fireEvent(RS_ONROWENTER);
@if (@trace_events)
thisPage._traceEvent(this.name,RS_ONDATASETCHANGED);
@end
this._objEventManager.fireEvent(RS_ONDATASETCHANGED);
@if (@trace_events)
thisPage._traceEvent(this.name,RS_ONDATASETCOMPLETE);
@end
this._objEventManager.fireEvent(RS_ONDATASETCOMPLETE);
return true;
}
@if (@trace_warnings)
thisPage._traceWarning('Err 415: Cannot requery a closed recordset.','recordset.asp',this.name + '.requery()');
@end
return false;
}
function _RS_setBookmark(bookmark)
{
var nAbsPos = bookmark;
var strKeys = '';
var nSemi = bookmark.indexOf(';');
if (nSemi != -1)
{ // bookmark may contain keyfields for validation
nAbsPos = bookmark.substring(0,nSemi);
strKeys = bookmark.substring(nSemi+1,bookmark.length);
}
if (!isNaN(parseInt(nAbsPos)))
{
this._bookmark = bookmark;
if (this.isOpen() && !(this._rsADO.EOF && this._rsADO.BOF))
{ // reset to previous absolute position
@if (@trace_events)
thisPage._traceEvent(this.name,RS_ONROWEXIT);
@end
this._objEventManager.fireEvent(RS_ONROWEXIT);
var rsADO = this._rsADO;
var keyFields = null;
var bSeek = (strKeys.length > 1);
if (bSeek)
{ // extract key field values from bookmark
keyFields = new Object;
var nEq, nSemi, keyName, keyValue;
while (strKeys.length > 1)
{ // extract keyfield name/value pairs
nEq = strKeys.indexOf('=');
nSemi = strKeys.indexOf(';');
keyName = strKeys.substring(0,nEq);
keyValue = strKeys.substring(nEq+1,nSemi);
keyFields[keyName] = unescape(keyValue);
strKeys = strKeys.substring(nSemi+1,strKeys.length);
}
}
if (nAbsPos > 0)
{
rsADO.AbsolutePosition = (nAbsPos * 1);
if (bSeek)
{ // validate position using key field values
bSeek = false;
for (var keyName in keyFields)
{
if (typeof(rsADO.Fields(keyName)) != 'undefined' &&
keyFields[keyName] != rsADO.Fields(keyName))
{
bSeek = true;
break;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -