protected override void InternalExecute(DataFileBase datafile)
            {
                switch (this.cmd)
                {
                case TransactionCommands.Begin:
                    datafile.Transaction = this.conn.BeginTransaction();
                    break;

                case TransactionCommands.Commit:
                    if (datafile.Transaction != null)
                    {
                        datafile.Transaction.Commit();
                        datafile.Transaction = null;
                    }
                    break;

                case TransactionCommands.Rollback:
                    if (datafile.Transaction != null)
                    {
                        datafile.Transaction.Rollback();
                        datafile.Transaction = null;
                    }
                    break;
                }
            }
        protected override void InternalExecute(DataFileBase datafile)
        {
            DateTime start = DateTime.Now;

            //PIPS.Logger.WriteLine(false, "DataFileBase.Initialize({0})", datafile.FileName);
            this.conn = this.ConnectForce(datafile, dir);
            //PIPS.Logger.WriteLine(false, "DataFileBase.Initialize.Complete({0}, {1})", datafile.FileName, (DateTime.Now - start).TotalMilliseconds);
        }
 public void Execute(DataFileBase datafile)
 {
     try
     {
         this.InternalExecute(datafile);
     }
     finally
     {
         if (this.trigger != null)
         {
             this.trigger.Set();
         }
         if (this.dispose)
         {
             this.Dispose();
         }
     }
 }
        private SQLiteConnection ConnectForce(DataFileBase file, string direc)
        {
            string           filename = direc + @"\" + file.FileName + ".db";
            SQLiteConnection c        = this.Connect(filename, file.SQLiteVersion);

            if (c == null)
            {
                try
                {
                    if (File.Exists(filename))
                    {
                        File.Delete(filename);
                    }
                }
                catch (Exception ex)
                {
                    //PIPS.Logger.Exception(ex);
                }
                c = this.Connect(filename, file.SQLiteVersion);
            }
            return(c);
        }
예제 #5
0
 public bool Contains(DataFileBase value)
 {
     return(List.Contains(value));
 }
예제 #6
0
 public void Remove(DataFileBase value)
 {
     List.Remove(value);
 }
예제 #7
0
 public void Insert(int index, DataFileBase value)
 {
     List.Insert(index, value);
 }
예제 #8
0
 public int IndexOf(DataFileBase value)
 {
     return(List.IndexOf(value));
 }
예제 #9
0
 public int Add(DataFileBase value)
 {
     return(List.Add(value));
 }
        /// <summary>
        /// sqlite commands which build the sql table
        /// </summary>
        /// <param name="dataFileBase"></param>
        protected void createTable(DataFileBase dataFileBase)
        {
            if (_isOpen)
            {
                return;
            }
            _file = dataFileBase;
            var bld = new StringBuilder();

            if (!TableExists)
            {
                bld.Append("create table ").Append(Name).Append("(id integer primary key");
                foreach (DataColumn col in _columns)
                {
                    bld.Append(", ").Append(col.Name).Append(" ").Append(col.Type);
                }
                bld.Append(")");
                //cmd.CommandText = bld.ToString();
                using (DataCommandBase dcb = new NullDataCommand(bld.ToString()))
                {
                    _file.AddCommand(dcb);
                    dcb.Wait();
                }

                //Logger.WriteLine("DataTableBase.CreatedTable({0})", Name);
                if (IndexColumn >= 0)
                {
                    string cmdText = string.Format("create index i_{0} on {0}({1})", Name, _columns[IndexColumn].Name);
                    using (DataCommandBase dcb = new NullDataCommand(cmdText))
                    {
                        _file.AddCommand(dcb);
                        dcb.Wait();
                    }
                    //Logger.WriteLine("DataTableBase.CreatedIndex({0}, {1})", Name, _columns[IndexColumn].Name);
                }

                //add the maneual entry default here to hotlists.db because the zero folder does not get added.
                if (Name == "t_hotlists")
                {
                    var cmdText =
                        "insert into t_hotlists (name, priority, timestamp, color, covert, alarm, active, file, whitelist, bossid, sound) " +
                        "values ('Manual Reports',500, " + DateTime.Now.Ticks + ", -16776961,'False','MED','True','','False','','')";
                    using (DataCommandBase dcb = new NullDataCommand(cmdText))
                    {
                        _file.AddCommand(dcb);
                        dcb.Wait();
                    }
                }
            }
            //adds unique constraint on hotlist tables
            if (Name == "t_hotlist")
            {
                /////////**************///////////
                /// this is here to check the file dir is equal to 1 so we do not add the Unique Index to the Manual Entry data file.
                var f = _file as HotLists.HotListDataFile;
                if (f != null)
                {
                    var path      = f.Dir;
                    var folderNum = path.Substring(path.LastIndexOf('\\'));

                    var    ini  = new IniFile(Environment.CurrentDirectory + @"\Synchronizer.ini");
                    string type = ini.ReadString("Synchronizer", "Type", "BOF2").ToUpper();
                    if (folderNum != "\\0")
                    {
                        if (folderNum != "\\1" && type != "BOF2")
                        //excluding uniqueness because InStation does not have a BOSS ID
                        {
                            try
                            {
                                string cmdText = string.Format("create unique index iu_{0} on {0} (", Name);
                                cmdText += string.Format("{0} asc", Columns[8].Name);
                                cmdText += string.Format(")");
                                using (DataCommandBase dcb = new NullDataCommand(cmdText))
                                {
                                    _file.AddCommand(dcb);
                                    dcb.Wait();
                                }
                                //Logger.WriteLine("DataTableBase.CreatedUniqueIndex({0})", Name);
                            }
                            catch (Exception ex)
                            {
                                //Logger.WriteLine("Data Table {0} already has Unique Index", Name);
                            }
                        }
                        ////////*****************///////////
                    }
                }
            }

            //this.lastId = this.GetLastId();
            foreach (DataTableBase table in _linkedTables)
            {
                table.Initialize(DataFile);
            }

            _isOpen    = true;
            count      = IsCountInitialized ? GetCount(null) : 0;
            bld.Length = 0;
            bld.Append("insert into ");
            bld.Append(Name).Append(" (");

            if (Columns.Count > 0)
            {
                bld.Append(Columns[0].Name);
            }

            for (int i = 1; i < Columns.Count; i++)
            {
                bld.Append(", ").Append(Columns[i].Name);
            }

            bld.Append(") values (");
            if (Columns.Count > 0)
            {
                bld.Append("?");
            }

            for (int i = 1; i < Columns.Count; i++)
            {
                bld.Append(", ?");
            }

            bld.Append(")");
            _insertCommand = bld.ToString();

            OnInitialized();
        }
 public virtual void Initialize(DataFileBase dataFileBase)
 {
     createTable(dataFileBase);
 }
 protected abstract void InternalExecute(DataFileBase datafile);
예제 #13
0
        protected override void InternalExecute(DataFileBase datafile)
        {
            SQLiteCommand cmd = datafile.GetCommand(cmdText, parameters);

            this.InternalExecute(cmd);
        }