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

[RFE] Simplify working with temporary tables #53

Closed
saaj opened this issue May 18, 2021 · 0 comments
Closed

[RFE] Simplify working with temporary tables #53

saaj opened this issue May 18, 2021 · 0 comments
Labels
enhancement New feature or request
Milestone

Comments

@saaj
Copy link
Contributor

saaj commented May 18, 2021

As a user of sqliteviz,
In order to use temporary tables in my SQL scripts,
I want sqliteviz to run a script in a new connection each time.

From SQLite docs on temporary tables:

Tables created using the CREATE TEMP TABLE syntax are only visible to the database connection in which the CREATE TEMP TABLE statement is originally evaluated. These TEMP tables, together with any associated indices, triggers, and views, are collectively stored in a separate temporary database file that is created as soon as the first CREATE TEMP TABLE statement is seen. [...] The temporary database file used to store TEMP tables is deleted automatically when the database connection is closed using sqlite3_close().

Currently it looks like that all tabs operate on the same connection as you can't execute a SQL script twice that uses, say CREATE TEMPORARY TABLE house(name TEXT);. On second run in you'll get "Error: table house already exists". So currently temporary tables are a bit impractical, because one either needs to renames them, or wrap the script in a transaction, like this.

BEGIN;
CREATE TEMP TABLE house
(
  name TEXT,
  points INTEGER
);
INSERT INTO house VALUES
('Gryffindor', 100),
('Hufflepuff', 90),
('Ravenclaw', 95),
('Slytherin', 80);
SELECT * FROM house;
ROLLBACK;

But then you can just use regular tables instead, because DDLs are transactional in SQLite.

The overhead of creating the connection on each query seems close to zero for a DB stored in the browser's memory.

@saaj saaj changed the title [RFE] Simplify working with temorary tables [RFE] Simplify working with temporary tables May 20, 2021
@lana-k lana-k added this to the v0.13.0 milestone May 21, 2021
@lana-k lana-k added the enhancement New feature or request label May 22, 2021
lana-k added a commit that referenced this issue May 24, 2021
- Add csv to existing db #32
- [RFE] Simplify working with temporary tables #53
@lana-k lana-k closed this as completed May 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants