updated sample queries

This commit is contained in:
Pedro 2014-12-05 09:37:59 +01:00
parent adcdc490dd
commit 7d2cc528b3
4 changed files with 27 additions and 13 deletions

View File

@ -76,7 +76,7 @@
<script type="text/javascript"> <script type="text/javascript">
$(function() { $(function() {
function addSampleQuery(name, query) { function addSampleQuery(name, query) {
var btn = $('<button type="button" class="btn btn-success">' + name + '</button>'); var btn = $('<button type="button" class="btn btn-sm btn-success">' + name + '</button>');
btn.click(function(evt) { btn.click(function(evt) {
$('#queryInput').val(query); $('#queryInput').val(query);
if (!evt.shiftKey) { if (!evt.shiftKey) {
@ -87,7 +87,7 @@ $(function() {
} }
function addBuggyQuery(name, query) { function addBuggyQuery(name, query) {
var btn = $('<button type="button" class="btn btn-danger">' + name + '</button>'); var btn = $('<button type="button" class="btn btn-sm btn-danger">' + name + '</button>');
btn.click(function(evt) { btn.click(function(evt) {
$('#queryInput').val(query); $('#queryInput').val(query);
if (!evt.shiftKey) { if (!evt.shiftKey) {
@ -176,26 +176,28 @@ $(function() {
return true; return true;
}); });
addBuggyQuery('GROUP', 'SELECT AVG(grade) FROM (SELECT city, AVG(grade) FROM students GROUP BY city) t1');
addBuggyQuery('UNION (kills hyrise)', 'SELECT name FROM students WHERE grade > 2.0 UNION SELECT name FROM students');
////////////////////////////////////////////////// //////////////////////////////////////////////////
// Load sample queries // Load sample queries
$.get('sample-queries.sql', function(data) { $.get('sample-queries.sql', function(data) {
var lines = data.split('\n'); var lines = data.split('\n');
var name, query = ""; var name, query = "", isBuggy = false;
$.each(lines, function(i, line) { $.each(lines, function(i, line) {
if (line[0] == '#') { if (line[0] == '#') {
// Append last query
if (name && !isBuggy) addSampleQuery(name, query);
if (name && isBuggy) addBuggyQuery(name, query);
// New query // New query
if (name) addSampleQuery(name, query); isBuggy = (line[1] == '!');
name = line.substring(1); name = line.substring((isBuggy) ? 3 : 2);
query = ""; query = "";
} else { } else {
query += line + '\n'; query += line + '\n';
} }
}); });
if (name) addSampleQuery(name, query);
if (name && !isBuggy) addSampleQuery(name, query);
if (name && isBuggy) addBuggyQuery(name, query);
}); });
////////////////////////////////////////////////// //////////////////////////////////////////////////

View File

@ -26,3 +26,13 @@ SELECT * FROM test;
CREATE TABLE IF NOT EXISTS test (v1 INTEGER, v2 INTEGER, v3 INTEGER); CREATE TABLE IF NOT EXISTS test (v1 INTEGER, v2 INTEGER, v3 INTEGER);
INSERT INTO test VALUES (1, 12, 43); INSERT INTO test VALUES (1, 12, 43);
SELECT * FROM test; SELECT * FROM test;
#! GROUP
SELECT AVG(grade) FROM (SELECT city, AVG(grade) FROM students GROUP BY city) t1
#! UNION (kills hyrise)
SELECT name FROM students WHERE grade > 2.0 UNION SELECT name FROM students
#! UPDATE
UPDATE companies SET company_id = 44 WHERE company_name = 'Microsoft';
#! SELECT
SELECT * FROM companies;
#! SELECT Microsoft
SELECT * FROM companies WHERE company_name = 'Microsoft';

View File

@ -6,7 +6,7 @@ BIN_DIR = ../bin
CC = g++ CC = g++
CFLAGS = -O3 -I./ -Ilib/ -Ilib/statements/ -Iparser/ -std=c++11 -pthread -Wall -g CFLAGS = -O3 -I./ -Ilib/ -Ilib/statements/ -Iparser/ -std=c++11 -pthread -Wall -g
LIB_FILES = $(shell find lib/ -name '*.cpp') $(shell find lib/ -name '*.h') parser/bison_parser.cpp parser/flex_lexer.cpp parser/SQLParser.cpp LIB_HEADERS = $(shell find lib/ -name '*.h') parser/bison_parser.h parser/flex_lexer.h parser/SQLParser.h
LIB_SOURCES = $(shell find lib/ -name '*.cpp') parser/bison_parser.cpp parser/flex_lexer.cpp parser/SQLParser.cpp LIB_SOURCES = $(shell find lib/ -name '*.cpp') parser/bison_parser.cpp parser/flex_lexer.cpp parser/SQLParser.cpp
TEST_SOURCES = $(shell find tests/ -name '*.cpp') TEST_SOURCES = $(shell find tests/ -name '*.cpp')
@ -14,7 +14,8 @@ TEST_SOURCES = $(shell find tests/ -name '*.cpp')
build: clean build: clean
make -C parser/ make -C parser/
mkdir $(BUILD_DIR) mkdir $(BUILD_DIR)
cp $(LIB_FILES) $(BUILD_DIR) cp $(LIB_SOURCES) $(BUILD_DIR)
cp $(LIB_HEADERS) $(BUILD_DIR)
analysis: $(LIB_SOURCES) sql_analysis.cpp analysis: $(LIB_SOURCES) sql_analysis.cpp

View File

@ -19,6 +19,7 @@ struct UpdateStatement : SQLStatement {
virtual ~UpdateStatement(); // defined in destructors.cpp virtual ~UpdateStatement(); // defined in destructors.cpp
// TODO: switch to char* instead of TableRef
TableRef* table; TableRef* table;
List<UpdateClause*>* updates; List<UpdateClause*>* updates;
Expr* where; Expr* where;