Beispiel #1
2
        public static string CreateInsert(SimpleConfig config)
        {
            StringBuilder sb = new StringBuilder();
            sb.AppendLine("INSERT INTO " + config.TableName);

            sb.AppendLine(" ( ");
            IList<DBField> fieldList = config.Fields;

            bool hasAutoIncrementPk = config.HasAutoIncrementPK();

            sb.Append(FieldsToStringForInsert(fieldList, false));
            sb.AppendLine(" ) VALUES ( ");

            if (!config.hasPK()) {
                throw new SimpleBeanException(config.Type.Name + " dont has a Pk Configured");
            }

            sb.Append(FieldsToStringForInsert(fieldList, true));

            sb.AppendLine(")");

            if (hasAutoIncrementPk) {
                sb.Append("  SET @GeneratedID = SCOPE_IDENTITY()");
            }
            return sb.ToString();
        }
Beispiel #2
0
        /// <summary>
        /// Create  a SQL Update Statement 
        /// 
        /// </summary>
        /// <param name="config">SimpleConfig  used to generate a SQL String</param>
        /// <returns></returns>
        public static string CreateUpdate(SimpleConfig config)
        {
            StringBuilder sb = new StringBuilder();
            sb.AppendLine("UPDATE " + config.TableName);

            sb.AppendLine(" SET ");
            IList<DBField> fieldList = config.Fields;

            int count = 0;

            sb.Append(FieldsToStringForUpdate(fieldList));

            sb.AppendLine(" WHERE     ");
            if (!config.hasPK())
                throw new SimpleBeanException(config.Type.Name + " dont has a Pk Configured");

            IList<DBField> pkList = config.PKS;

            count = 0;

            foreach (DBField pk in pkList) {
                if (count > 0)
                    sb.Append(" AND ");
                sb.Append(pk.getDbName()).Append(" = ").Append("@" + pk.getDbName());
                count++;
            }

            return sb.ToString();
        }