Open SQLite DB file from command-line

ddevienne's profile image ddevienne posted 1 year ago in General Permalink

Hi. Complete newbie to HeidiSQL, but not to DBs in general.

I have tons of SQLite DB files that I open:

  • sometimes from the Shell (Explorer);
  • sometimes from the command-line.

I've tried from the command-line, but that ignores the file on the CLI, and just opens the Session Manager. I've tried passing /? or -h or --help but that's not listing any options either, and just opens the UI

(well, not -h which errors out complaining about a missing host, so there are options seemingly hidding somewhere...)

From the CLI, why not directly open the SQLite DB? I'd like to similarly double-click .db files and have HeidiSQL open right away (after associating it to that extension of course). That's what I do with SQLiteSpy for example. Cannot do the same with HeidiSQL?

I have also tried drag-and-dropping the DB file to the left-hand-side session/connection area, to no avail.

I'm surprised to have to jump through hoops to open one-of SQLite DB. User ignorance? Am I missing something?

Would seem strange to force using that Session Manager for SQLite DBs, and forcing reselecting what the CLI or Explorer double-click know in terms of the DB to open.

Thanks for any insights. --DD

PS: I'm discovering the UI. There are interesting things, and seems fast. Nice. Thanks!

ansgar's profile image ansgar posted 1 year ago Permalink

Command line switches are documented in the online help.

Opening a file via double click by heidisql.exe will tell HeidiSQL to open it as a textfile and load that into a query tab. So that's not what you want.

Instead, you can open a SQLite file with the -h option (which is the "host" for all other database types). Plus some others, like so:

path\to\heidisql.exe -n=10 -l="sqlite3.dll" -h="C:\Users\whatever\Chinook_Sqlite.sqlite"
  • -n is the network type
  • -l is the library
  • -h is the host (or database file in case of SQLite)

Alternatively, you can create a session with multiple databases attached to the first one, with the context menu on the tree:

Description

ddevienne's profile image ddevienne posted 1 year ago Permalink

Thanks for the reply.

But honestly, this feels clunky. SQLite DB files have a magic cookie that easily allows them to identify them as such (and not a text file), from which the rest can be inferred.

PS: it's customary for tools with CLI args to have a textual help, on Windows with /? and/or with --help. You've used -h for something else, which is unfortunate, but at least you could support /? and --help IMHO. FWIW :)

PPS: Forum refuses that I post an HTTP link, so here it is messed-up on purpose sqlite-dot-org/fileformat.html#magic_header_string

Please login to leave a reply, or register at first.