Commit Graph

189 Commits

Author SHA1 Message Date
Levy A.
d65fe0f978 refactor: simplification and better names 2025-06-11 14:18:41 -03:00
Levy A.
a7761e431b fix: escape string literals 2025-06-11 14:18:41 -03:00
Levy A.
15e0cab8d8 refactor+fix: precompute default values from schema 2025-06-11 14:18:39 -03:00
Levy A.
7638b0dab7 fix: use default value on empty columns added via ALTER TABLE 2025-06-11 14:18:19 -03:00
Levy A.
6945c0c09e fix+refactor: incorrect label placement
also added a `cursor_loop` helper on `ProgramBuilder` to avoid making
this mistake in the future. this is zero-cost, and will be optimized to
the same thing (hopefully).
2025-06-11 14:17:36 -03:00
Levy A.
3bc24eb86f feat: proper column definition parsing 2025-06-11 14:17:36 -03:00
Levy A.
587cf345cc refactor: merge branches 2025-06-11 14:17:36 -03:00
Levy A.
65b6984c2a fix: make sure to not modify a index 2025-06-11 14:17:36 -03:00
Levy A.
5f25ed0738 fix UNIQUE constraints 2025-06-11 14:17:36 -03:00
Levy A.
de2ac89ad2 feat: complete ALTER TABLE implementation 2025-06-11 14:17:36 -03:00
Pere Diaz Bou
9383ba207d introduce integrity_check pragma 2025-06-11 11:14:29 +02:00
Jussi Saurio
51637ccad2 Merge 'Reverse Parse Limbo ast and Plans' from Pedro Muniz
This PR implements the `ToSqlString` trait to most of the `ast` structs
and to the `SelectPlan`, `UpdatePlan`, `DeletePlan`,
`CompoundSelectPlan`.
Inside the files in the `to_sql_string` folder, I annotated many `TODOs`
with things that seem to diverge from SQLite syntax. The most egregious
by far was that Create Trigger statements do not use the standard
`delete`, `select`, `update`, and `insert` statements. The parser uses
different structs for those statements only in Create Trigger. E.g
`ast::TriggerCmdUpdate` instead of `ast::Update` and so on.
Also, as this iteration of reverse parsing is not particularly efficient
in the number of string allocations it does. I tested different methods
of achieving this by using `format!`, pushing directly to a `String`, or
just pushing to `Vec<String>` and joining all the string with a space
separator. I focused mainly on trying to get the syntax to print
correctly without major hurdles in understanding the code.
Lastly, I intend in the future to use this code in the simulator to
expand the its available syntax.

Closes #1619
2025-06-09 08:14:19 +03:00
김선우
a9c096bb01 Skip increasing n_changes for insn::Insert when it's UPDATE query 2025-06-07 17:23:23 +09:00
meteorgan
a242bac340 Fix: ensure PRAGMA cache_size changes persist only for current session 2025-06-05 16:55:41 +08:00
pedrocarlo
bfc8cb6d4c move display and to_sql_string impls to separate modules for plan 2025-06-04 12:06:43 -03:00
Jussi Saurio
ea301de726 Merge 'Pass input string to translate function' from Pedro Muniz
In preparation for `CREATE VIEW`, we need to have the original sql query
that was used to create the view. I'm using the scanner's offset to
slice into the original input, trimming the newlines, and passing it to
the translate function.

Reviewed-by: Jussi Saurio <jussi.saurio@gmail.com>

Closes #1621
2025-06-02 17:43:11 +03:00
pedrocarlo
bc563266b3 add instrumentation to more functions for debugging + adjust how cursors are opened 2025-05-30 20:35:50 -03:00
pedrocarlo
b73200de86 pass input string to translate function 2025-05-30 11:20:36 -03:00
pedrocarlo
bb7da39c72 remove assumption that translate_select is always called from a top-level context + adjust insert to use translate_select when needed 2025-05-25 19:12:30 -03:00
pedrocarlo
fd9e0db5cc pass the owned ast to translate_insert + remove assumption of a list of values in populate_columns_insert 2025-05-25 19:02:17 -03:00
pedrocarlo
15ffdd3e51 modify translate_select to return number of result columns 2025-05-25 19:02:17 -03:00
meteorgan
0467d7e11b Support values statement and values in select 2025-05-23 00:29:54 +08:00
pedrocarlo
53bf5d5ef5 adjust translate functions to take a program instead of Option<ProgramBuilder> + remove any Init emission in traslate functions + use epilogue in all places necessary 2025-05-21 16:41:10 -03:00
pedrocarlo
1c12535d9f push prologue to top-level translate function 2025-05-21 15:50:43 -03:00
pedrocarlo
8084d54c26 lift pragma statement handling as it cannot be created in a nested context 2025-05-21 14:13:28 -03:00
pedrocarlo
d21229d4a3 create inner translate function to enable calling it from a nested context 2025-05-21 14:08:02 -03:00
pedrocarlo
517c7c81cd refactor to include optional program builder argument 2025-05-21 12:47:51 -03:00
pedrocarlo
510c70e919 Create CollationSeq enum and functions. Move strum to workspace dependency to avoid version mismatch with Parser 2025-05-19 15:22:14 -03:00
PThorpe92
0593a99f0e Remove insertCtx from parameters and replace fix with expr rewriting 2025-05-13 12:49:16 -04:00
Pekka Enberg
14ef25ebb8 Merge 'Add drop index' from Anton Harniakou
This commit adds suport for DROP INDEX.
Bytecode produced by this commit differs from SQLITE's bytecode, main
reason we don't do autovacuum or repacking of pages like SQLITE does.
Closes #1280

