?? mmhttpdb.js
字號:
<SCRIPT LANGUAGE=VBScript RUNAT=Server>
function CreateVBArray(elem1,elem2,elem3,elem4)
elem1 = "" + elem1
elem2 = "" + elem2
elem3 = "" + elem3
elem4 = "" + elem4
if (Len(elem1) = 0) then
elem1 = Empty
end if
if (Len(elem2) = 0) then
elem2 = Empty
end if
if (Len(elem3) = 0) then
elem3 = Empty
end if
if (Len(elem4) = 0) then
elem4 = Empty
end if
CreateVBArray = Array(elem1,elem2,elem3,elem4)
end function
</SCRIPT>
<SCRIPT LANGUAGE=JavaScript RUNAT=Server>
function CreateMMConnection(ConnectionString,UserName,Password,Timeout)
{
var Object;
Object = new MMConnection(ConnectionString,UserName,Password,Timeout);
return Object;
}
function MMConnection(ConnectionString,UserName,Password,Timeout)
{
MMConnReconnect(this);
this.isOpen = false;
this.ConnectionString = ConnectionString;
this.UserName = String(UserName);
this.Password = String(Password);
this.Connection = Server.CreateObject("ADODB.Connection");
this.Connection.ConnectionTimeout = Timeout;
}
function MMConnReconnect(Object)
{
Object.GetODBCDSNs = ConnGetODBCDSNs;
Object.Open = ConnOpen;
Object.GetTables = ConnGetTables;
Object.GetViews = ConnGetViews;
Object.GetProcedures = ConnGetProcedures;
Object.GetColumnsOfTable = ConnGetColumns;
Object.GetParametersOfProcedure = ConnGetParametersOfProcedure;
Object.ExecuteSQL = ConnExecuteSQL;
Object.ExecuteSP = ConnExecuteSP;
Object.ReturnsResultSet = ConnReturnsResultSet;
Object.SupportsProcedure = ConnSupportsProcedure;
Object.GetProviderTypes = ConnGetProviderTypes;
Object.HandleExceptions = ConnHandleExceptions;
Object.TestOpen = ConnIsOpen;
Object.Close = ConnClose;
}
function ConnOpen()
{
theConnectionString = this.ConnectionString;
if (this.UserName && this.UserName.length)
{
theConnectionString = theConnectionString + ";uid=" + this.UserName;
}
if (this.Password && this.Password.length)
{
theConnectionString = theConnectionString + ";pwd=" + this.Password;
}
var aConn = ConnEval(theConnectionString);
this.Connection.Open(aConn);
this.isOpen = (this.Connection.State == adStateOpen);
}
function ConnIsOpen()
{
var xmlOutput = "";
if (this.isOpen)
{
xmlOutput = xmlOutput + "<TEST status=";
xmlOutput = xmlOutput + this.isOpen;
xmlOutput = xmlOutput + "></TEST>";
}
else
{
xmlOutput = this.HandleExceptions();
}
return xmlOutput;
}
function ConnClose()
{
if (this.Connection && this.isOpen)
{
this.Connection.Close();
}
}
function ConnGetTables(SchemaName,CatalogName)
{
if (this.Connection && this.isOpen)
{
var VBVariant = new VBArray(CreateVBArray(CatalogName,SchemaName,"","TABLE"));
return MarshallRecordsetIntoHTML(this.Connection.OpenSchema(adSchemaTables,VBVariant));
}
return null;
}
function ConnGetViews(SchemaName,CatalogName)
{
if (this.Connection && this.isOpen)
{
var VBVariant = new VBArray(CreateVBArray(CatalogName,SchemaName,"","VIEW"));
return MarshallRecordsetIntoHTML(this.Connection.OpenSchema(adSchemaTables,VBVariant));
}
return null;
}
function ConnGetProcedures(SchemaName,CatalogName)
{
if (this.Connection && this.isOpen)
{
var VBVariant = new VBArray(CreateVBArray(CatalogName,SchemaName,"",""));
return MarshallRecordsetIntoHTML(this.Connection.OpenSchema(adSchemaProcedures,VBVariant));
}
return null;
}
function ConnGetColumns(TableName,SchemaName,CatalogName)
{
if (this.Connection && this.isOpen)
{
var VBVariant = new VBArray(CreateVBArray(CatalogName,SchemaName,TableName,""));
return MarshallRecordsetIntoHTML(this.Connection.OpenSchema(adSchemaColumns,VBVariant));
}
return null;
}
function ConnGetParametersOfProcedure(ProcedureName,SchemaName,CatalogName)
{
if (this.Connection && this.isOpen)
{
var VBVariant = new VBArray(CreateVBArray(CatalogName,SchemaName,ProcedureName,""));
return this.Connection.OpenSchema(adSchemaProcedureParameters,VBVariant);
}
return null;
}
function ConnExecuteSQL(aStatement,MaxRows)
{
if (this.Connection && this.isOpen)
{
var oRecordset = Server.CreateObject("ADODB.Recordset");
if (oRecordset)
{
aStatement = "" + aStatement;
oRecordset.MaxRecords = MaxRows;
oRecordset.Open(aStatement,this.Connection);
return MarshallRecordsetIntoHTML(oRecordset);
}
}
return null;
}
function ConnGetProviderTypes()
{
if (this.Connection && this.isOpen)
{
return MarshallRecordsetIntoHTML(this.Connection.OpenSchema(adSchemaProviderTypes));
}
return null;
}
function ConnExecuteSP(aProcStatement,TimeOut,Parameters)
{
if (this.Connection && this.isOpen)
{
var oCommand = Server.CreateObject("ADODB.Command");
aProcStatement = "" + aProcStatement;
oCommand.CommandTimeout = TimeOut;
oCommand.CommandText = aProcStatement;
oCommand.CommandType = adCmdStoredProc;
oCommand.ActiveConnection = this.Connection;
Parameters = "" + Parameters;
if (!Parameters.length)
{
if (oCommand)
{
return MarshallRecordsetIntoHTML(oCommand.Execute());
}
}
else
{
//Substitute Parameters.
var Params = Parameters;
var ParamArray = new Array();
if (Params && Params != "undefined")
{
var cSize = 0;
for (;;)
{
var index = Params.indexOf(",");
if (index == -1)
{
index = Params.length;
}
var name = Params.substring(0,index);
Params = Params.substring(index+1,Params.length);
index = Params.indexOf(",");
if (index == -1)
{
index = Params.length;
}
var value = Params.substring(0,index);
var Pair = new Object();
Pair.name = name;
Pair.value = value;
ParamArray[cSize] = Pair;
cSize++;
if (index >= Params.length)
{
break;
}
Params = Params.substring(index+1,Params.length);
}
if (oCommand.Parameters.Count == -1)
{
//Create Parameters
var oRecordset = ConnGetParametersOfProcedure(aProcStatement);
if (oRecordset)
{
var pCount=0;
while (!oRecordset.EOF)
{
var pName = oRecordset.Fields.Item("PARAMETER_NAME").Value;
var pOrdinal = oRecordset.Fields.Item("ORDINAL_POSITION").Value;
var pType = oRecordset.Fields.Item("PARAMETER_TYPE").Value;
var pDataType = oRecordset.Fields.Item("DATA_TYPE").Value;
switch (pDataType)
{
case adBinary:
case adBSTR:
case adChar:
case adLongVarBinary:
case adLongVarChar:
case adLongVarWChar:
case adLongVarChar:
case adVarBinary:
case adVarChar:
case adVarWChar:
{
var pSize = oRecordset.Fields.Item("CHARACTER_MAXIMUM_LENGTH").Value;
}
default:
{
var pSize = null;
}
}
if ((pType == adParamInput) || (pType == adParamInputOutput))
{
var pValue = ParamArray[pName];
//if we could not find parameter by name ..try to find
//parameter by index.
if (!pValue)
{
//try the case when the parameter is set by index.
pStrCount = "" + pCount;
pValue = ParamArray[pStrCount];
}
oCommand.CreateParameter(pName,pDataType,pType,pSize,pValue);
}
else
{
var pValue = null;
oCommand.CreateParameter(pName,pDataType,pType,pSize,pValue);
}
oRecordset.MoveNext();
pCount++;
}
}
}
else
{
for (var i =0 ; i < ParamArray.length ; i++)
{
Pair = ParamArray[i];
if (Pair.value)
{
var pIndex = "" + parseInt(Pair.name);
if (pIndex == Pair.name)
{
var aParameter = oCommand.Parameters(parseInt(Pair.name));
}
else
{
var aParameter = oCommand.Parameters(Pair.name);
}
if (aParameter)
{
if ((aParameter.Direction == adParamInput) || (aParameter.Direction == adParamInputOutput))
{
aParameter.Value = Pair.value;
}
}
}
}
return MarshallRecordsetIntoHTML(oCommand.Execute());
}
}
}
}
return null;
}
function ConnReturnsResultSet(ProcedureName,SchemaName,CatalogName)
{
if (this.Connection && this.isOpen)
{
var VBVariant = new VBArray(CreateVBArray(CatalogName,SchemaName,ProcedureName,""));
var oRecordset = this.Connection.OpenSchema(adSchemaProcedureColumns,VBVariant);
var status = "true";
if (oRecordset.EOF)
{
status = "false";
}
var xmlOutput = "";
xmlOutput = xmlOutput + "<RETURNSRESULTSET status=";
xmlOutput = xmlOutput + status;
xmlOutput = xmlOutput + "></RETURNSRESULTSET>";
return xmlOutput;
}
}
function ConnSupportsProcedure()
{
if (this.Connection && this.isOpen)
{
var aProvider = "" + this.Connection.Provider;
var status = "true";
if (aProvider.indexOf("Microsoft.Jet") != -1)
{
status = "false";
}
if (aProvider.indexOf("MSDASQL")!=-1)
{
var ProviderTypes = this.Connection.OpenSchema(adSchemaProviderTypes);
if (ProviderTypes.Fields.Count > 0)
{
//Access
aProviderType = ProviderTypes.Fields(0).Value;
aProviderType = aProviderType.toLowerCase();
if (aProviderType == "guid")
{
status = "false";
}//Paradox/DBaseIII.
else if (aProviderType == "short")
{
status = "false";
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -