#!/bin/sh

# This script will load extension and convert test queries
# into fancy query results that include original quuery and string
# "OK" or "FAILED" depending if query was successful.
#
# Script output is ready to go into `sqlite3` input stream.

[ -z "$NU" ] && NU='./libnusqlite3.so' # Prefer env variable

echo "-- NU: $NU"
echo ".load $NU sqlite3_nunicode_init"

while read -r SQL; do
	if [ -z "$SQL" ]; then
		continue
	fi

	ESCAPED_SQL=$(echo "$SQL" | sed -r "s|'|''|g")
	echo "SELECT '$ESCAPED_SQL: ' || (CASE WHEN ($SQL) THEN 'OK' ELSE 'FAILED' END);"
done
