Skip to content

Commit a02a592

Browse files
committed
fix: only call query on statements that return rows
1 parent 08b59be commit a02a592

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/lib.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -581,15 +581,18 @@ async fn execute(cursor: &Cursor, sql: String, parameters: Option<&PyTuple>) ->
581581
.prepare(&sql)
582582
.await
583583
.map_err(to_py_err)?;
584-
let rows = stmt.query(params).await.map_err(to_py_err)?;
585-
if stmt_is_dml {
586-
let mut rowcount = cursor.rowcount.borrow_mut();
587-
*rowcount += cursor.conn.borrow().as_ref().unwrap().changes() as i64;
584+
585+
if stmt.columns().iter().len() > 0 {
586+
let rows = stmt.query(params).await.map_err(to_py_err)?;
587+
cursor.rows.replace(Some(rows));
588588
} else {
589-
cursor.rowcount.replace(-1);
589+
stmt.execute(params).await.map_err(to_py_err)?;
590590
}
591+
592+
let mut rowcount = cursor.rowcount.borrow_mut();
593+
*rowcount += cursor.conn.borrow().as_ref().unwrap().changes() as i64;
594+
591595
cursor.stmt.replace(Some(stmt));
592-
cursor.rows.replace(Some(rows));
593596
Ok(())
594597
}
595598

0 commit comments

Comments
 (0)