Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
张磊
/
FileStorageBeego
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
4cae7af3
authored
2014-10-17 12:53:59 +0400
by
supar
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Add attribute DEFAULT '' to the CREAT, ALTER constructors
1 parent
e4988b71
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
47 additions
and
1 deletions
orm/cmd_utils.go
orm/cmd_utils.go
View file @
4cae7af
...
...
@@ -104,7 +104,11 @@ func getColumnAddQuery(al *alias, fi *fieldInfo) string {
typ
+=
" "
+
"NOT NULL"
}
return
fmt
.
Sprintf
(
"ALTER TABLE %s%s%s ADD COLUMN %s%s%s %s"
,
Q
,
fi
.
mi
.
table
,
Q
,
Q
,
fi
.
column
,
Q
,
typ
)
return
fmt
.
Sprintf
(
"ALTER TABLE %s%s%s ADD COLUMN %s%s%s %s %s"
,
Q
,
fi
.
mi
.
table
,
Q
,
Q
,
fi
.
column
,
Q
,
typ
,
getColumnDefault
(
fi
),
)
}
// create database creation string.
...
...
@@ -156,6 +160,9 @@ func getDbCreateSql(al *alias) (sqls []string, tableIndexes map[string][]dbIndex
// column += " DEFAULT " + fi.initial.String()
//}
// Append attribute DEFAULT
column
+=
getColumnDefault
(
fi
)
if
fi
.
unique
{
column
+=
" "
+
"UNIQUE"
}
...
...
@@ -239,3 +246,42 @@ func getDbCreateSql(al *alias) (sqls []string, tableIndexes map[string][]dbIndex
return
}
// Get string value for the attribute "DEFAULT" for the CREATE, ALTER commands
func
getColumnDefault
(
fi
*
fieldInfo
)
string
{
var
(
v
,
t
,
d
string
)
t
=
" DEFAULT '%s' "
// These defaults will be useful if there no config value orm:"default" and NOT NULL is on
switch
fieldType
{
case
TypeDateField
:
d
=
"0000-00-00"
case
TypeDateTimeField
:
d
=
"0000-00-00 00:00:00"
case
TypeBooleanField
,
TypeBitField
,
TypeSmallIntegerField
,
TypeIntegerField
,
TypeBigIntegerField
,
TypePositiveBitField
,
TypePositiveSmallIntegerField
,
TypePositiveIntegerField
,
TypePositiveBigIntegerField
,
TypeFloatField
:
TypeDecimalField
:
d
=
"0"
}
if
fi
.
colDefault
{
if
!
fi
.
initial
.
Exist
()
{
v
=
fmt
.
Strintf
(
t
,
""
)
}
else
{
v
=
fmt
.
Strintf
(
t
,
fi
.
initial
.
String
())
}
}
else
{
if
!
fi
.
null
{
v
=
fmt
.
Strintf
(
t
,
d
)
}
}
return
v
}
...
...
Write
Preview
Styling with
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment