On Thu, Jul 5, 2018 at 8:09 AM, Thinakar Samy <[email protected]> wrote:
> sqlalchemy+cx_Oracle sql query has an isssue. CAn you help please?
>
> ------------------ code -------
> from sqlalchemy import create_engine
> from sqlalchemy import MetaData
> from sqlalchemy import Table
> import cx_Oracle
>
> engine = create_engine('oracle+cx_oracle://user:passwd@FTSDBLAB')
> meta = MetaData()
> meta.reflect(bind=engine)
> tbl_mgr_theater = Table('mgr_table', meta, autoload=True,
> autoload_with=engine)
>
> connection = engine.connect()
> result = connection.execute(tbl_mgr_theater.select())
>
> print(result.rowcount())
> ---- code ends ---
>
> above print statement gives the following ERROR:
> --------------------------
> Traceback (most recent call last):
> File "<input>", line 1, in <module>
> TypeError: 'int' object is not callable
> Error closing cursor
> Traceback (most recent call last):
> AttributeError: 'cx_Oracle.Cursor' object has no attribute 'lastrowid'
the "rowcount" attribute is a property, so normaly you'd call it like this:
print(str(result.rowcount))
however there's no "rowcount" for a SELECT statement. As for the
"lastrowid" part, that's also an attribute that you won't have for a
SELECT statement, however I'm not sure why the code as written
produces that and I'd need to see the full traceback.
to get the number of rows for a table:
print(connection.scalar(select([func.count('*')]).select_from(tbl_mgr_theater)))
or more succinctly, count() has a helper:
print(connection.scalar(tbl_mgr_theater.count()))
>
> --
> SQLAlchemy -
> The Python SQL Toolkit and Object Relational Mapper
>
> http://www.sqlalchemy.org/
>
> To post example code, please provide an MCVE: Minimal, Complete, and
> Verifiable Example. See http://stackoverflow.com/help/mcve for a full
> description.
> ---
> You received this message because you are subscribed to the Google Groups
> "sqlalchemy" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at https://groups.google.com/group/sqlalchemy.
> For more options, visit https://groups.google.com/d/optout.
--
SQLAlchemy -
The Python SQL Toolkit and Object Relational Mapper
http://www.sqlalchemy.org/
To post example code, please provide an MCVE: Minimal, Complete, and Verifiable
Example. See http://stackoverflow.com/help/mcve for a full description.
---
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.