[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y ] [Home]
4chanarchives logo
Quick! Write a program in your favourite language that reads

You are currently reading a thread in /g/ - Technology

Thread replies: 12
Thread images: 3
File: qKNNQCM.jpg (119 KB, 528x960) Image search: [Google]
qKNNQCM.jpg
119 KB, 528x960
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!
>>
File: Untitled.png (32 KB, 1920x1080) Image search: [Google]
Untitled.png
32 KB, 1920x1080
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.
>>
File: 1468102590495.jpg (51 KB, 540x489) Image search: [Google]
1468102590495.jpg
51 KB, 540x489
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 :^)?
Thread replies: 12
Thread images: 3

[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y] [Home]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
If a post contains personal/copyrighted/illegal content you can contact me at [email protected] with that post and thread number and it will be removed as soon as possible.
If a post contains illegal content, please click on its [Report] button and follow the instructions.
This is a 4chan archive - all of the content originated from them. If you need information for a Poster - you need to contact them.
This website shows only archived content and is not affiliated with 4chan in any way.
If you like this website please support us by donating with Bitcoin at 1XVgDnu36zCj97gLdeSwHMdiJaBkqhtMK