Skip to content

Commit

Permalink
Merge pull request #570 from tursodatabase/sqldrandomrowid
Browse files Browse the repository at this point in the history
vendored/sqlite3-parser: support RANDOM ROWID
  • Loading branch information
LucioFranco committed Nov 7, 2023
2 parents f436d7b + 392f205 commit 3ef74dc
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
22 changes: 22 additions & 0 deletions libsql-server/tests/standalone/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,3 +201,25 @@ fn execute_transaction() {

sim.run().unwrap();
}

#[test]
fn random_rowid() {
let mut sim = turmoil::Builder::new().build();

sim.host("primary", make_standalone_server);

sim.client("test", async {
let db = Database::open_remote_with_connector("http://primary:8080", "", TurmoilConnector)?;
let conn = db.connect()?;

conn.execute(
"CREATE TABLE shopping_list(item text, quantity int) RANDOM ROWID",
(),
)
.await?;

Ok(())
});

sim.run().unwrap();
}
4 changes: 4 additions & 0 deletions vendored/sqlite3-parser/src/parser/ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2038,6 +2038,9 @@ impl ToTokens for CreateTableBody {
if options.contains(TableOptions::WITHOUT_ROWID) {
s.append(TK_WITHOUT, None)?;
s.append(TK_ID, Some("ROWID"))?;
} else if options.contains(TableOptions::RANDOM_ROWID) {
s.append(TK_ID, Some("RANDOM"))?;
s.append(TK_ID, Some("ROWID"))?;
}
if options.contains(TableOptions::STRICT) {
s.append(TK_ID, Some("STRICT"))?;
Expand Down Expand Up @@ -2327,6 +2330,7 @@ bitflags::bitflags! {
const NONE = 0;
const WITHOUT_ROWID = 1;
const STRICT = 2;
const RANDOM_ROWID = 3;
}
}

Expand Down
9 changes: 9 additions & 0 deletions vendored/sqlite3-parser/src/parser/parse.y
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,15 @@ table_option(A) ::= WITHOUT nm(X). {
self.ctx.sqlite3_error_msg(&msg);
}
}
table_option(A) ::= nm(X) nm(Y). {
if "random".eq_ignore_ascii_case(&X.0) && "rowid".eq_ignore_ascii_case(&Y.0) {
A = TableOptions::RANDOM_ROWID;
}else{
A = TableOptions::NONE;
let msg = format!("unknown table option: {} {}", &X, &Y);
self.ctx.sqlite3_error_msg(&msg);
}
}
table_option(A) ::= nm(X). {
if "strict".eq_ignore_ascii_case(&X.0) {
A = TableOptions::STRICT;
Expand Down

0 comments on commit 3ef74dc

Please sign in to comment.