Skip to main content

sqlx_core_oldapi/odbc/connection/
executor.rs

1use crate::describe::Describe;
2use crate::error::Error;
3use crate::executor::{Execute, Executor};
4use crate::odbc::{Odbc, OdbcConnection, OdbcQueryResult, OdbcRow, OdbcStatement, OdbcTypeInfo};
5use either::Either;
6use futures_core::future::BoxFuture;
7use futures_core::stream::BoxStream;
8use futures_util::TryStreamExt;
9
10impl<'c> Executor<'c> for &'c mut OdbcConnection {
11    type Database = Odbc;
12
13    fn fetch_many<'e, 'q: 'e, E>(
14        self,
15        mut query: E,
16    ) -> BoxStream<'e, Result<Either<OdbcQueryResult, OdbcRow>, Error>>
17    where
18        'c: 'e,
19        E: Execute<'q, Self::Database> + 'q,
20    {
21        let args = query.take_arguments();
22        Box::pin(self.execute_stream(query.sql(), args).into_stream())
23    }
24
25    fn fetch_optional<'e, 'q: 'e, E>(
26        self,
27        query: E,
28    ) -> BoxFuture<'e, Result<Option<OdbcRow>, Error>>
29    where
30        'c: 'e,
31        E: Execute<'q, Self::Database> + 'q,
32    {
33        let mut stream = self.fetch_many(query);
34
35        Box::pin(async move {
36            while let Some(step) = stream.try_next().await? {
37                if let Either::Right(row) = step {
38                    return Ok(Some(row));
39                }
40            }
41
42            Ok(None)
43        })
44    }
45
46    fn prepare_with<'e, 'q: 'e>(
47        self,
48        sql: &'q str,
49        _parameters: &'e [OdbcTypeInfo],
50    ) -> BoxFuture<'e, Result<OdbcStatement<'q>, Error>>
51    where
52        'c: 'e,
53    {
54        Box::pin(async move { self.prepare(sql).await })
55    }
56
57    #[doc(hidden)]
58    fn describe<'e, 'q: 'e>(self, sql: &'q str) -> BoxFuture<'e, Result<Describe<Odbc>, Error>>
59    where
60        'c: 'e,
61    {
62        Box::pin(async move {
63            let statement = self.describe_statement(sql).await?;
64            let nullable = vec![None; statement.metadata.columns.len()];
65
66            Ok(Describe {
67                columns: statement.metadata.columns,
68                parameters: Some(Either::Right(statement.metadata.parameters)),
69                nullable,
70            })
71        })
72    }
73}