a month ago
Hi, I don't know why the `executemany()` calls of Python hdbcli library returns -2 rather than 0.
cursor.execute("CREATE TABLE PERSON ( ID INTEGER, NAME NVARCHAR(50), AGE INTEGER, CITY NVARCHAR(50), PRIMARY KEY (ID, NAME) )")
print("INSERT ===")
ret_count = cursor.executemany("INSERT INTO PERSON VALUES (?, ?, ?, ?)", [[1, 'Jack', 15, 'SF']])
print(ret_count)
print("UPDATE ===")
ret_count = cursor.executemany("UPDATE PERSON SET AGE = 25 WHERE NAME = ? AND ID = ?", [['Jack', 1]]) # ok
print(ret_count)
ret_count = cursor.executemany("UPDATE PERSON SET AGE = 25 WHERE NAME = ? AND ID = ?", [['Jack', 2]]) # partial match
print(ret_count)
ret_count = cursor.executemany("UPDATE PERSON SET AGE = 25 WHERE NAME = ? AND ID = ?", [['Anna', 3]]) # none of them
print(ret_count)
print("DELETE ===")
ret_count = cursor.executemany("DELETE FROM PERSON WHERE ID = ? AND NAME = ?", [[1, 'Anna']]) # partial match
print(ret_count)
ret_count = cursor.executemany("DELETE FROM PERSON WHERE ID = ? AND NAME = ?", [[1, 'Jack']]) # ok
print(ret_count)
ret_count = cursor.executemany("DELETE FROM PERSON WHERE ID = ? AND NAME = ?", [[1, 'Jack']]) # none of them
It's output is,
INSERT ===
(1,)
UPDATE ===
(1,)
(-2,)
(-2,)
DELETE ===
(-2,)
(1,)
(-2,)
I did in the latest version, hdbcli==2.20.15. Could you explain the reason? Thank you!
One option may be to use the code below:
ret_count = cursor.executemany("DELETE FROM PERSON WHERE ID = ? AND NAME = ?", [[1, 'Jack']], batcherrors=True) # ok
print(cursor.getrowsaffectedcounts())
See also getrowsaffectedcounts() Method.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
82 | |
11 | |
10 | |
8 | |
6 | |
6 | |
6 | |
6 | |
5 | |
5 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.