sqlx_sqlite/statement/
mod.rs1use crate::column::ColumnIndex;
2use crate::error::Error;
3use crate::ext::ustr::UStr;
4use crate::{Sqlite, SqliteArguments, SqliteColumn, SqliteTypeInfo};
5use sqlx_core::{Either, HashMap};
6use std::borrow::Cow;
7use std::sync::Arc;
8
9pub(crate) use sqlx_core::statement::*;
10
11mod handle;
12pub(super) mod unlock_notify;
13mod r#virtual;
14
15pub(crate) use handle::StatementHandle;
16pub(crate) use r#virtual::VirtualStatement;
17
18#[derive(Debug, Clone)]
19#[allow(clippy::rc_buffer)]
20pub struct SqliteStatement<'q> {
21 pub(crate) sql: Cow<'q, str>,
22 pub(crate) parameters: usize,
23 pub(crate) columns: Arc<Vec<SqliteColumn>>,
24 pub(crate) column_names: Arc<HashMap<UStr, usize>>,
25}
26
27impl<'q> Statement<'q> for SqliteStatement<'q> {
28 type Database = Sqlite;
29
30 fn to_owned(&self) -> SqliteStatement<'static> {
31 SqliteStatement::<'static> {
32 sql: Cow::Owned(self.sql.clone().into_owned()),
33 parameters: self.parameters,
34 columns: Arc::clone(&self.columns),
35 column_names: Arc::clone(&self.column_names),
36 }
37 }
38
39 fn sql(&self) -> &str {
40 &self.sql
41 }
42
43 fn parameters(&self) -> Option<Either<&[SqliteTypeInfo], usize>> {
44 Some(Either::Right(self.parameters))
45 }
46
47 fn columns(&self) -> &[SqliteColumn] {
48 &self.columns
49 }
50
51 impl_statement_query!(SqliteArguments<'_>);
52}
53
54impl ColumnIndex<SqliteStatement<'_>> for &'_ str {
55 fn index(&self, statement: &SqliteStatement<'_>) -> Result<usize, Error> {
56 statement
57 .column_names
58 .get(*self)
59 .ok_or_else(|| Error::ColumnNotFound((*self).into()))
60 .copied()
61 }
62}
63
64