Example #1
0
        /// <summary>
        /// insert profile data
        /// </summary>
        /// <param name="model">insert data</param>
        /// <returns>row id</returns>
        internal long Insert(ProfileModel model)
        {
            var sql = new SqlBuilder();

            sql.AppendSql("INSERT INTO profiles")
            .AppendSql("(")
            .AppendSql(" file_path")
            .AppendSql(",display_name")
            .AppendSql(",row_order")
            .AppendSql(")")
            .AppendSql("VALUES")
            .AppendSql("(")
            .AppendSql(" @file_path")
            .AppendSql(",@display_name")
            .AppendSql(",@row_order")
            .AppendSql(")");
            var paramList = new ParameterList();

            paramList.Add("@file_path", model.FilePath);
            paramList.Add("@display_name", model.DisplayName);
            paramList.Add("@row_order", model.RowOrder);

            var id = -1L;

            using (var database = new SystemDatabase()) {
                database.Open();
                id = database.Insert(sql, paramList);
            }
            return(id);
        }
Example #2
0
        /// <summary>
        /// delete by id
        /// </summary>
        /// <param name="id">id</param>
        /// <returns>delete record count</returns>
        internal int DeleteById(long id)
        {
            var sql = new SqlBuilder();

            sql.AppendSql("DELETE FROM profiles")
            .AppendSql("WHERE id = @id");
            var paramList = new ParameterList();

            paramList.Add("@id", id);
            var count = 0;

            using (var database = new SystemDatabase()) {
                database.Open();
                count = database.ExecuteNonQuery(sql, paramList);
            }
            return(count);
        }
Example #3
0
        /// <summary>
        /// update display name by id
        /// </summary>
        /// <param name="model">profile model</param>
        /// <returns>affected record count</returns>
        internal int UpdateDisplayNameById(ProfileModel model)
        {
            var sql = new SqlBuilder();

            sql.AppendSql("UPDATE profiles SET")
            .AppendSql(" display_name = @display_name")
            .AppendSql("WHERE id = @id");
            var paramList = new ParameterList();

            paramList.Add("@display_name", model.DisplayName)
            .Add("@id", model.Id);
            var count = 0;

            using (var database = new SystemDatabase()) {
                database.Open();
                count = database.ExecuteNonQuery(sql, paramList);
            }
            return(count);
        }
Example #4
0
        /// <summary>
        /// get record count by filePath
        /// </summary>
        /// <param name="filePath">file path</param>
        /// <returns>count of record</returns>
        internal int SelectCountByFilePath(string filePath)
        {
            int count = 0;
            var sql   = new SqlBuilder();

            sql.AppendSql(" SELECT COUNT(id) FROM profiles")
            .AppendSql("WHERE file_path = @file_path");
            var paramList = new ParameterList();

            paramList.Add("@file_path", filePath);
            using (var database = new SystemDatabase()) {
                database.Open();
                using (var record = database.OpenRecordset(sql, paramList)) {
                    if (record.Read())
                    {
                        count = record.GetInt(0);
                    }
                }
            }
            return(count);
        }
Example #5
0
        /// <summary>
        /// select id by file path
        /// </summary>
        /// <param name="filePath">file path</param>
        /// <returns>profile id</returns>
        internal int SelectIdByFilePath(string filePath)
        {
            var sql = new SqlBuilder();

            sql.AppendSql(" SELECT id FROM profiles")
            .AppendSql("WHERE file_path = @file_path");
            var paramList = new ParameterList();

            paramList.Add("@file_path", filePath);
            int id = -1;

            using (var database = new SystemDatabase()) {
                database.Open();
                using (var record = database.OpenRecordset(sql, paramList)) {
                    if (record.Read())
                    {
                        id = record.GetInt("id");
                    }
                }
            }
            return(id);
        }