Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)

Paste

Pasted as Bash by ncl ( 2 years ago )
#!/bin/bash

# Define colors
COLORS=(
    '\033[0;31m' # Red
    '\033[0;32m' # Green
    '\033[0;33m' # Yellow
    '\033[0;34m' # Blue
    '\033[0;35m' # Purple
    '\033[0;36m' # Cyan
    '\033[0;37m' # White
)

# Reset color
RESET='\033[0m'

# Read SQL query from stdin
read -r sql_query

# Extract columns and values
columns=$(echo "$sql_query" | grep -oP '(?<=\().*?(?=\))' | head -n 1)
values=$(echo "$sql_query" | grep -oP '(?<=VALUES\s\().*?(?=\))' | head -n 1)

# Split columns and values into arrays
IFS=', ' read -r -a col_array <<< "$columns"
IFS=', ' read -r -a val_array <<< "$values"

# Initialize color index
color_idx=0

# Output the INSERT INTO and table part
echo -n "INSERT INTO TBL ("

# Print colored columns
for ((i = 0; i < ${#col_array[@]}; i++)); do
    # Cycle through colors
    color="${COLORS[$((color_idx % ${#COLORS[@]}))]}"
    echo -ne "${color}${col_array[$i]}${RESET}"
    if [[ $i -lt $((${#col_array[@]} - 1)) ]]; then
        echo -n ", "
    fi
    ((color_idx++))
done

echo -n ") VALUES ("

# Print colored values
color_idx=0
for ((i = 0; i < ${#val_array[@]}; i++)); do
    # Cycle through colors
    color="${COLORS[$((color_idx % ${#COLORS[@]}))]}"
    echo -ne "${color}${val_array[$i]}${RESET}"
    if [[ $i -lt $((${#val_array[@]} - 1)) ]]; then
        echo -n ", "
    fi
    ((color_idx++))
done

echo ")"

 

Revise this Paste

Children: 127993
Your Name: Code Language: