constraints

Receiving HTTP 404 when validating a Double property with min constraint in Grails

Hi, For a simple class like, class Person { String Name Double incomeFromWork = new Double(0.0) static constraints = { incomeFromWork(min:0d) } } However on the GSP page I get an "HTTP ERROR: 404" error when I enter alphabets for incomeFromWork value. What constraints should I use to accept a valid Double v...

How can make Column that allow null to be unique from SQL Server 2005 ?

I have column in a table that allow null but i want to make constraint that make him null or unique ... How can i do that ? Note : I validate it from the frontend but i want to have a physical in sql server that allow this even developer try to enter data ...

Adding Constraints for Nullable Enum

Hi Everyone, I'm writing some Enum functionality, and have the following: public static T ConvertStringToEnumValue<T>(string valueToConvert, bool isCaseSensitive) { if (typeof(T).BaseType.FullName != "System.Enum" && typeof(T).BaseType.FullName != "System.ValueType") { throw new ArgumentException("Type must be of Enum a...

XOR Constraint in Mysql

Hi. I want to implement a kind of xor constraint on foreign keys in mysql 5.1 There is this table, let's say Entity which can refer to two different kinds of valuesets represented by Tables ValsA and ValsB. Now I would like to implement a constraint wich makes sure that exactly one of those two is mapped, and the other one isn't. In ...

return domain objects from grails constraint validation

Is it possible to write your own validator in grails that will return a valid object? Something like: static constraints = { name(validator: {val, obj -> if (Drink.findByName(val)) return [Drink.findByName(val)] }) } In other words - if the Drink already exists in the DB, just return the existing one when someone does...

Sqlserver Table Time field constraint

In SqlServer 2005 I have a table with a TimeOfDay field that is a varchar(5). I want to limit the field value to valid times only (13:40,2:20). This is what I have so far ALTER TABLE tbl ADD CONSTRAINT ck CHECK (TimeOfDay like '[1-2][0-9]:[0-9][0-9]' ) I want the constraint to allow the first digit to be optional, but not having much ...

Algorithm problem: Packing rods into a row

Alright, this might be a tricky problem. It is actually an analogy for another similar problem relating to my actual application, but I've simplified it into this hypothetical problem for clarity. Here goes: I have a line of rods I need to be sorted. Because it is a line, only 1 dimension needs to be of concern. Rods are different l...

SQL Server NULL constraint

Is is possible in SQL Server 2008 to create such a constraint that would restrict two columns to have NULL values at the same time? So that Column1 Column2 NULL NULL -- not allowed 1 NULL -- allowed NULL 2 -- allowed 2 3 -- allowed ...

Rules are deprecated, what's instead (TSQL)?

Rules (Transact-SQL)[1] are reusable what permitted to overcome the shortcoming of non-re-usability of check constraints. And now I read [1] that: "This feature will be removed in a future version of Microsoft SQL Server. Avoid using this feature in new development work, and plan to modify applications that currently use this feat...

Disabling foreign key constraint, still can't truncate table? (SQL Server 2005)

I have a table called PX_Child that has a foreign key on PX_Parent. I'd like to temporarily disable this FK constraint so that I can truncate PX_Parent. I'm not sure how this goes however. I've tried these commands ALTER TABLE PX_Child NOCHECK CONSTRAINT ALL ALTER TABLE PX_Parent NOCHECK CONSTRAINT ALL (truncate commands) ALTER ...

How do you test route constraints using RSpec

Given a couple of cities in the DB: City.first.attributes => {:id => 1, :name => 'nyc'} City.last.attributes => {:id => 2, :name => 'boston'} And a route like: match '/:city/*dest' => 'cities#do_something', :constraints => {:city => /#{City.all.map{|c| c.name}.join('|'}/} (so the constraints should evaluate to: /nyc|boston/) And a ...

Query to find all FK constraints and their delete rules (SQL Server)

In SQL Server 2005, can I issue an SQL query to list all FK constraints on tables within the DB, and show the delete rule? (ie nothing, cascade, set null, or set default) The output I'm looking for is something akin to: FK_NAME ON_DELETE ================================== FK_LINEITEM_STATEMENT CASCADE FK_ACCOUNTREP_...

GCC inline assembly: constraints

I'm having difficulty understanding the role constraints play in GCC inline assembly (x86). I've read the manual, which explains exactly what each constraint does. The problem is that even though I understand what each constraint does, I have very little understanding of why you would use one constraint over another, or what the implic...

MySQL: Add constraint if not exists

In my create script for my database create script looking something like this: CREATE TABLE IF NOT EXISTS `rabbits` ( `id` INT UNSIGNED NOT NULL AUTO_INCREMENT, `name` VARCHAR(255) NOT NULL, `main_page_id` INT UNSIGNED COMMENT 'What page is the main one', PRIMARY KEY (`id`), KEY `main_page_id` (`main_page_id`) ) ENGI...

Subsonic 2.0.3: Save() causes problem due to identity field constraint

Here's a strange one. I'm using SubSonic 2.0.3 to insert a new row into a given table. The table includes an int identity field that is set up properly in the database (Identity seed = 1, Identity increment = 1). Obviously I do not explicitly set this value before calling .Save(). Ever since I rebuilt my development DB (copying fro...

How to add constraints on inherited properties in a grails domain sub-class

Here's what I'd like to do: class A { String string static constraints = { string(maxSize:100) } } class B extends A { static constraints = { string(url:true) } } So class A should have some constraints and B should have the same plus additional constraints on the same property. I couldn't get that to work though a...

C# Generics Constraints: Is there a way to express is not a?

I have the following code: interface IConverter<T, U> { U Convert(T obj); } interface IBusinessEntityConveter<T, U> : IConverter<T, U> where U : BusinessEntity { } class LookupConveter<B> : IBusinessEntityConveter<Lookup, B>, IConverter<Lookup, Moniker> where B : BusinessEntity, new() { #region IConverter<Lookup, Moni...

Apply the unique constraint to combinations of columns in SQL

Hi, I have a table called product_attributes in a MySQL Database. It consists of a product SKU (foreign key), an attribute label and an attribute value. I need to ensure that combinations of SKU and attribute labels are unique. EXAMPLE - inserting this would be legal {001, 'weight', '100 lbs'} {001, 'color', 'blue'} {002, 'weight'...

Ensuring that column follows a sequence in Oracle

Is there any way of constraining a column (say "ID") to follow a created sequence (say "ID_SEQ")? Without an automatic constraint, manual inserts might throw the entire sequence out-of-whack. What can be done to fix this? Just call NextVal twice? ...

PostgreSQL: How to constrain more than just existence on foreign key?

In PostgreSQL, what's the simplest way to enforce more than just existence on a foreign key? For example, given the following tables: create table "bar" ( bar_id serial primary key, status boolean not null ) create table "foo" ( foo_id serial primary key, bar_id integer references "bar" ) How could f...