Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SqlInputError { error: Error { code: Unknown, extended_code: 1 }, msg: "unrecognized token: \"{\"" #1452

Closed
ArunGust opened this issue Feb 15, 2024 · 1 comment
Labels

Comments

@ArunGust
Copy link

I am not able to execute JSON object insert . Create table is working though

Here is my code
let createtableddl = format!("CREATE TABLE {} (id INTEGER PRIMARY KEY, data JSON)",tabel_name);
println!("json_query parsed.len() {:?} ", parsed.len());
let mut conn = Connection::open_in_memory()?;
match conn.execute(&createtableddl,(),).unwrap();
let insertddl_columns = r#"INSERT INTO users (id, data) VALUES (1, json_encode({"name": "Alice","age": 25,"email": "alice@example.com"}));"#;
conn.execute(&insertddl_columns,[]).unwrap();

Here the error
SqlInputError { error: Error { code: Unknown, extended_code: 1 }, msg: "unrecognized token: "{"", sql: "INSERT INTO users (id, data) VALUES (1, json_encode({"name": "Alice","age": 25,"email": "alice@example.com"}));", offset: 52 }

@gwenn
Copy link
Collaborator

gwenn commented Feb 15, 2024

Not related to rusqlite:

sqlite>
sqlite> CREATE TABLE users (id INTEGER PRIMARY KEY, data JSON);
sqlite> INSERT INTO users (id, data) VALUES (1, json_encode({"name": "Alice","age": 25,"email": "alice@example.com"}));
Parse error: unrecognized token: "{"
  SERT INTO users (id, data) VALUES (1, json_encode({"name": "Alice","age": 25,"
                                      error here ---^
sqlite>

@gwenn gwenn added the invalid label Feb 15, 2024
@gwenn gwenn closed this as completed Feb 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants