views:

319

answers:

2

I've encountered a strange problem with getting data from a Database and casting it to the correct type using VBScript for ASP.

I have a recordset retrieved using the following function:

Public Function vfuncGetRS(strQuery)
    'Returns a disconnected paging capable recordset
    'Note - Non Windows servers don't support disconnected recordsets so you'll always get a connected recordset on
    ' a non Windows server!

    On Error Resume Next
    Err.Clear

    Dim objData

    Set objData = Server.CreateObject("ADODB.Recordset")
    objData.CursorLocation = adUseClient
    objData.CursorType = adOpenStatic
    objData.LockType = adLockReadOnly
    objData.Open vlogSQLFilter(strQuery), objDB

    If Not blnUNIXMode Then
     Set objData.ActiveConnection = Nothing
    End If

    Set vfuncGetRS = objData
End Function

If I select a value from the recordset and gets its VarType it returns the value 16 eg.

Set objRS = vfuncGetRS("SELECT * FROM SOME_TABLE")
Response.Write(VarType(objRS("someColumn")))

The weirdness is in two parts

  1. This ONLY happens on a particular server, this code is part of a CMS which I deploy on multiple sites and it's only the instance running on IIS 6.0 that causes me an issue. Also this seems to be dependent on the recordset options.
  2. The value 16 is not a valid value for VarType to return according to the official MSDN reference

I can get round this fairly easily by adding a check to the function that is being affected by the weird values which is as follows

If VarType(strValue) = 16 Then strValue = CInt(strValue)

I have to do the above because I need the function in question to correctly detect that the type is numeric and if the VarType is 16 then IsNumeric() gives false even if the value in the variable is numeric (and it will always be numeric)

So my question is does anyone know why this happens?

A: 

According to this, 16 might stand for VT_I1, thus a single byte signed integer.

Stijn Sanders
+2  A: 

As Stijn have stated, the value of 16 means that it's a One Byte Variant, specified in the C++ headers as VT_I1.

And you're only getting this value because of the MySQL connection driver (as you've stated that the environment where you encounter this 16 value is IIS6 with MySQL).

Apparently this is a bug in the MySQL driver that instead of reporting adBoolean for a BIT field it's Reporting VT_I1.

Paulo Santos