pyodbc

pandas/sqlalchemy/pyodbc: Result object does not return rows from stored proc when UPDATE statement appears before SELECT

人盡茶涼 提交于 2021-02-10 17:44:43
问题 I'm using SQL Server 2014, pandas 0.23.4, sqlalchemy 1.2.11, pyodbc 4.0.24, and Python 3.7.0. I have a very simple stored procedure that performs an UPDATE on a table and then a SELECT on it: CREATE PROCEDURE my_proc_1 @v2 INT AS BEGIN UPDATE my_table_1 SET v2 = @v2 ; SELECT * from my_table_1 ; END GO This runs fine in MS SQL Server Management Studio. However, when I try to invoke it via Python using this code: import pandas as pd from sqlalchemy import create_engine if __name__ == "__main__"

TypeError: 'pyodbc.Cursor' object is not callable (Python 3.6)

余生长醉 提交于 2021-02-10 16:42:54
问题 I'm connecting to a database and trying to run an MS SQL query whose result is saved as a CSV file. When I try to execute my code, it's returning this error: Traceback (most recent call last): File "C:\Users\aubrey_s\PycharmProjects\Drawings_Converter\src\DrawingsConverter.py", line 220, in <module> main() File "C:\Users\aubrey_s\PycharmProjects\Drawings_Converter\src\DrawingsConverter.py", line 202, in main db_conn.retrieve_part_list() File "C:\Users\aubrey_s\PycharmProjects\Drawings

How to connect to SQL Server using FreeTDS ODBC

半腔热情 提交于 2021-02-10 15:57:11
问题 I am trying to connect to my company's SQL Server Databases via my MacBook and have followed the steps outlined here: https://github.com/mkleehammer/pyodbc/wiki/Connecting-to-SQL-Server-from-Mac-OSX but keep getting the following error when I get to the following step: Check that all is OK by running isql TEST myuser mypassword . You should see the following: +---------------------------------------+ | Connected! | | | | sql-statement | | help [tablename] | | quit | | | +---------------------

How to connect to SQL Server using FreeTDS ODBC

元气小坏坏 提交于 2021-02-10 15:56:00
问题 I am trying to connect to my company's SQL Server Databases via my MacBook and have followed the steps outlined here: https://github.com/mkleehammer/pyodbc/wiki/Connecting-to-SQL-Server-from-Mac-OSX but keep getting the following error when I get to the following step: Check that all is OK by running isql TEST myuser mypassword . You should see the following: +---------------------------------------+ | Connected! | | | | sql-statement | | help [tablename] | | quit | | | +---------------------

Trying to insert pandas dataframe to temporary table

≡放荡痞女 提交于 2021-02-08 08:37:15
问题 I'm looking to create a temp table and insert a some data into it. I have used pyodbc extensively to pull data but I am not familiar with writing data to SQL from a python environment. I am doing this at work so I dont have the ability to create tables, but I can create temp and global temp tables. My intent is to insert a relatively small dataframe (150rows x 4cols)into a temp table and reference it throughout my session, my program structure makes it so that a global variable in the session

when executing “import pyodbc” in python 3.6 (anaconda3) Jupyter Notebook throws error: ImportError: DLL load failed

一个人想着一个人 提交于 2021-02-08 08:16:58
问题 What I want to accomplish: execute import pyodbc statement within Jupyter Notebook and thus use pyodbc to import data from sql databases such as SQL Server, Exasol, etc. What is the environment: Anaconda3 (py36_0) installed on Windows 10 - 64 bit Version pyodbc installed via conda ( conda install pyodbc ) -> this worked as conda list shows that pyodbc 4.0.16 py36_0 is installed jupyter notebook works, for example import pandas works fine What happens: after issuing the command import pyodbc

pyodbc execute variable becomes @P1

≯℡__Kan透↙ 提交于 2021-02-07 20:43:04
问题 Hi I'm doing something like: # pyodbc extension cursor.execute("select a from tbl where b=? and c=?", x, y) -- some values in the query in provided by variables. But sometimes the variable is interpreted as @P1 in the query. For example: import pyodbc ch = pyodbc.connect('DRIVER={SQL Server};SERVER=xxxx;DATABASE=xxx;Trusted_Connection=True') cur = ch.cursor() x = 123 cur.execute(''' CREATE TABLE table_? ( id int IDENTITY(1,1) PRIMARY KEY, obj varchar(max) NOT NULL ) ''', x).commit() This

pyodbc execute variable becomes @P1

痴心易碎 提交于 2021-02-07 20:41:39
问题 Hi I'm doing something like: # pyodbc extension cursor.execute("select a from tbl where b=? and c=?", x, y) -- some values in the query in provided by variables. But sometimes the variable is interpreted as @P1 in the query. For example: import pyodbc ch = pyodbc.connect('DRIVER={SQL Server};SERVER=xxxx;DATABASE=xxx;Trusted_Connection=True') cur = ch.cursor() x = 123 cur.execute(''' CREATE TABLE table_? ( id int IDENTITY(1,1) PRIMARY KEY, obj varchar(max) NOT NULL ) ''', x).commit() This

Connect pyodbc to Postgres

早过忘川 提交于 2021-02-07 04:58:06
问题 Trying to connect to Postgres using pyodbc. I can connect to the DB with isql: echo "select 1" | isql -v my-connector Returns: +---------------------------------------+ | Connected! | | | | sql-statement | | help [tablename] | | quit | | | +---------------------------------------+ SQL> select 1 +------------+ | ?column? | +------------+ | 1 | +------------+ SQLRowCount returns 1 1 rows fetched But when I try to connect with pyodbc: import pyodbc con = pyodbc.connect("DRIVER={PostgreSQL

Python - Passing datetime parameters into a SQL Command

非 Y 不嫁゛ 提交于 2021-02-05 08:10:52
问题 I am trying to do something like this in Python, SQLCommand = ("Delete From %s where [Date] >= %s and [Date] <= %s", (calendar_table_name, required_starting_date, required_ending_date)) cursor.execute(SQLCommand) calendar_table_name is a string variable required_starting_date is a datetime variable required_ending_date is a datetime variable Trying this gives me an error: The first argument to execute must be a string or unicode query. Tried this and it gives me the same error: SQLCommand = (