-
Notifications
You must be signed in to change notification settings - Fork 1
/
sample2
executable file
·57 lines (49 loc) · 1.25 KB
/
sample2
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
#!/bin/bash
declare -ag COLUMN_WIDTHS
declare -g FORMAT_STR
# This step is not necessary if we call bashmysql with source:
# Get separator characters used by bashmysql:
# sepstr=$( ./bashmysql -S )
# declare RSEP="${sepstr:0:1}"
# declare FSEP="${sepstr:1:1}"
# declare VSEP="${sepstr:2:1}"
column_sizer()
{
local -i colcount
colcount="${#RESULT_COLUMN_NAMES[@]}"
for (( i=0; i<$colcount; i++ )); do
COLUMN_WIDTHS[$i]=0
done
local -i collen
local rowstr
local -a row
local IFS="${FSEP}"
for rowstr in "${RESULT_ROWS[@]}"; do
row=( $( echo "${rowstr[*]}" ) )
for (( i=0; i<$colcount; i++ )); do
collen="${#row[$i]}"
if [ $collen -gt "${COLUMN_WIDTHS[$i]}" ]; then
COLUMN_WIDTHS[$i]="${collen}"
fi
done
done
FORMAT_STR=$( printf " %%%ds |" "${COLUMN_WIDTHS[@]}" )
FORMAT_STR="|${FORMAT_STR}"
}
column_printer()
{
local rowstr
local -a row
local IFS="${FSEP}"
for rowstr in "${RESULT_ROWS[@]}"; do
row=( $( echo "${rowstr[*]}" ) )
printf "${FORMAT_STR}" "${row[@]}"
echo
done
}
data_ready()
{
column_sizer
column_printer
}
source ./bashmysql sys "SELECT * FROM sys_config" -c data_ready