forked from dsferruzza/simpleSqlParser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.html
31 lines (30 loc) · 1.87 KB
/
example.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<!DOCTYPE html>
<html lang="en" >
<head>
<title>simpleSqlParser</title>
<meta charset="utf-8" />
</head>
<body>
<p><em>Check console to see the output</em></p>
<script src="simpleSqlParser.js"></script>
<script>
window.onload = function () {
// Example queries
var q = new Array();
q[0] = 'SELECT table1.champ1, table2.champ2 AS "label", FONCTION2(table3.champ3, 5,12,13,49), FONCTION(table3.champ3, 5) "autre label" FROM table1, table2 LEFT JOIN table2 ON table2.id = table1.id_table1 JOIN table3 ON table3.id = table2.id_table3 AND table2.truc = 5 OR table.batman = table.robin LEFT JOIN table2 ON table2.id = table1.id_table1 WHERE table1.machin = "bidule" AND (table2.truc != UPPER("chose (grth") OR `table3`.`batman`<=10) AND (machin) AND machin IS NOT NULL OR machin IS null ORDER BY table1.id ASC, table2.id DESC LIMIT 1,100';
q[1] = 'DELETE FROM table WHERE id = 5;';
q[2] = 'DELETE FROM table WHERE id = 5; DELETE FROM table WHERE id = 5; SELECT FONCTION_BIDON(1;2;3) FROM table;';
q[3] = 'SELECT * FROM table ORDER BY id ASC';
q[4] = 'SELECT EXTRACT(MICROSECOND FROM "2003-01-02 10:30:00.00123"), FONCTION_BIDON(1;2;3) FROM table INNER JOIN table2 ON table2.id = table.id_table2';
q[5] = 'SELECT * FROM table WHERE batman = 1';
q[6] = 'INSERT INTO table (test,test2, test3, contents) VALUES(1,2,3, "grogktr optkrhorp, geophgktrhopk , t")';
q[7] = 'UPDATE table SET truc = "machin", bidule=7 WHERE bool_column';
q[8] = 'SELECT table1.column1, UPPER(table2.column2) AS "alias for column2" FROM table1 LEFT JOIN table2 ON `table1`.`id` = table2.id_table1 WHERE table1.column1 AND (table2.column2 != 5 OR table.column3 IS NOT NULL) ORDER BY table1.id ASC, table2.id DESC LIMIT 5;';
// Parse & display
q.forEach(function (item, key) {
console.log(item, simpleSqlParser.sql2ast(item));
});
};
</script>
</body>
</html>