简体   繁体   English

python中的cursor.execute for SQL

[英]cursor.execute in python for SQL

I need the script to monitor the sql server expiration from linux by python code and 我需要脚本来通过python代码从Linux监视sql server到期

In SQL output is coming but in linux, it gives the following error: 在SQL输出中,但是在Linux中,它给出以下错误:

>>> cursor.execute("select loginproperty('tibbr_db','DaysUntilExpiration')")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
pyodbc.Error: ('ODBC data type -150 is not supported.  Cannot read column .', 'HY000')

Explicitly cast the LOGINPROPERTY return value to an integer to work around the data type mapping problem by changing the query from this: 通过将查询更改为以下形式,将LOGINPROPERTY返回值显式转换为整数,以解决数据类型映射问题:

"select loginproperty('tibbr_db','DaysUntilExpiration')"

to this: 对此:

"select cast(loginproperty('tibbr_db','DaysUntilExpiration') as integer)"

The DaysUntilExpiration property in SQL Server should always return an integer, so you won't see any type errors with the explicit conversion. SQL Server中的DaysUntilExpiration属性应始终返回一个整数,因此使用显式转换不会看到任何类型错误。

ODBC type -150 looks like a SQL Server variant type, which pyodbc doesn't map to a python type. ODBC类型-150看起来像SQL Server 变量类型,pyodbc不会映射到python类型。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM