⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mmhttpdb.js

📁 用JAVA WEB编程中的jsp开发的一个留言本系统功能比较完整。是一个完整系统
💻 JS
📖 第 1 页 / 共 2 页
字号:
// Copyright 2001-2002 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
</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.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"));
		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 ConnGetPrimaryKeys(TableName,SchemaName,CatalogName)
{
	if (this.Connection && this.isOpen)
	{
		var VBVariant = new VBArray(CreateVBArray(CatalogName,SchemaName,TableName,"PrimaryKeys"));
		return MarshallRecordsetIntoHTML(this.Connection.OpenSchema(adSchemaPrimaryKeys,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";
				}
				else if (aProviderType == "image")
				{
					status = "false";
				}
				else if (aProviderType == "logical")
				{
					status = "false";
				} //For FoxPro
				else if (aProviderType == "l")
				{
					status = "false";
				} //For MySQL....
				else if (aProviderType == "tinyint")
				{
					status = "false";
				}
			}
		}

		var xmlOutput = "";
		xmlOutput = xmlOutput + "<SUPPORTSPROCEDURE status=";
		xmlOutput = xmlOutput + status;
		xmlOutput = xmlOutput + "></SUPPORTSPROCEDURE>";
		return xmlOutput;
	}
}

function ConnHandleExceptions()
{
	var xmlOutput = "";

	xmlOutput = xmlOutput + "<ERRORS>";
	if (this.Connection)
	{
		var Errors = this.Connection.Errors;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -