Skip to content

Commit e758463

Browse files
authored
Only call query on statements that returns rows (#93)
Fixes #92.
2 parents 91c60bd + d5d46a7 commit e758463

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/lib.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -581,15 +581,19 @@ 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)?;
590+
cursor.rows.replace(None);
590591
}
592+
593+
let mut rowcount = cursor.rowcount.borrow_mut();
594+
*rowcount += cursor.conn.borrow().as_ref().unwrap().changes() as i64;
595+
591596
cursor.stmt.replace(Some(stmt));
592-
cursor.rows.replace(Some(rows));
593597
Ok(())
594598
}
595599

0 commit comments

Comments
 (0)