1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | #! /bin/sh
QUERY=$1
TABLE=$2
echo -e "Here is your statement:\n"
CMD="BEGIN;\n"
CMD=$CMD`echo '.tables' | sqlite3 $TABLE | tr ' ' '\n' | grep $QUERY | sed 's/^/DROP TABLE /g' | sed 's/$/;/g'`
CMD=$CMD"\nCOMMIT;"
echo -e "$CMD\n"
echo -n "Do you want to commit this statement? (Y/N) "
read -e ANSWER
if test "$ANSWER" = "Y"; then
echo -e "$CMD" | sqlite3 $TABLE
echo "Done!"
else
echo "Nothing changed, have a good day."
fi
exit
|
More like this
- oneliner to delete SQLite tables by kifkif 2 years, 3 months ago
- fast table flush without raw SQL by dsblank 2 years, 1 month ago
- duplicate, please delete by RommeDeSerieux 2 years, 4 months ago
- easy absolute path for settings.py by pgugged 3 years, 7 months ago
- SQLite database vacuum script by pbx 4 years, 9 months ago
Comments