Exemple #1
0
        public string UpdateOneSql(XModel setsModel)
        {
            _CheckKeyField();
            string sets = setsModel.SetsListString();

            if (string.IsNullOrEmpty(sets))
            {
                return(null);
            }
            else
            {
                return("Update " + this.TableName + " set " + sets + GetKeyConditionString(true, setsModel));
            }
        }
Exemple #2
0
        ///**************************************************************
        public int SaveToDb(XModel updateModel)
        {
            _CheckKeyField();
            string sets       = updateModel.SetsListString();
            string fieldLists = updateModel.FieldsListStringForInsert(false);
            string valueLists = updateModel.ValuesListStringForInsert(false);
            //string whereStr=updateModel.DefaultConditionString(this.KeyField);
            string whereStr = GetKeyConditionString(false, updateModel);
            //if (string.IsNullOrEmpty(sets))
            //{
            //    return 0;
            //}
            string sSql_Exists = "Select * from  " + this.TableName + " where " + whereStr;
            string sSql_Update = String.IsNullOrEmpty(sets) ? "Select 1;" : "Update " + this.TableName + " set " + sets + " where " + whereStr + ";";
            string sSql_Insert = String.IsNullOrEmpty(fieldLists) || String.IsNullOrEmpty(valueLists) ? "Select 1;" : "Insert into " + this.TableName + "(" + fieldLists + ") values(" + valueLists + ");";
            string sSql        = String.Format("if exists({0}) {1} else {2}", sSql_Exists, sSql_Update, sSql_Insert);
            int    iR          = 0;

            ULCode.QDA.ProviderType ct = XSql.GetDB(this.CnName).GetProviderType();
            if (ct == ProviderType.MsSql)
            {
                iR = this.Execute(sSql);
            }
            else// if (ct == ProviderType.OleDb)
            {
                if (XSql.IsHasRow(this.CnName, sSql_Exists))
                {
                    iR = this.Execute(sSql_Update);
                }
                else
                {
                    iR = this.Execute(sSql_Insert);
                }
            }
            if (iR > 0)
            {
                updateModel.ClearAllUpdated();
            }
            return(iR);
        }