Quick! Write a program in your favourite language that reads an input file that contains SQL commands that might or might not be wrong and outputs in another file the number or wrong commands and each correct command on a new line, before this birds stabs you!
What is a correct SQL command?
Is ; correct?
A command is correct when it does what you want it to.
An SQL command is correct when:
- it begins with either: CREATE, ALTER, INSERT, UPDATE, DELETE
- it ends with ;
- if they're strings they must begin and end with '
>>55537823
>no SELECT
>no DROP
>no USE
>>55537823
>>55537863
>no USING
>requiring ;
>>55537764
Bash, checks for a sqlite query.#!/bin/bash
! sqlite3 -cmd "$1" <<< '' |& grep -q '^Error:.*syntax error$'
>>55538642
wait, that's not according to the spec#!/bin/bash
wrong=0
while read -r cmd; do
if sqlite3 -cmd "$cmd" <<< '' |& grep -q '^Error:.*syntax error$'; then
(( wrong++ ))
else
echo "$cmd"
fi
done
echo "Wrong commands: $wrong"
that bird isn't red, i don't think he's actually going to stab me
>>55539464
It has a red bracelet.
Bird-kun, do you seriously want me to write a fucking SQL parser? There's like 6 million dialects each with its own convoluted grammar. Be reasonable.
This is retarded but which SQL? ANSI? Oracle?
Even if it's syntactically correct, how do you check if it's semantically correct too, like an Insert into a child table with no parent key or drop a table which does not exists?
what about NoSQL :^)?