Can't use .once more than once.
mjpieters opened this issue · 1 comments
I expect the .once
command to work more than once in a session, each time resulting in the next query output to be written to a designated file.
Instead, you can use .once
just once in a session. After that you have to restart litecli. It doesn't matter what the arguments are; executing .once
a second time in the same session has no effect.
This is caused by the written_to_once_file
flag; it is set to True
when output is sent to a file, but then never set back to False
.
With written_to_once_file
set to True
, the next time you execute .once
, the set_once()
command still sets once_file
, but immediately afterwards, unset_once_if_written()
is executed after the command completes, which sets once_file
back to None
, so by the time your next output-producing command is run, nothing will be written out to the file.
I can confirm that changing unset_once_if_written
to:
@export
def unset_once_if_written():
"""Unset the once file, if it has been written to."""
global once_file, written_to_once_file
if written_to_once_file:
once_file = written_to_once_file = None
fixes the issue. Clearing written_to_once_file
makes sure that the trigger doesn't fire forever for later commands.