Ex3: -echo not printing steps taken & sqlite>

Hi, I’m on Ex.3 running windows 7. When I run the following, PowerShell does not show the steps that SQLite is taking. Any thoughts on why this is the case?

Also, after I create ex3.db from ex2.sql, I am shoved into sqlite and have to .quit before continuing (i.e. PowerShell switches the line’s “prefix” from C:\xxxxxx to sqlite>). When I try to init ex3.sql into the newly created ex3.db, it won’t let me while the sqlite> prefix is active. Am I missing something?

Thanks!

1 Like

Hi, I’d need more context. Zed might know because he knows what is in exercise 3. Post the code you are running. You’ve describe well what you expect to happen. But, without seeing the code your trying to run, I can’t help fix it.

Hmmm, can you show me a screenshot please so I make sure I’m giving you the right advice? Chances are you doing it right but just don’t understand how sqlite3.exe works.

I have the same problem using Powershell. Commands like

$ sqlite3 ex3.db < ex2.sql

$ sqlite3 -echo ex3.db < ex3.sql

do not work. What are the alternate commands that are used for Powershell to insert data from ex3.db to ex2.sql?

Ah yes, good old powershell. I believe I replied to you on email but you do this:

sqlite3 -init ex2.sql ex3.db

Then you’ll drop into sqlite3 and you can get out with:

.quit
2 Likes

Thank you :+1: @zedshaw

Some info that might help others:
From my experience “-init” must be followed by the SQL script name “ex2.sql”
So the following 2 commands work on Windows PowerShell:

sqlite3 -init ex2.sql ex3.db

From the html version of the book:

sqlite3 ex3.db -init ex2.sql

Please :pray: @zedshaw would you have a workaround to the fact that

-echo

does not print the SQL commands on Windows PowerShell? As in:

sqlite3 ex3.db -init ex2.sql -echo

I have tried to place “-echo” to several places in the command line, but with no success.
Option “-help” works, but I wasn’t able to make “-column” nor “-header” options work either :confused:

They work perfectly fine on Mac OS X terminal.

Cheers!

1 Like

I have just reached ex12 of Learn SQL The Hard Way and I noticed @zedshaw using:

.schema person

to print the “person” table.

It gave me the idea :bulb: of a workaround for our -echo, -header and -column problem with Windows PowerShell :computer::

Add the following at the begining of your .sql script to enable echo, header and column:

.echo on
.headers on
.mode column

In my SQL modified Ex12 script ex12bis.sql:

.echo on
.headers on
.mode column

ALTER TABLE person ADD COLUMN hatred INTEGER;

.schema person

SELECT * FROM person;

Voilà the result on Windows PowerShell:

To add to jbbourdu’s response, there are a couple of other possibilities for this too…

Firstly you can set up a Debian Virtual Machine (there is a video describing this process in the Learn SQL The Hard Way package) and use the bash terminal from there. That way -echo, -column and -header all work, as does the < (redirect input from file) operator which means you don’t subsequently need to run the .exit command to exit the sqlite3 shell.

Secondly, if you don’t wan’t to set up a Debian (or other Unix) virtual machine and are running Windows 10 (up to date; specifically, including the “Creators update” from September 2017) you can use the Linux/bash shell with the Windows Subsystem for Linux. This page on Microsoft’s website explains how to install the Windows Subsystem for Linux with either Ubuntu, OpenSUSE or SLES (it’s quick and easy). From here, you can simply open a PowerShell window, run the bash command to enter the bash shell then complete all exercises from there. As above, -echo, -column and -header all work, as does the < (redirect input from file) operator which means you don’t subsequently need to run the .exit command to exit the sqlite3 shell. If you want to exit the bash shell (and return to PowerShell) just run the exit command.

1 Like

Edit: Actually when I scroll down I see you basically figured this all out. Great.

Either one of those should work, but go with the first one then:

sqlite3 -init ex2.sql ex3.db

As for -echo, I’m not sure why that wouldn’t work. I’d say don’t worry about it so much, and for the other options, type this inside sqlite3:

.help

There’s a ton of commands that might give you the options you need.

1 Like

[Windows 10 Powershell]

When I type in

sqlite3 -init ex2.sql ex3.db

Then type in

.schema

It prints out ex2.sql file and not the ex3.sql file. My “What you should see doesn’t print like the book.”

Take a a look at your command line again @businesscoach. You’re telling it to run ex2.sql not ex3.sql.