<?php

$db = new SQLite3('test.db');

/*


$db->exec('CREATE TABLE "bridges" (
	"plug_id"	INTEGER,
	"id"	INTEGER UNIQUE,
	PRIMARY KEY("id"),
	FOREIGN KEY("plug_id") REFERENCES "plugs"("id")
)');

$db->exec('CREATE TABLE "measurement_nodes" (
	"required_by"	INTEGER,
	"node_from"	INTEGER,
	"node_to"	INTEGER,
	UNIQUE("required_by","node_from","node_to"),
	FOREIGN KEY("required_by") REFERENCES ""
)');

$db->exec('CREATE TABLE "measurement_program_id_bits" (
	"value"	TEXT,
	"position"	INTEGER,
	"measurement_id"	INTEGER,
	UNIQUE("position","measurement_id"),
	FOREIGN KEY("measurement_id") REFERENCES ""
)');

$db->exec('CREATE TABLE "measurements" (
	"id"	INTEGER UNIQUE,
	"place_name"	TEXT,
	"comment"	TEXT,
	"timestamp"	INTEGER,
	PRIMARY KEY("id" AUTOINCREMENT),
	FOREIGN KEY("place_name") REFERENCES ""
)');

$db->exec('CREATE TABLE "nodes" (
	"plug_id"	INTEGER,
	"required_by"	INTEGER,
	"node_from"	INTEGER,
	"node_to"	INTEGER,
	UNIQUE("plug_id","required_by","node_from","node_to"),
	FOREIGN KEY("required_by") REFERENCES "bridges"("id")
)');

$db->exec('CREATE TABLE "places" (
	"plug_id"	INTEGER,
	"name"	TEXT UNIQUE,
	PRIMARY KEY("name"),
	FOREIGN KEY("plug_id") REFERENCES "plugs"("id")
)');

$db->exec('CREATE TABLE "plugs" (
	"id"	INTEGER UNIQUE,
	"name"	TEXT,
	"char_number"	INTEGER,
	PRIMARY KEY("id")
)');

$db->exec('CREATE TABLE "program_bridge_relation" (
	"program_id"	INTEGER,
	"bridge_id"	INTEGER,
	"plug_id"	INTEGER,
	UNIQUE("program_id","bridge_id","plug_id"),
	FOREIGN KEY("bridge_id") REFERENCES "bridges"("id"),
	FOREIGN KEY("plug_id") REFERENCES "plugs"("id"),
	FOREIGN KEY("program_id") REFERENCES "programs"("id")
)');

$db->exec('CREATE TABLE "program_id_bits" (
	"value"	TEXT,
	"position"	INTEGER,
	"program_id"	INTEGER,
	UNIQUE("position","program_id"),
	FOREIGN KEY("program_id") REFERENCES "programs"("id")
)');


$db->exec('CREATE TABLE "programs" (
	"id"	INTEGER UNIQUE,
	"plug_id"	INTEGER,
	"program_description"	TEXT,
	PRIMARY KEY("id"),
	FOREIGN KEY("plug_id") REFERENCES "plugs"("id")
)');

*/


$db->exec('DELETE FROM "places" WHERE 1');



?>