Closes #1444
2025-05-10 08:04:39 +03:00
Levy A.
007cdb7ce0 fix: clippy 2025-05-08 09:24:58 -03:00
Levy A.
023a116b0d feat: initial implementation of ALTER TABLE
only supporting renaming tables
2025-05-08 09:24:56 -03:00
Anton Harniakou
6c8eef2fac Support DROP INDEX
This commit adds suport for DROP INDEX.
Bytecode produced by this commit differs from SQLITE's bytecode, main
reason we don't do autovacuum or repacking of pages like SQLITE does.
2025-05-04 12:13:16 +03:00
Preston Thorpe
d837f89d74 Merge branch 'main' into vtab_schema 2025-04-28 22:09:10 -04:00
PThorpe92
b0016a0ee2 Support create index with SeekEnd and IdxCreate opcode functionality 2025-04-05 11:15:36 -04:00
PThorpe92
4384659e5f Adjust vtab schema creation to display the underlying columns 2025-03-24 20:50:54 -04:00
Pekka Enberg
0ec7dbc44e core: Move translate_create_table() to schema module 2025-03-24 10:44:41 +02:00
Pekka Enberg
0727f4aca6 core: Move temporary table handling to translate_create_table() 2025-03-24 10:38:55 +02:00
Pekka Enberg
7d4ac13926 core: Move translate_drop_table() to schema module 2025-03-24 10:37:02 +02:00
PThorpe92
a0188e5163 Use bind_col_refs to rewrite the Id expressions 2025-03-23 22:18:41 -04:00
PThorpe92
676ddd4fb6 Add logic to handle overwrite cell if insert to same rowid to support update 2025-03-23 17:08:14 -04:00
Pere Diaz Bou
00ab3d1c0c Fix ordering and implement Deref 2025-03-17 10:22:42 +01:00
Pere Diaz Bou
20f5ade95e Experiment with a custom Lock for database header 2025-03-17 10:21:34 +01:00
Pekka Enberg
b0636e4494 Merge 'Adds Drop Table' from Zaid Humayun
This PR adds support for `DROP TABLE` and addresses issue
https://github.com/tursodatabase/limbo/issues/894
It depends on https://github.com/tursodatabase/limbo/pull/785 being
merged in because it requires the implementation of `free_page`.
EDIT: The PR above has been merged.
It adds the following:
* an implementation for the `DropTable` AST instruction via a method
called `translate_drop_table`
* a couple of new instructions - `Destroy` and `DropTable`. The former
is to modify physical b-tree pages and the latter is to modify in-memory
structures like the schema hash table.
* `btree_destroy` on `BTreeCursor` to walk the tree of pages for this
table and place it in free list.
* state machine traversal for both `btree_destroy` and
`clear_overflow_pages` to ensure performant, correct code.
* unit & tcl tests
* modifies the `Null` instruction to follow SQLite semantics and accept
a second register. It will set all registers in this range to null. This
is required for `DROP TABLE`.
The screenshots below have a comparison of the bytecodes generated via
SQLite & Limbo.
Limbo has the same instruction set except for the subroutines which
involve opening an ephemeral table, copying over the triggers from the
`sqlite_schema` table and then re-inserting them back into the
`sqlite_schema` table.
This is because `OpenEphemeral` is still a WIP and is being tracked at
https://github.com/tursodatabase/limbo/pull/768
![Screenshot 2025-02-09 at 7 05 03 PM](https://github.com/user-
attachments/assets/1d597001-a60c-4a76-89fd-8b90881c77c9)
![Screenshot 2025-02-09 at 7 05 35 PM](https://github.com/user-
attachments/assets/ecfd2a7a-2edc-49cd-a8d1-7b4db8657444)

Reviewed-by: Pere Diaz Bou <pere-altea@homail.com>

Closes #897
2025-03-06 18:27:41 +02:00
Pere Diaz Bou
8daf7666d1 Make database Sync + Send 2025-03-05 14:07:48 +01:00
Zaid Humayun
2f14b5ddbc fix: addresses comment https://github.com/tursodatabase/limbo/pull/897#discussion_r1975723452
renames the variable r1 to null_reg since that's the purpose anyway
2025-03-01 01:26:00 +05:30
Zaid Humayun
23a904f38d Merge branch 'main' of https://github.com/tursodatabase/limbo 2025-03-01 01:18:45 +05:30
Zaid Humayun
07efc9b902 DROP TABLE: index drop
added missing instructions to drop the indices for a table physically from btree pages in a loop
2025-02-19 21:46:26 +05:30
Zaid Humayun
34f390abc9 cleanup: removed commented code 2025-02-19 21:46:26 +05:30
Zaid Humayun
40b08c559c vdbe: modified instruction DropTable
the instruction DropTable has been modified to correctly match SQLite semantics
2025-02-19 21:46:26 +05:30