Skip to content

Fix bad init file loading in dump_cmd/3#111

Merged
warmwaffles merged 1 commit into
elixir-sqlite:mainfrom
joeljuca:fix-dotsqliterc
May 5, 2023
Merged

Fix bad init file loading in dump_cmd/3#111
warmwaffles merged 1 commit into
elixir-sqlite:mainfrom
joeljuca:fix-dotsqliterc

Conversation

@joeljuca
Copy link
Copy Markdown
Contributor

@joeljuca joeljuca commented May 4, 2023

A test over dump_cmd/3 was failing with a strange error:

$ mix test
Compiling 2 files (.ex)
.........................warning: missing `:on` in join, defaulting to `on: true`.
  test/ecto/adapters/sqlite3/connection_test.exs:307: Ecto.Adapters.SQLite3.ConnectionTest."test parent binding subquery and CTE"/1

warning: missing `:on` in join on Ecto.Adapters.SQLite3.ConnectionTest.Schema2, defaulting to `on: true`.
  test/ecto/adapters/sqlite3/connection_test.exs:1412: Ecto.Adapters.SQLite3.ConnectionTest."test join with hints"/1

warning: missing `:on` in join, defaulting to `on: true`.
  test/ecto/adapters/sqlite3/connection_test.exs:1478: Ecto.Adapters.SQLite3.ConnectionTest."test join with subquery"/1

warning: missing `:on` in join, defaulting to `on: true`.
  test/ecto/adapters/sqlite3/connection_test.exs:1515: Ecto.Adapters.SQLite3.ConnectionTest."test join with fragment"/1

warning: missing `:on` in join, defaulting to `on: true`.
  test/ecto/adapters/sqlite3/connection_test.exs:1548: Ecto.Adapters.SQLite3.ConnectionTest."test join with query interpolation"/1

warning: missing `:on` in join, defaulting to `on: true`.
  test/ecto/adapters/sqlite3/connection_test.exs:1557: Ecto.Adapters.SQLite3.ConnectionTest."test lateral join with fragment"/1

...................................................................................................................................................................................

  1) test dump_cmd/3 runs command (Ecto.Adapters.SQLite3ConnTest)
     test/ecto/adapters/sqlite3_test.exs:86
     match (=) failed
     code:  assert {"CREATE TABLE test (id INTEGER PRIMARY KEY);\n", 0} = SQLite3.dump_cmd([".schema"], [], opts)
     left:  {"CREATE TABLE test (id INTEGER PRIMARY KEY);\n", 0}
     right: {".auth off\n.mode column\n.headers on\n.prompt \"> \"\nCREATE TABLE test (id INTEGER PRIMARY KEY);\n", 0}
     stacktrace:
       test/ecto/adapters/sqlite3_test.exs:98: (test)

.........................
Finished in 0.8 seconds (0.7s async, 0.09s sync)
230 tests, 1 failure

Randomized with seed 760049

The reason? Well, it's probably my .sqliterc:

.echo on
.auth off
.mode column
.headers on
.prompt "> "

The sqlite3 program loads an initialization file ~/.sqliterc, if present. Since I do have one, it'll be used during dump_cmd/3 operations. It's quite a dangerous behavior since any destructive command present in ~/.sqliterc will be executed against a project's database, possibly destroying data, etc.

I couldn't find a way to make sqlite3 not load my .sqliterc, but after setting /dev/null as -init argument, test passes again (and my .sqliterc is not being loaded/used).

@warmwaffles
Copy link
Copy Markdown
Member

Weird I didn't realize sqlite had an init file it could use similar to psql's

@warmwaffles warmwaffles merged commit 2c164f4 into elixir-sqlite:main May 5, 2023
@joeljuca joeljuca deleted the fix-dotsqliterc branch May 5, 2023 01:37
@joeljuca
Copy link
Copy Markdown
Contributor Author

joeljuca commented May 5, 2023

I personally love it! I can easily configure and apply pre-defined queries in any database I open locally.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants