Subversion Repositories oidplus

Rev

Rev 863 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
783 daniel-mar 1
#!/bin/bash
2
 
3
# OIDplus 2.0
4
# Copyright 2019 - 2022 Daniel Marschall, ViaThinkSoft
5
#
6
# Licensed under the Apache License, Version 2.0 (the "License");
7
# you may not use this file except in compliance with the License.
8
# You may obtain a copy of the License at
9
#
10
#     http://www.apache.org/licenses/LICENSE-2.0
11
#
12
# Unless required by applicable law or agreed to in writing, software
13
# distributed under the License is distributed on an "AS IS" BASIS,
14
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
# See the License for the specific language governing permissions and
16
# limitations under the License.
17
 
848 daniel-mar 18
DIR=$( dirname "$0" )
19
cd "$DIR"
20
 
1244 daniel-mar 21
# Export tables "demo_*" into file plugins/viathinksoft/sqlSlang/oracle/sql/example.sql
783 daniel-mar 22
# We don't print to console because of encoding issues
1244 daniel-mar 23
#mysqldump --default-character-set=utf8 --no-create-info --extended-insert=FALSE oidplus demo_iri demo_asn1id demo_ra demo_objects -r ../plugins/viathinksoft/sqlSlang/oracle/sql/example.sql
783 daniel-mar 24
 
25
# Remove database prefix
1244 daniel-mar 26
#sed -i 's/`demo_/`/g' ../plugins/viathinksoft/sqlSlang/oracle/sql/example.sql
783 daniel-mar 27
 
848 daniel-mar 28
# Since we have to do some manual work to the MySQL data, we do not create a new dump
29
# but instead use the MySQL example script (that has been carefully checked)
1244 daniel-mar 30
cat ../plugins/viathinksoft/sqlSlang/oracle/sql/example_mysql.sql > ../plugins/viathinksoft/sqlSlang/pgsql/sql/example.sql
848 daniel-mar 31
 
783 daniel-mar 32
# Avoid that there is a conflict with well known IDs (e.g. 2.999)
1244 daniel-mar 33
#sed -i 's/INSERT INTO `iri`/INSERT IGNORE INTO `iri`/g' ../plugins/viathinksoft/sqlSlang/pgsql/sql/example.sql
34
#sed -i 's/INSERT INTO `asn1id`/INSERT IGNORE INTO `asn1id`/g' ../plugins/viathinksoft/sqlSlang/pgsql/sql/example.sql
783 daniel-mar 35
 
36
# Change backticks to double quotes
37
# and write everything inside upper case! (very important)
1244 daniel-mar 38
sed -i 's/`/"/g' ../plugins/viathinksoft/sqlSlang/oracle/sql/example.sql
39
sed -i 's/"asn1id"/"ASN1ID"/g' ../plugins/viathinksoft/sqlSlang/oracle/sql/example.sql
40
sed -i 's/"objects"/"OBJECTS"/g' ../plugins/viathinksoft/sqlSlang/oracle/sql/example.sql
41
sed -i 's/"iri"/"IRI"/g' ../plugins/viathinksoft/sqlSlang/oracle/sql/example.sql
783 daniel-mar 42
 
43
# Change \" to "
1244 daniel-mar 44
sed -i 's/\\"/"/g' ../plugins/viathinksoft/sqlSlang/oracle/sql/example.sql
783 daniel-mar 45
 
46
# Add at the beginning
47
# ALTER SESSION SET NLS_DATE_FORMAT = 'yyyy-mm-dd hh24:mi:ss';
1244 daniel-mar 48
mv ../plugins/viathinksoft/sqlSlang/oracle/sql/example.sql example_oracle.tmp
49
echo "ALTER SESSION SET NLS_DATE_FORMAT = 'yyyy-mm-dd hh24:mi:ss';" > ../plugins/viathinksoft/sqlSlang/oracle/sql/example.sql
863 daniel-mar 50
# "set define off" is important, otherwise we cannot use "&" in a SQL statement
1244 daniel-mar 51
echo "set define off" >> ../plugins/viathinksoft/sqlSlang/oracle/sql/example.sql
52
echo "" >> ../plugins/viathinksoft/sqlSlang/oracle/sql/example.sql
53
cat example_oracle.tmp >> ../plugins/viathinksoft/sqlSlang/oracle/sql/example.sql
54
rm example_oracle.tmp
783 daniel-mar 55
 
56
# Dates need "TIMESTAMP" prefix
863 daniel-mar 57
for year in {2010..2099}
58
do
1244 daniel-mar 59
    sed -i "s/'$year/TIMESTAMP '$year/g" ../plugins/viathinksoft/sqlSlang/oracle/sql/example.sql
863 daniel-mar 60
done
783 daniel-mar 61
 
62
# Change "\n" to "' || chr(10) || '"
1244 daniel-mar 63
sed -i "s/\\\n/' \|\| chr\(10\) \|\| '/g" ../plugins/viathinksoft/sqlSlang/oracle/sql/example.sql