Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
smradius
smradius
Commits
4297ea5c
Commit
4297ea5c
authored
Sep 22, 2016
by
Nigel Kukard
Browse files
CHANGE: convert-tsql is part of AWITPT
parent
4b76ff14
Changes
1
Hide whitespace changes
Inline
Side-by-side
database/convert-tsql
deleted
100755 → 0
View file @
4b76ff14
#!/bin/bash
# Database translation/creation script
# Copyright (C) 2009-2016, AllWorldIT
# Copyright (C) 2008, LinuxRulz
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
database
=
"
$1
"
file
=
"
$2
"
prefix
=
"
$3
"
# Display usage info
display_usage
()
{
echo
"Usage:
$0
<database type> <file> [prefix]"
echo
echo
"Valid database types:"
echo
" mysql - For MySQL v5.5+"
echo
" pgsql - For PostgreSQL"
echo
" sqlite - For SQLite v3"
echo
exit
}
# Check we have our params
if
[
-z
"
$database
"
-o
-z
"
$file
"
]
then
display_usage
fi
# Check file exists
if
[
!
-f
"
$file
"
]
then
echo
"ERROR: Cannot open file '
$file
'"
exit
1
fi
# Check what we converting for
case
"
$database
"
in
"mysql"
)
sed
\
-e
"s/@PREFIX@/
$prefix
/g"
\
-e
's/@PRELOAD@/SET FOREIGN_KEY_CHECKS=0;/'
\
-e
's/@POSTLOAD@/SET FOREIGN_KEY_CHECKS=1;/'
\
-e
's/@CREATE_TABLE_SUFFIX@/ENGINE=InnoDB CHARACTER SET latin1 COLLATE latin1_bin/'
\
-e
's/@SERIAL_TYPE@/SERIAL/'
\
-e
's/@BIGINT_UNSIGNED@/BIGINT UNSIGNED/'
\
-e
's/@INT_UNSIGNED@/INT UNSIGNED/'
\
-e
's/@TRACK_KEY_LEN@/512/'
\
-e
's/@SERIAL_REF_TYPE@/BIGINT UNSIGNED/'
<
"
$file
"
;;
"pgsql"
)
sed
\
-e
"s/@PREFIX@/
$prefix
/g"
\
-e
's/@PRELOAD@/SET CONSTRAINTS ALL DEFERRED;/'
\
-e
's/@POSTLOAD@//'
\
-e
's/@CREATE_TABLE_SUFFIX@//'
\
-e
's/@SERIAL_TYPE@/SERIAL PRIMARY KEY/'
\
-e
's/@BIGINT_UNSIGNED@/INT8/'
\
-e
's/@INT_UNSIGNED@/INT8/'
\
-e
's/@TRACK_KEY_LEN@/512/'
\
-e
's/@SERIAL_REF_TYPE@/INT8/'
<
"
$file
"
;;
"sqlite"
)
sed
\
-e
"s/@PREFIX@/
$prefix
/g"
\
-e
's/@PRELOAD@//'
\
-e
's/@POSTLOAD@//'
\
-e
's/@CREATE_TABLE_SUFFIX@//'
\
-e
's/@SERIAL_TYPE@/INTEGER PRIMARY KEY AUTOINCREMENT/'
\
-e
's/@BIGINT_UNSIGNED@/INT8/'
\
-e
's/@INT_UNSIGNED@/INT8/'
\
-e
's/@TRACK_KEY_LEN@/512/'
\
-e
's/@SERIAL_REF_TYPE@/INT8/'
<
"
$file
"
;;
*
)
echo
"ERROR: Invalid database type '
$database
'"
exit
1
;;
esac
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
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 comment