Skip to content

Commit

Permalink
Add support for multiple SQL statements
Browse files Browse the repository at this point in the history
Add support for multiple SQL statements so that one can use the special
commands for apsw.

They need to be individual sql statements because apsw does not use any
delimeter to distinguish a SQL statement a special command.
  • Loading branch information
fzakaria committed Sep 6, 2023
1 parent 53ced81 commit 5bee337
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,16 @@ path|num_sections
/usr/bin/ruby|28
```

You can provide _multiple SQL_ statements to the CLI. This is useful if you want to invoke many of the special _dot_ commands. You can use `.help` to see the list of possible commands or refer to the [apsw shell documentation](https://rogerbinns.github.io/apsw/shell.html).

For instance, to have _sqelf_ emit JSON you can do the following:
```console
sqlelf /usr/bin/ruby --sql ".mode json" --sql "select path,name from elf_sections LIMIT 3;"
{ "path": "\/usr\/bin\/ruby", "name": ""},
{ "path": "\/usr\/bin\/ruby", "name": ".interp"},
{ "path": "\/usr\/bin\/ruby", "name": ".note.gnu.property"},
```

### Queries

#### List all symbol resolutions
Expand Down
8 changes: 6 additions & 2 deletions sqlelf/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ def start(args=sys.argv[1:], stdin=sys.stdin):
"filenames", nargs="+", metavar="FILE", help="The ELF file to analyze"
)
parser.add_argument(
"-s", "--sql", help="Potential SQL to execute. Omitting this enters the REPL."
"-s",
"--sql",
action="append",
help="Potential SQL to execute. Omitting this enters the REPL.",
)
parser.add_argument(
"--recursive",
Expand Down Expand Up @@ -83,6 +86,7 @@ def start(args=sys.argv[1:], stdin=sys.stdin):
shell = apsw.shell.Shell(db=connection, stdin=stdin)

if args.sql:
shell.process_complete_line(args.sql)
for sql in args.sql:
shell.process_complete_line(sql)
else:
shell.cmdloop()

0 comments on commit 5bee337

Please sign in to comment.