Skip to content

Instantly share code, notes, and snippets.

@sholsinger
Created March 9, 2011 16:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sholsinger/862528 to your computer and use it in GitHub Desktop.
Save sholsinger/862528 to your computer and use it in GitHub Desktop.
Some functions to aid in "describing" a SQL table that you don't have direct SQL access to via COM ADO library.
<%
Function GetTableDefinition( table_name, conn, id, idfield )
dim rs, fld, rec
dim where: where = ""
If IsNumeric(id) And id > 0 and idfield <> "" Then
where = " WHERE " & idfield & " = " & id
End If
Set rs = conn.Execute("SELECT TOP 1 * FROM [" & table_name & "]" & where)
rec = ""
For i = 0 To rs.Fields.Count - 1
set fld = rs.Fields(i)
if rec <> "" Then
rec = rec & vbCrLf
End If
rec = rec & fld.name & " [" & GetTypeString(fld.type) & "] => " & fld.value
Next
set fld = Nothing
GetTableDefinition = rec
End Function
' pass in the int Type and receive the corresponding string name
Function GetTypeString( int )
dim str: str = ""
Select Case int
case 0 ' vbEmpty
str = "Empty"
case 1 ' vbNull
str = "Null"
case 2 ' vbInteger
str = "Integer"
case 3 ' vbLong
str = "Long"
case 4 ' vbSingle
str = "Single"
case 5 ' vbDouble
str = "Double"
case 6 ' vbCurrency
str = "Currency"
case 7 ' vbDate
str = "Date"
case 8 ' vbString
str = "String"
case 9 ' vbObject
str = "Object"
case 10 ' vbError
str = "Error"
case 11 ' vbBoolean
str = "Boolean"
case 12 ' vbVariant
str = "Variant"
case 13 ' vbDataObject
str = "DataObject"
case 17 ' vbByte
str = "Byte"
case 20 ' adBigInt
str = "ADO BigInt"
case 129 ' adChar
str = "ADO Char"
case 130 ' adWChar
str = "ADO Unicode Char"
case 131 ' adNumeric
str = "ADO Numeric"
case 135 ' adDBTimeStamp
str = "ADO Timestamp"
case 200 ' adVarChar
str = "ADO VarChar"
case 201 ' adLongVarChar
str = "ADO LongVarChar"
case 202 ' adVarWChar
str = "ADO Unicode VarChar"
case 203 ' adLongVarWChar
str = "ADO Unicode LongVarChar"
case 204 ' adVarBinary
str = "ADO VarBinary"
case 205 ' adLongVarBinary
str = "ADO LongVarBinary"
case 8192 ' vbArray
str = "Array"
case else
str = "Unknown Type"
End Select
GetTypeString = str
End Function
%>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment