Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "sql-parse"
version = "0.24.0"
version = "0.25.0"
edition = "2021"
authors = ["Jakob Truelsen <antialize@gmail.com>"]
keywords = [ "mysql", "postgresql", "sql", "lexer", "parser" ]
Expand Down
2 changes: 1 addition & 1 deletion src/alter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -757,7 +757,7 @@ fn parse_alter_table<'a>(
Token::Ident(_, Keyword::DEFAULT) => {
let drop_default_span = parser.consume().join_span(&set_span);
AlterColumnAction::DropDefault {
drop_default_span: drop_default_span,
drop_default_span,
}
}
Token::Ident(_, Keyword::NOT) => {
Expand Down
2 changes: 1 addition & 1 deletion src/lexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ impl<'a> Lexer<'a> {
}
// Data ends at EOF without NL '\' '.' [NL].
let span = start..self.src.len();
return (self.s(span.clone()), span);
(self.s(span.clone()), span)
}

pub fn next_token(&mut self) -> (Token<'a>, Span) {
Expand Down
17 changes: 1 addition & 16 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use alloc::{borrow::Cow, fmt::Write, format, string::String, vec::Vec};
use alloc::{borrow::Cow, format, string::String, vec::Vec};

use crate::{
issue::{IssueHandle, Issues},
Expand Down Expand Up @@ -75,21 +75,6 @@ pub(crate) fn decode_double_quoted_string(s: &str) -> Cow<'_, str> {
}
}

pub(crate) struct SingleQuotedString<'a>(pub(crate) &'a str);

impl<'a> alloc::fmt::Display for SingleQuotedString<'a> {
fn fmt(&self, f: &mut alloc::fmt::Formatter<'_>) -> alloc::fmt::Result {
f.write_char('\'')?;
for c in self.0.chars() {
if c == '\'' {
f.write_char('\'')?;
}
f.write_char(c)?;
}
f.write_char('\'')
}
}

impl<'a, 'b> Parser<'a, 'b> {
pub(crate) fn new(src: &'a str, issues: &'b mut Issues<'a>, options: &'b ParseOptions) -> Self {
let mut lexer = Lexer::new(src);
Expand Down
3 changes: 1 addition & 2 deletions src/span.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ use alloc::{boxed::Box, vec::Vec};
pub type Span = core::ops::Range<usize>;

/// Compute an optional byte span of an ast fragment

pub trait OptSpanned {
/// Compute an optional byte span of an ast fragment
fn opt_span(&self) -> Option<Span>;
Expand Down Expand Up @@ -123,7 +122,7 @@ impl<S: Spanned> Spanned for (bool, S) {
}
}

impl<'a, S: Spanned> Spanned for (&'a str, S) {
impl<S: Spanned> Spanned for (& str, S) {
fn span(&self) -> Span {
self.1.span()
}
Expand Down
1 change: 1 addition & 0 deletions src/statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,7 @@ fn parse_signal<'a>(parser: &mut Parser<'a, '_>) -> Result<Signal<'a>, ParseErro
}

/// SQL statement
#[allow(clippy::large_enum_variant)]
#[derive(Clone, Debug)]
pub enum Statement<'a> {
CreateIndex(CreateIndex<'a>),
Expand Down
24 changes: 22 additions & 2 deletions src/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ use crate::{
keywords::Keyword,
lexer::Token,
parser::{ParseError, Parser},
select::{parse_table_reference, TableReference},
select::{parse_select_expr, parse_table_reference, TableReference},
span::OptSpanned,
Identifier, Span, Spanned,
Identifier, SelectExpr, Span, Spanned,
};

/// Flags specified after "UPDATE"
Expand Down Expand Up @@ -71,6 +71,8 @@ pub struct Update<'a> {
pub set: Vec<(Vec<Identifier<'a>>, Expression<'a>)>,
/// Where expression and span of "WHERE" if specified
pub where_: Option<(Expression<'a>, Span)>,
/// Span of "RETURNING" and select expressions after "RETURNING", if "RETURNING" is present
pub returning: Option<(Span, Vec<SelectExpr<'a>>)>,
}

impl<'a> Spanned for Update<'a> {
Expand All @@ -86,6 +88,7 @@ impl<'a> Spanned for Update<'a> {
.join_span(&self.set_span)
.join_span(&set_span)
.join_span(&self.where_)
.join_span(&self.returning)
}
}

Expand Down Expand Up @@ -134,13 +137,30 @@ pub(crate) fn parse_update<'a>(parser: &mut Parser<'a, '_>) -> Result<Update<'a>
None
};

let returning = if let Some(returning_span) = parser.skip_keyword(Keyword::RETURNING) {
let mut returning_exprs = Vec::new();
loop {
returning_exprs.push(parse_select_expr(parser)?);
if parser.skip_token(Token::Comma).is_none() {
break;
}
}
if !parser.options.dialect.is_postgresql() {
parser.err("Only support by postgesql", &returning_span);
}
Some((returning_span, returning_exprs))
} else {
None
};

Ok(Update {
flags,
update_span,
tables,
set_span,
set,
where_,
returning,
})
}

Expand Down