private void ProcessColumn(ColumnInfo ci, DbDialect dd)
 {
     string nullDefine = ci.AllowNull ? dd.NullString : dd.NotNullString;
     _sql.Append("\n\t");
     _sql.Append(dd.QuoteForColumnName(ci.Key));
     _sql.Append(" ");
     if (ci.IsDbGenerate && dd.IdentityTypeString != null)
     {
         _sql.Append(dd.IdentityTypeString);
     }
     else
     {
         _sql.Append(dd.GetTypeName(ci));
     }
     if (ci.IsDbGenerate)
     {
         _sql.Append(" ").Append(dd.IdentityColumnString);
     }
     if (ci.IsKey)
     {
         ProcessKeyColumn(ci, dd, nullDefine);
     }
     else
     {
         _sql.Append(nullDefine);
     }
     _sql.Append(",");
 }
 protected override SqlStatement ToSqlStatement(DbDialect dd, List<string> queryRequiredFields)
 {
     var sb = new StringBuilder("ALTER TABLE ");
     sb.Append(dd.QuoteForTableName(_from.MainTableName));
     if(AddColumn != null)
     {
         sb.Append(" ADD ");
         sb.Append(dd.QuoteForColumnName(AddColumn.Key));
         sb.Append(" ");
         sb.Append(dd.GetTypeName(AddColumn));
         if(DefaultValue != null)
         {
             if (DefaultFirst)
             {
                 sb.Append(" DEFAULT(").Append(DefaultValue).Append(")");
                 sb.Append(AddColumn.AllowNull ? " NULL" : " NOT NULL");
             }
             else
             {
                 sb.Append(AddColumn.AllowNull ? " NULL" : " NOT NULL");
                 sb.Append(" DEFAULT(").Append(DefaultValue).Append(")");
             }
         }
         else
         {
             sb.Append(AddColumn.AllowNull ? " NULL" : " NOT NULL");
         }
         sb.Append(";");
     }
     return new SqlStatement(sb.ToString());
 }
예제 #3
0
 protected override string GetValueString(DataParameterCollection dpc, DbDialect dd, KeyValue kv)
 {
     if(kv.Value == null)
     {
         return "NULL";
     }
     return dd.QuoteForColumnName((string)kv.Value);
 }
 private void ProcessForeignKeys(DbDialect dd)
 {
     if(!DataSettings.UsingForeignKey)
     {
         return;
     }
     foreach (ColumnInfo ci in Columns)
     {
         if(ci.IsForeignKey)
         {
             _sql.Append("\n\tFOREIGN KEY(");
             _sql.Append(dd.QuoteForColumnName(ci.Key));
             _sql.Append(") REFERENCES ");
             _sql.Append(dd.QuoteForTableName(ci.BelongsToTableName));
             _sql.Append(" ([Id]) ,");
         }
     }
 }
예제 #5
0
 public override string ToSqlText(DataParameterCollection dpc, DbDialect dd, List<string> queryRequiredFields)
 {
     if (queryRequiredFields != null && dpc.FindQueryRequiedFieldOrId == false)
     {
         if(_column == "Id" || queryRequiredFields.Contains(_column))
         {
             dpc.FindQueryRequiedFieldOrId = true;
         }
     }
     var sb = new StringBuilder();
     sb.Append(dd.QuoteForColumnName(_column));
     if (_notIn)
     {
         sb.Append(" NOT");
     }
     sb.Append(" IN (");
     if(_args.Length == 1 && _args[0].GetType() == typeof(SqlStatement))
     {
         sb.Append(((SqlStatement)_args[0]).SqlCommandText);
     }
     else if (_args.Length == 1 && _args[0].GetType() == typeof(SelectStatementBuilder))
     {
         sb.Append(((SelectStatementBuilder)_args[0]).ToSqlText(dpc, dd, queryRequiredFields));
     }
     else
     {
         foreach (var o in _args)
         {
             var v = GetValueString(dpc, dd, new KeyValue("in", o));
             sb.Append(v);
             sb.Append(",");
         }
         if (_args.Length > 0)
         {
             sb.Length--;
         }
     }
     sb.Append(")");
     return sb.ToString();
 }
