示例#1
0
        private void AddColumnTo(CreateTableSQLCommand table, string columnName, DbType type, int size, byte precision, byte scale, bool isNotNull, object defaultValue)
        {
            SqlObjectModel.LDD.ColumnConstraint constraint = null;
            if (defaultValue != null)
                constraint = new SqlObjectModel.LDD.DefaultConstraint(new Constant(defaultValue, type), !isNotNull);
            else
                constraint = new SqlObjectModel.LDD.ColumnConstraint(!isNotNull);

            if (!table.ColumnDefinitions.Contains(columnName))
            {

                ColumnDefinition column = new ColumnDefinition(columnName, type, size, precision, scale, constraint);
                table.ColumnDefinitions.Add(columnName, column);
            }
            else
            {
                ColumnDefinition column = table.ColumnDefinitions[columnName] as ColumnDefinition;
                column.ColumnConstraint = constraint;
            }
        }
示例#2
0
        private void AddForeignKeysTo(CreateTableSQLCommand table, string columnName, string ref_column_name, string ref_table_name, GeneratorMapping map_generator, object defaultValue)
        {
            if (!table.ColumnDefinitions.Contains(columnName))
            {
                DbType type = _Dialect.GetDbTypeToPrimaryKey(map_generator);

                SqlObjectModel.LDD.ColumnConstraint constraint = null;
                if (defaultValue != null)
                    constraint = new SqlObjectModel.LDD.DefaultConstraint(new Constant(defaultValue, type), false);
                else
                    constraint = new SqlObjectModel.LDD.ColumnConstraint(true);

                int size = _Dialect.GetSizeToPrimaryKey(map_generator);
                ColumnDefinition column = new ColumnDefinition(columnName, type, size, constraint);
                table.ColumnDefinitions.Add(columnName, column);

                // Add foreign keys here

            }
        }
示例#3
0
        private void AddPrimaryKeysTo(CreateTableSQLCommand table, string columnName, GeneratorMapping map_generator)
        {
            if (!table.ColumnDefinitions.Contains(columnName))
            {
                DbType type;
                try
                {
                    type = _Dialect.GetDbTypeToPrimaryKey(map_generator);
                }
                catch (NullReferenceException ex)
                {
                    throw new MappingNotFoundException(string.Format("The type is not defined for the field {0} in the table {1}", columnName, table.TableName));
                }
                int size = _Dialect.GetSizeToPrimaryKey(map_generator);
                ColumnDefinition column = new ColumnDefinition(columnName, type, size);
                if (map_generator.Name == GeneratorMapping.GeneratorType.native)
                {
                    int seed = map_generator.GetParam("seed") != null ? Convert.ToInt32(map_generator.GetParam("seed").Value) : 1;
                    int increment = map_generator.GetParam("increment") != null ? Convert.ToInt32(map_generator.GetParam("increment").Value) : 1;
                    column.EnableAutoIncrement(increment, seed);
                }
                table.ColumnDefinitions.Add(columnName, column);

                if (table.PrimaryKey == null)
                    table.PrimaryKey = new PrimaryKey(String.Concat("PK_", table.TableName), new ColumnDefinition[] { column });
                else
                    table.PrimaryKey.Columns.Add(column);
            }
            else
            {
                if (map_generator.Name == GeneratorMapping.GeneratorType.business)
                {
                    ColumnDefinition column = table.ColumnDefinitions[columnName] as ColumnDefinition;
                    if (table.PrimaryKey == null)
                        table.PrimaryKey = new PrimaryKey(String.Concat("PK_", table.TableName), new ColumnDefinition[] { column });
                    else
                    {
                        if (!table.PrimaryKey.Columns.Contains(column))
                            table.PrimaryKey.Columns.Add(column);
                    }
                }
            }
        }
示例#4
0
		public abstract void Visit(CreateTableSQLCommand command);
示例#5
0
 public override void Visit(CreateTableSQLCommand command)
 {
     base.Visit(command);
     if (command.PrimaryKey != null && ((ColumnDefinition)command.PrimaryKey.Columns[0]).IsAutoIncrement)
     {
         _Query.Append(ENDQUERY);
         _Query.Append(DROP).Append(SEQUENCE).Append(FormatSequenceName(command.TableName)).Append(SPACE).Append(ENDQUERY);
         _Query.Append(CREATE).Append(SEQUENCE).Append(FormatSequenceName(command.TableName)).Append(SPACE).Append(ENDQUERY);
         _Query.Append(CREATE).Append(OR).Append(REPLACE).Append(TRIGGER).Append(FormatTriggerName(command.TableName)).Append(SPACE).Append(BEFORE).Append(INSERT).Append(ON).Append(FormatTableAlias(command.TableName)).Append(SPACE).Append(FOREACHROWWHEN).Append(OPENBRACE).Append(NEW).Append(DOT).Append(FormatAttribute(((ColumnDefinition)command.PrimaryKey.Columns[0]).ColumnName)).Append(SPACE).Append(IS).Append(NULL).Append(CLOSEBRACE).Append(BEGIN).Append(SELECT).Append(FormatSequenceName(command.TableName)).Append(DOT).Append(NEXTVAL).Append(INTO).Append(COLON).Append(NEW).Append(DOT).Append(FormatAttribute(((ColumnDefinition)command.PrimaryKey.Columns[0]).ColumnName)).Append(SPACE).Append(FROM).Append(DUAL).Append(SEMICOLON).Append(SPACE).Append(END).Append(SEMICOLON);
     }
 }
示例#6
0
文件: DBDialect.cs 项目: npenin/uss
		public virtual void Visit(CreateTableSQLCommand command)
		{
            // "CREATE TABLE {0} ("
            //if (string.IsNullOrEmpty(schema))
            _Query.Append(CREATE).Append(TABLE).Append(FormatAttribute(command.TableName)).Append(SPACE).Append(OPENBRACE);
            //else
            //    _Query.Append(CREATE).Append(TABLE).Append(FormatAttribute(schema + DBDialect.DOT + command.TableName)).Append(SPACE).Append(OPENBRACE);
			SortedList columns = command.ColumnDefinitions;
			foreach(ColumnDefinition column in columns.Values)
			{
				column.Accept(this);
				if (columns.Count-1 != columns.IndexOfValue(column) || command.PrimaryKey != null)
					_Query.Append(COMMA);
			}

			if(command.PrimaryKey != null)
			{
				ArrayList columnNames = new ArrayList();
				foreach(ColumnDefinition column in command.PrimaryKey.Columns)
					columnNames.Add(FormatAttribute(column.ColumnName));

                _Query.Append(CONSTRAINT);

                //if(!string.IsNullOrEmpty(schema))
                //    _Query.Append(schema)
                //        .Append(DBDialect.DOT);

                _Query.Append(FormatAttribute(command.PrimaryKey.Name))
                    .Append(SPACE).Append(PRIMARY).Append(KEY).Append(OPENBRACE)
                    .Append(String.Join(COMMA, (string[])columnNames.ToArray(typeof(string))))
                    .Append(CLOSEBRACE);
			}


			_Query.Append(CLOSEBRACE);
		}