Using " Generating all permutations of a given string " as a reference, I try to get my program (when a name field is found) to write all combinations of the name to the database (queryID aka qid is not a primary key. I assume that all this will be duplicated).
example: John Michael Doe
- John Michael Dow
- John Doe Michael
- Michael John Doe
- Michael Dow John
- Doy John Michael
- Doy Michael John
To better understand the scenario, when someone uses my program to search, they can add โrestrictionsโ.

Therefore, when they add a restriction, they have a drop-down menu, they can select several categories, and one of them is a name.

, :
Name CONTAINS foo bar
.
Id CONTAINS 1234
.
Name CONTAINS john doe
.
SQL:
insert into qal.query_input values('df084b1f-1337','1234','','','foo bar john doe','','');
( - , )
, ( ):
insert into qal.query_input values('df084b1f-1337','1234','','','foo bar','','');
insert into qal.query_input values('df084b1f-1337','1234','','','bar foo','','');
insert into qal.query_input values('df084b1f-1337','1234','','','john doe','','');
insert into qal.query_input values('df084b1f-1337','1234','','','doe john','','');
:
ArrayList<String> fields = constraintToInputLogFieldMap.get(key);
ArrayList<String> names;
for (String field : fields) {
ArrayList<String> values = inputLogFieldValues.get(field);
if (values == null) {
values = new ArrayList<>();
inputLogFieldValues.put(field, values);
}
if (singletonRange != null) {
values.add((String) singletonRange.getValue());
}
if (listRange != null) {
for (Object v : listRange.getValues()) {
values.add((String) v);
}
}
}
names = inputLogFieldValues.get("Name");
for (String field : inputLogFields) {
ArrayList<String> values = inputLogFieldValues.get(field);
if (values == null)
inputEntry += ",''";
else {
String valueStr = "";
for (String value : values)
valueStr += " " + value;
inputEntry += ",'" + valueStr.substring(1) + "'";
}
}
inputEntry = "insert into qal.query_input values('" + qid + "'" + inputEntry + ");";
logger.info("Stackoverflow SQL output: " + inputEntry);
dbUpdate(inputEntry);
- , , arraylist ? ( , .. firstname middlename lastname secondlastname)
- , .
2/10/2016 17: 36EST
, ( ), .
:
insert into qal.query_input values('df084b1f-1337','1234','','','foo bar john doe','','');
:
insert into qal.query_input values('df084b1f-1337','1234','','','foo bar','','');
insert into qal.query_input values('df084b1f-1337','1234','','','john doe','','');
( ):
ArrayList<String> inputEntries = new ArrayList<>();
for (String name : names) {
inputEntry = "";
for (String field : inputLogFields) {
ArrayList<String> values = inputLogFieldValues.get(field);
if (values == null)
inputEntry += ",''";
else {
if (field.equals("Name")) {
inputEntry += ",'" + name + "'";
} else {
String valueStr = "";
for (String value : values)
valueStr += " " + value;
inputEntry += ",'" + valueStr.substring(1) + "'";
}
}
}
inputEntry = "insert into qal.query_input values('" + qid + "'" + inputEntry + ");";
inputEntries.add(inputEntry);
}
for (String sqlEntry : inputEntries) {
dbUpdate(sqlEntry);
}
, , - .