pyodbc

Inserting datetime into a MS SQL table using pyodbc

寵の児 提交于 2019-12-10 12:54:06
问题 I'm trying to insert a datetime value into a MS SQL Server table using pyodbc. If I do it manually, something like: cursor.execute("""insert into currentvalue(value1,currentdatetime) values(55,'2014-06-27 16:42:48.533')""") I have no problem at all, but when I try to do: currenttime = str(datetime.datetime.now()) cursor.execute("""insert into currentvalue(value1,currentdatetime) values(55,"""+ currenttime+")") I got this error: SQL server Incorrect syntax near '07' which i think is the number

UnicodeDecodeError on Python 3.5 when doing SQL query

廉价感情. 提交于 2019-12-10 11:44:35
问题 I was using Python 3.5 + pyodbc (on windows 10) to do apply some SQL queries on a server, and everything was doing fine like this: In [1]: import pyodbc ...: In [2]: server = 'tcp:192.168.100.76' ...: database = 'database' ...: username = 'username' ...: password = 'password' ...: In [3]: cnxn = pyodbc.connect('DRIVER={ODBC Driver 13 for SQL Server};SERVER='+server+';DATABASE='+database+';UID='+use ...: rname+';PWD='+ password) ...: cursor = cnxn.cursor() In [29]: sqlQuery = "SELECT TOP 50 *

pyodbc execute SQL code

只愿长相守 提交于 2019-12-10 11:35:35
问题 I am trying to use pyodbc cursor execute the right way to prevent injection attacks, as suggested here: what does ? mean in python pyodbc module My code is as follows: query = """\ SELECT ?,count(*) FROM ? WHERE ?=? """, ('date', 'myTable', 'date', '2017-05-08') cursor.execute(query) And I get an error: TypeError: The first argument to execute must be a string or unicode query. For the right answer I'd want to: Keep the question mark format to avoid SQL injection attacks Keep the triple

Python pyodbc connections to IBM Netezza Erroring

天涯浪子 提交于 2019-12-10 03:01:31
问题 So. This issue is almost exactly the same as the one discussed here -- but the fix (such as it is) discussed in that post doesn't fix things for me. I'm trying to use Python 2.7.5 and pyodbc 3.0.7 to connect from an Ubuntu 12.04 64bit machine to an IBM Netezza Database. I'm using unixODBC to handle specifying a DSN. This DSN works beautifully from the isql CLI -- so I know it's configured correctly, and unixODBC is ticking right along. The code is currently dead simple, and easy to reproduce

How to backup a database by pyodbc

青春壹個敷衍的年華 提交于 2019-12-09 18:58:51
问题 The backup statement can't be used in a transaction when it execute with pyodbc cursor. It seems that the pyodbc execute the query inside a default transaction. I have also tried to use the autocommit mode or add the commit statement before the backup statement. Both of these are not working. #can't execute the backup statement in transaction cur.execute("backup database database_name to disk = 'backup_path'") #not working too cur.execute("commit;backup database database_name to disk =

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

狂风中的少年 提交于 2019-12-09 13:23:06
问题 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

Calling a stored procedure python

依然范特西╮ 提交于 2019-12-09 05:41:01
问题 I am writing a script to pull info/update a MsSQL server and i can get my one stored procedure call to work but not my second one in the updateDB function. here is my code the script runs fine no error codes import pyodbc import json import argparse import cgi, cgitb #GLOBALS BUILDCODE = " " deptCODE = 0 bldgCODE = " " def getCodes(conn, building, department): #just for testing departmentt = 'COMPUTER SCIENCE' buildingt = 'PEARCE HALL' #geting the building code from db cursorBuild = conn

Slow loading SQL Server table into pandas DataFrame

泪湿孤枕 提交于 2019-12-08 19:45:46
问题 Pandas gets ridiculously slow when loading more than 10 million records from a SQL Server DB using pyodbc and mainly the function pandas.read_sql(query,pyodbc_conn). The following code takes up to 40-45 minutes to load 10-15 million records from SQL table: Table1 Is there a better and faster method to read SQL Table into pandas Dataframe? import pyodbc import pandas server = <server_ip> database = <db_name> username = <db_user> password = <password> port='1443' conn = pyodbc.connect('DRIVER=

Driver for pyodbc: how to specify its location in macOS?

喜欢而已 提交于 2019-12-08 13:16:53
问题 I want to find a way to specify the path of a driver -- or otherwise resolve problem that Pyodbc cannot find a Vertica driver -- for the following Python 3 command with Pyodbc package Pyodbc.connect(...) but I keep getting the error that a Vertica driver 9.0.x cannot be found. I used the installer here and the installer here on macOS. I currently use an alias Vertica in the command but unknown for the Pyodbc connect so apparently some driver file problem, now need to find a way to resolve

Unable to use pydobc to connect to SQL Server using pyodbc in Python 3.6 in AWS Lambda

ⅰ亾dé卋堺 提交于 2019-12-08 10:07:19
问题 I have been struggling, and am unable to figure out how to connect to SQL Server using python 3.6 via pydobc and AWS Lambda. I followed the instructions provided by AWS to create an Amazon Linux AMI on which I was able to install the Microsoft ODBC drivers (v13 and v17), upgrade the unixODBC to a supported version, and get my python code to connect to the AWS RDS SQL Server instance. However, I have not been able to figure out how to package those changes successfully to deploy this code to