MySQL ODBC 5.1 driver returns wrong datatype to ADODB

▼魔方 西西 提交于 2020-12-12 08:43:22

问题


Situation: working with legacy classic ASP code, attempting to move the codebase from an old server to a new one.

The code attempts to connect to a MySQL database on a Windows server using the MySQL ODBC 5.1 driver and the ADODB.Connection object.

Connection String = "Driver={MySQL ODBC 5.1 Driver};Server=dbserver;Database=dbname;Uid=username;Password=password;Option=3"

Query results are returned in ADODB.RecordSet objects. When I try to access a field containing a standard MySQL Integer, I get this error:

Microsoft VBScript runtime error '800a01ca'
Variable uses an Automation type not supported in VBScript

If I manually convert the field using cLng() then the error is eliminated and the correct value is returned. However, there is too much code to manually look for each reference to an integer and manually convert it.

VarType() returns 19 for these values, which appears to be some type of Long datatype that VB doesn't understand. (See here) Isn't the ODBC driver supposed to return VarType 3 for long integers? (see here)

I tried passing the option 16384 (NO_BIGINT) in the "option=" parameter of the connection string but it didn't make any difference.

Any idea how to correct this? It seems there should be an option to pass to the MySQL ODBC driver to return longs as Long Integer datatype, but I can't find it.

Before anyone mentions it: yes we know classic ASP is bad. No we don't have the resources to port this code to something else right now. We just need it to continue working on classic ASP for the current time.


回答1:


OK by the process of elimination I finally discovered the problem. Not sure why this occurs but it must be a bug in the MySQL ODBC driver.

Integer fields having the UNSIGNED attribute cause the error. Removing this attribute causes the field value to be returned as a standard Integer type. Apparently the ODBC driver is not handling the conversion from unsigned int to vbscript Integer type properly, and is instead returning a pointer to a Long.

I also noticed this problem on tinyint(1) fields which I was using as boolean values. Changing the datatype from tinyint(1) to int(11) [the default] eliminated this error also.

Hopefully this will help someone else. FYI I also posted this issue in the MySQL ODBC Driver forum but nobody bothered to respond.



来源:https://stackoverflow.com/questions/37032330/mysql-odbc-5-1-driver-returns-wrong-datatype-to-adodb

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!