<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://k2.ixota.com/index.php?action=history&amp;feed=atom&amp;title=SQLite</id>
	<title>SQLite - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://k2.ixota.com/index.php?action=history&amp;feed=atom&amp;title=SQLite"/>
	<link rel="alternate" type="text/html" href="https://k2.ixota.com/index.php?title=SQLite&amp;action=history"/>
	<updated>2026-06-26T16:23:05Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.33.1</generator>
	<entry>
		<id>https://k2.ixota.com/index.php?title=SQLite&amp;diff=1962&amp;oldid=prev</id>
		<title>Kenneth: /* SQL */</title>
		<link rel="alternate" type="text/html" href="https://k2.ixota.com/index.php?title=SQLite&amp;diff=1962&amp;oldid=prev"/>
		<updated>2015-03-26T16:26:50Z</updated>

		<summary type="html">&lt;p&gt;&lt;span dir=&quot;auto&quot;&gt;&lt;span class=&quot;autocomment&quot;&gt;SQL&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;== SQLite ==&lt;br /&gt;
&lt;br /&gt;
SQLite Home Page - http://sqlite.org/&lt;br /&gt;
&lt;br /&gt;
&amp;quot;SQLite is a software library that implements a self-contained, serverless, zero-configuration, transactional SQL database engine. SQLite is the most widely deployed SQL database engine in the world. The source code for SQLite is in the public domain.&amp;quot; [http://sqlite.org/]&lt;br /&gt;
&lt;br /&gt;
== Command Line ==&lt;br /&gt;
&lt;br /&gt;
Show help:&lt;br /&gt;
 sqlite3 mydb.db &amp;quot;.help&amp;quot;&lt;br /&gt;
&lt;br /&gt;
SQL&lt;br /&gt;
 sqlite3 mydb.db &amp;quot;select * from mytable;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Dump data from table &amp;#039;t1&amp;#039; to new table &amp;#039;t2&amp;#039;:&lt;br /&gt;
 sqlite3 test.db &amp;quot;.dump&amp;quot;|sed -e s/t1/t2/|sqlite3 test2.db&lt;br /&gt;
&lt;br /&gt;
== SQLite Commands ==&lt;br /&gt;
&lt;br /&gt;
Help:&lt;br /&gt;
 .help&lt;br /&gt;
&lt;br /&gt;
List tables:&lt;br /&gt;
 .tables&lt;br /&gt;
&lt;br /&gt;
Describe tables:&lt;br /&gt;
 select * from sqlite_master;&lt;br /&gt;
&lt;br /&gt;
Dump all data, and table creates:&lt;br /&gt;
 .dump&lt;br /&gt;
&lt;br /&gt;
Show table schema:&lt;br /&gt;
 .schema [table]&lt;br /&gt;
&lt;br /&gt;
== Linux ==&lt;br /&gt;
&lt;br /&gt;
Install:&lt;br /&gt;
 yum install sqlite3&lt;br /&gt;
&lt;br /&gt;
Man:&lt;br /&gt;
 man sqlite3&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
       $ sqlite3 mydata.db&lt;br /&gt;
       SQLite version 3.1.3&lt;br /&gt;
       Enter &amp;quot;.help&amp;quot; for instructions&lt;br /&gt;
       sqlite&amp;gt; create table memos(text, priority INTEGER);&lt;br /&gt;
       sqlite&amp;gt; insert into memos values(&amp;#039;deliver project description&amp;#039;, 10);&lt;br /&gt;
       sqlite&amp;gt; insert into memos values(&amp;#039;lunch with Christine&amp;#039;, 100);&lt;br /&gt;
       sqlite&amp;gt; select * from memos;&lt;br /&gt;
       deliver project description|10&lt;br /&gt;
       lunch with Christine|100&lt;br /&gt;
       sqlite&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== SQL ==&lt;br /&gt;
&lt;br /&gt;
Query Language Understood by SQLite - https://www.sqlite.org/lang.html&lt;br /&gt;
&lt;br /&gt;
=== Create Table ===&lt;br /&gt;
&lt;br /&gt;
Note: type definitions do not appear to be strictly enforced, unless primary key&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Expression Affinity	Column Declared Type&lt;br /&gt;
TEXT			&amp;quot;TEXT&amp;quot;&lt;br /&gt;
NUMERIC			&amp;quot;NUM&amp;quot;&lt;br /&gt;
INTEGER			&amp;quot;INT&amp;quot;&lt;br /&gt;
REAL			&amp;quot;REAL&amp;quot;&lt;br /&gt;
NONE			&amp;quot;&amp;quot; (empty string)  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE t1(a, b NOT NULL);	# can&amp;#039;t be null&lt;br /&gt;
 CREATE TABLE t1(a, b UNIQUE);		# must be unique&lt;br /&gt;
 CREATE TABLE t1(a, b PRIMARY KEY);	# primary key same as unique, but can only have one&lt;br /&gt;
 CREATE TABLE t1(a, b INTEGER NOT NULL, c INTEGER PRIMARY KEY);		# auto increments &amp;#039;c&amp;#039;&lt;br /&gt;
&lt;br /&gt;
https://www.sqlite.org/lang_createtable.html&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CREATE TABLE android_metadata (locale TEXT);&lt;br /&gt;
CREATE TABLE attendees (meeting_id INTEGER, scout_id INTEGER, FOREIGN KEY(meeting_id) REFERENCES meetings(_id), FOREIGN KEY (scout_id) REFERENCES scouts(_id));&lt;br /&gt;
CREATE TABLE completions (_id INTEGER PRIMARY KEY AUTOINCREMENT, scout_id INTEGER NOT NULL, part_id INTEGER NOT NULL, timestamp DATETIME, reported DATETIME, FOREIGN KEY (scout_id) REFERENCES scouts(_id), FOREIGN KEY (part_id) REFERENCES parts(_id));&lt;br /&gt;
CREATE TABLE dens (_id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, rank_id INTEGER, FOREIGN KEY (rank_id) REFERENCES ranks(_id));&lt;br /&gt;
CREATE TABLE groups (_id INTEGER PRIMARY KEY AUTOINCREMENT, item_id INTEGER NOT NULL, name TEXT, number TEXT, qty_required INTEGER , notes TEXT, part_count int, FOREIGN KEY (item_id) REFERENCES items(_id));&lt;br /&gt;
CREATE TABLE item_completions (_id INTEGER PRIMARY KEY AUTOINCREMENT, scout_id INTEGER NOT NULL, item_id INTEGER NOT NULL, completed DATETIME, reported DATETIME, FOREIGN KEY (scout_id) REFERENCES scouts(_id), FOREIGN KEY (item_id) REFERENCES items(_id));&lt;br /&gt;
CREATE TABLE items (_id INTEGER PRIMARY KEY AUTOINCREMENT, type TEXT, rank_id INTEGER, number TEXT, title TEXT, notes TEXT, image BLOB, group_count int, FOREIGN KEY (rank_id) REFERENCES ranks(_id));&lt;br /&gt;
CREATE TABLE meetings (_id INTEGER PRIMARY KEY AUTOINCREMENT, rank_id INTEGER, meeting_date DATETIME, notes TEXT, reported DATETIME, den_id INTEGER REFERENCES dens(_id), FOREIGN KEY (rank_id) REFERENCES ranks(_id));&lt;br /&gt;
CREATE TABLE parts (_id INTEGER PRIMARY KEY AUTOINCREMENT, group_id INTEGER NOT NULL, number TEXT, description TEXT, notes TEXT, FOREIGN KEY (group_id) REFERENCES groups(_id));&lt;br /&gt;
CREATE TABLE ranks (_id INTEGER PRIMARY KEY, name TEXT NOT NULL);&lt;br /&gt;
CREATE TABLE scouts (_id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, den_id INTEGER REFERENCES dens(_id), contacts TEXT, photo BLOB, email_address text, phone_number text);&lt;br /&gt;
CREATE TABLE settings (setting_key char(50) primary key, setting_value text);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Alter Table ===&lt;br /&gt;
&lt;br /&gt;
 ALTER TABLE t1 ADD COLUMN hostid TEXT;&lt;br /&gt;
&lt;br /&gt;
=== Destroy Table ===&lt;br /&gt;
&lt;br /&gt;
 DROP TABLE t1;&lt;br /&gt;
&lt;br /&gt;
=== Create ===&lt;br /&gt;
&lt;br /&gt;
 INSERT INTO t1 VALUES(&amp;#039;test&amp;#039;, 1);&lt;br /&gt;
 INSERT INTO t1 VALUES(&amp;#039;test&amp;#039;);&lt;br /&gt;
&lt;br /&gt;
=== Read ===&lt;br /&gt;
&lt;br /&gt;
 SELECT * FROM t1;&lt;br /&gt;
 SELECT count(*) FROM t1;&lt;br /&gt;
&lt;br /&gt;
=== Update ===&lt;br /&gt;
&lt;br /&gt;
 UPDATE t1 SET a = &amp;#039;test&amp;#039;, b = 1 WHERE c = 1;&lt;br /&gt;
&lt;br /&gt;
=== Destroy ===&lt;br /&gt;
&lt;br /&gt;
 DELETE FROM t1;&lt;br /&gt;
 DELETE FROM t1 WHERE c = 1;&lt;br /&gt;
&lt;br /&gt;
== Auto increment ==&lt;br /&gt;
&lt;br /&gt;
Create table with auto inc primary key:&lt;br /&gt;
 sqlite3 test.db  &amp;quot;create table t1 (t1key INTEGER &lt;br /&gt;
                  PRIMARY KEY,data TEXT,num double,timeEnter DATE);&amp;quot;&lt;br /&gt;
&lt;br /&gt;
the primary key &amp;quot;t1key&amp;quot; auto increments; &lt;br /&gt;
&lt;br /&gt;
== SQL ==&lt;br /&gt;
&lt;br /&gt;
SQLite Query Language: SELECT - http://www.sqlite.org/lang_select.html&lt;br /&gt;
&lt;br /&gt;
core functions: (SQLite Query Language: Core Functions - http://www.sqlite.org/lang_corefunc.html)&lt;br /&gt;
* abs, length&lt;br /&gt;
* length, lower, ltrim, rtrim, substr, trim, upper&lt;br /&gt;
* random, round&lt;br /&gt;
&lt;br /&gt;
SQLite Query Language: Aggregate Functions - http://www.sqlite.org/lang_aggfunc.html&lt;br /&gt;
* count, min, max&lt;br /&gt;
* avg, sum&lt;br /&gt;
&lt;br /&gt;
Distinct (aka unique)&lt;br /&gt;
 select distinct name from test;&lt;br /&gt;
&lt;br /&gt;
Limit:&lt;br /&gt;
 select * from test limit 1;&lt;br /&gt;
&lt;br /&gt;
== Python ==&lt;br /&gt;
&lt;br /&gt;
See [[Python#SQLite]]&lt;br /&gt;
&lt;br /&gt;
== Tutorials ==&lt;br /&gt;
&lt;br /&gt;
* SQLite Tutorial: Common Commands and Triggers LG #109 - http://linuxgazette.net/109/chirico1.html&lt;br /&gt;
* SQLite Tutorial - http://souptonuts.sourceforge.net/readme_sqlite_tutorial.html&lt;br /&gt;
* SQLite YoLinux.com Embedded Database - http://www.yolinux.com/TUTORIALS/SQLite.html&lt;br /&gt;
&lt;br /&gt;
== Compiling ==&lt;br /&gt;
&lt;br /&gt;
Building python 2.6 w/ sqlite3 module if sqlite is installed in non-standard location - Stack Overflow - http://stackoverflow.com/questions/1677666/building-python-2-6-w-sqlite3-module-if-sqlite-is-installed-in-non-standard-loc&lt;br /&gt;
&lt;br /&gt;
 ./configure LDFLAGS=&amp;#039;-L/path/to/lib&amp;#039; CPPFLAGS=&amp;quot;-I/path/to/include&amp;#039;&lt;br /&gt;
&lt;br /&gt;
Note: This didn&amp;#039;t work.&lt;br /&gt;
&lt;br /&gt;
=== Amalgamation Method ===&lt;br /&gt;
&lt;br /&gt;
 wget http://www.sqlite.org/sqlite-amalgamation-3071100.zip&lt;br /&gt;
 unzip sqlite-amalgamation-3071100.zip&lt;br /&gt;
 cd sqlite-amalgamation-3071100&lt;br /&gt;
 gcc shell.c sqlite3.c -lpthread -ldl&lt;br /&gt;
&lt;br /&gt;
References:&lt;br /&gt;
* How To Compile SQLite - http://www.sqlite.org/howtocompile.html&lt;br /&gt;
* The SQLite Amalgamation - http://www.sqlite.org/amalgamation.html&lt;br /&gt;
&lt;br /&gt;
=== Autoconf Method ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
wget http://www.sqlite.org/sqlite-autoconf-3070500.tar.gz&lt;br /&gt;
tar xvzf sqlite-autoconf-3070500.tar.gz&lt;br /&gt;
cd sqlite-autoconf-3070500&lt;br /&gt;
./configure&lt;br /&gt;
make&lt;br /&gt;
sudo make install&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Source: http://eveningsamurai.wordpress.com/2011/02/18/installing-sqlite3-ruby-on-centos-5/&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
Although CentOS 5 has SQLite3 installed out of the box it is an older version so we must build a new one.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd /tmp&lt;br /&gt;
wget http://www.sqlite.org/sqlite-autoconf-3070800.tar.gz&lt;br /&gt;
tar -zxvf sqlite-autoconf-3070800.tar.gz&lt;br /&gt;
cd sqlite-autoconf-3070800&lt;br /&gt;
./configure --prefix=/opt/sqlite3 &amp;amp;&amp;amp; make &amp;amp;&amp;amp; make install&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Source: http://www.geekytidbits.com/ruby-on-rails-in-centos-5/&lt;br /&gt;
&lt;br /&gt;
== Issues ==&lt;br /&gt;
&lt;br /&gt;
=== attempt to write a readonly database ===&lt;br /&gt;
&lt;br /&gt;
The database needs write permission&lt;br /&gt;
&lt;br /&gt;
 chmod g+w .data/sql.db&lt;br /&gt;
 chown :apache .data/sql.db&lt;br /&gt;
&lt;br /&gt;
References:&lt;br /&gt;
* django - Why do I get sqlite error, &amp;quot;unable to open database file&amp;quot;? - Server Fault - http://serverfault.com/questions/57596/why-do-i-get-sqlite-error-unable-to-open-database-file&lt;br /&gt;
&lt;br /&gt;
=== unable to open database file ===&lt;br /&gt;
&lt;br /&gt;
The directory needs write permissions.  (assuming for temporary files?)&lt;br /&gt;
&lt;br /&gt;
 chmod g+w .data&lt;br /&gt;
 chown :apache .data&lt;br /&gt;
&lt;br /&gt;
References:&lt;br /&gt;
* django - Why do I get sqlite error, &amp;quot;unable to open database file&amp;quot;? - Server Fault - http://serverfault.com/questions/57596/why-do-i-get-sqlite-error-unable-to-open-database-file&lt;br /&gt;
&lt;br /&gt;
== keywords ==&lt;br /&gt;
&lt;br /&gt;
[[Category:Database]]&lt;br /&gt;
[[Category:Programming]]&lt;/div&gt;</summary>
		<author><name>Kenneth</name></author>
		
	</entry>
</feed>