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

--sql-log debug option #35

Open
simonw opened this issue Dec 6, 2021 · 0 comments
Open

--sql-log debug option #35

simonw opened this issue Dec 6, 2021 · 0 comments
Labels
enhancement New feature or request

Comments

@simonw
Copy link
Owner

simonw commented Dec 6, 2021

Found this useful while working on #33 - I should turn it into a documented feature:

+@click.option(
+    "--trace-file",
+    type=click.File("w"),
+    help="Store executed SQL in this file",
+)
 @click.option(
     "--silent",
     is_flag=True,
@@ -145,6 +150,7 @@ def file(
     ignore_duplicate_ids,
     wal,
     debug,
+    trace_file,
     silent,
 ):
     "Analyze the history of a specific file and write it to SQLite"
@@ -159,7 +165,15 @@ def file(
             "Cannot use --start-at and --start-after at the same time"
         )
 
-    db = sqlite_utils.Database(database)
+    if trace_file:
+        db = sqlite_utils.Database(
+            database,
+            tracer=lambda sql, params: trace_file.write(
+                "{} - {}\n".format(sql, params)
+            ),
+        )
+    else:
+        db = sqlite_utils.Database(database)
     if wal:
         db.enable_wal()
@simonw simonw added the enhancement New feature or request label Dec 6, 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

1 participant