fzakaria / sqlelf

Explore ELF objects through the power of SQL
MIT License
240 stars 8 forks source link

Introduce new merge CLI #19

Closed fzakaria closed 2 months ago

fzakaria commented 5 months ago
❯ sqlelf-merge ruby.sqlite bash.sqlite

❯ sqlite3 output.sqlite
-- Loading resources from /usr/local/google/home/fmzakari/.sqliterc
SQLite version 3.44.0 2023-11-01 11:23:50
Enter ".help" for usage hints.
sqlite> select * from elf_headers;
path           type     machine  version  entry   is_pie
-------------  -------  -------  -------  ------  ------
/usr/bin/ruby  DYNAMIC  x86_64   CURRENT  4400    1     
/bin/bash      DYNAMIC  x86_64   CURRENT  202576  1     
Program interrupted.m elf_headers;^C

The assumption are that the schemas are identical otherwise you get errors if there is a missing column such as:

❯ sqlelf-merge ruby.sqlite bash.sqlite
ERROR:root:SQLITE_LOG: SELECTs to the left and right of UNION ALL do not have the same number of result columns in "
            CREATE TABLE elf_headers AS
            SELECT * FROM DB0.elf_headers UNION ALL SELECT * FROM DB1.elf_h (1) SQLITE_ERROR
Traceback (most recent call last):
  File "/usr/local/google/home/fmzakari/code/github.com/fzakaria/sqlelf/.direnv/python-3.11/bin/sqlelf-merge", line 8, in <module>
    sys.exit(start())
             ^^^^^^^
  File "/usr/local/google/home/fmzakari/code/github.com/fzakaria/sqlelf/sqlelf/tools/merge.py", line 84, in start
    conn.execute(sql)
  File "src/cursor.c", line 959, in APSWCursor_execute.sqlite3_prepare_v3
apsw.SQLError: SQLError: SELECTs to the left and right of UNION ALL do not have the same number of result columns
fzakaria commented 5 months ago

@markrwilliams what do you think?