Beispiel #1
0
        private int getLastID(TableItem item)
        {
            var currentID     = item.lastID;
            var realTableName = item.plusItem ? ("trigger4" + item.tableName) : item.tableName;

            object obj = this.dbConn.scalar(
                string.Format("select ident_current('{0}')", realTableName));

            if (obj != null)
            {
                currentID = int.Parse(obj.ToString());
            }

            return(currentID);
        }
Beispiel #2
0
        private bool getRecords(TableItem item, int maxSize = 50)
        {
            var currentID     = getLastID(item);
            var realTableName = item.plusItem ? ("trigger4" + item.tableName) : item.tableName;

            if (item.lastID < currentID)
            {
                this.log("Detect changes in table " + item.tableName);
                this.localTable = this.dbConn.getTable(realTableName);

                string sql = string.Format("select top {0} * from {1} where {2}>{3}",
                                           maxSize, realTableName, item.identColumn, item.lastID);
                SqlDataAdapter adapter = this.dbConn.select(sql);
                adapter.Fill(this.localTable);
                adapter.Dispose();

                var rows = this.localTable.Rows.Count;
                this.log("Get " + rows + " records.");

                // 更新lastID
                if (rows == 0)
                {
                    item.lastID = currentID;
                    return(false);
                }

                return(true);
            }
            else
            {
                if (item.backoffCycle > 16)
                {
                    item.backoffTime  = 0;
                    item.backoffCycle = 2;
                }
                else
                {
                    item.backoffTime   = item.backoffCycle;
                    item.backoffCycle *= 2;
                }
                return(false);
            }
        }