pacman82/odbc-api

how to known exec update sql get SQLRowCount.

Closed this issue · 11 comments

when I use odbc-api call conn.execute(sql, ()), but the function return cursor get None. Aactually, I expect row count result.

let sql =  r#"UPDATE "request" SET "id" = 1, "name" = 'hallo', "created_at" = '2022-08-25 00:14:05 +08:00', "updated_at" = '2022-08-25 00:14:05 +08:00' WHERE "request"."id" = 1"#;
> let res:Option<CursorImpl<StatementImpl<'_>>> = conn.execute(sql.as_str(), ())?;  

res return None.

How to get update sql get SQLRowCount with odbc-api?

With reference :https://docs.microsoft.com/en-us/sql/relational-databases/native-client-odbc-results/processing-results-odbc?view=sql-server-ver16

That use case is not supported (yet). Should be comparatively easy to implement though. In terms of API I am currently leaning towards adding a method to both the Preallocated and the Prepared query in order to retrieve the number of columns changed using the last statement.

In case you need somethig right now. Here is the prototype in unsafe code:

fn row_count_one_shot_query(profile: &Profile) {

odbc-api 0.47.0 is released with support for fetching the numbers of affected rows. Using either Preallocated::row_count or Prepared::row_count, depending on the fact if one shot or prepared queries are being used.

so great 👍

Thx.
I tested some cases with Preallocated::row_count api,

  • The actual number of items returned by insert,delete and update is no problem.
  • The execution result of create table and drop table returns -1.

The execution result of create table and drop table returns -1.

That's expected. -1 is ODBCs way of saying "row count not available". What's your thought on this, should the interface change to Option<usize>?

" should the interface change to Option"

I voted for this, if could not effect,return -1 can returnNone. Normal execution return Some(usize).

odbc-api 0.48.0 has been released and now returns an Option<usize>.

Oh,my mistake, it's okay.