Skip to content

Commit 6585718

Browse files
committed
Fixed identifier in sqlite if identifier matches a builtin
1 parent a79c915 commit 6585718

File tree

9 files changed

+15
-14
lines changed

9 files changed

+15
-14
lines changed

src/conditional.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ impl<'a> BuildCondition<'a> for Condition<'a> {
235235
#[cfg(feature = "sqlite")]
236236
DBImpl::SQLite => {
237237
if let Some(table_name) = table_name {
238-
write!(writer, "{table_name}.")?;
238+
write!(writer, "\"{table_name}\".")?;
239239
}
240240
write!(writer, "{column_name}")
241241
}

src/delete.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ impl<'until_build, 'post_query> Delete<'until_build, 'post_query>
7878
match self {
7979
#[cfg(feature = "sqlite")]
8080
DeleteImpl::SQLite(mut d) => {
81-
let mut s = format!("DELETE FROM {} ", d.model);
81+
let mut s = format!("DELETE FROM \"{}\" ", d.model);
8282

8383
if d.where_clause.is_some() {
8484
write!(

src/drop_table.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ impl DropTable for DropTableImpl<'_> {
6363
match self {
6464
#[cfg(feature = "sqlite")]
6565
DropTableImpl::SQLite(d) => format!(
66-
"DROP TABLE {}{};",
66+
"DROP TABLE \"{}\"{};",
6767
d.name,
6868
if d.if_exists { " IF EXISTS" } else { "" }
6969
),

src/insert.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ impl<'post_build> Insert<'post_build> for InsertImpl<'_, 'post_build> {
8989
// Handle case, if no columns should be inserted, aka an empty insert
9090
if d.columns.is_empty() {
9191
let mut s = format!(
92-
"INSERT {}INTO {} DEFAULT VALUES",
92+
"INSERT {}INTO \"{}\" DEFAULT VALUES",
9393
match d.on_conflict {
9494
OnConflict::ABORT => "OR ABORT ",
9595
OnConflict::ROLLBACK => "OR ROLLBACK ",
@@ -114,15 +114,15 @@ impl<'post_build> Insert<'post_build> for InsertImpl<'_, 'post_build> {
114114
}
115115

116116
let mut s = format!(
117-
"INSERT {}INTO {} (",
117+
"INSERT {}INTO \"{}\" (",
118118
match d.on_conflict {
119119
OnConflict::ABORT => "OR ABORT ",
120120
OnConflict::ROLLBACK => "OR ROLLBACK ",
121121
},
122122
d.into_clause,
123123
);
124124
for (idx, x) in d.columns.iter().enumerate() {
125-
write!(s, "{x}").unwrap();
125+
write!(s, "\"{x}\"").unwrap();
126126
if idx != d.columns.len() - 1 {
127127
write!(s, ", ").unwrap();
128128
}
@@ -133,7 +133,7 @@ impl<'post_build> Insert<'post_build> for InsertImpl<'_, 'post_build> {
133133
write!(s, "(").unwrap();
134134
for (idx_2, y) in x.iter().enumerate() {
135135
match y {
136-
Value::Ident(st) => write!(s, "{}", *st).unwrap(),
136+
Value::Ident(st) => write!(s, "\"{}\"", *st).unwrap(),
137137
Value::Choice(c) => write!(s, "{}", sqlite::fmt(c)).unwrap(),
138138
Value::Null(NullType::Choice) => write!(s, "NULL").unwrap(),
139139
_ => {

src/join_table.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ impl<'post_query> JoinTable<'post_query> for JoinTableImpl<'_, 'post_query> {
112112
#[cfg(feature = "sqlite")]
113113
JoinTableImpl::SQLite(d) => write!(
114114
s,
115-
"{} {} AS {} ON {}",
115+
"{} \"{}\" AS {} ON {}",
116116
d.join_type,
117117
d.table_name,
118118
d.join_alias,

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,7 @@ impl DBImpl {
412412
*/
413413
pub fn update<'until_build, 'post_query>(
414414
&self,
415+
415416
table_name: &'until_build str,
416417
) -> impl Update<'until_build, 'post_query>
417418
where

src/select.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ impl<'until_build, 'post_build> Select<'until_build, 'post_build>
135135
}
136136
}
137137

138-
write!(s, " FROM {}", d.from_clause).unwrap();
138+
write!(s, " FROM \"{}\"", d.from_clause).unwrap();
139139

140140
for x in d.join_tables {
141141
write!(s, " ").unwrap();

src/select_column.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,10 @@ impl SelectColumn for SelectColumnImpl<'_> {
6464
}
6565

6666
if let Some(table_name) = d.table_name {
67-
write!(s, "{table_name}.").unwrap();
67+
write!(s, "\"{table_name}\".").unwrap();
6868
}
6969

70-
write!(s, "{}", d.column_name).unwrap();
70+
write!(s, "\"{}\"", d.column_name).unwrap();
7171

7272
if d.aggregation.is_some() {
7373
write!(s, ")").unwrap();

src/update.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,11 @@ impl<'until_build, 'post_build> Update<'until_build, 'post_build>
150150
let update_index = d.updates.len() - 1;
151151
for (idx, (name, value)) in d.updates.into_iter().enumerate() {
152152
if let Value::Choice(c) = value {
153-
write!(s, "{name} = {}", sqlite::fmt(c)).unwrap();
153+
write!(s, "\"{name}\" = {}", sqlite::fmt(c)).unwrap();
154154
} else if let Value::Null(NullType::Choice) = value {
155-
write!(s, "{name} = NULL").unwrap();
155+
write!(s, "\"{name}\" = NULL").unwrap();
156156
} else {
157-
write!(s, "{name} = ?").unwrap();
157+
write!(s, "\"{name}\" = ?").unwrap();
158158
d.lookup.push(value);
159159
}
160160
if idx != update_index {

0 commit comments

Comments
 (0)