Rust client library: Unexpected `Token(Some("1"))` when querying data
emilpriver opened this issue Β· comments
Emil Priver commented
Hey π I don't know if this is me doing wrong but I get a weird error when I am quering data using libsql client.
I am using libsql-rs
version 0.4.0
the error
near VARIABLE, "Token(Some("1"))": syntax error
Setting up client connection
This is how I setup connection
let db = if !db_url.starts_with("./") {
let auth_token = if let Some(t) = token {
t
} else {
info!("Token is not set, using empty string");
"".to_string()
};
Builder::new_remote(db_url.to_owned(), auth_token)
.build()
.await
.unwrap()
} else {
Builder::new_local(db_url).build().await.unwrap()
};
let client = db.connect()?;
The code executing the query
self.db
.execute(
"CREATE TABLE IF NOT EXISTS ?1 (id VARCHAR(255) NOT NULL PRIMARY KEY);",
params!["schema_migrations"],
)
.await?;
self.db is the Connection
type which comes from the let client
What worked
Replacing
self.db
.execute(
"CREATE TABLE IF NOT EXISTS ?1 (id VARCHAR(255) NOT NULL PRIMARY KEY);",
params!["schema_migrations"],
)
.await?;
with
self.db
.execute(
format!(
"CREATE TABLE IF NOT EXISTS {} (id VARCHAR(255) NOT NULL PRIMARY KEY);",
self.migrations_table
)
.as_str(),
params![],
)
.await?;
aka we're instead of using params using format!(). I don't think this is long-term as I think params![] also do query escpaing right?
Emil Priver commented
Please let me know if you need more code. I happily share more