您在MySQL Connector / ODBC中遇到此错误。
编辑:该错误现已修复。
以下(Python 3)测试代码验证MySQL Connector /
ODBC返回零(不正确),而mysqlclient返回正确的值:
import MySQLdb # from mysqlclientimport pyodbchost = 'localhost'user = 'root'passwd = 'whatever'db = 'mydb'port = 3307charset = 'utf8mb4'use_odbc = False # or Trueprint(f'{"" if use_odbc else "not "}using ODBC ...')if use_odbc: connection_string = ( f'DRIVER=MySQL ODBC 8.0 ANSI Driver;' f'SERVER={host};UID={user};PWD={passwd};DATAbase={db};PORT={port};' f'charset={charset};' ) cnxn = pyodbc.connect(connection_string) print(f'{cnxn.getinfo(pyodbc.SQL_DRIVER_NAME)}, version {cnxn.getinfo(pyodbc.SQL_DRIVER_VER)}')else: cnxn = MySQLdb.connect( host=host, user=user, passwd=passwd, db=db, port=port, charset=charset )int_value = 123crsr = cnxn.cursor()crsr.execute("CREATE TEMPORARY TABLE foo (id varchar(10) PRIMARY KEY, intcol int, othercol longblob)")crsr.execute(f"INSERT INTO foo (id, intcol) VALUES ('Alfa', {int_value})")sql = f"SELECt intcol, othercol FROM foo WHERe id = {'?' if use_odbc else '%s'}"crsr.execute(sql, ('Alfa',))result = crsr.fetchone()[0]print(f'{"pass" if result == int_value else "FAIL"} -- expected: {repr(int_value)} ; actual: {repr(result)}')
use_odbc = True:
using ODBC ...myodbc8a.dll, version 08.00.0018FAIL -- expected: 123 ; actual: 0
控制台输出
use_odbc = False:
not using ODBC ...pass -- expected: 123 ; actual: 123
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)