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

[sqlite-] prevent creation of ./- file when reading from stdin #1945

Merged
merged 1 commit into from
Jul 3, 2023

Conversation

midichef
Copy link
Contributor

@midichef midichef commented Jul 2, 2023

If visidata tries to read a SQLite file from standard input, it will load an empty sheet and create the file - in the current directory. This can be seen with cat sample_data/employees.sqlite |vd -f sqlite3

That's because the path for stdin gets resolved as the file - in the current directory.
As far as I can tell, there's no way to read an SQLite file from standard input, at least not with the Python sqlite library. When I try it, using sqlite.connect() with '/dev/stdin', I get this error

Traceback (most recent call last):
  File "/home/midichef/.local/lib/python3.10/site-packages/visidata/threads.py", line 200, in _toplevelTryFunc
    t.status = func(*args, **kwargs)
  File "/home/midichef/.local/lib/python3.10/site-packages/visidata/sheets.py", line 235, in reload
    for r in self.iterload():
  File "/home/midichef/.local/lib/python3.10/site-packages/visidata/loaders/sqlite.py", line 179, in iterload
    for row in SqliteSheet.iterload(self):
  File "/home/midichef/.local/lib/python3.10/site-packages/visidata/loaders/sqlite.py", line 84, in iterload
    with self.conn() as conn:
  File "/home/midichef/.local/lib/python3.10/site-packages/visidata/loaders/sqlite.py", line 58, in conn
    con = sqlite3.connect(url, uri=True, **self.options.getall('sqlite_connect_'))
sqlite3.OperationalError: disk I/O error

So this commit just disables reading any sqlite file from standard input.

Copy link
Owner

@saulpw saulpw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Heh, okay. How did you find this one? I never would have thought to pipe a sqlite db into vd.

@anjakefala anjakefala merged commit 64fd46b into saulpw:develop Jul 3, 2023
13 checks passed
@midichef midichef deleted the sqlite_stdin branch July 9, 2023 00:01
@midichef
Copy link
Contributor Author

Yeah, it's an odd thing to try! I was trying to find a hack to effectively make the sqlite db read-only, in response to #1805

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants