Exemplo n.º 1
0
        public bool Open()
        {
            if (!_accessor.Open())
            {
                return(false);
            }
            if (_accessor.IsTableExists("Channels") == false)
            {
                string cmd;

                cmd  = "CREATE TABLE Channels (";
                cmd += "PluginId VARCHAR(255), ";
                cmd += "ChannelName VARCHAR(255), ";
                cmd += "Time DATETIME, ";
                cmd += "Value VARCHAR(255), ";
                cmd += "Status SMALLINT";
                cmd += ");";
                _accessor.ExeсCommand(cmd);

                _accessor.ExeсCommand("CREATE INDEX IF NOT EXISTS ChIndex ON Channels (Time);");
                _accessor.ExeсCommand("CREATE TRIGGER fifo_limit_channels after insert on channels\n"
                                      + "WHEN 100<(SELECT Count() FROM channels WHERE time<= datetime('now','localtime','-45 day'))"
                                      + "BEGIN\n"
                                      + "DELETE FROM channels WHERE Time<= datetime('now','localtime','-45 day');"
                                      + "END;"
                                      );
                // _accessor.ExeсCommand("PRAGMA max_page_count = 300000");
            }
            if (_accessor.IsTableExists("Events") == false)
            {
                string cmd;
                cmd  = "CREATE TABLE Events (";
                cmd += "EventID INT, ";
                cmd += "Text VARCHAR(255), ";
                cmd += "Time DATETIME, ";
                cmd += "Cause SMALLINT";
                cmd += ");";
                _accessor.ExeсCommand(cmd);

                _accessor.ExeсCommand("CREATE INDEX IF NOT EXISTS EvIndex ON Events (Time);");
                _accessor.ExeсCommand("CREATE TRIGGER fifo_limit_events after insert on events\n"
                                      + "WHEN 100<(SELECT Count() FROM channels WHERE time<= datetime('now','localtime','-45 day'))"
                                      + "BEGIN\n"
                                      + "DELETE FROM events WHERE Time<= datetime('now','localtime','-45 day');"
                                      + "END;"
                                      );
            }
            _accessor.ExeсCommand("PRAGMA journal_mode=off");
            return(true);
        }
Exemplo n.º 2
0
 public bool Open()
 {
     dbReader = new DbAccessor(_archiver.DatabaseSettings);
     return(dbReader.Open());
 }