Exemple #1
0
        private string InternalPrepareQueryText(DatabaseEngineType dbtype)
        {
            var result = new StringBuilder();

            result.Append(DatabaseExtensions.GetCallCommandPrefix(CommandType, dbtype));
            result.Append(" ");
            AppendQuotedName(dbtype, result);
            result.Append(" ");

            var writeBraces = DatabaseExtensions.IsRequireBracesToCall(dbtype);

            if (writeBraces)
            {
                result.Append("( ");
            }
            if (null != _paramdict)
            {
                WriteParameters(dbtype, result);
            }
            if (writeBraces)
            {
                result.Append(" )");
            }
            return(result.ToString());
        }
Exemple #2
0
        private void WriteParameters(DatabaseEngineType dbtype, StringBuilder result)
        {
            var  writeAssigns = DatabaseExtensions.IsSupportNamedParameters(dbtype);
            var  innerPrefix  = DatabaseExtensions.GetPrefixOfInnerParameter(dbtype);
            var  outerPrefix  = DatabaseExtensions.GetPrefixOfOuterParameter(dbtype);
            var  assignSymbol = DatabaseExtensions.GetAssignOperator(dbtype);
            bool first        = true;

            foreach (var pair in _paramdict)
            {
                if (!first)
                {
                    result.Append(", ");
                }
                first = false;
                if (writeAssigns)
                {
                    result.Append(innerPrefix);
                    result.Append(pair.Key);
                    result.Append(" ");
                    result.Append(assignSymbol);
                    result.Append(" ");
                }
                var item = pair.Value;
                if (null == item || item is DBNull)
                {
                    result.Append("null");
                }
                if (item is string)
                {
                    var stritem = item as string;
                    if (stritem.StartsWith("~"))
                    {
                        result.Append(outerPrefix);
                        result.Append(stritem.Substring(1));
                    }
                    else
                    {
                        result.Append("'" + stritem.Replace("'", "''") + "'");
                    }
                }
                else
                {
                    var anyitem = item.ToString();
                    if (!Regex.IsMatch(anyitem, @"^[\w\d\.]+$", RegexOptions.Compiled))
                    {
                        anyitem = "'" + anyitem.Replace("'", "''") + "'";
                    }
                    result.Append(anyitem);
                }
            }
        }
Exemple #3
0
 private void AppendQuotedName(DatabaseEngineType dbtype, StringBuilder result)
 {
     if (!string.IsNullOrWhiteSpace(Schema))
     {
         if (dbtype == DatabaseEngineType.MySql)
         {
             result.Append(DatabaseExtensions.QuoteIdentifier(Schema + "_" + Name, dbtype));
         }
         else
         {
             result.Append(DatabaseExtensions.QuoteIdentifier(Schema, dbtype));
             result.Append(".");
             result.Append(DatabaseExtensions.QuoteIdentifier(Name, dbtype));
         }
     }
     else
     {
         result.Append(DatabaseExtensions.QuoteIdentifier(Name, dbtype));
     }
 }