mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-07-23 01:14:31 +02:00
parent
42ec59d8ee
commit
7684bbf097
3 changed files with 59 additions and 2 deletions
|
|
@ -1138,6 +1138,10 @@ def query(
|
|||
type=(str, str),
|
||||
help="Named :parameters for SQL query",
|
||||
)
|
||||
@click.option(
|
||||
"--encoding",
|
||||
help="Character encoding for CSV input, defaults to utf-8",
|
||||
)
|
||||
@click.option("--dump", is_flag=True, help="Dump SQL for in-memory database")
|
||||
@click.option(
|
||||
"--save",
|
||||
|
|
@ -1159,6 +1163,7 @@ def memory(
|
|||
json_cols,
|
||||
raw,
|
||||
param,
|
||||
encoding,
|
||||
dump,
|
||||
save,
|
||||
load_extension,
|
||||
|
|
@ -1171,13 +1176,17 @@ def memory(
|
|||
sql = None
|
||||
for i, path in enumerate(paths):
|
||||
if path == "-":
|
||||
csv_fp = sys.stdin
|
||||
csv_fp = sys.stdin.buffer
|
||||
csv_table = "stdin"
|
||||
else:
|
||||
csv_path = pathlib.Path(path)
|
||||
csv_table = csv_path.stem
|
||||
csv_fp = csv_path.open()
|
||||
db[csv_table].insert_all(csv_std.DictReader(csv_fp))
|
||||
|
||||
encoding = encoding or "utf-8-sig"
|
||||
decoded_fp = io.TextIOWrapper(csv_fp, encoding=encoding)
|
||||
|
||||
db[csv_table].insert_all(csv_std.DictReader(decoded_fp))
|
||||
# Add convenient t / t1 / t2 views
|
||||
view_names = ["t{}".format(i + 1)]
|
||||
if i == 0:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue