pyodbc

Iterating over PyoDBC result without fetchall()

可紊 提交于 2020-01-01 05:04:33
问题 I'm trying to process a very large query with pyodbc and I need to iterate over the rows without loading them all at once with fetchall(). Is there a good and principled way to do this? 回答1: Sure - use a while loop with fetchone . http://code.google.com/p/pyodbc/wiki/Cursor#fetchone row = cursor.fetchone() while row is not None: # do something row = cursor.fetchone() 回答2: you could also use cursor.fetchmany() if you want to batch up the fetches (defaults to 1 if you don't override it) http:/

Binding list to params in Pandas read_sql_query with other params

牧云@^-^@ 提交于 2020-01-01 05:03:07
问题 I've been trying to test various methods for making my code to run. To begin with, I have this list: member_list = [111,222,333,444,555,...] I tried to pass it into this query: query = pd.read_sql_query( """ select member id ,yearmonth from queried_table where yearmonth between ? and ? and member_id in ? """, db2conn, params = [201601, 201603, member_list]) However, I get an error that says: 'Invalid parameter type. param-index=2 param-type=list', 'HY105' So I looked around and tried using

Connecting to SQL Server with pypyodbc

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-01 04:40:07
问题 I need to send unicode to SQL Server with Python 2.7. I failed with pymssql. I'm now trying to get pypyodbc working (as opposed to pyodbc ), as it gives working unicode examples. The problem is that the connection string in the example doesn't look like anything I recognize. I looked at this, and, after a little trial and error, constructed this string: conn = pypyodbc.connect("DRIVER={SQL Server};SERVER='MyServer';UID='me';PWD='MyPassword';DATABASE='db'") Got back a DatabaseError focused on

Connect to MS Access in Python

时光怂恿深爱的人放手 提交于 2019-12-31 04:50:31
问题 I tried a lot of examples from internet to include a MS Access connection to my python project without sucess I have my python project in Eclipse with Anaconda, and my code is: import win32com.client import pyodbc def ado(): ''' connect with com dispatch objs ''' conn = win32com.client.Dispatch(r'ADODB.Connection') DSN = ('PROVIDER = Microsoft.Jet.OLEDB.4.0;DATA SOURCE = ' + db + ';') conn.Open(DSN) rs = win32com.client.Dispatch(r'ADODB.Recordset') strsql = "select * from Empresas" rs.Open

By adding one statement import pyodbc causes Internal Server Error in Apache HTTP Server

女生的网名这么多〃 提交于 2019-12-31 04:27:12
问题 To run the normal school old python file in Apache Server. I had coded this way index.html <form action="/cgi-bin/hello_get.py" method="post"> First Name: <input type="text" name="first_name"> <br /> Last Name: <input type="text" name="last_name" /> <input type="submit" value="Submit" /> </form> hello_get.py #!C:/Users/Desktop/AppData/Local/Programs/Python/Python36-32/python # Import modules for CGI handling import cgi, cgitb import pyodbc # Create instance of FieldStorage form = cgi

“Optional feature not implemented” error with pyodbc query against Access database

非 Y 不嫁゛ 提交于 2019-12-31 03:28:45
问题 To anyone that can help, thank you in advance. I am running 64bit windows 10, 64bit office and 64bit python 3.7.2 Using pyodbc, I am trying to execute a Select statement such as this: "SELECT * FROM EconVars WHERE Year(ValueDate) = 1999" In order to do this, my code is as follows: existquery = """SELECT * FROM EconVars WHERE Year(ValueDate) = ?""" params = (1999,) cursor.execute(existquery,params) When I run this, I get the following error pyodbc.Error: ('HYC00', '[HYC00] [Microsoft][ODBC

“Optional feature not implemented” error with pyodbc query against Access database

杀马特。学长 韩版系。学妹 提交于 2019-12-31 03:28:05
问题 To anyone that can help, thank you in advance. I am running 64bit windows 10, 64bit office and 64bit python 3.7.2 Using pyodbc, I am trying to execute a Select statement such as this: "SELECT * FROM EconVars WHERE Year(ValueDate) = 1999" In order to do this, my code is as follows: existquery = """SELECT * FROM EconVars WHERE Year(ValueDate) = ?""" params = (1999,) cursor.execute(existquery,params) When I run this, I get the following error pyodbc.Error: ('HYC00', '[HYC00] [Microsoft][ODBC

pyodbc - error while running application within a container

回眸只為那壹抹淺笑 提交于 2019-12-31 02:09:43
问题 I am having a python application that uses mssql - instead of using pymssql, i was trying pyodbc. There seems to be no problems while running the application in a Windows local machine. While deploying the application in a dev env packaged as a container, I see the following errors. from pyodbc import Error 2017-04-14T13:58:28.858638588Z ImportError: Error loading shared library libodbc.so.2: No such file or directory (needed by /usr/local/lib/python3.5/site-packages/pyodbc.cpython-35m-x86_64

Python with MS SQL - truncated output

家住魔仙堡 提交于 2019-12-30 23:07:04
问题 I try to connect to MSSQL DB with python from Linux box ( Python 2.7 , Ubuntu 11.04 ) . Output that I receive is truncated to 500 characters. Please, see script and configs below. How it could be resolved? The problem I suppose in ODBC driver or near it. The code (pyodbc, pymssql): conn = pymssql.connect(host='my_remote_host', user='ro_user', password='password', database='current', as_dict=True) cur = conn.cursor() cur.execute(sql) for i in cur: print i conn.close() cnxn = pyodbc.connect

Python with MS SQL - truncated output

烈酒焚心 提交于 2019-12-30 23:06:21
问题 I try to connect to MSSQL DB with python from Linux box ( Python 2.7 , Ubuntu 11.04 ) . Output that I receive is truncated to 500 characters. Please, see script and configs below. How it could be resolved? The problem I suppose in ODBC driver or near it. The code (pyodbc, pymssql): conn = pymssql.connect(host='my_remote_host', user='ro_user', password='password', database='current', as_dict=True) cur = conn.cursor() cur.execute(sql) for i in cur: print i conn.close() cnxn = pyodbc.connect