예제 #6
0
 public override string ToSqlText(DataParameterCollection dpc, DbDialect dd, List<string> queryRequiredFields)
 {
     if (queryRequiredFields != null && dpc.FindQueryRequiedFieldOrId == false)
     {
         if (KV.Key == "Id" || queryRequiredFields.Contains(KV.Key))
         {
             dpc.FindQueryRequiedFieldOrId = true;
         }
     }
     string dpStr = GetValueString(dpc, dd, KV);
     string dkStr = dd.QuoteForColumnName(KV.Key);
     switch (function)
     {
         case ColumnFunction.ToLower:
             dkStr = string.Format("LOWER({0})", dkStr);
             break;
         case ColumnFunction.ToUpper:
             dkStr = string.Format("UPPER({0})", dkStr);
             break;
     }
     return string.Format("{0} {2} {1}", dkStr, dpStr, Comp);
 }
 private void AddCreateIndexStatement(StringBuilder sb, DbDialect dd)
 {
     string prefix = "IX_" + TableName.Replace('.', '_') + "_";
     foreach (DbIndex i in Indexes)
     {
         string n = prefix;
         n += i.IndexName ?? i.Columns[0].Key;
         string gn = dd.GenIndexName(n);
         if(gn != null)
         {
             n = "IX_" + gn; 
         }
         sb.Append(i.Unique ? "CREATE UNIQUE " : "CREATE ");
         if (!dd.SupportDirctionOfEachColumnInIndex)
         {
             if (i.Columns[0] is DESC)
             {
                 sb.Append("DESC ");
             }
         }
         sb.Append("INDEX ");
         sb.Append(dd.QuoteForColumnName(n));
         sb.Append(" ON ");
         sb.Append(dd.QuoteForLimitTableName(TableName));
         sb.Append(" (");
         foreach (ASC c in i.Columns)
         {
             sb.Append(dd.SupportDirctionOfEachColumnInIndex ? c.ToString(dd) : dd.QuoteForColumnName(c.Key));
             sb.Append(", ");
         }
         if (i.Columns.Length > 0)
         {
             sb.Length -= 2;
         }
         sb.Append(");\n");
     }
 }
 private void CheckIsMutiKey(DbDialect dd)
 {
     int n = 0;
     foreach (ColumnInfo ci in Columns)
     {
         if (ci.IsKey)
         {
             n++;
             _keys += dd.QuoteForColumnName(ci.Key) + ", ";
         }
     }
     _isMutiKey = n > 1;
 }
예제 #9
0
 private string GetFunctionArgs(DbDialect dd)
 {
     var ret = new StringBuilder();
     foreach (string s in GroupbyArgs)
     {
         ret.Append(dd.QuoteForColumnName(s));
         ret.Append(",");
     }
     if (ret.Length > 1)
     {
         ret.Length--;
     }
     return ret.ToString();
 }
예제 #10
0
	    private static void AddColumn(DbDialect dd, StringBuilder columns, bool includeOrigin, bool includeAlias, KeyValuePair<string, string> k)
	    {
	        if (includeOrigin)
	        {
	            columns.Append(dd.QuoteForColumnName(k.Key));
	            if (includeAlias && k.Value != null) { columns.Append(" AS "); }
	        }
	        if (includeAlias)
	        {
	            if (k.Value != null)
	            {
	                columns.Append(dd.QuoteForColumnName(k.Value));
	            }
	            else if (!includeOrigin)
	            {
	                columns.Append(dd.QuoteForColumnName(k.Key));
	            }
	        }
	        columns.Append(",");
	    }
예제 #11
0
        internal string GetColumns(DbDialect dd, bool includeOrigin, bool includeAlias)
		{
			var columns = new StringBuilder();
            if(IsDistinct)
            {
                columns.Append("DISTINCT ");
            }
			foreach ( var k in _keys )
			{
                AddColumn(dd, columns, includeOrigin, includeAlias, k);
			}
            //if(IsGroupBy)
            //{
            //    if (GroupbyArgs.Count != 0)
            //    {
            //        if (GroupbyArgs[0] == "*" || GroupbyArgs.Count > 1)
            //        {
            //        }
            //        else
            //        {
            //            string fa = GroupbyArgs[0];
            //            string fn = fa.StartsWith("DISTINCT ") ? fa : dd.QuoteForColumnName(fa);
            //            string gfn = FunctionName == "COUNT" ? DbEntry.CountColumn : fn;
            //            columns.Append("(")
            //                .Append(fn)
            //                .Append(") AS ").Append(gfn).Append(",");
            //        }
            //    }
            //}
            if (FunctionArgs.Count != 0)
            {
                columns.Append(FunctionName);
                if (FunctionArgs[0] == "*" || FunctionArgs.Count > 1)
                {
                    columns.Append("(*) AS ").Append(DbEntry.CountColumn).Append(",");
                }
                else
                {
                    string fa = FunctionArgs[0];
                    string fn = fa.StartsWith("DISTINCT ") ? fa : dd.QuoteForColumnName(fa);
                    string gfn = FunctionName == "COUNT" ? DbEntry.CountColumn : fn;
                    columns.Append("(")
                        .Append(fn)
                        .Append(") AS ").Append(gfn).Append(",");
                }
            }
            if (columns.Length > 0)
            {
                columns.Length--;
            }
            return columns.ToString();
		}