On Tue, Jan 9, 2018 at 8:45 PM, Russ Wilson <
rpwi...@gmail.com> wrote:
> So i loaded and tested the mmsql dialect and it gave the same results. It
> returns a list of pyodbc.Row
>
> from sqlalchemy import Column, Integer, String
> from sqlalchemy.ext.declarative import declarative_base
> from sqlalchemy import create_engine
> from sqlalchemy import Table, Column, Integer, String, MetaData, ForeignKey
> from sqlalchemy import inspect
> from sqlalchemy.dialects import registry
>
>
> engine =
> create_engine("mssql+pyodbc://MYUSER:MYPASSWORD@IP:1433/corn?driver=FreeTDS")
> connection = engine.raw_connection()
> try:
> cursor = connection.cursor()
> cursor.execute("SELECT * FROM ADV.MYTABLE")
> results_one = cursor.fetchmany(100)
> for row in results_one:
> print(type(row))
>
> cursor.close()
> finally:
> connection.close()
When you use raw_connection(), you are stating that you would like to
use a raw DBAPI connection object, and you are no longer using the
SQLAlchemy dialect. You are using the plain pyodbc cursor directly,
which is usually not necessary unless you need to work with stored
procedures or special cursor methods.
Using SQLAlchemy normally, your code above would be:
with engine.connect() as conn:
result = conn.execute("SELECT * FROM ADV.MYTABLE")
result is then a ResultProxy object and returns RowProxy objects when
you call fetchone(), fetchmany(), and fetchall(). RowProxy then
acts like a tuple.