Esempio n. 1
0
        public string InsertSql(XModel insertModel)
        {
            string f1 = insertModel.FieldsListStringForInsert(false);
            string f2 = insertModel.ValuesListStringForInsert(false);

            if (String.IsNullOrEmpty(f1) || String.IsNullOrEmpty(f2))
            {
                return(null);
            }
            else
            {
                return("Insert into " + this.TableName + "(" + f1 + ") values(" + f2 + ")");
            }
        }
Esempio n. 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);
        }