Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
public
/
sequelize
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
不要怂,就是干,撸起袖子干!
Commit e10c3309
authored
Oct 14, 2013
by
Jan Aagaard Meier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Proper handling on UNSIGNED, BINARY and ZEROFILL in combi with length for sqlite
1 parent
59ba0b7c
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
9 deletions
lib/dialects/sqlite/query-generator.js
lib/dialects/sqlite/query-generator.js
View file @
e10c330
...
...
@@ -55,8 +55,7 @@ module.exports = (function() {
return
Utils
.
_
.
includes
(
definition
,
'PRIMARY KEY'
)
}).
length
>
1
)
,
attrStr
=
[]
,
endParen
,
modifierLastIndex
=
-
1
for
(
var
attr
in
attributes
)
{
if
(
attributes
.
hasOwnProperty
(
attr
))
{
...
...
@@ -66,14 +65,23 @@ module.exports = (function() {
dataType
=
dataType
.
replace
(
/BIGINT/
,
'INTEGER'
)
}
if
((
endParen
=
dataType
.
indexOf
(
')'
))
!==
-
1
&&
endParen
!==
(
dataType
.
length
-
1
))
{
// Move the length to the end of the string, as required by SQLite (needed for things like INTEGER(5) UNSIGNED -> INTEGER UNSIGNED(5))
var
match
=
dataType
.
match
(
/
\(\s
*
\d
+
(\s
*,
\s
*
\d)?\s
*
\)
/
)
if
(
match
)
{
match
=
match
[
0
]
// SQLite thinks that certain modifiers should come before the length declaration,
// whereas other dialects want them after, see http://www.sqlite.org/lang_createtable.html.
// Start by finding the index of the last of the modifiers
[
'UNSIGNED'
,
'BINARY'
,
'ZEROFILL'
].
forEach
(
function
(
modifier
)
{
var
tmpIndex
=
dataType
.
indexOf
(
modifier
)
dataType
=
dataType
.
replace
(
match
,
''
)
dataType
+=
match
if
(
tmpIndex
>
modifierLastIndex
)
{
modifierLastIndex
=
tmpIndex
+
modifier
.
length
}
})
if
(
modifierLastIndex
)
{
// If a modifier was found, and a lenght declaration is given before the modifier, move the length
var
length
=
dataType
.
match
(
/
\(\s
*
\d
+
(\s
*,
\s
*
\d)?\s
*
\)
/
)
if
(
length
&&
length
.
index
<
modifierLastIndex
)
{
dataType
=
dataType
.
replace
(
length
[
0
],
''
)
dataType
=
Utils
.
_
.
insert
(
dataType
,
modifierLastIndex
,
length
[
0
])
}
}
...
...
Write
Preview
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