[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] [taler-schemafuzz] branch master updated: Main loop work bu
From: |
gnunet |
Subject: |
[GNUnet-SVN] [taler-schemafuzz] branch master updated: Main loop work but Primary key is still a problem |
Date: |
Mon, 11 Jun 2018 13:38:28 +0200 |
This is an automated email from the git hooks/post-receive script.
erwan-ulrich pushed a commit to branch master
in repository schemafuzz.
The following commit(s) were added to refs/heads/master by this push:
new 19d8c4d Main loop work but Primary key is still a problem
19d8c4d is described below
commit 19d8c4d45e03e93ab1a6a3942a630209cd6d450b
Author: Feideus <address@hidden>
AuthorDate: Mon Jun 11 13:38:22 2018 +0200
Main loop work but Primary key is still a problem
---
src/main/java/org/schemaspy/DBFuzzer.java | 11 ++--
.../java/org/schemaspy/model/GenericTreeNode.java | 77 +++++++++++++++++-----
2 files changed, 66 insertions(+), 22 deletions(-)
diff --git a/src/main/java/org/schemaspy/DBFuzzer.java
b/src/main/java/org/schemaspy/DBFuzzer.java
index bf5d0f1..064a842 100644
--- a/src/main/java/org/schemaspy/DBFuzzer.java
+++ b/src/main/java/org/schemaspy/DBFuzzer.java
@@ -89,7 +89,7 @@ public class DBFuzzer
// Building root Mutation. Could be extended by looking for a relevant
first SingleChange as rootMutation
do {
Row randomRow = pickRandomRow();
- currentMutation = new GenericTreeNode(randomRow, nextId());
+ currentMutation = new GenericTreeNode(randomRow,
nextId(),analyzer.getSqlService());
} while(currentMutation.getPotential_changes().isEmpty());
currentMutation.setChosenChange(currentMutation.getPotential_changes().get(0));
currentMutation.initPostChangeRow();
@@ -126,7 +126,6 @@ public class DBFuzzer
e.printStackTrace();
}
}
- mutationTree.addToTree(currentMutation);
//Injection
try
{
@@ -136,6 +135,7 @@ public class DBFuzzer
if(resQuery)
{
LOGGER.info("GenericTreeNode was sucessfull");
+ mutationTree.addToTree(currentMutation);
}
else
LOGGER.info("QueryError");
@@ -147,7 +147,6 @@ public class DBFuzzer
returnStatus = false;
}
-
//Evalutation
try
{
@@ -322,7 +321,7 @@ public class DBFuzzer
if (markingDiff > 0) //
{
int randNumber =
rand.nextInt(previousMutation.getPotential_changes().size());
- nextMut = new
GenericTreeNode(previousMutation.getPost_change_row(), nextId(),
mutationTree.getRoot(), previousMutation,false);
+ nextMut = new
GenericTreeNode(previousMutation.getPost_change_row(), nextId(),
mutationTree.getRoot(), previousMutation,false,analyzer.getSqlService());
nextMut.setChosenChange(previousMutation.getPotential_changes().get(randNumber));
nextMut.initPostChangeRow();
}
@@ -333,7 +332,7 @@ public class DBFuzzer
if(changeOrDepthen.nextInt(2) == 1)
{
SingleChange tmp =
mutationTree.getRoot().singleChangeBasedOnWeight();
- nextMut = new
GenericTreeNode(tmp.getAttachedToMutation().getPost_change_row(), nextId(),
mutationTree.getRoot(), tmp.getAttachedToMutation(),false);
+ nextMut = new
GenericTreeNode(tmp.getAttachedToMutation().getPost_change_row(), nextId(),
mutationTree.getRoot(),
tmp.getAttachedToMutation(),false,analyzer.getSqlService());
nextMut.setChosenChange(tmp);
nextMut.initPostChangeRow();
}
@@ -343,7 +342,7 @@ public class DBFuzzer
do
{
nextRow = pickRandomRow();
- nextMut = new GenericTreeNode(nextRow, nextId(),
mutationTree.getRoot(), previousMutation, true);
+ nextMut = new GenericTreeNode(nextRow, nextId(),
mutationTree.getRoot(), previousMutation, true, analyzer.getSqlService());
}while(nextMut.getPotential_changes().isEmpty());
Random nextSingleChangeId = new Random();
diff --git a/src/main/java/org/schemaspy/model/GenericTreeNode.java
b/src/main/java/org/schemaspy/model/GenericTreeNode.java
index 51f6516..23d29f7 100644
--- a/src/main/java/org/schemaspy/model/GenericTreeNode.java
+++ b/src/main/java/org/schemaspy/model/GenericTreeNode.java
@@ -34,7 +34,7 @@ public class GenericTreeNode {
/**
* Default GenericTreeNode constructor
*/
- public GenericTreeNode(Row initial_state_row, int id) { // used only for
rootMutation and Tests
+ public GenericTreeNode(Row initial_state_row, int id,SqlService
sqlService) { // used only for rootMutation and Tests
//this.cascadingFK = false;
this.subTreeWeight = 0;
this.parent = null;
@@ -43,11 +43,11 @@ public class GenericTreeNode {
this.id = id;
this.isFirstApperance = true;
this.initial_state_row = initial_state_row;
- this.potential_changes = discoverMutationPossibilities(this);
+ this.potential_changes =
discoverMutationPossibilities(this,sqlService);
}
- public GenericTreeNode(Row initial_state_row, int id, GenericTreeNode
rootMutation, GenericTreeNode parentMutation,boolean isFirstApperance) {
+ public GenericTreeNode(Row initial_state_row, int id, GenericTreeNode
rootMutation, GenericTreeNode parentMutation,boolean
isFirstApperance,SqlService sqlService) {
//this.cascadingFK = false;
this.parent = parentMutation;
this.subTreeWeight = 0;
@@ -56,7 +56,7 @@ public class GenericTreeNode {
initDepth();
this.isFirstApperance = isFirstApperance;
this.initial_state_row = initial_state_row;
- this.potential_changes = discoverMutationPossibilities(rootMutation);
+ this.potential_changes =
discoverMutationPossibilities(rootMutation,sqlService);
}
@@ -207,7 +207,7 @@ public class GenericTreeNode {
this.parent = parent;
}
- public ArrayList<SingleChange>
discoverMutationPossibilities(GenericTreeNode rootMutation) {
+ public ArrayList<SingleChange>
discoverMutationPossibilities(GenericTreeNode rootMutation,SqlService
sqlService) {
if(initial_state_row == null)
{
@@ -230,15 +230,10 @@ public class GenericTreeNode {
e.printStackTrace();
}
}
+ possibilities =
removePotentialChangesThatDontMatchConstraints(possibilities,sqlService);
if(possibilities.isEmpty())
System.out.println("No raw Mutation could be found for this row");
- //REMOVING POSSIBILITIES THAT DONT MATCH CONSTRAINTS
- // for(SingleChange singleChange : possibilities)
- // {
- // if (!singleChange.respectsConstraints())
- // possibilities.remove(singleChange);
- // }
return possibilities;
}
@@ -264,7 +259,7 @@ public class GenericTreeNode {
int tmp =
Integer.parseInt(rootForThisMutation.getInitial_state_row().getContent().get(tableColumn.getName()).toString());
oneChange.add(new SingleChange(tableColumn, this,
column_value, Integer.toString(tmp++)));
oneChange.add(new SingleChange(tableColumn, this,
column_value, Integer.toString(32767)));
- oneChange.add(new SingleChange(tableColumn, this,
column_value, Integer.toString(1)));
+ oneChange.add(new SingleChange(tableColumn, this,
column_value, Integer.toString(0)));
break;
}
case "character":
@@ -341,7 +336,10 @@ public class GenericTreeNode {
else
System.out.println("INJECT");
if(checkIfHasParentFk(db))
+ {
+ System.out.println("TRANSFERT");
transferMutationToParent(db,sqlService);
+ }
theQuery = updateQueryBuilder(undo,db,sqlService);
try
@@ -353,7 +351,7 @@ public class GenericTreeNode {
}
catch (Exception e)
{
- e.printStackTrace();
+ System.out.println("Error ! : Mutation Canceled"+e); //
temporerally putting aside the Unique constraint brought by the
tranfertToParent Mechanic
return false;
}
}
@@ -425,7 +423,12 @@ public class GenericTreeNode {
||
chosenChange.getParentTableColumn().getTable().getColumn(entry.getKey()).getTypeName().equals("text")
||
chosenChange.getParentTableColumn().getTable().getColumn(entry.getKey()).getTypeName().equals("fulltext")
||
chosenChange.getParentTableColumn().getTable().getColumn(entry.getKey()).getTypeName().equals("email"))
- theQuery = theQuery + (entry.getKey() + "='" +
entry.getValue().toString() + "' AND ");
+ {
+ if(entry.getValue() != null )
+ theQuery = theQuery + (entry.getKey() + "='" +
entry.getValue().toString() + "' AND ");
+ else
+ theQuery = theQuery + (entry.getKey() + "= null
AND ");
+ }
}
else
{
@@ -736,8 +739,6 @@ public class GenericTreeNode {
else
semiQuery = semiQuery + " WHERE " +
chosenChange.getParentTableColumn().getName() + "="+chosenChange.getOldValue();
-
-
try {
Statement stmt = sqlService.getConnection().createStatement();
ResultSet res = stmt.executeQuery(semiQuery);
@@ -762,4 +763,48 @@ public class GenericTreeNode {
return false;
}
+ public ArrayList<SingleChange>
removePotentialChangesThatDontMatchConstraints(ArrayList<SingleChange>
possibilities, SqlService sqlService)
+ {
+ QueryResponseParser qrp;
+ QueryResponse response = null;
+ ArrayList<SingleChange> newPossibilities = possibilities;
+
+ for(SingleChange sg : possibilities)
+ {
+
if(sg.getParentTableColumn().getTable().getPrimaryColumns().contains(sg.getParentTableColumn()))
// unique OR PK constraints
+ {
+ String semiQuery = "SELECT * FROM " +
sg.getParentTableColumn().getTable().getName();
+ if (sg.getParentTableColumn().getTypeName().equals("varchar")
+ ||
sg.getParentTableColumn().getTypeName().equals("bool")
+ ||
sg.getParentTableColumn().getTypeName().equals("timestamp")
+ ||
sg.getParentTableColumn().getTypeName().equals("date")
+ ||
sg.getParentTableColumn().getTypeName().equals("_text")
+ ||
sg.getParentTableColumn().getTypeName().equals("text")
+ ||
sg.getParentTableColumn().getTypeName().equals("fulltext")
+ ||
sg.getParentTableColumn().getTypeName().equals("email"))
+ semiQuery = semiQuery + " WHERE " +
sg.getParentTableColumn().getName() + "= '" + sg.getNewValue() + " '";
+ else
+ semiQuery = semiQuery + " WHERE " +
sg.getParentTableColumn().getName() + "=" + sg.getNewValue();
+
+ System.out.println("removing = " + semiQuery);
+
+ try
+ {
+ Statement stmt =
sqlService.getConnection().createStatement();
+ ResultSet res = stmt.executeQuery(semiQuery);
+ qrp = new QueryResponseParser();
+ ArrayList<Row> rows = new ArrayList<Row>(qrp.parse(res,
sg.getParentTableColumn().getTable()).getRows());
+ response = new QueryResponse(rows);
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+
+ if(response.getRows() != null)
+ newPossibilities.remove(sg);
+ }
+ }
+ return newPossibilities;
+ }
}
--
To stop receiving notification emails like this one, please contact
address@hidden
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] [taler-schemafuzz] branch master updated: Main loop work but Primary key is still a problem,
gnunet <=