pyodbc | open source Python module that makes accessing ODBC | Database library

 by   mkleehammer Python Version: 5.1.0 License: MIT-0

kandi X-RAY | pyodbc Summary

kandi X-RAY | pyodbc Summary

pyodbc is a Python library typically used in Database applications. pyodbc has no bugs, it has no vulnerabilities, it has build file available, it has a Permissive License and it has medium support. You can install using 'pip install pyodbc' or download it from GitHub, PyPI.

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

            kandi-support Support

              pyodbc has a medium active ecosystem.
              It has 2678 star(s) with 534 fork(s). There are 125 watchers for this library.
              There were 1 major release(s) in the last 6 months.
              There are 54 open issues and 926 have been closed. On average issues are closed in 228 days. There are 13 open pull requests and 0 closed requests.
              It has a neutral sentiment in the developer community.
              The latest version of pyodbc is 5.1.0

            kandi-Quality Quality

              pyodbc has 0 bugs and 0 code smells.

            kandi-Security Security

              pyodbc has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
              pyodbc code analysis shows 0 unresolved vulnerabilities.
              There are 0 security hotspots that need review.

            kandi-License License

              pyodbc is licensed under the MIT-0 License. This license is Permissive.
              Permissive licenses have the least restrictions, and you can use them in most projects.

            kandi-Reuse Reuse

              pyodbc releases are available to install and integrate.
              Deployable package is available in PyPI.
              Build file is available. You can build the component from source.
              Installation instructions are not available. Examples and code snippets are available.
              pyodbc saves you 5278 person hours of effort in developing the same functionality from scratch.
              It has 11081 lines of code, 1423 functions and 27 files.
              It has high code complexity. Code complexity directly impacts maintainability of the code.

            Top functions reviewed by kandi - BETA

            kandi has reviewed pyodbc and discovered the below as its top functions. This is intended to give you an instant insight into pyodbc implemented functionality, and help decide if they suit your requirements.
            • 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
            Get all kandi verified functions for this library.

            pyodbc Key Features

            No Key Features are available at this moment for pyodbc.

            pyodbc Examples and Code Snippets

            Parsing a dataframe with a JSON structure on one of the columns
            Pythondot img1Lines of Code : 4dot img1License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            query['Schedule8812']=query['JSON'].apply(lambda x: 'Schedule8812' in json.loads(x.to_string())['ReturnData'])
            
            query['Schedule8812']=query['JSON'].str.contains('Schedule8812')
            
            JSON string Replace single quote with two single quotes in Python
            Pythondot img2Lines of Code : 8dot img2License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            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
            Is there a function under pyodbc that can replace cursor.copy_expert
            Pythondot img3Lines of Code : 10dot img3License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            # upload to db
            SQL_STATEMENT = (
               f"BULK INSERT {tbl_name} "
               f"FROM '{my_file}' "
               "WITH (FORMAT='CSV');"
            )
            
            cur.execute(SQL_STATEMENT)
            conn.commit()
            
            how to get intergers from pyodbc's fetch?
            Pythondot img4Lines of Code : 3dot img4License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            rowiercount = str(rowcount)
            rowiercount.replace("(", "").replace(")", "").replace(" ", "").replace(",", ""))
            
            how to get intergers from pyodbc's fetch?
            Pythondot img5Lines of Code : 3dot img5License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            for row in weathertable:
                rowcount = row[0]
            
            What python object-type is compatible with the ms-access date/time field?
            Pythondot img6Lines of Code : 7dot img6License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            # PREPARED STATEMENT WITH QMARK
            sql = "insert into WeatherAnalisis (Time_UTC) values (?)"
            
            # EXECUTE QUERY WITH BINDED PARAM
            crsr.execute(sql, timeCET)
            cnxn.commit()
            
            pyodbc query with dates variable (get data for last week +4hours)
            Pythondot img7Lines of Code : 33dot img7License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            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']
            retrive two tables from a single query in pyoDBC
            Pythondot img8Lines of Code : 26dot img8License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            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
            How to select one variable based on another in Tkinter/SQL?
            Pythondot img9Lines of Code : 68dot img9License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            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
            copy iconCopy
            cursor.fast_executemany = True
            cursor.fast_executemany(my_insert_statement,df.values.tolist())
            
            cursor.executemany(my_insert_statement,df.values.tolist())
            

            Community Discussions

            QUESTION

            Invalid argument(s) 'fast_executemany' sent to create_engine()
            Asked 2022-Mar-24 at 14:55

            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:55

            fast_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.

            Source https://stackoverflow.com/questions/71603664

            QUESTION

            python pyodbc: Closing the cursor before conn.commit()?
            Asked 2022-Mar-08 at 16:07

            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:07

            You seem to have encountered a quirk in MySQL Connector/ODBC's handling of result sets from a stored procedure. For this example procedure:

            Source https://stackoverflow.com/questions/71392955

            QUESTION

            unable to install pyodbc using python 3.10 in windows 10
            Asked 2022-Feb-24 at 20:07

            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:38

            The 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

            Source https://stackoverflow.com/questions/69943254

            QUESTION

            How to install MS Access Driver to my docker image? Or is there any other work around this problem?
            Asked 2022-Feb-15 at 11:58

            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:

            1. 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)

            2. 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:58

            So 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 **

            Source https://stackoverflow.com/questions/70937202

            QUESTION

            Getting a warning when using a pyodbc Connection object with pandas
            Asked 2022-Feb-11 at 16:32

            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:30

            Is 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:

            Source https://stackoverflow.com/questions/71082494

            QUESTION

            AttributeError: 'SnowflakeCursor' object has no attribute 'shape'
            Asked 2022-Jan-31 at 19:47
            Is there a way to use "pd.read_sql_query" w/ Snowflake?

            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:28

            QUESTION

            PyODBC takes 6 seconds to establish a connection with Azure SQL Server
            Asked 2022-Jan-05 at 15:27

            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:51

            Could you please try to connect using the ODBC Driver 17 for SQL Server? You may find this way faster.

            Source https://stackoverflow.com/questions/70569192

            QUESTION

            Running odoo in Debugging VSCode and found error ModuleNotFoundError: No module named 'stdnum' - - -
            Asked 2021-Dec-27 at 17:01

            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:01

            After 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

            1. to solve .venv that doesn't work by deleting the .venv folder, create venv in python, and install all requirements again

            Source https://stackoverflow.com/questions/70457690

            QUESTION

            Data is not inserted MSSQL Python
            Asked 2021-Dec-22 at 10:33

            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:22

            You're missing a call to cnxn.commit() after the loops are done.

            Source https://stackoverflow.com/questions/68956885

            QUESTION

            Querying Informix table using pyodbc produces ODBC SQL type -103 is not yet supported error
            Asked 2021-Dec-16 at 08:58

            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:58

            Because 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

            Source https://stackoverflow.com/questions/70247964

            Community Discussions, Code Snippets contain sources that include Stack Exchange Network

            Vulnerabilities

            No vulnerabilities reported

            Install pyodbc

            You can install using 'pip install pyodbc' or download it from GitHub, PyPI.
            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

            For any new features, suggestions and bugs create an issue on GitHub. If you have any questions check and ask questions on community page Stack Overflow .
            Find more information at:

            Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items

            Find more libraries
            Install
          • PyPI

            pip install pyodbc

          • CLONE
          • HTTPS

            https://github.com/mkleehammer/pyodbc.git

          • CLI

            gh repo clone mkleehammer/pyodbc

          • sshUrl

            git@github.com:mkleehammer/pyodbc.git

          • Stay Updated

            Subscribe to our newsletter for trending solutions and developer bootcamps

            Agree to Sign up and Terms & Conditions

            Share this Page

            share link