constraints

'one-to-many' relation integrity issue for time ranges

╄→гoц情女王★ 提交于 2019-12-13 20:04:19
问题 Suppose I have table like: CREATE TABLE foo ( id SERIAL PRIMARY KEY , barid integer NOT NULL REFERENCES bar(id) , bazid integer NOT NULL REFERENCES baz(id) , startdate timestamp(0) NOT NULL , enddate timestamp(0) NOT NULL ); The purpose for that table is to provide a pseudo 'one-to-many' relation between tables bar and baz, but the relation can change through time: SELECT * FROM bar JOIN foo on TRUE AND foo.barid = bar.id AND now() BETWEEN foo.startdate AND foo.enddate JOIN baz on baz.id =

Make UIView and contents expand to fill available horizontal space in UIToolbar with Auto Layout

丶灬走出姿态 提交于 2019-12-13 19:39:26
问题 I have a UIBarButtonItem and a UIView containing two UITextField controls, all within a UIToolbar . This is a screenshot of my storyboard: http://i.8px.co/x8eC.png. I'd like to create something similar to this: http://i.8px.co/1hvY.png. I'm trying to make the UIView and its children expand to fill the available horizontal space in the UIToolbar with Auto Layout . I don't know how to accomplish what I want. I experimented with a dirty solution for the UIView and was able to have it size

Has generic type's features/operator overloading improved in C# 5.0?

爱⌒轻易说出口 提交于 2019-12-13 19:19:36
问题 I know there are many question on SO like this "Operator 'whatever' cannot be applied to operands of type 'T' (whatever may be ++, += or <= etc. etc. But bear with me, I wanna ask something different. Let's say I have this code public class GenericCls<T> where T : struct { public static T AddValues(params T[] values) { T sum = default(T); if (values != null) { for (int i = 0; i < values.Length; i++) { sum += values[i]; } } return sum; } } even though I've made my type struct, and value type I

How to create a check constraint that ensures one active detail record for a table?

我们两清 提交于 2019-12-13 19:14:10
问题 Let's say I have this as a table: InvoiceDetailId (int, not null, PK), InvoiceId (int, not null, FK), InvoiceNumber (varchar(50), null), EndEffectiveTime (datetime, null) How can I write a check constraint on this table that makes sure that for each invoice in the table there is only one record with a null EndEffectiveTime (meaning it's the active detail record)? So basically this query can never return results: SELECT InvoiceId FROM InvoiceDetails GROUP BY InvoiceId, EndEffectiveTime HAVING

How to set a conditional DEFAULT value to a column in oracle without using triggers?

被刻印的时光 ゝ 提交于 2019-12-13 18:07:15
问题 How to set a conditional DEFAULT value to a column in oracle without using triggers? I want to achieve following needs: If "flag1"=1 then Default value to column Newfield must be "4". If "flag1"=2 then Default value to column Newfield must be "5". 回答1: That's what triggers are for. Use them. 回答2: A column DEFAULT is not allowed to reference another column, so this is not possible. You could perhaps just let the default remain as NULL, and then have a view to adjust it like: create view

Rails simulating Constraints and sub-Constraints

我与影子孤独终老i 提交于 2019-12-13 17:55:33
问题 I am building a scheduling platform with tasks for a current project Let's say there are some Global Constraints (money, people, etc.) for the project, and that each tasks also has individual Constraints. The big deal is that I have to match each Global Constraint to every Constraint of the tasks of a same project Now the real big deal, is that in addition to having a nature (financial -> Float, people -> Integer) the constraints can also have a type (ex : costs of wages, costs of raw

AutoLayout: center two views center to superview's center

Deadly 提交于 2019-12-13 17:17:25
问题 I want to create custom UIView with UIImageView and UILabel . UIImageView should be automatically resizable to image size and UILabel should be automatically resizable vertically to text content. Could you help me to create constraints. I need to center of dynamic views: UIIamgeView and UILabel should be in center of my custom view. 回答1: I usually achieve this by using some sort of containerView. By doing this, I can center the containerView within self.view (or wherever you want to centre it

Is it possible to constrain a table to have a value in only one of a set of columns

为君一笑 提交于 2019-12-13 16:58:54
问题 I have a table which needs to link one of three seperate tables, but it should only link to one of them, e.g. Main_Table id UNIQUEIDENTIFIER t1_id UNIQUEIDENTIFIER t2_id INT t3_id INT T1 id UNIQUEIDENTIFIER name VARCHAR(255) T2 id INT name VARCHAR(255) T3 id INT name VARCHAR(255) Is it possible to have a constraint whereby only one of t1, t2 or t3 is not null at any one time? Is this just bad design? If so, what suggestions would you make for the design? EDIT: I've been asked to elaborate the

Declaring string type with min/max length in typescript

拟墨画扇 提交于 2019-12-13 15:24:57
问题 After going through the docs, it seems there is no direct way to type check for min/max length of a string datatype. But, is there a way to declare a string datatype using some custom types so that it checks whether the string length is with the given bounds? 回答1: You can achieve this using a type constructor and something called a "Phantom Type" (read a nice article about this here) which is a technique to ensure that a type can not be assigned to a value directly. Here's an example of a

Xcode 4.4 constraint errors

亡梦爱人 提交于 2019-12-13 15:06:17
问题 I am using Xcode 4.4 and creating my views in interface builder. When I run my app, I consistently get the following constraint errors. Unable to simultaneously satisfy constraints: ( "<NSAutoresizingMaskLayoutConstraint:0x104486db0 h=-&- v=-&- V:[NSView:0x106a33090]-(0)-| (Names: '|':NSClipView:0x106a0cef0 )>", "<NSAutoresizingMaskLayoutConstraint:0x104486e10 h=-&- v=-&- V:|-(15)-[NSView:0x106a33090] (Names: '|':NSClipView:0x106a0cef0 )>", "<NSAutoresizingMaskLayoutConstraint:0x1002da350 h=-