command line dialog - create database, load population, execute queries. ================ softmaple:Desktop mahoney$ l total 8 4 create.sql 4 populate.sql softmaple:Desktop mahoney$ l total 8 4 create.sql 4 populate.sql softmaple:Desktop mahoney$ sqlite3 warehouse.db SQLite version 3.20.1 2017-08-24 16:21:36 Enter ".help" for usage hints. sqlite> .help .auth ON|OFF Show authorizer callbacks .backup ?DB? FILE Backup DB (default "main") to FILE .bail on|off Stop after hitting an error. Default OFF .binary on|off Turn binary output on or off. Default OFF .cd DIRECTORY Change the working directory to DIRECTORY .changes on|off Show number of rows changed by SQL .check GLOB Fail if output since .testcase does not match .clone NEWDB Clone data into NEWDB from the existing database .databases List names and files of attached databases .dbinfo ?DB? Show status information about the database .dump ?TABLE? ... Dump the database in an SQL text format If TABLE specified, only dump tables matching LIKE pattern TABLE. .echo on|off Turn command echo on or off .eqp on|off|full Enable or disable automatic EXPLAIN QUERY PLAN .exit Exit this program .fullschema ?--indent? Show schema and the content of sqlite_stat tables .headers on|off Turn display of headers on or off .help Show this message .import FILE TABLE Import data from FILE into TABLE .imposter INDEX TABLE Create imposter table TABLE on index INDEX .indexes ?TABLE? Show names of all indexes If TABLE specified, only show indexes for tables matching LIKE pattern TABLE. .limit ?LIMIT? ?VAL? Display or change the value of an SQLITE_LIMIT .lint OPTIONS Report potential schema issues. Options: fkey-indexes Find missing foreign key indexes .load FILE ?ENTRY? Load an extension library .log FILE|off Turn logging on or off. FILE can be stderr/stdout .mode MODE ?TABLE? Set output mode where MODE is one of: ascii Columns/rows delimited by 0x1F and 0x1E csv Comma-separated values column Left-aligned columns. (See .width) html HTML code insert SQL insert statements for TABLE line One value per line list Values delimited by "|" quote Escape answers as for SQL tabs Tab-separated values tcl TCL list elements .nullvalue STRING Use STRING in place of NULL values .once FILENAME Output for the next SQL command only to FILENAME .open ?OPTIONS? ?FILE? Close existing database and reopen FILE The --new option starts with an empty file .output ?FILENAME? Send output to FILENAME or stdout .print STRING... Print literal STRING .prompt MAIN CONTINUE Replace the standard prompts .quit Exit this program .read FILENAME Execute SQL in FILENAME .restore ?DB? FILE Restore content of DB (default "main") from FILE .save FILE Write in-memory database into FILE .scanstats on|off Turn sqlite3_stmt_scanstatus() metrics on or off .schema ?PATTERN? Show the CREATE statements matching PATTERN Add --indent for pretty-printing .selftest ?--init? Run tests defined in the SELFTEST table .separator COL ?ROW? Change the column separator and optionally the row separator for both the output mode and .import .sha3sum ?OPTIONS...? Compute a SHA3 hash of database content .shell CMD ARGS... Run CMD ARGS... in a system shell .show Show the current values for various settings .stats ?on|off? Show stats or turn stats on or off .system CMD ARGS... Run CMD ARGS... in a system shell .tables ?TABLE? List names of tables If TABLE specified, only list tables matching LIKE pattern TABLE. .testcase NAME Begin redirecting output to 'testcase-out.txt' .timeout MS Try opening locked tables for MS milliseconds .timer on|off Turn SQL timer on or off .trace FILE|off Output each SQL statement as it is run .vfsinfo ?AUX? Information about the top-level VFS .vfslist List all available VFSes .vfsname ?AUX? Print the name of the VFS stack .width NUM1 NUM2 ... Set column widths for "column" mode Negative values right-justify sqlite> .read create.sql sqlite> .tables Boxes Warehouses sqlite> select * from Boxes; sqlite> .read populate.sql sqlite> select * from Boxes; 0MN7|Rocks|180.0|3 4H8P|Rocks|250.0|1 4RT3|Scissors|190.0|4 7G3H|Rocks|200.0|1 8JN6|Papers|75.0|1 8Y6U|Papers|50.0|3 9J6F|Papers|175.0|2 LL08|Rocks|140.0|4 P0H6|Scissors|125.0|1 P2T6|Scissors|150.0|2 TU55|Papers|90.0|5 sqlite> .schema Boxes CREATE TABLE Boxes ( Code TEXT PRIMARY KEY NOT NULL, Contents TEXT NOT NULL , Value REAL NOT NULL , Warehouse INTEGER NOT NULL, CONSTRAINT fk_Warehouses_Code FOREIGN KEY (Warehouse) REFERENCES Warehouses(Code) ); sqlite> .quit softmaple:Desktop mahoney$ l total 24 4 create.sql 4 populate.sql 16 warehouse.db softmaple:Desktop mahoney$ sqlite3 SQLite version 3.20.1 2017-08-24 16:21:36 Enter ".help" for usage hints. Connected to a transient in-memory database. Use ".open FILENAME" to reopen on a persistent database. sqlite> sqlite> sqlite> SELECT Value FROM Boxes WHERE Code = "9J6F"; Error: no such table: Boxes sqlite> ^D softmaple:Desktop mahoney$ sqlite3 warehouse.db SQLite version 3.20.1 2017-08-24 16:21:36 Enter ".help" for usage hints. sqlite> SELECT Value FROM Boxes WHERE Code = "9J6F"; 175.0 sqlite> select * from Boxes; 0MN7|Rocks|180.0|3 4H8P|Rocks|250.0|1 4RT3|Scissors|190.0|4 7G3H|Rocks|200.0|1 8JN6|Papers|75.0|1 8Y6U|Papers|50.0|3 9J6F|Papers|175.0|2 LL08|Rocks|140.0|4 P0H6|Scissors|125.0|1 P2T6|Scissors|150.0|2 TU55|Papers|90.0|5 sqlite> select * from Warehouses; 1|Chicago|3 2|Chicago|4 3|New York|7 4|Los Angeles|2 5|San Francisco|8 sqlite> SELECT Boxes.Code FROM (Boxes INNER JOIN Warehouses ON Warehouses.Code = Boxes.Warehouse) WHERE Wsqlite> SELECT Boxes.Code FROM (Boxes INNER JOIN Warehouses ON Warehouses.Code = Boxes.Warehouse) WHERE Warehouses.Location = "Chicago"; 4H8P 7G3H 8JN6 9J6F P0H6 P2T6 sqlite> SELECT Code FROM Boxes WHERE Warehouse = (SELECT Warehouses.Code FROM Warehouses WHERE Warehouses.Location = "Chicago"); 4H8P 7G3H 8JN6 P0H6 sqlite> SELECT Code FROM Boxes WHERE Warehouse IN (SELECT Warehouses.Code FROM Warehouses WHERE Warehouses.Location = "Chicago"); 4H8P 7G3H 8JN6 9J6F P0H6 P2T6 sqlite>