-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathdropdb
executable file
·159 lines (143 loc) · 3.14 KB
/
dropdb
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#!/bin/bash
#
# Copyright (c) 1999, 2017, Oracle and/or its affiliates. All rights reserved.
#
# Licensed under the Universal Permissive License v 1.0 as shown
# at http://oss.oracle.com/licenses/upl
#
declare -r dfltDSN="sampledb"
declare -r dfltUID="appuser"
declare sname=`basename "$0"`
declare dsn="${dfltDSN}"
declare username="${dfltUID}"
declare password=""
declare connstr=""
declare cs=""
declare dir=""
usage()
{
echo
echo "Usage:"
echo
echo " ${sname} [-dsn dsn] [-uid username] -pwd password [-cs]"
echo
echo "Drops the objects for the mobiledemo database. Parameters are"
echo "the DSN (connectable) name, the username and password. If the DSN"
echo "/ connectable is a client/server one you must also specify '-cs'."
echo
echo "If you are using the default DSN (sampledb/sampledbCS) or the"
echo "default username (appuser) then the corresponding parameter can"
echo "be omitted."
echo
exit 99
}
canonPath()
{
local cwd
local nwd
local nfn
cwd=`pwd -P`
nwd=`dirname "$1"`
nfn=`basename "$1"`
cd "${nwd}" >/dev/null 2>&1
if [ $? -ne 0 ]
then
cd "${cwd}"
return 1
fi
nwd=`pwd -P`
if [ -d "${nfn}" ]
then
cd "${nfn}" >/dev/null 2>&1
if [ $? -ne 0 ]
then
cd "${cwd}"
return 1
fi
nwd=`pwd -P`
echo "${nwd}"
else
echo "${nwd}/${nfn}"
fi
cd "${cwd}"
return 0
}
parseArgs()
{
local -i foundDSN=1
local -i foundUID=1
local -i foundPWD=1
local -i foundCS=1
while [ $# -gt 0 ]
do
case "$1" in
"-dsn" )
shift
if [ \( ${foundDSN} -eq 0 \) -o \( $# -lt 1 \) ]
then
usage
fi
dsn="$1"
foundDSN=0
;;
"-uid" )
shift
if [ \( ${foundUID} -eq 0 \) -o \( $# -lt 1 \) ]
then
usage
fi
username="$1"
foundUID=0
;;
"-pwd" )
shift
if [ \( ${foundPWD} -eq 0 \) -o \( $# -lt 1 \) ]
then
usage
fi
password="$1"
foundPWD=0
;;
"-cs" )
if [ ${foundCS} -eq 0 ]
then
usage
fi
cs="CS"
foundCS=0
;;
* )
usage
;;
esac
shift
done
if [ ${foundPWD} -eq 1 ]
then
usage
fi
if [ \( ${foundDSN} -eq 1 \) -a \( ${foundCS} -eq 0 \) ]
then
dsn="${dsn}${cs}"
fi
connstr="DSN=${dsn};UID=${username};PWD=${password}"
return 0
}
dropDB()
{
echo
echo "Dropping database objects..."
echo
ttIsql${cs} -f sql/dr_schema.sql -connstr "${connstr}"
if [ $? -ne 0 ]
then
return 1
fi
return 0
}
parseArgs "$@"
dir=`canonPath "$0"`
dir=`dirname "${dir}"`
cd "${dir}"
dropDB
exit $?