DROP TABLE IF EXISTS Phases;
DROP TABLE IF EXISTS GeneralInfo;
DROP TABLE IF EXISTS Comments;
DROP TABLE IF EXISTS ranges;
DROP TABLE IF EXISTS Transactions;
DROP TABLE IF EXISTS DebugMessages;

CREATE TABLE Phases(
        ID INTEGER PRIMARY KEY,
        PhaseName TEXT,
        PhaseBegin INTEGER,
        PhaseEnd INTEGER,
        Transact INTEGER
);

CREATE TABLE GeneralInfo(
        NumberOfTransactions INTEGER, 
        TraceEnd INTEGER,
        NumberOfBanks INTEGER,
        Description TEXT, 
        clk INTEGER, 
        UnitOfTime TEXT
);


CREATE TABLE Comments(
        Time INTEGER,
        Text TEXT
);

CREATE TABLE DebugMessages(
        Time INTEGER,
        Message TEXT
);

-- use SQLITE R* TREE Module to make queries on timespans effecient (see http://www.sqlite.org/rtree.html)
CREATE VIRTUAL TABLE ranges USING rtree(
   id,              
   begin, end      
);

CREATE TABLE Transactions(
        ID INTEGER PRIMARY KEY,
        Range   INTEGER, 
        Address INTEGER,
        Burstlength INTEGER,
        TThread INTEGER,
        TChannel INTEGER,
        TBank INTEGER,
        TRow INTEGER,
        TColumn INTEGER,
        Command TEXT,
        DataStrobeBegin INTEGER,
        DataStrobeEnd INTEGER 
        );

CREATE INDEX ranges_index ON Transactions(Range);
CREATE INDEX "phasesTransactions" ON "Phases" ("Transact" ASC);
CREATE INDEX "messageTimes" ON "DebugMessages" ("Time" ASC)