ADOType.WSC

ADO type constants translator.
1.2, 2004-11-13

Methods and Properties

adoconst(adotype)

Converts an ADO type value into the corresponding generic type string. Calling adotype.adoconst(16), for example, would return the string "adTinyInt". This is useful when using the OpenSchema method of the ADO Connection object to generate ADO script code.

simpletype(adotype)

Converts an ADO type value into the corresponding generic type string. Calling adotype.simpletype(16), for example, would return the string "int".

datatype(adotype,size,precision,scale,flags)

Generates a generic type string that corresponds to the ADO type, size, precision, and scale using the given flags.

mssql(adotype,size,precision,scale,flags)

Returns a MSSQL type string for the ADO type, size, precision, and scale using the given flags (if possible).

vbs(adotype,size,precision,scale,flags)

Returns a VBScript type string for the ADO type, size, precision, and scale using the given flags (if possible).

Examples

Example 1.1. VBScript ASP

<html><head><title>Table Columns</title></head><body>
<%
Set adotype= Server.CreateObject("ADOType.WSC")
Set conn= Server.CreateObject("ADODB.Connection")
conn.Properties("Prompt")= ADODB.adPromptComplete
conn.Open Application("ConnectString")
Set rs= conn.OpenSchema(ADODB.adSchemaColumns,Request("table"))
%>
<table border="0" cellpadding="2" cellspacing="0">
  <caption><%= Request("table") %></caption>
  <tr><th>Column</th><th>Datatype</th><th>Nullable</th><th>Default</th></tr>
  <% Do Until rs.EOF %>
  <tr>
    <td><%= rs("COLUMN_NAME") %></td>
    <td><%= adotype.mssql(rs("DATA_TYPE"),rs("CHARACTER_MAXIMUM_LENGTH"),rs("NUMERIC_PRECISION"),rs("NUMERIC_SCALE")) %></td>
    <td><% If rs("IS_NULLABLE") Then %>null<% Else %>not null<% End If %></td>
    <td><%= rs("COLUMN_DEFAULT") %></td>
  </tr>
  <% rs.MoveNext: Loop %>
</table>
<% conn.Close %>
</body>
</html>

Example 1.2. JScript WSH

<?xml version="1.0" ?>
<package>
<job id="default">
<object id="conn" progid="ADODB.Connection"/>
<reference object="ADODB.Connection"/>
<script language="jscript"><![CDATA[
conn.Properties('Prompt')= ADODB.adPromptComplete;
conn.Open();
var adodir= new Array('adParamUnknown','adParamInput','adParamOutput',
  'adParamInputOutput','adParamReturnValue');
var adotype= WScript.CreateObject('ADOType.WSC');
var rs= conn.OpenSchema(ADODB.adSchemaProcedureParameters,
  Array(null,null,WScript.Arguments.Named('proc')));
WScript.Echo('Set cmd= CreateObject("ADODB.Command")');
for(;!rs.EOF;rs.MoveNext())
{
  if(rs('NUMERIC_SCALE').Value!=null) 
    WScript.Echo('Set param= cmd.CreateParameter("'+rs('PARAMETER_NAME').Value+'",ADODB.'
      +adotype.adoconst(rs('DATA_TYPE').Value)
      +',ADODB.'+adodir[rs('PARAMETER_TYPE').Value]+','
      +rs('CHARACTER_MAXIMUM_LENGTH').Value+')\n  param.Precision= '+rs('NUMERIC_PRECISION')
      +': param.NumericScale= '+rs('NUMERIC_SCALE')+':  cmd.Parameters.Append param');
  else
    WScript.Echo('cmd.Parameters.Append cmd.CreateParameter("'+rs('PARAMETER_NAME').Value
      +'",ADODB.'+adotype.adoconst(rs('DATA_TYPE').Value)+',ADODB.'
      +adodir[rs('PARAMETER_TYPE').Value]+','
      +rs('CHARACTER_MAXIMUM_LENGTH').Value+')');
}
]]></script>
</job>
</package>

Setup

  1. Download adotype.wsc to the web server (somewhere permanent, like a system directory).

  2. Right-click the file and choose Register.