예제 #1
0
        public static bool Delete(OracleConnection connection, object obj)
        {
            Type          type   = obj.GetType();
            StringBuilder strSql = new StringBuilder();

            try
            {
                strSql.Append(string.Format("delete from {0}", DBAttribute.GetDBTable(type)));
            }
            catch (ArgumentException e)
            {
                throw new ArgumentException(e.Message);
                //   throw new ArgumentException("Invaild Argument!\n\n from Delete(OracleConnection connection, object obj) \n");
            }
            List <string> propertyPrimaryKeyList   = new List <string>();
            List <string> propertyPrimaryValueList = new List <string>();

            DBAttribute.GetDBPrimaryElement(type, obj, propertyPrimaryKeyList, propertyPrimaryValueList);
            if (!(propertyPrimaryKeyList.Any() && propertyPrimaryValueList.Any()))
            {
                throw new ArgumentException("Invaild Argument!\n\n from Delete(OracleConnection connection, object obj) \n");
            }
            strSql.Append(string.Format(" where "));
            for (int i = 0; i < propertyPrimaryKeyList.Count; ++i)
            {
                strSql.Append(string.Format(" {0}={1} AND", propertyPrimaryKeyList[i], propertyPrimaryValueList[i]));
            }
            strSql.Length -= 3;
            return(ExecuteSql(connection, strSql.ToString()) > 0);
        }
예제 #2
0
        public static bool Update(OracleConnection connection, object obj)
        {
            //不允许更改主码
            StringBuilder strSql = new StringBuilder();
            List <string> key = new List <string>(), pri = new List <string>();
            Dictionary <string, OracleParameter> opd = GetDBMember(obj, key, pri);
            List <OracleParameter> op = new List <OracleParameter>();

            strSql.Append(string.Format("update {0} set ", DBAttribute.GetDBTable(obj.GetType())));
            for (int i = 0; i < key.Count(); ++i)
            {
                strSql.Append(string.Format(" {0} = :{0} ,", key[i]));
                op.Add(opd[key[i]]);
            }
            --strSql.Length;
            strSql.Append(" where ");
            for (int i = 0; i < pri.Count(); ++i)
            {
                strSql.Append(string.Format(" {0} = :{0} AND", pri[i]));
                op.Add(opd[pri[i]]);
            }
            strSql.Length -= 3;

            return(ExecuteSql(connection, strSql.ToString(), op.ToArray()) > 0);
        }
        public static bool exist(Type type, List <string> key, List <string> val)
        {
            OracleConnection conn = pool.fetchConnection();
            StringBuilder    sb   = new StringBuilder();

            sb.Append(string.Format("select * from {0} where ", DBAttribute.GetDBTable(type)));
            int len = key.Count();

            for (int i = 0; i < len; ++i)
            {
                if (i != 0)
                {
                    sb.Append(" AND ");
                }
                sb.Append($"{key[i]}='{val[i]}'");
            }
            bool res = OracleHelper.Exists(conn, sb.ToString());

            pool.releaseConnection(conn);
            return(res);
        }