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

row_count* keywords doesn't work #24

Closed
poliarush opened this issue Aug 9, 2013 · 6 comments
Closed

row_count* keywords doesn't work #24

poliarush opened this issue Aug 9, 2013 · 6 comments

Comments

@poliarush
Copy link

i'm using DatabaseLibrary to connect to oracle thru cx_Oracle

${results} Row Count select * from dual
Row Count Is Equal To X select * from dual 1

and it's always returning 0 records

i've fixed query.py and added cur.fetchall() and it's working

    cur = None
    try:
        cur = self._dbconnection.cursor()
        self.__execute_sql(cur, selectStatement)
        cur.fetchall()
        rowCount = cur.rowcount
        return rowCount
    finally :
        if cur :
            self._dbconnection.rollback() 
@zmlpjuran
Copy link
Contributor

This fix is correct. From documentation:

As required by the Python DB API Spec, the rowcount attribute
“is -1 in case no executeXX() has been performed on the cursor or the rowcount of the last operation is not determinable by the interface”.
This includes SELECT statements because we cannot determine the number of rows a query produced until all rows were fetched.

You can also return size of results and don't stick with rowcount attribute:

results = cur.fetchall()
return len(results)

However, it can be very expensive for data transfer between server and client.
I prefer something like:

self.__execute_sql(cur, "select count(1) from (%)" % (selectStatement))
result = cur.fetchone()
rowCount = result[0]
return rowCount

What is your opinion?

@franz-see
Copy link
Collaborator

I prefer select count(1) as well. But I think doing a fetchall() prior to rowcount should be enough.

franz-see added a commit that referenced this issue Nov 20, 2013
…() function prior to invocation of #rowcount() as suggested by polusok.
@zmlpjuran
Copy link
Contributor

Forgot to enclose sub-query in brackets, previous comment edited.

@zmlpjuran
Copy link
Contributor

No problem with fetch_all() fix. In case of required performance optimization it can be done the other way.

@jerry57
Copy link
Collaborator

jerry57 commented Dec 1, 2014

I believe this is now fixed for Oracle and SQLite. Please retest on Oracle as I don't have access to a setup right now.

@jerry57
Copy link
Collaborator

jerry57 commented Dec 9, 2014

This should now be resolved with the 0.7 release

@jerry57 jerry57 closed this as completed Dec 9, 2014
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

4 participants