Skip to content

Commit 235b776

Browse files
David AndersonDavid Anderson
authored andcommitted
updated function to generate qcp counts table to also count QCP4 subcases
1 parent ff9f9e9 commit 235b776

File tree

3 files changed

+74
-19
lines changed

3 files changed

+74
-19
lines changed

QCPAnalysis/src/QCPAnalysis/QCP4SubcaseAnalysis.rsc

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import ValueIO;
2323
set[str] superglobals = {"_SERVER", "_REQUEST", "_POST", "_GET", "_FILES",
2424
"_ENV", "_COOKIE", "_SESSION"};
2525

26-
// write QCP4 list to file since function takes a long time to execute
26+
// write QCP4 list to file since the getQCP function takes a long time to execute
2727
public void writeQCP4(){
2828
qcp4 = getQCP("4");
2929
writeBinaryValueFile(|project://QCPAnalysis/results/lists/qcp4|, qcp4);
@@ -39,7 +39,24 @@ public void analyzeQCP4(){
3939
println("Types of dynamic snippets: <types>");
4040
println("Counts for each type:\n <(n : size(d) | n <- groupDynamicSnippetsByType(ds), d := groupDynamicSnippetsByType(ds)[n])>");
4141
println("Counts for each role:\n <(n : size(d) | n <- groupDynamicSnippetsByRole(qcp4), d := groupDynamicSnippetsByRole(qcp4)[n])>");
42-
//for(q <- groupDynamicSnippetsByRole(qcp4)["Other"]) println(q.dynamicpart@at);
42+
43+
// for validation of param grouiping
44+
/*params = groupDynamicSnippetsByRole(qcp4)["Parameter"];
45+
sublist = [];
46+
for(i <- [0..100]){
47+
p = getOneFrom(params);
48+
while(p in sublist){
49+
p = getOneFrom(params);
50+
}
51+
sublist += p.dynamicpart@at;
52+
}
53+
for(q <- sublist) println(q.dynamicpart@at);*/
54+
55+
// for validation of column, table, and database name grouping
56+
for(q <- groupDynamicSnippetsByRole(qcp4)["Column, Table, or Database Name"]) println(q.dynamicpart@at);
57+
58+
// for validation of other grouping
59+
//for(q <- groupDynamicSnippetsByRole(qcp4)["Column, Table, or Database Name"]) println(q.dynamicpart@at);
4360
}
4461

4562
public map[str, list[QuerySnippet]] groupDynamicSnippetsByType(list[QuerySnippet] ds){

QCPAnalysis/src/QCPAnalysis/QueryStringAnalysis.rsc

Lines changed: 47 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -132,17 +132,54 @@ private list[QuerySnippet] buildQG2Snippets(list[Expr] parts){
132132
return snippets;
133133
}
134134

135-
public lrel[str,int] reportQCPCounts(){
135+
public lrel[str,int] reportQCPCounts(bool subcases){
136136
qs = buildAndClassifyQueryStrings();
137-
return [
138-
<"QCP1", size({q | q <- qs, q.flags.qcp1 == true})>,
139-
<"QCP2", size({q | q <- qs, q.flags.qcp2 == true})>,
140-
<"QCP3a", size({q | q <- qs, q.flags.qcp3a == true})>,
141-
<"QCP3b", size({q | q <- qs, q.flags.qcp3b == true})>,
142-
<"QCP4", size({q | q <- qs, q.flags.qcp4 == true})>,
143-
<"QCP5", size({q | q <- qs, q.flags.qcp5 == true})>,
144-
<"other", size({q | q <- qs, q.flags.unclassified == true})>
145-
];
137+
if(!subcases){
138+
return [
139+
<"QCP1", size({q | q <- qs, q.flags.qcp1 == true})>,
140+
<"QCP2", size({q | q <- qs, q.flags.qcp2 == true})>,
141+
<"QCP3a", size({q | q <- qs, q.flags.qcp3a == true})>,
142+
<"QCP3b", size({q | q <- qs, q.flags.qcp3b == true})>,
143+
<"QCP4", size({q | q <- qs, q.flags.qcp4 == true})>,
144+
<"other", size({q | q <- qs, q.flags.unclassified == true})>
145+
];
146+
}
147+
else{
148+
return [
149+
<"QCP1", size({q | q <- qs, q.flags.qcp1 == true})>,
150+
<"QCP2", size({q | q <- qs, q.flags.qcp2 == true})>,
151+
<"QCP3a", size({q | q <- qs, q.flags.qcp3a == true})>,
152+
<"QCP3b", size({q | q <- qs, q.flags.qcp3b == true})>
153+
154+
] + getQCP4SubcaseCounts() + [<"other", size({q | q <- qs, q.flags.unclassified == true})>];
155+
}
156+
}
157+
158+
private lrel[str, int] getQCP4SubcaseCounts(){
159+
Corpus corpus = getCorpus();
160+
qcp4 = readBinaryValueFile(#set[QueryString], |project://QCPAnalysis/results/lists/qcp4|);
161+
locs = [q.callloc | q <- qcp4];
162+
queriesRel = [];
163+
for (p <- corpus, v := corpus[p]) {
164+
pt = loadBinary(p,v);
165+
// Get all the calls to mysql_query
166+
queriesRel += [ <c, params> | /c:call(name(name("mysql_query")),params) := pt, c@at in locs];
167+
}
168+
169+
170+
res = [<"QCP4a", 0>, <"QCP4b" , 0>, <"QCP4c", 0>];
171+
for(<q, params> <- queriesRel){
172+
switch(params){
173+
case [actualParameter(scalar(encapsed(_)),_)]: res[0][1] += 1;
174+
case [actualParameter(scalar(encapsed(_)), _),_]: res[0][1] += 1;
175+
case [actualParameter(binaryOperation(left,right,concat()),_)]: res[1][1] += 1;
176+
case [actualParameter(binaryOperation(left,right,concat()),_), _]: res[1][1] += 1;
177+
case [actualParameter(var(name(name(_))), _)] : res[2][1] += 1;
178+
case [actualParameter(var(name(name(_))), _), _] : res[2][1] += 1;
179+
default: println("this is broken");
180+
}
181+
}
182+
return res;
146183
}
147184
148185
public set[QueryString] getQCP(str id){

QCPAnalysis/src/QCPAnalysis/WriteResults.rsc

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,18 @@ import lang::php::util::Corpus;
1414
import lang::php::util::Utils;
1515

1616
import IO;
17+
import ValueIO;
1718
import List;
1819
import String;
1920
import Set;
2021

2122
loc tables = |project://QCPAnalysis/results/tables/|;
2223
public void writeTables(){
23-
qs = getQCP("4");
24-
ds = getDynamicSnippets(qs);
24+
qcp4 = readBinaryValueFile(#set[QueryString], |project://QCPAnalysis/results/lists/qcp4|);
25+
ds = getDynamicSnippets(qcp4);
2526
writeFile(tables + "qcpCounts.txt", qcpCountsAsLatexTable());
2627
writeFile(tables + "qcp4Types.txt", qcp4TypesAsLatexTable(ds));
27-
writeFile(tables + "qcp4Roles.txt", qcp4RolesAsLatexTable(qs));
28+
writeFile(tables + "qcp4Roles.txt", qcp4RolesAsLatexTable(qcp4));
2829
}
2930

3031
public str qcpCountsAsLatexTable(){
@@ -34,11 +35,11 @@ public str qcpCountsAsLatexTable(){
3435
'\\npfourdigitsep
3536
'\\begin{table}
3637
'\\centering
37-
'\\caption{Counts of Each Query Construction Pattern\\label{tbl:php-corpus}}
38+
'\\caption{Counts of Each Query Construction Pattern\\label{tbl:qcp-counts}}
3839
'\\ra{1.2}
3940
'\\begin{tabularx}{\\columnwidth}{Xrrr} \\toprule
4041
'Query Construction Pattern & Number of Occurrences\\\\ \\midrule
41-
'<for(<p,c> <- reportQCPCounts()){><getLine(p,c)> \\\\
42+
'<for(<p,c> <- reportQCPCounts(true)){><getLine(p,c)> \\\\
4243
'<}>
4344
'\\bottomrule
4445
'\\end{tabularx}
@@ -57,7 +58,7 @@ public str qcp4TypesAsLatexTable(list[QuerySnippet] qs){
5758
'\\npfourdigitsep
5859
'\\begin{table}
5960
'\\centering
60-
'\\caption{Counts of Each Type of Dynamic Query Part in QCP4 Occurrences\\label{tbl:php-qcp4-types}}
61+
'\\caption{Counts of Each Type of Dynamic Query Part in QCP4 Occurrences\\label{tbl:qcp4-types}}
6162
'\\ra{1.2}
6263
'\\begin{tabularx}{\\columnwidth}{Xrrr} \\toprule
6364
'Type & Number of Occurrences\\\\ \\midrule
@@ -80,7 +81,7 @@ public str qcp4RolesAsLatexTable(set[QueryString] qs){
8081
'\\npfourdigitsep
8182
'\\begin{table}
8283
'\\centering
83-
'\\caption{Counts of Each QCP4 Dynamic Part Grouped by Role\\label{tbl:php-qcp4-roles}}
84+
'\\caption{Counts of Each QCP4 Dynamic Part Grouped by Role\\label{qcp4-roles}}
8485
'\\ra{1.2}
8586
'\\begin{tabularx}{\\columnwidth}{Xrrr} \\toprule
8687
'Role & Number of Occurrences\\\\ \\midrule

0 commit comments

Comments
 (0)