diff options
author | Feideus <erwan.ulrich@gmail.com> | 2018-06-04 10:40:26 +0200 |
---|---|---|
committer | Feideus <erwan.ulrich@gmail.com> | 2018-06-04 10:40:26 +0200 |
commit | 19de5e7918e6daa19616e2e71ec1bf2cc842d2ca (patch) | |
tree | 86c2d16bc76de783cd429d8223aa3ecda3be7c03 /src | |
parent | 5bced49df755b66ea27af818139dbd206cd74cde (diff) | |
download | schemafuzz-19de5e7918e6daa19616e2e71ec1bf2cc842d2ca.tar.gz schemafuzz-19de5e7918e6daa19616e2e71ec1bf2cc842d2ca.tar.bz2 schemafuzz-19de5e7918e6daa19616e2e71ec1bf2cc842d2ca.zip |
All buged fixed. Only FK violation left to handle.(DEFFERED ?)
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/org/schemaspy/DBFuzzer.java | 40 | ||||
-rw-r--r-- | src/main/java/org/schemaspy/model/GenericTreeNode.java | 56 |
2 files changed, 62 insertions, 34 deletions
diff --git a/src/main/java/org/schemaspy/DBFuzzer.java b/src/main/java/org/schemaspy/DBFuzzer.java index 772c1e4..1a5f24e 100644 --- a/src/main/java/org/schemaspy/DBFuzzer.java +++ b/src/main/java/org/schemaspy/DBFuzzer.java @@ -178,26 +178,26 @@ public class DBFuzzer //Extract Random row from the db specified in sqlService public Row pickRandomRow() { - Table randomTable = pickRandomTable(); - - - String theQuery = "SELECT * FROM "+randomTable.getName()+" ORDER BY RANDOM() LIMIT 1"; - //String theQuery = "SELECT * FROM test_table2 ORDER BY RANDOM() LIMIT 1"; // Change test_table2 to test_table here to swap back to line finding - QueryResponseParser qrp = new QueryResponseParser(); - ResultSet rs = null; - Row res = null ; - PreparedStatement stmt; - - try - { - stmt = analyzer.getSqlService().prepareStatement(theQuery); - rs = stmt.executeQuery(); - res = qrp.parse(rs,analyzer.getDb().getTablesMap().get(randomTable.getName())).getRows().get(0); //randomTable should be set there - } - catch (Exception e) - { - LOGGER.info("This query threw an error"+e); - } + Row res = null; + + do { + Table randomTable = pickRandomTable(); + + String theQuery = "SELECT * FROM " + randomTable.getName() + " ORDER BY RANDOM() LIMIT 1"; + //String theQuery = "SELECT * FROM test_table2 ORDER BY RANDOM() LIMIT 1"; // Change test_table2 to test_table here to swap back to line finding + QueryResponseParser qrp = new QueryResponseParser(); + ResultSet rs = null; + PreparedStatement stmt; + + try { + stmt = analyzer.getSqlService().prepareStatement(theQuery); + rs = stmt.executeQuery(); + res = qrp.parse(rs, analyzer.getDb().getTablesMap().get(randomTable.getName())).getRows().get(0); //randomTable should be set there + } catch (Exception e) { + LOGGER.info("This query threw an error" + e); + } + } + while(res == null); return res; } diff --git a/src/main/java/org/schemaspy/model/GenericTreeNode.java b/src/main/java/org/schemaspy/model/GenericTreeNode.java index 46b039b..e6f2f15 100644 --- a/src/main/java/org/schemaspy/model/GenericTreeNode.java +++ b/src/main/java/org/schemaspy/model/GenericTreeNode.java @@ -228,7 +228,10 @@ public class GenericTreeNode { public ArrayList<SingleChange> discoverMutationPossibilities(GenericTreeNode rootMutation) { if(initial_state_row == null) + { + System.out.println("NO INITIAL STATE"); return null ; + } ArrayList<SingleChange> possibilities = new ArrayList<SingleChange>(); @@ -246,7 +249,7 @@ public class GenericTreeNode { } } if(possibilities.isEmpty()) - System.out.println("No raw Mutation could be found for this row"); // TO BE HANDLED. juste create another GenericTreeNode + System.out.println("No raw Mutation could be found for this row"); //REMOVING POSSIBILITIES THAT DONT MATCH CONSTRAINTS // for(SingleChange singleChange : possibilities) @@ -265,27 +268,37 @@ public class GenericTreeNode { String typeName = tableColumn.getTypeName(); GenericTreeNode rootForThisMutation = FirstApperanceOf(this); + switch (typeName) { case "smallint": case "integer": case "int2": - 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))); - break; - + Object tmp3 = rootForThisMutation.getInitial_state_row().getContent().get(tableColumn.getName()); + if( tmp3 != null && tmp3.toString() != "" ) + { + 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))); + break; + } case "character": - case "character varying": + case "character varying": // MIXED CHARACTERS/NUMBERS STRINGS MAKE CHARAT CRASH AT 0 IF FIRST CHAR IS NUMBER. USE REGEX TO FIND FIRST ACTUAL LETTER ? case "varchar": - char tmp2 = (char) rootForThisMutation.getInitial_state_row().getContent().get(tableColumn.getName()).toString().charAt(0); + + Object tmp4 = rootForThisMutation.getInitial_state_row().getContent().get(tableColumn.getName()); + if(tmp4 != null && tmp4.toString() != "" ) + { + + char tmp2 = tmp4.toString().replaceAll("\\d","").charAt(0); char nextChar = (char) (tmp2 + 1); char prevChar = (char) (tmp2 - 1); SingleChange sg = new SingleChange(tableColumn, this, column_value, (Character.toString(nextChar) + column_value.toString().substring(1))); - oneChange.add(new SingleChange(tableColumn, this, column_value, (Character.toString(nextChar) + column_value.toString().substring(1))));oneChange.add(new SingleChange(tableColumn, this, column_value, (Character.toString(prevChar) + column_value.toString().substring(1)))); - + oneChange.add(new SingleChange(tableColumn, this, column_value, (Character.toString(nextChar) + column_value.toString().substring(1)))); + oneChange.add(new SingleChange(tableColumn, this, column_value, (Character.toString(prevChar) + column_value.toString().substring(1)))); + } break; case "bool": if (column_value.equals("f")) @@ -331,7 +344,6 @@ public class GenericTreeNode { System.out.println("Unsupported dataType = "+typeName); } - return oneChange; } @@ -410,7 +422,16 @@ public class GenericTreeNode { || chosenChange.getParentTableColumn().getTable().getColumn(entry.getKey()).getTypeName().equals("date")) theQuery = theQuery + (entry.getKey() + "='" + entry.getValue().toString() + "', "); else - theQuery = theQuery + (entry.getKey() + "=" + entry.getValue().toString() + ", "); + { + if(entry.getValue() == null || entry.getValue().toString() == "" || entry.getValue().toString() == null) + { + String tmp = "null"; + theQuery = theQuery + (entry.getKey() + "=" + tmp+ ", "); // A CHANGER DURGENCE + + } + else + theQuery = theQuery + (entry.getKey() + "=" + entry.getValue().toString() + ", "); + } } } @@ -428,7 +449,14 @@ public class GenericTreeNode { || chosenChange.getParentTableColumn().getTable().getColumn(entry.getKey()).getTypeName().equals("date")) theQuery = theQuery + (entry.getKey() + "='" + entry.getValue().toString() + "' AND "); else - theQuery = theQuery + (entry.getKey() + "=" + entry.getValue().toString() + " AND "); + { + if (entry.getValue() == null || entry.getValue().toString() == "" || entry.getValue().toString() == null) { + String tmp = "null"; + theQuery = theQuery + (entry.getKey() + "=" + tmp + " AND "); // A CHANGER DURGENCE + + } else + theQuery = theQuery + (entry.getKey() + "=" + entry.getValue().toString() + " AND ");; + } } else { |