pyodbc

Using an Access database (.mdb) with Python on Ubuntu [duplicate]

爱⌒轻易说出口 提交于 2019-12-04 05:27:01
This question already has an answer here: Working with an Access database in Python on non-Windows platform (Linux or Mac) 4 answers I'm trying to use pyodbc to access a .mdb on Ubuntu. I've based my progress so far on this link Query crashes MS Access I have installed pyodbc, unixodbc, and unixodbc-dev My code looks like this: import csv import pyodbc MDB = 'URY.mdb' DRV ='Microsoft Access Driver (*.mdb)' PWD = 'pass' conn = pyodbc.connect('DRIVER=%s;DBQ=%s;PWD=%s' % (DRV,MDB,PWD)) curs = conn.cursor() When I run it, I receive this error message: Traceback (most recent call last): File

pyodbc on SQL Server - How can I do an insert and get the row ID back?

空扰寡人 提交于 2019-12-04 05:17:44
I'm using pyodbc with SQL Server 2000. I want to be able to insert a row and get the auto incremented row id value back? Any ideas? Here's what I have so far: cursor.execute("insert into products(id, name) values ('pyodbc', 'awesome library')") cnxn.commit() Sorry, I asked too soon, it's addressed in their FAQ Use "SELECT @@IDENTITY". 来源: https://stackoverflow.com/questions/2883722/pyodbc-on-sql-server-how-can-i-do-an-insert-and-get-the-row-id-back

Pyodbc query string quote escaping

一曲冷凌霜 提交于 2019-12-04 04:28:24
问题 I'm trying to execute a query using pyodbc with this kind of code cursor.execute("SELECT x from y where Name='%s'"%namepar) The parameter may have a quote and so it needs to be escaped in order to work, how do i do thos? I tried by simply replacing " ' " with " \\' " in namepar and it still doesn't work, I get a pyodbc.ProgrammingError 回答1: You can pass parameters, and that will be escaped. cursor.execute("SELECT x from y where Name = ?", (namepar,)) http://www.python.org/dev/peps/pep-0249/

SQL Server temp table not available in pyodbc code

孤街醉人 提交于 2019-12-04 04:26:35
I'm running a series of complex sql queries in python and it involves temp tables. My auto-commit method doesn't seem to be working to retrieve the data from the temp table. The code snippet I'm using below and this is the output I'm getting: testQuery=""" Select top 10 * INTO #Temp1 FROM Table1 t1 JOIN Table2 t2 on t1.key=t2.key """ cnxn=pyodbc.connect(r'DRIVER={SQL Server Native Client 11.0};SERVER=server;DATABASE=DB;UID=UID;PWD=PWD') cnxn.autocommit=True cursor=cnxn.cursor() cursor.execute(testQuery) cursor.execute("""Select top 10 * from #Temp1""") <pyodbc.Cursor at 0x8f78930> cnxn=pyodbc

pyodbc calls sp_unprepare after sp_prepexec. Does that affect performance of parameterized queries?

[亡魂溺海] 提交于 2019-12-04 04:16:44
问题 In continuation of SqlAlchemy+pymssql. Will raw parametrized queries use same execution plan? I switched from pymssql to pyodbc tried to get parametrized queries sent to SQL Server. pyodbc with Microsoft driver does the trick, but something seems strange to me: declare @p1 int set @p1=6 exec sp_prepexec @p1 output,N'@P1 nvarchar(6),@P2 bigint,@P3 bigint,@P4 bigint',N' SELECT * FROM CC_sold WHERE id_contract =@P1 AND id_tip_cont=@P2 AND CC_sold.anul =@P3 AND CC_sold.luna =@P4 ORDER BY CC_sold

PyODBC : can't open the driver even if it exists

白昼怎懂夜的黑 提交于 2019-12-03 19:21:19
问题 I'm new to the linux world and I want to query a Microsoft SQL Server from Python. I used it on Windows and it was perfectly fine but in Linux it's quite painful. After some hours, I finally succeed to install the Microsoft ODBC driver on Linux Mint with unixODBC. Then, I set up an anaconda with python 3 environment. I then do this : import pyodbc as odbc sql_PIM = odbc.connect("Driver={ODBC Driver 13 for SQL Server};Server=XXX;Database=YYY;Trusted_Connection=Yes") It returns : ('01000', "

PYODBC to Pandas - DataFrame not working - Shape of passed values is (x,y), indices imply (w,z)

*爱你&永不变心* 提交于 2019-12-03 19:06:55
问题 I used pyodbc with python before but now I have installed it on a new machine ( win 8 64 bit, Python 2.7 64 bit, PythonXY with Spyder). Before I used to (at the bottom you can find more real examples): columns = [column[0] for column in cursor.description] temp = cursor.fetchall() data = pandas.DataFrame(temp,columns=columns) and it would work fine. Now it seems like DataFrame is not able to convert from the data fetched from the cursor anymore. It returns: Shape of passed values is (x,y),

BULK INSERT error code 3: The system cannot find the path specified

限于喜欢 提交于 2019-12-03 17:36:11
I am trying to bulk insert a local file into a remote MS_SQL database using pyodbc. I am able to connect to the DB and I am able to INSERT INTO tables, as I have done it before. Where I have been having issues is to BULK INSERT . I am using BULK INSERT as a way to speed up my INSERT process. The code looks like this: statement = """ BULK INSERT BulkTable FROM 'C:\\Users\\userName\\Desktop\\Folder\\Book1.csv' WITH ( FIRSTROW=2, FIELDTERMINATOR=',', ROWTERMINATOR = '\\n' ); """ cursor.execute(statement) cnxn.commit() This code yields this error: Traceback (most recent call last): File "tester.py

How to connect MS Access to Python using pyodbc

荒凉一梦 提交于 2019-12-03 17:15:30
问题 I'm having trouble connecting a database in access with pyodbc. I've seen other example codes that appear near identical to mine that work: import pyodbc cnxn = pyodbc.connect('DRIVER={SQL Server};SERVER=localhost;DATABASE=PYODBC.accdb;UID=me;PWD=pass') cursor = cnxn.cursor() cursor.execute("SELECT Forename FROM Student") row = cursor.fetchone() if row: print(row) My machine is running on windows 7 home premium 64-bit. I have Microsoft office 2010; 32-bit I'm running python 3.3; 32-bit I have

Using SQL Server stored procedures from Python (pyodbc)

て烟熏妆下的殇ゞ 提交于 2019-12-03 16:32:15
问题 I'm have a stored procedure, code: DECLARE @RC int DECLARE @id varchar(13) DECLARE @pw varchar(13) DECLARE @depart varchar(32) DECLARE @class varchar(12) DECLARE @name varchar(12) DECLARE @birthday varchar(10) DECLARE @grade int DECLARE @subgrade int SELECT @id = 'test' SELECT @pw = '12345' SELECT @depart = 'none' SELECT @class = 'GM' SELECT @name = 'name' SELECT @birthday = 'None' SELECT @grade = 3 SELECT @subgrade = 2 EXEC @RC = [my_database].[dbo].[my_table] @id, @pw, @depart, @class,