edgarrmondragon commented on PR #5029:
URL: https://github.com/apache/arrow-adbc/pull/5029#issuecomment-6960359131

   > Let me come up with a Python MRE for that.
   
   Ok, so here it is:
   
   ```python
   # mre_deferred.py
   import os
   import sys
   import tempfile
   
   import adbc_driver_manager.dbapi as dbapi
   
   DRIVER = sys.argv[1] if len(sys.argv) > 1 else "adbc_driver_sqlite"
   path = os.path.join(tempfile.mkdtemp(), "mre.db")
   
   with (
       dbapi.connect(driver=DRIVER, db_kwargs={"uri": path}, autocommit=True) 
as writer,
       dbapi.connect(driver=DRIVER, db_kwargs={"uri": path}) as reader,
   ):
       with writer.cursor() as cur:
           cur.execute("CREATE TABLE t (id INTEGER)")
   
       # Open a read transaction (autocommit is off) so the writer can't commit
       with reader.cursor() as cur:
           cur.execute("SELECT COUNT(*) FROM t")
           print("rows before:", cur.fetchall())
   
       with writer.cursor() as cur:
           cur.adbc_statement.set_options(**{"adbc.sqlite.query.batch_rows": 
"1"})
           query = "INSERT INTO t VALUES (1), (2) RETURNING id"
           cur.execute(query)
           print("first execute:", cur.fetchone())
           # Same SQL, so the prepared statement is reused
           cur.execute(query)
           print("second execute:", cur.fetchall())
   
       reader.commit()
       with reader.cursor() as cur:
           cur.execute("SELECT COUNT(*) FROM t")
           print("rows after:", cur.fetchall())
   ```
   
   With the PR as is (and in `main`, FWIW), this fails with `OSError: database 
is locked` at the line `print("second execute:", cur.fetchall())`.
   
   If we checked the return code of `sqlite3_reset()`, an error with more 
contextual info could be returned, e.g. `adbc_driver_manager.OperationalError: 
IO: [SQLite] previous execution failed: database is locked`.
   
   I believe fixing that would be out of scope, but I can look into handling 
the return code and returning an appropriate status, and maybe adding a test 
for it since it is a user-facing change.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to