示例#1
0
文件: Model.cs 项目: qrakhen/struqt
        /// <summary>
        /// Updates the existing entry within the table using the primaryField
        /// </summary>
        protected virtual void update(bool overwritePrimaryKey = false)
        {
            var q = new Query.Update(__tbl, new Where.Equals(__pkyc, this[__pkyn]));

            foreach (var field in __def.fields.Values)
            {
                if (field.primary && !overwritePrimaryKey)
                {
                    continue;
                }
                q.addValue(field.column, RowWriter.write(field.type, this[field.name]));
            }
            __db.exec(q);
        }
示例#2
0
文件: Model.cs 项目: qrakhen/struqt
        /// <summary>
        /// Inserts this object's data into the table as a new row.
        /// </summary>
        protected virtual void insert()
        {
            var q = new Query.Insert(__tbl);

            q.output(__pkyc);
            foreach (var field in __def.fields.Values)
            {
                if (field.primary)
                {
                    continue;
                }
                q.addValue(field.column, RowWriter.write(field.type, this[field.name]));
            }
            var r = __db.scalar(q);

            this[__pkyn] = r;
        }