-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathxfieldinteger.go
95 lines (82 loc) · 2.04 KB
/
xfieldinteger.go
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
package xdominion
import (
"fmt"
)
var fieldintegertypes = map[string]string{
DB_Postgres: "integer",
DB_MySQL: "integer",
/*
DB_Base::MSSQL => array(
DB_Field::INTEGER => "int"
),
DB_Base::ORACLE => array(
DB_Field::INTEGER => "number(16)"
)
*/
}
type XFieldInteger struct {
Name string
Constraints XConstraints
}
// creates the name of the field with its type (to create the table)
func (f XFieldInteger) CreateField(prepend string, DB string, ifText *bool) string {
field := prepend + f.Name
if DB == DB_Postgres && f.IsAutoIncrement() {
field += " serial"
} else {
field += " " + fieldintegertypes[DB]
}
/*
if ($this->checks != null)
$line .= $this->checks->createCheck($id.$this->name, $DB);
else
{
if ($DB == DB_Base::MSSQL)
{
$line .= " NULL";
}
}
*/
extra := ""
if f.Constraints != nil {
extra = f.Constraints.CreateConstraints(prepend, f.Name, DB)
}
return field + extra
}
// creates a string representation of the value of the field for insert/update
func (f XFieldInteger) CreateValue(v interface{}, table string, DB string, id string) string {
return fmt.Sprint(v)
}
// creates the sequence used by the field (only autoincrement fields)
func (f XFieldInteger) CreateSequence(table string) string {
return ""
}
// creates the index used by the field (normal, unique, multi, multi unique)
func (f XFieldInteger) CreateIndex(table string, id string, DB string) []string {
if f.Constraints != nil {
return f.Constraints.CreateIndex(table, id, f.Name, DB)
}
return []string{}
}
// gets the name of the field
func (f XFieldInteger) GetName() string {
return f.Name
}
// gets the type of the field
func (f XFieldInteger) GetType() int {
return XField_Int
}
// gets the checks of the field
func (f XFieldInteger) GetConstraints() XConstraints {
return f.Constraints
}
// Is it autoincrement
func (f XFieldInteger) IsAutoIncrement() bool {
if f.Constraints != nil {
c := f.Constraints.Get(AI)
if c != nil {
return true
}
}
return false
}