forked from danzel/Npgsql
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPrimaryKey.cs
More file actions
118 lines (105 loc) · 2.57 KB
/
PrimaryKey.cs
File metadata and controls
118 lines (105 loc) · 2.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/********************************************************
* ADO.NET 2.0 Data Provider for SQLite Version 3.X
* Written by Robert Simpson (robert@blackcastlesoft.com)
*
* Released to the public domain, use at your own risk!
********************************************************/
namespace Npgsql.Designer.Design
{
using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;
using System.Data;
using System.Data.Common;
internal class PrimaryKey : Index, ICloneable
{
private bool _autoincrement;
internal PrimaryKey(DbConnection cnn, Table table, DataRow row)
: base(cnn, table, row)
{
if (String.IsNullOrEmpty(_name) == false && _name.StartsWith("sqlite_", StringComparison.OrdinalIgnoreCase))
_name = null;
}
protected PrimaryKey(PrimaryKey source)
: base(source)
{
_autoincrement = source._autoincrement;
}
public override IndexTypeEnum IndexType
{
get
{
return IndexTypeEnum.PrimaryKey;
}
}
protected override string NamePrefix
{
get
{
return "PK";
}
}
protected override string NewName
{
get
{
return Table.Name;
}
}
[Browsable(false)]
public override bool Unique
{
get
{
return true;
}
set
{
base.Unique = true;
}
}
[DefaultValue(ConflictEnum.Abort)]
[DisplayName("On Conflict")]
[Category("Constraints")]
[Description("Specifies what action to take when the primary key constraint is violated.")]
public ConflictEnum Conflict
{
get { return _conflict; }
set
{
if (value != _conflict)
{
_conflict = value;
MakeDirty();
}
}
}
[DefaultValue(false)]
[Category("Constraints")]
[Description("Can only be enabled for a single column primary key of type INTEGER. When set, the primary key is guaranteed to increment in sequence, and no previously deleted or uncommitted values will ever be used.")]
public bool AutoIncrement
{
get
{
if (Columns.Count > 1) return false;
if (Columns.Count == 1 && Columns[0].SortMode != ColumnSortMode.Ascending) return false;
return _autoincrement;
}
set
{
if (value != _autoincrement)
{
_autoincrement = value;
MakeDirty();
}
}
}
#region ICloneable Members
object ICloneable.Clone()
{
return new PrimaryKey(this);
}
#endregion
}
}