sqlite3 current directory tables can't be found - sqlite

Based on the threads I read, I know if you launch sqlite3 when you're in whatever folder, then that's your current folder.
But I can't find any existing tables. It's like this:
XXXX/User/Folder$ ls
123.db 344.db
XXXX/User/Folder$ sqlite3
SQLITE version .....
sqlite> .tables
sqlite>

First you must select database because tables exist in specific databases. In Sqlite3 file system file represents separate database. So in your example you have two databases 123.db and 344.db. To select a database simply specify it to sqlite3 cli:
$ sqlite3 123.db
sqlite> .tables
Now you should see the list of tables in database 123.db.

Related

How to open .SQLite files

I'm trying to open a .sqlite file on Windows, but I don't know how to. Do you know a good program for it?
It contains data for statistical analysis, but I prefer having a .txt file.
I also have a .spatialite file. Can you help me?
If you just want to see what's in the database without installing anything extra, you might already have SQLite CLI on your system. To check, open a command prompt and try:
sqlite3 database.sqlite
Replace database.sqlite with your database file. Then, if the database is small enough, you can view the entire contents with:
sqlite> .dump
Or you can list the tables:
sqlite> .tables
Regular SQL works here as well:
sqlite> select * from some_table;
Replace some_table as appropriate.
SQLite is database engine, .sqlite or .db should be a database. If you don't need to program anything, you can use a GUI like sqlitebrowser or anything like that to view the database contents.
Website: http://sqlitebrowser.org/
Project: https://github.com/sqlitebrowser/sqlitebrowser
There is also spatialite, https://www.gaia-gis.it/fossil/spatialite_gui/index
My favorite:
https://inloop.github.io/sqlite-viewer/
No installation needed. Just drop the file.
I would suggest using R and the package RSQLite
#install.packages("RSQLite") #perhaps needed
library("RSQLite")
# connect to the sqlite file
sqlite <- dbDriver("SQLite")
exampledb <- dbConnect(sqlite,"database.sqlite")
dbListTables(exampledb)

How to know what table there are in a sqlite file?

I have a sqlite file but I don't know what tables there are in it and thus I can't use a SELECT query.
So, is there a way to know what table are in it ?
P.S. I am under Ubuntu Linux and I have already installed sqlite3 from shell.
You can open the database using sqlite3 using:
sqlite3 <databasefile>
Once in the sqlite3 shell you can simply type:
.tables
to see a list of all the tables.
You can see the table structure of a particular table using:
.schema <tablename>
You can also omit the table name to see the schema for the whole database.
Information about these commands and more can be seen by typing:
.help

Creating Databases and Tables using SQLite3

I have used SQLIte3 to create databases and then added tables to it. Then i closed the terminal and reopened it.
I typed the command sqlite3, and typed select * from tableName; It says the table is not found.
Think i have to select the database first and then type the above select statement to work. So how can i do that ?
SQL commands like show databases; is not recognized.
You have to write sqlite3 DB_NAME on terminal to open database. Then you can see sqlite prompt like sqlite3> You can enter command select * from tableName there, so that your tables will be listed. You can also try .schema command to see the schema of your data base. Refer the site http://www.sqlite.org/ for more details.
You can use SQLite Manager firefox add-on to view sqlite database, table and execute query there.

create new sqlite Db

I am working on Mac OS X,
I want to create a new SQLite DB, and
I am using http://www.sqlite.org/quickstart.html as a reference.
I am entering: sqlite3 test.db
and getting the response:
SQLite version 3.6.12
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
Why is this happening?
It worked. Quit out and test - the database has been created.
You are now in the SQLite shell, and it is ready to receive commands like CREATE TABLE..., INSERT INTO..., etc.
If you would prefer not to use the interactive shell, you can build your schema straight from the command line:
sqlite3 test.db "CREATE TABLE ..."
Or just create an empty database with no schema:
sqlite3 test.db ""
But that's the same as just creating an empty file, anyway:
touch test.db
Because that is the administrative shell prompt. The shell created test.db and is now waiting for you to do something with it thus the sqlite> prompt you see.
You may want to create table ... at this point.
so it is fine. you are prompted to enter commands. create table, insert, select. have fun!
You're being taken to the SQLite prompt (where you can create tables, add data, etc.). Nothing appears out of the ordinary based on what you've posted.

Accessing .sqlite db from phpmyadmin? FF cookies

I'm trying to view my firefox cookies db (cookies.sqlite). Since I've never accessed dbs with anything other than phpmyadmin, I'm at a loss as to how to view the content of this sqlite file. There's localhost/sqlitemanager, but I'd rather stick to the phpmyadmin interface that I'm used to.
Any ideas how I can open/view this sqlite db the normal way in phpmyadmin? Is it possible?
Thanks in advance
P.S. I know that browser cookies are very commonly accessed/played with. If you know another tool that's more specific for this goal, please drop me an answer or suggest in the comments.
There are also several web interfaces for sqlite.
phpSQLiteAdmin
SQLiteManager
Simple SQLite Manager
SQLite Admin
WizSQLiteAdmin
ezSqliteAdmin
SQLiteWebAdmin
knoda
I have not yet tried any of them - in fact, I found this SO question while researching sqlite web front-ends for my own use. But I, too, come from a phpMyAdmin background, so the first one I plan to try is phpSQLiteAdmin.
I imagine there are various GUI programs that will hold your hand. However, I'm going to show you what I would do if I was interested in table moz_cookies in db cookies.sqlite.
$
$ sqlite3 cookies.sqlite
SQLite version 3.5.9
Enter ".help" for instructions
sqlite> .schema
CREATE TABLE moz_cookies (id INTEGER PRIMARY KEY, name TEXT, value TEXT, host TEXT, path TEXT,expiry INTEGER, lastAccessed INTEGER, isSecure INTEGER, isHttpOnly INTEGER);
sqlite> select * from moz_cookies limit 1;
1248713741170186|PREF|ID=12d44375be9e7c86:U=d07dae1b87f4537c:LD=en:NR=100:TM=1248713740:LM=1254091506:FV=2:IG=3:S=Jdo_PXt92J5ojL6E|.google.com|/|1317163505|1255144201180851|0|0
sqlite>
You may want the sqlite3 CLI program. It is available on Unix and Windows.
SQLITE3(1) SQLITE3(1)
NAME
sqlite3 - A command line interface for SQLite version 3
SYNOPSIS
sqlite3 [options] [databasefile] [SQL]
SUMMARY
sqlite3 is a terminal-based front-end to the SQLite library that can
evaluate queries interactively and display the results in multiple for‐
mats. sqlite3 can also be used within shell scripts and other applica‐
tions to provide batch processing features.
DESCRIPTION
To start a sqlite3 interactive session, invoke the sqlite3 command and
optionally provide the name of a database file. If the database file
does not exist, it will be created. If the database file does exist,
it will be opened.
It has two categories of operations.
Commands intended directly for the interactive shell begin with .. Anything is an SQL query terminated as usual with ;.
Adminer is a PHPMyAdmin-like system that has support for MySQL, PostgreSQL, SQLite, MS SQL, Oracle, SimpleDB, Elasticsearch, MongoDB, etc.

Resources