-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Open
Labels
bugbug:dbInvolves a bug in the database serverInvolves a bug in the database serverdb:mysqlRelated to MySQLRelated to MySQL
Description
Problem
I'm using sqlx version 0.5.9 with MariaDB 10.5 to test the support of RETURNING syntax on SQLx. Found something unusual... I can get value with column index (row.get::<i32, _>(0)), but not column name (row.get::<i32, _>("id")).
Is this the intended behaviour or it's a bug? Thanks!!
Source Code
use sqlx::{mysql::*, *};
#[async_std::main]
async fn main() -> Result<()> {
let pool = MySqlPoolOptions::new()
.max_connections(5)
.connect("mysql://root:root@localhost/returning_tests")
.await?;
let mut query = sqlx::query("INSERT INTO `bakery` (`name`, `profit_margin`) VALUES (?, ?) RETURNING `id`, `name`, `profit_margin`");
query = query.bind("Bakery Shop");
query = query.bind(0.5);
let row = query.fetch_one(&pool).await?;
println!("{:#?}", row);
// Working...
row.get::<i32, _>(0);
row.get::<String, _>(1);
row.get::<f64, _>(2);
// Not Working... panicked at 'called `Result::unwrap()` on an `Err` value: ColumnNotFound("id")
row.get::<i32, _>("id");
row.get::<String, _>("name");
row.get::<f64, _>("profit_margin");
Ok(())
}Full Log
MySqlRow {
row: Row {
storage: b"\0\x0c\0\0\0\x0bBakery Shop\0\0\0\0\0\0\xe0?",
values: [
Some(
1..5,
),
Some(
6..17,
),
Some(
17..25,
),
],
},
format: Binary,
columns: [
MySqlColumn {
ordinal: 0,
name: id,
type_info: MySqlTypeInfo {
type: Long,
flags: NOT_NULL | PRIMARY_KEY | AUTO_INCREMENT,
char_set: 63,
max_size: Some(
11,
),
},
flags: Some(
NOT_NULL | PRIMARY_KEY | AUTO_INCREMENT,
),
},
MySqlColumn {
ordinal: 1,
name: name,
type_info: MySqlTypeInfo {
type: VarString,
flags: NOT_NULL | NO_DEFAULT_VALUE,
char_set: 224,
max_size: Some(
1020,
),
},
flags: Some(
NOT_NULL | NO_DEFAULT_VALUE,
),
},
MySqlColumn {
ordinal: 2,
name: profit_margin,
type_info: MySqlTypeInfo {
type: Double,
flags: NOT_NULL | NO_DEFAULT_VALUE,
char_set: 63,
max_size: Some(
22,
),
},
flags: Some(
NOT_NULL | NO_DEFAULT_VALUE,
),
},
],
column_names: {},
}
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: ColumnNotFound("id")', /Users/billy/.cargo/registry/src/github.com-1ecc6299db9ec823/sqlx-core-0.5.9/src/row.rs:73:37
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
tgross35yyykt and tgross35
Metadata
Metadata
Assignees
Labels
bugbug:dbInvolves a bug in the database serverInvolves a bug in the database serverdb:mysqlRelated to MySQLRelated to MySQL