Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mssql query works for sqlalchemy but not for records #193

Open
dangets opened this issue May 18, 2020 · 1 comment
Open

mssql query works for sqlalchemy but not for records #193

dangets opened this issue May 18, 2020 · 1 comment

Comments

@dangets
Copy link

dangets commented May 18, 2020

I am having the same issue as in this SO question. https://stackoverflow.com/questions/56622256/connection-string-and-query-works-for-sqlalchemy-but-not-records

def main():
    server = 'MyServer'
    database = 'MyDatabase'

    connection_string = f"DRIVER={{ODBC Driver 17 for SQL Server}};SERVER={server};DATABASE={database};Trusted_Connection=yes"
    connection_string = "mssql+pyodbc:///?odbc_connect=" + urllib.parse.quote(connection_string)

    engine = sqlalchemy.create_engine(connection_string)
    conn = engine.connect()
    rows = conn.execute("select @@version").fetchall()
    print(rows)
    conn.close()

    db = records.Database(connection_string)
    rows = db.query("select @@version")
    for r in rows:
        print(r)
    db.close()

Output for sqlalchemy:

[('Microsoft SQL Server 2014 (SP3-CU4) (KB4500181) - 12.0.6329.1 (X64) \n\tJul 20 2019 21:42:29 \n\tCopyright (c) Microsoft Corporation\n\tEnterprise Edition: Core-based Licensing (64-bit) on Windows NT 6.3 <X64> (Build 9600: )\n',)]

Output for records:

Traceback (most recent call last):
  File "/home/ARBFUND/dangets/python-venvs/venv3.8/lib/python3.8/site-packages/sqlalchemy/engine/result.py", line 1336, in fetchone
    row = self._fetchone_impl()
  File "/home/ARBFUND/dangets/python-venvs/venv3.8/lib/python3.8/site-packages/sqlalchemy/engine/result.py", line 1215, in _fetchone_impl
    return self.cursor.fetchone()
pyodbc.Error: ('HY010', '[HY010] [unixODBC][Driver Manager]Function sequence error (0) (SQLFetch)')

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/home/ARBFUND/dangets/dev/myproject/main.py", line 31, in main
    for r in rows:
  File "/home/ARBFUND/dangets/python-venvs/venv3.8/lib/python3.8/site-packages/records.py", line 126, in __iter__
    yield next(self)
  File "/home/ARBFUND/dangets/python-venvs/venv3.8/lib/python3.8/site-packages/records.py", line 136, in __next__
    nextrow = next(self._rows)
  File "/home/ARBFUND/dangets/python-venvs/venv3.8/lib/python3.8/site-packages/records.py", line 365, in <genexpr>
    row_gen = (Record(cursor.keys(), row) for row in cursor)
  File "/home/ARBFUND/dangets/python-venvs/venv3.8/lib/python3.8/site-packages/sqlalchemy/engine/result.py", line 1010, in __iter__
    row = self.fetchone()
  File "/home/ARBFUND/dangets/python-venvs/venv3.8/lib/python3.8/site-packages/sqlalchemy/engine/result.py", line 1343, in fetchone
    self.connection._handle_dbapi_exception(
  File "/home/ARBFUND/dangets/python-venvs/venv3.8/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1517, in _handle_dbapi_exception
    util.raise_(
  File "/home/ARBFUND/dangets/python-venvs/venv3.8/lib/python3.8/site-packages/sqlalchemy/util/compat.py", line 178, in raise_
    raise exception
  File "/home/ARBFUND/dangets/python-venvs/venv3.8/lib/python3.8/site-packages/sqlalchemy/engine/result.py", line 1336, in fetchone
    row = self._fetchone_impl()
  File "/home/ARBFUND/dangets/python-venvs/venv3.8/lib/python3.8/site-packages/sqlalchemy/engine/result.py", line 1215, in _fetchone_impl
    return self.cursor.fetchone()
sqlalchemy.exc.DBAPIError: (pyodbc.Error) ('HY010', '[HY010] [unixODBC][Driver Manager]Function sequence error (0) (SQLFetch)')
(Background on this error at: http://sqlalche.me/e/dbapi)
@geographika
Copy link

It seems as though the fetchall parameter is required, although I am unsure if this is by design or not.
https://stackoverflow.com/a/62301364/179520

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants