Sqlite

From Leo's Notes
Revision as of 05:47, 3 July 2020 by Leo (talk | contribs) (Created page with "== Quick Usage == Run <code>sqlite3</code>. Use .tables to show tables. Create a table {{Highlight | code = create table bandwidth ( mac character(12), time datetime, tx_b...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
This page was last edited on 3 July 2020, at 05:47.

Quick Usage

Run sqlite3. Use .tables to show tables.

Create a table

create table bandwidth (
	mac character(12),
	time datetime,
	tx_bytes unsigned int,
	rx_bytes unsigned int
);

Create a composite key

CREATE UNIQUE INDEX pk_index ON "bandwidth" ("mac", "time");

Find the current hour as a timestamp, which you can insert as a datetime field?

select strftime('%s', 'now') - (strftime('%s','now')%3600);

To insert a record:

insert into bandwidth ('mac', 'time', 'tx_bytes', 'rx_bytes') 
VALUES ('000c2958db2f', strftime('%s', 'now') - (strftime('%s','now')%3600), 100, 100);

See Also