SQLite how to open a database from the sqlite> prompt? lazarus / 16-Databases ---------------------------------------------------------------------- Elmug · 2012-06-26 20:41 Hi everyone, Have been studying SQLite, but can't seem to find how to OPEN an existing database while being at the SQLite prompt (the shell "squlite>" prompt). I know of starting SQLite from the SYSTEM-shell, by including the database name. But if I start the SQLite shell with no database name, how then to open an existing database? Also: How to close the database once it has been opened? Thanks! ---------------------------------------------------------------------- Dick, from the internet · 2012-06-26 21:18 .restore ---------------------------------------------------------------------- Elmug · 2012-06-26 21:54 Quote from: geno on June 26, 2012, 11:18:28 pm .restore Thanks Geno. However, I am not sure the .restore command is what I am after, since I find this definition for it: .restore Perform a low-level copy of a database file to a database Common Usage .restore [database_name] filename Description The .restore command performs a low-level copy of a database file into an open or attached database. If the database name is not provided, the main database will be populated. This command is frequently used to populate an active in-memory database from a database file. This command is safe to run against an active source database (although it may not succeed). This is the opposite of the .backup command. I wonder if I got misread? I thought opening and closing a database from the SQLite prompt would be an essential thing, but can't find yet how to and surely there must be a way? Thanks. ---------------------------------------------------------------------- CaptBill · 2012-06-26 22:10 I don't think you need to "open" a sqlite database per se, unless you want an in-memory database. You simply issue the sql commands and it handles any initialization (opening) of the disk file. You sql runs, gets it's data, and returns it. No "open table" command is necessary, if my understanding is correct. ---------------------------------------------------------------------- Dick, from the internet · 2012-06-26 23:27 @elmug yes, I read the help text within sqlite3 as well and it did not show any method of loading databases (such as mysql's \u or use command); however, .restore works in a pinch.  Your other option is simply .quit then reload with the correct database. ---------------------------------------------------------------------- Elmug · 2012-06-26 23:30 Quote from: CaptBill on June 27, 2012, 12:10:31 amI don't think you need to "open" a sqlite database per se, unless you want an in-memory database. You simply issue the sql commands and it handles any initialization (opening) of the disk file. You sql runs, gets it's data, and returns it. No "open table" command is necessary, if my understanding is correct. Hi, and thanks, CaptBill. I agree that maybe there isn't a dot command or query to open a database, but am not sure that there wouldn't be any need to close/open a database, as wished, specially when I have read that one of the features of SQLite is that it can open more than one database simultaneously. So, can one open two databases simultaneously, other than by code? I came to this issue since I actually started creating databases and tables using SQLite Administrator, which can connect and disconnect databases interactively, and naturally assumed this could also be done by the original SQLite prompt. It's not an indispensable thing for me right now, though. But it is great to be aware of what is possible and not. Thanks. ---------------------------------------------------------------------- Elmug · 2012-06-26 23:31 Quote from: geno on June 27, 2012, 01:27:01 am@elmug yes, I read the help text within sqlite3 as well and it did not show any method of loading databases (such as mysql's \u or use command); however, .restore works in a pinch.  Your other option is simply .quit then reload with the correct database. Thanks Geno, I learned about the restore command, any way. I'm sure I would use it! ---------------------------------------------------------------------- Dick, from the internet · 2012-06-27 00:29 I learned something here as well. At least I had never thought about it until CaptBill mentioned it; running a sql statement from the command line - and the output can be put into a text file (or use another pipe to the command of your choice I suppose) [geno@geno ~]$ sqlite3 audiocd.dat "select ArtistName From Albums" >> audiotest Thanks, ya'll.