pyodbc

Python list of ints in prepared sql statement

邮差的信 提交于 2019-12-01 19:42:35
My question is somewhat the same as Python list of String to SQL IN parameter but I have a list of integers. The python code I use is: ids = [1000032, 1000048] sql = 'SELECT CompNo, CompName, CompType FROM Component WHERE DeptID IN (?)' cursor.execute(sql, [','.join(ids)]) And the Sybase database engine responds with: pyodbc.Error: ('07006', "[07006] [Sybase][ODBC Driver][SQL Anywhere]Cannot convert '1000032','1000048' to a numeric (-157) (SQLExecDirectW)") What is the correct way to do this? IMO a more readable way to build a dynamic query string with placeholders using str.format ids =

ODBC SQL type -155 is not yet supported

≡放荡痞女 提交于 2019-12-01 19:35:14
I follow this link to query Azure database. import pyodbc server = 'your_server.database.windows.net' database = 'your_database' username = 'your_username' password = 'your_password' driver= '{ODBC Driver 13 for SQL Server}' cnxn = pyodbc.connect('DRIVER='+driver+';PORT=1433;SERVER='+server+';PORT=1443;DATABASE='+database+';UID='+username+';PWD='+ password) cursor = cnxn.cursor() cursor.execute("SELECT * FROM FinancialRecord where deleted=0") row = cursor.fetchone() while row: print (str(row[0]) + " " + str(row[1])) row = cursor.fetchone() When I run the code above, it show the error.

ODBC SQL type -155 is not yet supported

╄→гoц情女王★ 提交于 2019-12-01 18:36:21
问题 I follow this link to query Azure database. import pyodbc server = 'your_server.database.windows.net' database = 'your_database' username = 'your_username' password = 'your_password' driver= '{ODBC Driver 13 for SQL Server}' cnxn = pyodbc.connect('DRIVER='+driver+';PORT=1433;SERVER='+server+';PORT=1443;DATABASE='+database+';UID='+username+';PWD='+ password) cursor = cnxn.cursor() cursor.execute("SELECT * FROM FinancialRecord where deleted=0") row = cursor.fetchone() while row: print (str(row

Neither DSN nor SERVER keyword supplied

纵然是瞬间 提交于 2019-12-01 18:20:02
I am trying to connect to SQL database slightly different ways: with and without use of parameter. Why without use of parameters works fine, but with use of parameters - gives me an error. Did I make a syntax error? I went through each letters and couldn't see anything. import pandas as pd import pyodbc #parameters: server = 'SQLDEV' db = 'MEJAMES' #Create the connection conn = pyodbc.connect('DRIVER={SQL Server};server =' + server + ';DATABASE = ' + db + ';Trusted_Connection=yes;') # query db sql = """ select top 10 PolicyNumber, QuoteID, ProducerName from tblQuotes """ df = pd.read_sql(sql

Win7 + Python3.6 + Django2.1 + MS SqlServer 2008配置

时光毁灭记忆、已成空白 提交于 2019-12-01 18:17:56
最近开始学习Django,开发环境为Win7 + Python3.6 + Django2.1 + MS SqlServer。本篇文章记录在配置过程中碰到的各种问题以及解决方法。 一. 安装开发环境 1. 安装Python 到官网 https://www.python.org/downloads/ 下载需要的版本进行安装。 2. 安装Django pip install Django 3. 安装MS SqlServer 2008 到“MSDN我告诉你” https://msdn.itellyou.cn/ 下载需要的版本进行安装。 二. 安装依赖项 Django连接SqlServer 2008需要依赖以下库:django-pyodbc, django-pyodbc-azure, django-mssql, 。安装方法如下: pip install django-pyodbc pip install django-pyodbc-azure pip install django-mssql 测试开发环境 1. 创建Django项目 django-admin startproject helloworld 2. 修改数据库配置 修改项目文件夹下settings.py文件中的数据库的配置文件,如下: DATABASES = \ { 'default': { 'ENGINE': 'sql

Neither DSN nor SERVER keyword supplied

北慕城南 提交于 2019-12-01 18:02:13
问题 I am trying to connect to SQL database slightly different ways: with and without use of parameter. Why without use of parameters works fine, but with use of parameters - gives me an error. Did I make a syntax error? I went through each letters and couldn't see anything. import pandas as pd import pyodbc #parameters: server = 'SQLDEV' db = 'MEJAMES' #Create the connection conn = pyodbc.connect('DRIVER={SQL Server};server =' + server + ';DATABASE = ' + db + ';Trusted_Connection=yes;') # query

Does pyodbc support any form of named parameters?

♀尐吖头ヾ 提交于 2019-12-01 15:57:40
I know sqlite3 has data = {'test_col': 012345679} sqlite3_conn.execute(""" UPDATE test_db SET test_col = :test_col ;""", data) and mysql-connector-python has data = {'test_col': 012345679} mysql_conn.execute(""" UPDATE test_db SET test_col = %(test_col)s ;""", data) but does pyodbc support any form of named parameters? I like being able to just pass a dict to the execute method. It is very convenient, and with some of my queries, such as INSERT INTO ... ON DUPLICATE KEY UPDATE , it is needed. FlipperPA It doesn't support named parameters, but bound parameters passed in the correct order are

Pyodbc: Login Timeout Error

送分小仙女□ 提交于 2019-12-01 15:47:25
问题 I am trying to connect to MS SQL Server using pyodbc from a remote machine running Ubuntu 16.04. import pyodbc conn = pyodbc.connect(r'DRIVER=ODBC Driver 17 for SQL Server; SERVER=xxxTest-SRV; PORT=51333; DATABASE=TestDB; UID=xxxx; PWD=xxxx;') I'm getting following error: pyodbc.OperationalError: ('HYT00', '[HYT00] [unixODBC][Microsoft][ODBC Driver 17 for SQL Server]Login timeout expired (0) (SQLDriverConnect)') I tried using the server IP in the connection string but still no luck. However,

Does pyodbc support any form of named parameters?

橙三吉。 提交于 2019-12-01 14:45:27
问题 I know sqlite3 has data = {'test_col': 012345679} sqlite3_conn.execute(""" UPDATE test_db SET test_col = :test_col ;""", data) and mysql-connector-python has data = {'test_col': 012345679} mysql_conn.execute(""" UPDATE test_db SET test_col = %(test_col)s ;""", data) but does pyodbc support any form of named parameters? I like being able to just pass a dict to the execute method. It is very convenient, and with some of my queries, such as INSERT INTO ... ON DUPLICATE KEY UPDATE , it is needed.

Pyodbc can't find FreeTDS driver

荒凉一梦 提交于 2019-12-01 12:03:39
问题 I am on a Centos 7 Linux machine trying to connect to an SQL database through pyodbc. I learned that you need to setup the DSN and you do that by installing the freetds driver and doing something like: import pyodbc cnxn = pyodbc.connect('DRIVER={FreeTDS};SERVER=example;DATABASE=TEST;') Unfortunately when I do that I get an error saying the driver FreeTDS can't be found. I have ran: $ ./configure $ make $ make install It seemed to have installed it but I get the same error. Can someone please