cd C: mkdir sqlite cd sqliteThe trick is how to unzip the sqlite-tools-win32-x86-3390400.zip file. The thing to do is to launch the windows file explorer, go to my downloads folder and right click on the zip file in question. This brings up a dialog that includes an "extract all" option. This brings up a dialog that asks where I would like to extract to. I tell it c:\sqlite, but it ends up creating a directory in that folder and extracting into that. Windows has a command "move" that I can use to move the files to where they should be, and then I use rmdir to get rid of the empty directory.
They tell me to also unzip the DLL file into this same directory. So I repeat the process for sqlite-dll-win64-x64-3390400.zip. This gives me sqlite3.dll and sqlite3.def alongside the 3 executables in c:\sqlite
Now I am instructed to add c:\sqlite to my path environment variable. I click the windows start button and type "env" to start a search. It gives me a thing that says "environment variables" in the control panel. You can get to this "directly" by rattling your way along from the control panel to System properties, but this is by far easier.
A button near the button offers "Environment variables", so we click it. I find PATH under "system variables", select it, and click edit. Use "new" to add a new directory to the path.
I see an old entry in the path for c:\ruby193 that I should watch out for.
Indeed, now I can type "sqlite3" and get the sqlite3 shell.
None of the tutorials have said a thing about the .dll file, but we will see about that.
I play with the sqlite3 tool, create a database, user insert to add records to a table I create, use select to display the records and so forth. Note that you can feed an editor generated script to the tool via:
sqlite3 fish.db < myscriptThis works just fine without a .quit at the end of the file.
gem install sqlite3It finishes in just seconds. I am suspicious, but let's see. (See below, everything works out just fine). A ruby script with the require line for sqlite3 goes without errors. Maybe we are OK and it knows what to do, deeper tests are required.
Just for possible future reference, the following gives a short ruby script that extracts data from an Excel spreadsheet and loads it into a sqlite database.
I used the sqlite3 tool to create a silly database. The question now is whether I can write a ruby script that will find that database and display the records.I put the following into a file named "silly.sq":
create table person ( id integer, name text ); insert into person values ( 1, "joe" ); insert into person values ( 2, "fred" ); insert into person values ( 3, "sam" ); insert into person values ( 4, "hank" );Then I give the command:
sqlite3 fish.db < silly.sqIndeed after doing this I have a non empty file "fish.db". After this I run the following ruby script:
#!/usr/bin/ruby require 'sqlite3' db_path = "./fish.db" db = SQLite3::Database.open( db_path ) db.execute("select * from person") do |result| puts "----" line = result[0].to_s + ": " + result[1] puts line end # THE ENDThis runs just fine, producing the output:
---- 1: joe ---- 2: fred ---- 3: sam ---- 4: hankNote that the initial "shebang" line that is important on a linux system is not needed on windows, but is harmless. I am not sure who or what needs the sqlite3.dll file (or if it is being magically discovered and used). But what is most important is that simply doing "gem install sqlite3" does the job. For all I know it would work without even installing sqlite3 beforehand, but I want the sqlite3 shell, so I may never know or care.
All clear on the western front. Ready to move ahead with ruby and sqlite3.
Adventures in Computing / tom@mmto.org