public virtual CheckConstraintSchema GetNewCheckConstraintSchema(string name)
        {
            CheckConstraintSchema schema = new CheckConstraintSchema(this);

            schema.Name = name;
            return(schema);
        }
Esempio n. 2
0
        public override ConstraintSchemaCollection GetTableConstraints(TableSchema table)
        {
            ConstraintSchemaCollection constraints = new ConstraintSchemaCollection();

            IPooledDbConnection conn    = connectionPool.Request();
            IDbCommand          command = conn.CreateCommand("select name, xtype from sysobjects where xtype in ('F','PK','CK')");     //TODO: unique

            try {
                using (command) {
                    using (IDataReader r = command.ExecuteReader()) {
                        while (r.Read())
                        {
                            ConstraintSchema constraint = null;
                            switch (r.GetString(1))
                            {
                            case "F":                                     //foreign key
                                constraint = new ForeignKeyConstraintSchema(this);
                                break;

                            case "PK":                                     //primary key
                                constraint = new PrimaryKeyConstraintSchema(this);
                                break;

                            case "CK":                                     //check constraint
                                constraint = new CheckConstraintSchema(this);
                                break;

                            default:
                                break;
                            }

                            if (constraint != null)
                            {
                                constraint.Name = r.GetString(0);
                                constraints.Add(constraint);
                            }
                        }
                        r.Close();
                    }
                }
            } catch (Exception e) {
                QueryService.RaiseException(e);
            }
            conn.Release();

            return(constraints);
        }
Esempio n. 3
0
        protected virtual string GetConstraintString(ConstraintSchema constraint)
        {
            //PRIMARY KEY [sort-order] [ conflict-clause ] [AUTOINCREMENT]
            //UNIQUE [ conflict-clause ]
            //CHECK ( expr )
            //COLLATE collation-name

            StringBuilder sb = new StringBuilder();

            sb.Append("CONSTRAINT ");
            sb.Append(constraint.Name);
            sb.Append(' ');

            switch (constraint.ConstraintType)
            {
            case ConstraintType.PrimaryKey:
                //PrimaryKeyConstraintSchema pk = constraint as PrimaryKeyConstraintSchema;
                sb.Append("PRIMARY KEY");                  //TODO: auto inc + sort
                break;

            case ConstraintType.Unique:
                //UniqueConstraintSchema u = constraint as UniqueConstraintSchema;
                sb.Append("UNIQUE");
                break;

            case ConstraintType.Check:
                CheckConstraintSchema chk = constraint as CheckConstraintSchema;
                sb.Append("CHECK (");
                sb.Append(chk.Source);
                sb.Append(")");
                break;

            default:
                throw new NotImplementedException();
            }

            return(sb.ToString());
        }
		public CheckConstraintSchema (CheckConstraintSchema constraint)
			: base (constraint)
		{
			source = constraint.source;
		}
		public virtual CheckConstraintSchema GetNewCheckConstraintSchema (string name)
		{
			CheckConstraintSchema schema = new CheckConstraintSchema (this);
			schema.Name = name;
			return schema;
		}
		private void AddConstraint (CheckConstraintSchema check)
		{
			store.AppendValues (check.Name, String.Empty, false, String.Empty, check);
		}
Esempio n. 7
0
 public CheckConstraintSchema(CheckConstraintSchema constraint)
     : base(constraint)
 {
     source = constraint.source;
 }