Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/zabbix/zabbix.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/misc
diff options
context:
space:
mode:
authorAndris Zeila <andris.zeila@zabbix.com>2013-02-06 11:26:18 +0400
committerAndris Zeila <andris.zeila@zabbix.com>2013-02-06 11:26:18 +0400
commitadc565f9464e33fcec683932e240408be9406889 (patch)
treec5c945b3852200e3d183df0ccdd462e88757d988 /misc
parent9c0dcfa2c39b78af6cdb4303b9df7084605d3b81 (diff)
....I..... [ZBX-6197] updated DB2 images.sql script to assemble larger images from smaller chunks
[merge ^/branches/2.0 -c r33430]
Diffstat (limited to 'misc')
-rwxr-xr-xmisc/images/png_to_sql.sh33
1 files changed, 28 insertions, 5 deletions
diff --git a/misc/images/png_to_sql.sh b/misc/images/png_to_sql.sh
index 9c9666a6752..8d4f52ea2d0 100755
--- a/misc/images/png_to_sql.sh
+++ b/misc/images/png_to_sql.sh
@@ -3,6 +3,28 @@
# A script to generate SQL from PNG images
# depends on hexdump
+DB2_LENGTH_LIMIT=32000
+
+# Converts hexadecimal string to DB2 BLOB format.
+#
+# This function splits the string into 32000 byte chunks because
+# of DB2 limitation "For a hexadecimal constant (X, GX, or UX),
+# the number of hexadecimal digits must not exceed 32704"
+# Though it still did not work with 32704 length limit, so it was
+# lowered to 32000.
+db2_blob()
+{
+ image_data=$1
+ if [ ${#image_data} -le $DB2_LENGTH_LIMIT ]; then
+ echo "blob(x'$image_data')"
+ return;
+ fi
+ image_chunk=${image_data:0:$DB2_LENGTH_LIMIT}
+ image_data=${image_data:$DB2_LENGTH_LIMIT}
+ echo "$(db2_blob $image_chunk) || $(db2_blob $image_data)"
+}
+
+
scriptdir="$(dirname $0)"
pngdir="${1:-png_modern}"
sqlbasedir="$scriptdir/../../database"
@@ -32,18 +54,19 @@ imagecount=$(ls $pngdir/*.png | wc -l)
for imagefile in $pngdir/*.png; do
((imagesdone++))
imagename="$(basename "${imagefile%.png}")"
+ image_data=$(hexdump -ve '"" 1/1 "%02X"' "$imagefile")
# ----- MySQL
- echo "INSERT INTO images (imageid,imagetype,name,image) VALUES ($imagesdone,1,'$imagename',0x$(hexdump -ve '"" 1/1 "%02X"' "$imagefile"));" >> "$imagefile_mysql"
+ echo "INSERT INTO images (imageid,imagetype,name,image) VALUES ($imagesdone,1,'$imagename',0x$image_data);" >> "$imagefile_mysql"
# ----- PostgreSQL
- echo "INSERT INTO images (imageid,imagetype,name,image) VALUES ($imagesdone,1,'$imagename',decode('$(hexdump -ve '"" 1/1 "%02X"' "$imagefile")','hex'));" >> "$imagefile_pgsql"
+ echo "INSERT INTO images (imageid,imagetype,name,image) VALUES ($imagesdone,1,'$imagename',decode('$image_data','hex'));" >> "$imagefile_pgsql"
# ----- Oracle
echo -e "\tLOAD_IMAGE($imagesdone,1,'$imagename','$imagefile');" >> "$imagefile_oracle"
# ----- SQLite
- echo "INSERT INTO images (imageid,imagetype,name,image) VALUES ($imagesdone,1,'$imagename','$(hexdump -ve '"" 1/1 "%02X"' "$imagefile")');" >> "$imagefile_sqlite3"
+ echo "INSERT INTO images (imageid,imagetype,name,image) VALUES ($imagesdone,1,'$imagename','$image_data');" >> "$imagefile_sqlite3"
# ----- IBM DB2
- echo "INSERT INTO images (imageid,imagetype,name,image) VALUES ($imagesdone,1,'$imagename',blob(x'$(hexdump -ve '"" 1/1 "%02X"' "$imagefile")'));" >> "$imagefile_ibm_db2"
+ echo "INSERT INTO images (imageid,imagetype,name,image) VALUES ($imagesdone,1,'$imagename',$(db2_blob $image_data));" >> "$imagefile_ibm_db2"
- echo -n "$[$imagesdone*100/$imagecount]% "
+ echo -ne "\b\b\b\b$[$imagesdone*100/$imagecount]% "
done
cat images_oracle_end.txt >> "$imagefile_oracle"
echo