// Public
// ----------------------------------------------------------------
// Name Begin Modifiy Description
// Connection 2005-3-21 2005-3-21 System.Data.Connection 对象
function System.Data.Connection()
{
this.Connection;
this.ConnectionString;
this.State = -1;
this.CommandText;
this.CommandType = CommandType.Text;
this.RecordsAffected = 0;
// Private
// ----------------------------------------------------------------
// Name Begin Modifiy Description
// IsConnection 2005-1-28 2005-1-28 检查 this.Connection 对象
this.IsConnection = function()
{
if ( this.State == -1 )
{
this.Connection = Server.CreateObject("ADODB.Connection");
this.CursorLocation = adUseClient
this.State = 0;
}
if ( this.State == 0)
{
try
{
this.Connection.Open(this.ConnectionString);
this.State = 1;
}
catch(e)
{
new System.Exception("连接失败! "+ e.description)
}
}
return( this.State );
}
// Public
// ----------------------------------------------------------------
// Name Begin Modifiy Description
// ExecuteNonQuery 2005-1-28 2005-1-28 针对 Connection 执行 SQL 语句并返回受影响的行数
this.ExecuteNonQuery = function (CommandText, CommandType)
{
this.CheckCommandText(CommandText);
this.CheckCommandType(CommandType);
this.IsConnection();
this.Connection.Execute(this.CommandText, this.RecordsAffected, this.CommandType + adExecuteNoRecords);
return( this.RecordsAffected );
}
// Public
// ----------------------------------------------------------------
// Name Begin Modifiy Description
// ExecuteReader 2005-1-28 2005-1-28 将 CommandText 发送到 Connection 并生成一个 DataReader。
this.ExecuteReader = function (CommandText, CommandType)
{
this.CheckCommandText(CommandText);
this.CheckCommandType(CommandType);
this.IsConnection();
return( this.Connection.Execute(this.CommandText, this.RecordsAffected, this.CommandType) );
}
// Public
// ----------------------------------------------------------------
// Name Begin Modifiy Description
// ExecuteScalar 2005-1-28 2005-1-28 执行查询,并返回查询所返回的结果集中第一行的第一列。忽略额外的列或行。
this.ExecuteScalar = function (CommandText, CommandType)
{
return( this.ExecuteReader(CommandText, CommandType)(0) );
}
// Public
// ----------------------------------------------------------------
// Name Begin Modifiy Description
// ExecuteXmlReader 2005-1-28 2005-1-28 将 CommandText 发送到 Connection 并生成一个 XmlReader 对象。
this.ExecuteXmlReader = function (CommandText, CommandType)
{
var Stream = Server.CreateObject("ADODB.Stream");
this.ExecuteReader(CommandText, CommandType).Save(Stream, adPersistXML);
return( Stream.ReadText(-1) ); // var adReadAll = -1
}
// Private
// ----------------------------------------------------------------
// Name Begin Modifiy Description
// CheckCommandText 2005-1-28 2005-1-28 检查 CommandText
this.CheckCommandText = function(CommandText)
{
if ( !Utility.IsEmpty(CommandText) ) this.CommandText = CommandText;
}
// Private
// ----------------------------------------------------------------
// Name Begin Modifiy Description
// CheckCommandType 2005-1-28 2005-1-28 检查 CommandType
this.CheckCommandType = function(CommandType)
{
if ( !Utility.IsEmpty(CommandType) ) this.CommandType = CommandType;
}
// Public
// ----------------------------------------------------------------
// Name Begin Modifiy Description
// Close 2005-1-28 2005-1-28 关闭 Connection 对象
this.Close = function()
{
this.Connection.Close();
}
// Public
// ----------------------------------------------------------------
// Name Begin Modifiy Description
// Dispose 2005-3-18 2005-3-18 销毁 Connection 对象
this.Dispose = function()
{
this.Close();
this.Connection = null;
}
// Public
// ----------------------------------------------------------------
// Name Begin Modifiy Description
// toString 2005-3-21 2005-3-21 获取此实例的 String 表示形式
this.toString = function()
{
return( "System.Data.Connection" );
}
// Private
// ----------------------------------------------------------------
// Name Begin Modifiy Description
// ctor 2005-3-21 2005-3-21 重载支持
this.ctor = function(arguments)
{
this.ConnectionString = ( !Utility.IsEmpty(arguments[0]) && typeof(arguments[0]) == "string" ) ? arguments[0] : Setup.AppSettings["ConnectionString"];
}
// Private
// ----------------------------------------------------------------
// Name Begin Modifiy Description
// Call ctor() 2005-3-21 2005-3-21 调用重载
this.ctor(arguments);
}