Skip to content

Commit

Permalink
Support single quoted string in INSERT query (#145)
Browse files Browse the repository at this point in the history
Single quoted string is now supported in INSERT.
INSERT INTO Foo VALUES ("hello", 'world');
  • Loading branch information
KyGost committed Feb 27, 2021
1 parent 96d27b0 commit ca757c5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
3 changes: 3 additions & 0 deletions src/data/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,9 @@ impl Value {
(DataType::Boolean, AstValue::Boolean(v)) => {
Ok(nullable.into_value(Value::OptBool(Some(*v)), Value::Bool(*v)))
}
(DataType::Text, AstValue::SingleQuotedString(v)) => {
Ok(nullable.into_value(Value::OptStr(Some(v.clone())), Value::Str(v.clone())))
}
(DataType::Int, AstValue::Null) => nullable.as_result(
Value::OptI64(None),
ValueError::NullValueOnNotNullField.into(),
Expand Down
9 changes: 6 additions & 3 deletions src/tests/sql_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@ test_case!(sql_types, async move {
(id, content, verified, ratio)
VALUES
( 1, \"Hello\", True, 0.1),
( 1, \"World\", False, 0.9);
( 1, \"World\", False, 0.9),
( 1, 'test', False, 0.0);
"
);

let test_sqls = [
(2, "SELECT * FROM Item;"),
(3, "SELECT * FROM Item;"),
(1, "SELECT * FROM Item WHERE verified = True;"),
(1, "SELECT * FROM Item WHERE ratio > 0.5;"),
(1, "SELECT * FROM Item WHERE ratio = 0.1;"),
Expand All @@ -32,8 +33,10 @@ test_case!(sql_types, async move {
),
(0, "SELECT * FROM Item WHERE content=\"World\";"),
(1, "SELECT * FROM Item WHERE content=\"Foo\";"),
(1, "SELECT * FROM Item WHERE content='Foo';"),
(1, "UPDATE Item SET id = 11 WHERE content=\"Foo\";"),
(2, "SELECT * FROM Item;"),
(1, "UPDATE Item SET id = 14 WHERE content='Foo';"),
(3, "SELECT * FROM Item;"),
];

for (num, sql) in test_sqls.iter() {
Expand Down

0 comments on commit ca757c5

Please sign in to comment.