// Copyright 2001, 2002, 2003, 2004, 2005 Macromedia, Inc. All rights reserved.
<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
if (elem4 = "PrimaryKeys") then
CreateVBArray = Array(elem1,elem2,elem3)
else
CreateVBArray = Array(elem1,elem2,elem3,elem4)
end if
end function
function CreateVBEmpty()
CreateVBEmpty = Empty
end function
</SCRIPT>
<SCRIPT LANGUAGE=JavaScript RUNAT=Server>
//define the variant array for openSchema call
//create a javascript array instead of vb variant
//to fix SP2
function CreateJSArray(elem1,elem2,elem3,elem4)
{
var filterCriteriaArray = new Array();
var filterParam1 = "" + elem1
var filterParam2 = "" + elem2
var filterParam3 = "" + elem3
var filterParam4 = "" + elem4
if (!((filterParam1.length > 0) && (filterParam1 != "undefined")))
{
filterParam1 = CreateVBEmpty();
}
if (!((filterParam2.length > 0) && (filterParam2 != "undefined")))
{
filterParam2 = CreateVBEmpty();
}
if (!((filterParam3.length > 0) && (filterParam3 != "undefined")))
{
filterParam3 = CreateVBEmpty();
}
if (!((filterParam4.length > 0) && (filterParam4 != "undefined")))
{
filterParam4 = CreateVBEmpty();
}
if (filterParam4 == "PrimaryKeys")
{
filterCriteriaArray[0] = filterParam1;
filterCriteriaArray[1] = filterParam2;
filterCriteriaArray[2] = filterParam3;
}
else
{
filterCriteriaArray[0] = filterParam1;
filterCriteriaArray[1] = filterParam2;
filterCriteriaArray[2] = filterParam3;
filterCriteriaArray[3] = filterParam4;
}
return filterCriteriaArray;
}
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.GetPrimaryKeysOfTable = ConnGetPrimaryKeys;
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()
{
var theConnectionString = new String(this.ConnectionString);
// ????????????? OBSOLETE: begin ????????????????????????????????
if (this.UserName && this.UserName.length)
{
theConnectionString = theConnectionString + ";uid=" + this.UserName;
}
if (this.Password && this.Password.length)
{
theConnectionString = theConnectionString + ";pwd=" + this.Password;
}
// ????????????? OBSOLETE: end ????????????????????????????????
// The given connection string may not be formatted for OLE DB. It may, for example,
// be a SQL Server connection string. In such cases we need to morph it into
// an OLE DB connection string so it can be digested by the ADODB.Connection that
// we're using.
//
// For now, we are only dealing with morphing SQL Server connection strings. In the
// future, this logic may have to be expanded to deal with Oracle, Informix, etc. as
// those vendors make their own ASP.Net drivers available for use (circumventing
// the current need to go through OLE DB to access those databases).
var dbType = Request("DATABASETYPE");
if (dbType != null)
{
var strDBtype = new String(dbType);
if ((strDBtype.length > 0) && (strDBtype.toLowerCase() == "sqlserver"))
{
if (theConnectionString.charAt(0) == "\"")
{
theConnectionString = "\"Provider=SQLOLEDB;" + theConnectionString.substring(1);
}
else
{
theConnectionString = "Provider=SQLOLEDB;" + theConnectionString;
}
}
}
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>";
}
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"));
var JSVariant = CreateJSArray(CatalogName,SchemaName,"","TABLE");
return MarshallRecordsetIntoHTML(this.Connection.OpenSchema(adSchemaTables,JSVariant));
}
return null;
}
function ConnGetViews(SchemaName,CatalogName)
{
if (this.Connection && this.isOpen)
{
//var VBVariant = new VBArray(CreateVBArray(CatalogName,SchemaName,"","VIEW"));
var JSVariant = CreateJSArray(CatalogName,SchemaName,"","VIEW");
return MarshallRecordsetIntoHTML(this.Connection.OpenSchema(adSchemaTables,JSVariant));
}
return null;
}
function ConnGetProcedures(SchemaName,CatalogName)
{
if (this.Connection && this.isOpen)
{
//var VBVariant = new VBArray(CreateVBArray(CatalogName,SchemaName,"",""));
var JSVariant = CreateJSArray(CatalogName,SchemaName,"","");
return MarshallRecordsetIntoHTML(this.Connection.OpenSchema(adSchemaProcedures,JSVariant));
}
return null;
}
function ConnGetColumns(TableName,SchemaName,CatalogName)
{
if (this.Connection && this.isOpen)
{
//var VBVariant = new VBArray(CreateVBArray(CatalogName,SchemaName,TableName,""));
var JSVariant = CreateJSArray(CatalogName,SchemaName,TableName,"");
return MarshallRecordsetIntoHTML(this.Connection.OpenSchema(adSchemaColumns,JSVariant));
}
return null;
}
function ConnGetPrimaryKeys(TableName,SchemaName,CatalogName)
{
if (this.Connection && this.isOpen)
{
//var VBVariant = new VBArray(CreateVBArray(CatalogName,SchemaName,TableName,"PrimaryKeys"));
var JSVariant = CreateJSArray(CatalogName,SchemaName,TableName,"PrimaryKeys");
return MarshallRecordsetIntoHTML(this.Connection.OpenSchema(adSchemaPrimaryKeys,JSVariant));
}
return null;
}
function ConnGetParametersOfProcedure(ProcedureName,SchemaName,CatalogName)
{
if (this.Connection && this.isOpen)
{
//var VBVariant = new VBArray(CreateVBArray(CatalogName,SchemaName,ProcedureName,""));
var JSVariant = CreateJSArray(CatalogName,SchemaName,ProcedureName,"");
return this.Connection.OpenSchema(adSchemaProcedureParameters,JSVariant);
}
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)