Skip to content

Commit a21c637

Browse files
committed
fmt
1 parent a590b35 commit a21c637

File tree

2 files changed

+65
-39
lines changed

2 files changed

+65
-39
lines changed

sqlx-core/src/odbc/connection/worker.rs

Lines changed: 65 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -127,48 +127,73 @@ impl ConnectionWorker {
127127
}
128128
Command::Execute { sql, tx } => {
129129
// Helper closure to process using a given connection reference
130-
let process = |conn: &odbc_api::Connection<'static>| {
131-
match conn.execute(&sql, (), None) {
132-
Ok(Some(mut cursor)) => {
133-
use odbc_api::ResultSetMetadata;
134-
let mut columns: Vec<OdbcColumn> = Vec::new();
135-
if let Ok(count) = cursor.num_result_cols() {
136-
for i in 1..=count {
137-
let mut cd = odbc_api::ColumnDescription::default();
138-
let _ = cursor.describe_col(i as u16, &mut cd);
139-
let name = String::from_utf8(cd.name)
140-
.unwrap_or_else(|_| format!("col{}", i - 1));
141-
columns.push(OdbcColumn {
142-
name,
143-
type_info: OdbcTypeInfo { name: format!("{:?}", cd.data_type), is_null: false },
144-
ordinal: (i - 1) as usize,
145-
});
146-
}
130+
let process = |conn: &odbc_api::Connection<'static>| match conn.execute(
131+
&sql,
132+
(),
133+
None,
134+
) {
135+
Ok(Some(mut cursor)) => {
136+
use odbc_api::ResultSetMetadata;
137+
let mut columns: Vec<OdbcColumn> = Vec::new();
138+
if let Ok(count) = cursor.num_result_cols() {
139+
for i in 1..=count {
140+
let mut cd = odbc_api::ColumnDescription::default();
141+
let _ = cursor.describe_col(i as u16, &mut cd);
142+
let name = String::from_utf8(cd.name)
143+
.unwrap_or_else(|_| format!("col{}", i - 1));
144+
columns.push(OdbcColumn {
145+
name,
146+
type_info: OdbcTypeInfo {
147+
name: format!("{:?}", cd.data_type),
148+
is_null: false,
149+
},
150+
ordinal: (i - 1) as usize,
151+
});
147152
}
153+
}
148154

149-
while let Ok(Some(mut row)) = cursor.next_row() {
150-
let mut values: Vec<(OdbcTypeInfo, Option<Vec<u8>>)> = Vec::with_capacity(columns.len());
151-
for i in 1..=columns.len() {
152-
let mut buf = Vec::new();
153-
match row.get_text(i as u16, &mut buf) {
154-
Ok(true) => values.push((OdbcTypeInfo { name: "TEXT".into(), is_null: false }, Some(buf))),
155-
Ok(false) => values.push((OdbcTypeInfo { name: "TEXT".into(), is_null: true }, None)),
156-
Err(e) => {
157-
let _ = tx.send(Err(Error::from(e)));
158-
return;
159-
}
155+
while let Ok(Some(mut row)) = cursor.next_row() {
156+
let mut values: Vec<(OdbcTypeInfo, Option<Vec<u8>>)> =
157+
Vec::with_capacity(columns.len());
158+
for i in 1..=columns.len() {
159+
let mut buf = Vec::new();
160+
match row.get_text(i as u16, &mut buf) {
161+
Ok(true) => values.push((
162+
OdbcTypeInfo {
163+
name: "TEXT".into(),
164+
is_null: false,
165+
},
166+
Some(buf),
167+
)),
168+
Ok(false) => values.push((
169+
OdbcTypeInfo {
170+
name: "TEXT".into(),
171+
is_null: true,
172+
},
173+
None,
174+
)),
175+
Err(e) => {
176+
let _ = tx.send(Err(Error::from(e)));
177+
return;
160178
}
161179
}
162-
let _ = tx.send(Ok(Either::Right(OdbcRow { columns: columns.clone(), values })));
163180
}
164-
let _ = tx.send(Ok(Either::Left(OdbcQueryResult { rows_affected: 0 })));
165-
}
166-
Ok(None) => {
167-
let _ = tx.send(Ok(Either::Left(OdbcQueryResult { rows_affected: 0 })));
168-
}
169-
Err(e) => {
170-
let _ = tx.send(Err(Error::from(e)));
181+
let _ = tx.send(Ok(Either::Right(OdbcRow {
182+
columns: columns.clone(),
183+
values,
184+
})));
171185
}
186+
let _ = tx.send(Ok(Either::Left(OdbcQueryResult {
187+
rows_affected: 0,
188+
})));
189+
}
190+
Ok(None) => {
191+
let _ = tx.send(Ok(Either::Left(OdbcQueryResult {
192+
rows_affected: 0,
193+
})));
194+
}
195+
Err(e) => {
196+
let _ = tx.send(Err(Error::from(e)));
172197
}
173198
};
174199

@@ -240,7 +265,10 @@ impl ConnectionWorker {
240265
) -> Result<flume::Receiver<Result<Either<OdbcQueryResult, OdbcRow>, Error>>, Error> {
241266
let (tx, rx) = flume::bounded(64);
242267
self.command_tx
243-
.send_async(Command::Execute { sql: sql.into(), tx })
268+
.send_async(Command::Execute {
269+
sql: sql.into(),
270+
tx,
271+
})
244272
.await
245273
.map_err(|_| Error::WorkerCrashed)?;
246274
Ok(rx)

tests/odbc/odbc.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,3 @@ async fn it_can_work_with_transactions() -> anyhow::Result<()> {
1717
tx.rollback().await?;
1818
Ok(())
1919
}
20-
21-

0 commit comments

Comments
 (0)