Exemple #1
0
        /// <summary>
        /// Update record in the table
        /// </summary>
        public void Update()
        {
            XVar tableinfo   = GlobalVars.dal_info[this.m_infoKey];
            XVar updateParam = "";
            XVar updateValue = "";
            XVar blobs       = XVar.Array();

            foreach (var f in tableinfo.GetEnumerator())
            {
                var fieldInfo = this.GetType().GetField(f.Value["varname"]);
                if (fieldInfo != null && fieldInfo.GetValue(this) != null)
                {
                    if (f.Value["key"] != null)
                    {
                        this.Param[f.Value["varname"]] = fieldInfo.GetValue(this);
                    }
                    else
                    {
                        this.Value[f.Value["varname"]] = fieldInfo.GetValue(this);
                    }
                }
                if (f.Value["key"] == null && !MVCFunctions.array_change_key_case(this.Param, Constants.CASE_UPPER).KeyExists(MVCFunctions.strtoupper(f.Key)))
                {
                    foreach (var fieldValue in this.Value.GetEnumerator())
                    {
                        if (MVCFunctions.strtoupper(fieldValue.Key) != MVCFunctions.strtoupper(f.Key))
                        {
                            continue;
                        }
                        updateValue = MVCFunctions.Concat(updateValue, _connection.addFieldWrappers(f.Key), "=", this.PrepareValue(fieldValue.Value, f.Value["type"]), ", ");

                        if (_connection.dbType == Constants.nDATABASE_Oracle)
                        {
                            if (CommonFunctions.IsBinaryType(f.Value["type"]))
                            {
                                blobs[f.Key] = fieldValue.Value;
                            }
                        }
                        break;
                    }
                }
                else
                {
                    foreach (var fieldValue in this.Param.GetEnumerator())
                    {
                        if (MVCFunctions.strtoupper(fieldValue.Key) != MVCFunctions.strtoupper(f.Key))
                        {
                            continue;
                        }
                        updateParam = MVCFunctions.Concat(updateParam, _connection.addFieldWrappers(f.Key), "=", this.PrepareValue(fieldValue.Value, f.Value["type"]), " and ");
                        break;
                    }
                }
            }

            //	construct SQL and do update
            if (updateParam)
            {
                updateParam = MVCFunctions.substr(updateParam, 0, -5);
            }
            if (updateValue)
            {
                updateValue = MVCFunctions.substr(updateValue, 0, -2);
            }
            if (updateValue && updateParam)
            {
                XVar dalSQL = MVCFunctions.Concat("update ", _connection.addTableWrappers(this.m_TableName), " set ", updateValue, " where ", updateParam);
                this.Execute_Query(blobs, dalSQL, tableinfo);
            }

            //	cleanup
            this.Reset();
        }