使用default=Null的Sybase存储过程在Python(pyodbc)中对INT进行加扰?

2024-10-02 02:38:58 发布

您现在位置:Python中文网/ 问答频道 /正文

从pyodbc调用时,以下存储过程无法绑定到默认的Null参数,并且无法获取Null

create procedure test 
  @A INT = Null 
as begin
  select @A, 
  case when @A = Null then 'sybase sees @A as Null' else 'sybase sees @A as *NOT* Null' end,
  Null 
end

直接调用“exec test”会产生:

(null),sybase将@A视为null(null)

而通过下面的

sql = 'exec test'
conn = pyodbc.connect(... ANSINULL=off ...)
cursor = conn.cursor()
cursor.execute(sql)
cursor.fetchall()

收益率:

[(-34561235, 'sybase sees @A as Null, -34561235)]

注意,char(1)、varchar(1)和date的默认值为null,将生成预期的“无”

另外请注意,因为我正在编辑一个先前提出的问题,该问题将两个问题混为一谈。之前,我没有向连接字符串添加ANSINULL=off,这会产生:

[(-34561235, 'sybase sees @A as NOT Null, -34561235)]

评论中要求的其他细节

SQL\u驱动程序\u名称: 自适应服务器企业版(ANSI)

SQL驱动程序版本:15.7.0.104

选择@版本: Adaptive Server Enterprise/15.7/EBF 24647 SMP SP134/P/x86_64/Enterprise Linux/ase157sp133x/3925/64位/FBO/Sat 2015年5月2日10:31:07


Tags: testsqlasnotconnnullcursorend

热门问题