Example #1
0
        private void UpdateLastId(long lastId, DBAdapter.IDBAdapter dbAdapter)
        {
            string sql = string.Format("update {0} set id = {1} where Opr = 'Insert'",
                                       _DBProvider.Table.TriggerTableName, lastId);

            dbAdapter.ExcuteSql(sql);
        }
Example #2
0
        private long GetLastId(int lastDocId, DBAdapter.IDBAdapter dbAdapter)
        {
            if ((_Flags & SyncFlags.Rebuild) != 0)
            {
                //Rebuild
                return(long.MaxValue);
            }

            string sql = string.Format("select id from {0} where Opr = 'Insert'",
                                       _DBProvider.Table.TriggerTableName);

            System.Data.DataSet ds = dbAdapter.QuerySql(sql);

            if (ds.Tables[0].Rows.Count <= 0)
            {
                long from = -1;

                while (lastDocId > 0)
                {
                    from = _DBProvider.GetDocIdReplaceFieldValue(lastDocId);

                    if (from != long.MaxValue)
                    {
                        break;
                    }

                    lastDocId--;
                }

                if (from < 0)
                {
                    from = _DBProvider.GetDocIdReplaceFieldValue(lastDocId);
                }

                if (from == long.MaxValue)
                {
                    sql = string.Format("insert into {0} (id, Opr, Fields) values(-1, 'Insert', '')",
                                        _DBProvider.Table.TriggerTableName);
                }
                else
                {
                    sql = string.Format("insert into {0} (id, Opr, Fields) values({1}, 'Insert', '')",
                                        _DBProvider.Table.TriggerTableName, from);
                }
                dbAdapter.ExcuteSql(sql);
                return(from);
            }
            else
            {
                long lastId = long.Parse(ds.Tables[0].Rows[0][0].ToString());

                if (lastId < 0)
                {
                    return(long.MaxValue);
                }
                else
                {
                    return(lastId);
                }
            }
        }