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

cursor.rowcount does not reset when executing the same statement a second time under Python 3.7.2 #281

Closed
koqsz opened this issue Mar 13, 2019 · 4 comments
Labels

Comments

@koqsz
Copy link

koqsz commented Mar 13, 2019

What is your version of Python? Is it 32-bit or 64-bit?
3.7.2 64 bit

What is your cx_Oracle version?
7.1.1

What OS (and version) is Python executing on?
Windows 10 / Centos 7

What is your Oracle Database version?
12.1c

I have same issue than in #193 issue, but the Python version and cx_Oracle version is newer. The cursor.rowcount value doesn't reset.

@anthony-tuininga
Copy link
Member

I just ran the original test case with cx_Oracle 7.1.2 on Python 3.7.2 and I didn't see any issues. Can you provide a test case that demonstrates the problem?

@koqsz
Copy link
Author

koqsz commented Mar 14, 2019

Sorry for the late answer.
The situation is very interesting. I have 5 csv file and I insert their content to the Oracle db. If the csv file contains 1 or more data row, the cursor.rowcount is working well, but if the csv file doesn't contain any row, the value of cursow.rawcount is equal with the latest csv file row number. In the x1.csv there is 3 col, and 2000 row. In the x2.csv there isn't any data only the column name ( skip with next command)

Sample code:

for file in os.listdir('.'):
    if fnmatch.fnmatch(file, '*x1.csv'):
        with open (file, 'r') as f:
            reader = csv.reader(f)
            next(reader)
            FLEXPARAList= list (reader)
try:
    cursor.executemany("""insert into test1 (col1, col2, col3)
    values (:1, :2, :3)""",FLEXPARAList)
except  cx_Oracle.DatabaseError as err:
    errorObj, = err.args
    logger.info ("The error is: '%s' in the test1 table", errorObj.message)
    size = len(errorObj.message)
    if size > 0 :
        error_number = error_number + 1
logger.info ("'%s' row inserted in the test1 table", cursor.rowcount)

// X2 csv
for file in os.listdir('.'):
    if fnmatch.fnmatch(file, '*x2.csv'):
        with open (file, 'r') as f:
            reader = csv.reader(f)
            next(reader)
            LAPARAMList= list (reader)
try:
    cursor.executemany("""insert into test2 (col1,col2, col3, col4)
    values (:1, :2, :3, :4)""",LAPARAMList)
except  cx_Oracle.DatabaseError as err:
    errorObj, = err.args
    logger.info ("The error is: '%s' in the test2 table", errorObj.message)
    size = len(errorObj.message)
    if size > 0 :
        error_number = error_number + 1
logger.info ("'%s' row inserted in the test2 table", cursor.rowcount)

@anthony-tuininga
Copy link
Member

anthony-tuininga commented Mar 14, 2019

That would be expected. If you call cursor.executemany() with 0 rows you will get an error. In that case, the original row count from the last successful execute() or executemany() is retained. I would suggest modifying your code to check for zero rows and if that condition is met, simply don't call executemany() in that case!

@anthony-tuininga
Copy link
Member

Closing due to lack of activity

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

No branches or pull requests

2 participants