pyodbc | open source Python module that makes accessing ODBC | Database library
kandi X-RAY | pyodbc Summary
kandi X-RAY | pyodbc Summary
pyodbc is an open source Python module that makes accessing ODBC databases simple. It implements the DB API 2.0 specification but is packed with even more Pythonic convenience.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Return the current version number
- Get the current version of git
- Extract the version number from the pk - info file
- Get output from command
- Print s to stdout
- Prints the version information
- Get the current version number
- Returns a dictionary of compiler settings
pyodbc Key Features
pyodbc Examples and Code Snippets
query['Schedule8812']=query['JSON'].apply(lambda x: 'Schedule8812' in json.loads(x.to_string())['ReturnData'])
query['Schedule8812']=query['JSON'].str.contains('Schedule8812')
sql_declare = "DECLARE @json NVARCHAR(MAX) = N'" + json_str + "'"
sql_stat = "INSERT ... FROM OPENJSON(@json, '$.results') ..."
sql = sql_declare + " " + sql_stat
cursor.execute(sql)
sql = "INSERT ... FROM OPENJSON
# upload to db
SQL_STATEMENT = (
f"BULK INSERT {tbl_name} "
f"FROM '{my_file}' "
"WITH (FORMAT='CSV');"
)
cur.execute(SQL_STATEMENT)
conn.commit()
rowiercount = str(rowcount)
rowiercount.replace("(", "").replace(")", "").replace(" ", "").replace(",", ""))
# PREPARED STATEMENT WITH QMARK
sql = "insert into WeatherAnalisis (Time_UTC) values (?)"
# EXECUTE QUERY WITH BINDED PARAM
crsr.execute(sql, timeCET)
cnxn.commit()
end_date = datetime.datetime.now()
first_date = start_date - datetime.timedelta(days = 6)
df = pd.DataFrame(pd.date_range(first_date, end_date, freq = '1D'), columns = ['Date'])
df['Day'] = df['Date'].dt.day_name()
df['Date'] = df['Date']
query = f"""
BEGIN TRY
**a query that can give an error
with structure:
insert into TABLE
primary key
foreign key ---> that has no match on other tables, giving error**
END TRY
BEGIN CATCH
SELECT
ERRO
from tkinter import *
from tkinter import ttk
import tkinter as tk
# import pyodbc
DEFAULT_ENCODING = 'utf-8'
ws=Tk()
ws.title('Haapsalu Uksetehas')
ws.geometry('150x100')
ws['bg'] = '#26658f'
ws.resizable(False, False)
def callback_pi
cursor.fast_executemany = True
cursor.fast_executemany(my_insert_statement,df.values.tolist())
cursor.executemany(my_insert_statement,df.values.tolist())
Community Discussions
Trending Discussions on pyodbc
QUESTION
I have a piece of code that dumps a dataframe with 30k rows into a table on my Vertica database. But since its taking way too long to run, I'm trying to use fast_executemany
parameter of sqlalchemy.
ANSWER
Answered 2022-Mar-24 at 14:55fast_executemany
is apparently not implemented in the Vertica dialect for SQLAlchemy. In order for that option to be recognized the dialect would have to be modified similar to the way SQLAlchemy's built-in mssql+pyodbc://
dialect supports it. But before doing that the developers of the Vertica dialect would want to confirm that the Vertica ODBC driver works properly with fast_executemany = True
because not all drivers can use it.
QUESTION
I have an issue with inserting data into a database using the python package pyodbc and since I am pretty new to pyodbc & databases in general, I might lack some basic understanding.
I open a connection, and then I want the execute my query. Actually, in this query I call a stored procedure (which I didn't write and I am not allowed to change!). This procedure does "one or two" inserts. When I use pyodbc like this
...ANSWER
Answered 2022-Mar-08 at 16:07You seem to have encountered a quirk in MySQL Connector/ODBC's handling of result sets from a stored procedure. For this example procedure:
QUESTION
I get this Error when I try to install Pyodbc , I have already install visual studio and I have Microsoft Visual C++ 12 , 15-19 in my machine but still its giving this error.
...ANSWER
Answered 2021-Nov-12 at 13:38The current release of pyodbc (4.0.32) does not have pre-built wheel files for Python 3.10. The easiest way to get it installed at the moment is to download the appropriate wheel from
https://www.lfd.uci.edu/~gohlke/pythonlibs/#pyodbc
and then install it. For example, if you are running 64-bit Python then you would download the 64-bit wheel and use
QUESTION
Application Background: Trying to deploy an automation application where user selects *access file and visualize graphs from the python flask backend calculation.
Locally, Downloaded "Access Driver": https://www.microsoft.com/en-us/download/details.aspx?id=54920 [which ran fine]. But unable to deploy on Azure.
Things that I have tried:
I have tried to run this application using Github CI/CD but with Github actions azure can only give option to run on linux os. which will give me the same error (pyodbc connection)
Build Docker image that could eliminate this error however, when selected 'FROM python:slim-buster' under Dockerfile - It generated docker image with linux which gives the same error.
Also, tried adding windows OS in the Dockerfile using FROM microsoft/nanoserver
, still received an error while creating an image.
I am new to all these and think might be making mistakes. Any help will be appreciated.
...ANSWER
Answered 2022-Feb-15 at 11:58So After a lot of trial and error, I was able to deploy on windows server on Azure.
What worked:
Deploying application on windows server with ODBC driver (AccessDatabaseEngine.exe). Not the 64bit(AccessDatabaseEngine_X64.exe).
One can deploy using Docker image also but ** FROM microsoft/nanoserver ** was not able to build any image. Instead try with ** FROM mcr.microsoft.com/windows/servercore:ltsc2019 **
QUESTION
I am trying to make sense of the following error that I started getting when I setup my python code to run on a VM server, which has 3.9.5 installed instead of 3.8.5 on my desktop. Not sure that matters, but it could be part of the reason.
The error
...ANSWER
Answered 2022-Feb-11 at 16:30Is pyodbc becoming deprecated?
No. For at least the last couple of years pandas' documentation has clearly stated that it wants either a SQLAlchemy Connectable
(i.e., an Engine
or Connection
object) or a SQLite DBAPI connection. (The switch-over to SQLAlchemy was almost universal, but they continued supporting SQLite connections for backwards compatibility.) People have been passing other DBAPI connections (like pyodbc Connection
objects) for read operations and pandas hasn't complained … until now.
Is there a better way to achieve similar results without warning?
Yes. You can take your existing ODBC connection string and use it to create a SQLAlchemy Engine
object as described here:
QUESTION
I am trying to read my snowflake query in a pandas dataframe, however I get an "Attribute Error" stating 'SnowflakeCursor' object has no attribute 'shape' (code below) ...
Snowflake python connector works. fetch_pandas_all() works. Once I try reading the query as a pandas dataframe, it breaks.
...ANSWER
Answered 2022-Jan-31 at 15:28What about this way:
QUESTION
PyODBC takes ~7 seconds to establish a connection with Azure SQL Server, is there a way to minimize this?
...ANSWER
Answered 2022-Jan-05 at 14:51Could you please try to connect using the ODBC Driver 17 for SQL Server? You may find this way faster.
QUESTION
i using VSCode as my IDE for development odoo and for now run using Start > Debugging ( F5)
While running at web browser localhost:8069 ( default ) then appear Internal Server Error and in terminal VSCode there are errors :
...ANSWER
Answered 2021-Dec-27 at 17:01After trying for a few days and just found out that pip and python in the project are not pointing to .venv but to anaconda due to an update. when error
no module stdnum
actually there is a problem with pip so make sure your pip path with which pip or which python
- to solve .venv that doesn't work by deleting the .venv folder, create venv in python, and install all requirements again
QUESTION
I am doing a python script to add text files into an MSSQL table. Using pyodbc, I'm doing it. The data is not inserted in the result. There is no error showing when running.
Here is my code,
...ANSWER
Answered 2021-Aug-29 at 04:22You're missing a call to cnxn.commit()
after the loops are done.
QUESTION
I'm trying to query a table from an Informix database using pyodbc and write the results to a CSV file with the below code:
...ANSWER
Answered 2021-Dec-16 at 08:58Because the Informix datatype CLOB are BLOB are not standard ODBC types, you may need to tell the ODBC driver to automatically handle those types.
You do that enabling the "Report standard ODBC types" feature within the ODBC driver by setting the "SQL_INFX_ATTR_ODBC_TYPES_ONLY" ODBC attribute or by adding a "NeedODBCTypesOnly=1" to the connection string.
https://www.ibm.com/docs/en/informix-servers/14.10?topic=types-report-standard-odbc
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install pyodbc
You can use pyodbc like any standard Python library. You will need to make sure that you have a development environment consisting of a Python distribution including header files, a compiler, pip, and git installed. Make sure that your pip, setuptools, and wheel are up to date. When using pip it is generally recommended to install packages in a virtual environment to avoid changes to the system.
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page