fix: #15: Handle SQL queries for views where the SQL contains a ' character
This commit is contained in:
parent
94aa357ad8
commit
947cb5c6fd
|
@ -38,18 +38,21 @@ public class GamebaseImportWorker extends AbstractImportWorker
|
|||
int numberOfGenres = genreList.size();
|
||||
for (GenreInfo genre : genreList)
|
||||
{
|
||||
counter++;
|
||||
this.gbInporter.setGenreOption(genre);
|
||||
publish("Processing games for " + genre.getGenreName());
|
||||
String viewName = getViewName(genre);
|
||||
importManager.setViewTag(viewName);
|
||||
importManager.setViewName(viewName);
|
||||
String additonalInfo = ", genre: " + genre.getGenreName() + " (" + counter + " of " + numberOfGenres + ")";
|
||||
int processedForGenre = executeImport(additonalInfo);
|
||||
if (genre.getGenreName().contains("Collect"))
|
||||
{
|
||||
counter++;
|
||||
this.gbInporter.setGenreOption(genre);
|
||||
publish("Processing games for " + genre.getGenreName());
|
||||
String viewName = getViewName(genre);
|
||||
importManager.setViewTag(viewName);
|
||||
importManager.setViewName(viewName);
|
||||
String additonalInfo = ", genre: " + genre.getGenreName() + " (" + counter + " of " + numberOfGenres + ")";
|
||||
int processedForGenre = executeImport(additonalInfo);
|
||||
|
||||
createAdditionalGameViews(processedForGenre, viewName, genre.getGenreName());
|
||||
createAdditionalGameViews(processedForGenre, viewName);
|
||||
|
||||
totalProcessed = totalProcessed + processedForGenre;
|
||||
totalProcessed = totalProcessed + processedForGenre;
|
||||
}
|
||||
}
|
||||
publish("Processed " + totalProcessed + " games.");
|
||||
progressValueString = "Finished!";
|
||||
|
@ -71,7 +74,7 @@ public class GamebaseImportWorker extends AbstractImportWorker
|
|||
}
|
||||
}
|
||||
|
||||
private void createAdditionalGameViews(int processedGames, String viewName, String viewTag)
|
||||
private void createAdditionalGameViews(int processedGames, String viewName)
|
||||
{
|
||||
//Lets use 250 as limit for each view
|
||||
int numOfViews = processedGames / 250;
|
||||
|
@ -82,8 +85,9 @@ public class GamebaseImportWorker extends AbstractImportWorker
|
|||
for (int i = 2; i < (numOfViews + 1); i++)
|
||||
{
|
||||
//Create additional views that can be filled later by editing view tags
|
||||
importManager.setViewName(viewName + "/" + i);
|
||||
importManager.setViewTag(viewTag + "-" + i);
|
||||
String name = viewName + "/" + i;
|
||||
importManager.setViewName(name);
|
||||
importManager.setViewTag(name);
|
||||
importManager.createGameViewForViewTag(this);
|
||||
}
|
||||
}
|
||||
|
@ -94,7 +98,6 @@ public class GamebaseImportWorker extends AbstractImportWorker
|
|||
newName = newName.replaceAll(" - ", "/");
|
||||
newName = newName.replace("[", "");
|
||||
newName = newName.replace("]", "");
|
||||
newName = newName.replace("'", "");
|
||||
if (newName.startsWith("/"))
|
||||
{
|
||||
newName = newName.substring(1);
|
||||
|
@ -123,7 +126,8 @@ public class GamebaseImportWorker extends AbstractImportWorker
|
|||
return -1;
|
||||
}
|
||||
progressValue++;
|
||||
progressValueString = String.format("Checking game files (batch %s of %s)" + additionalInfo, progressValue, progressMaximum);
|
||||
progressValueString =
|
||||
String.format("Checking game files (batch %s of %s)" + additionalInfo, progressValue, progressMaximum);
|
||||
gbInporter.checkGameFileForGbGames(gbInfoList, this);
|
||||
}
|
||||
|
||||
|
@ -153,8 +157,8 @@ public class GamebaseImportWorker extends AbstractImportWorker
|
|||
}
|
||||
chunkCount++;
|
||||
progressValue++;
|
||||
progressValueString =
|
||||
String.format("Importing to db and copying files (batch %s of %s)" + additionalInfo, progressValue, progressMaximum);
|
||||
progressValueString = String
|
||||
.format("Importing to db and copying files (batch %s of %s)" + additionalInfo, progressValue, progressMaximum);
|
||||
//Copy the list to avoid modifying it when reading several chunks
|
||||
ArrayList<String> copyList = new ArrayList<>();
|
||||
copyList.addAll(rowList);
|
||||
|
|
|
@ -143,31 +143,31 @@ public class GameView implements Comparable
|
|||
{
|
||||
case ViewFilter.BEGINS_WITH_TEXT:
|
||||
builder.append(" LIKE '");
|
||||
builder.append(viewFilter.getFilterData());
|
||||
builder.append(adaptFilterData(viewFilter.getFilterData()));
|
||||
builder.append("%'");
|
||||
break;
|
||||
|
||||
case ViewFilter.ENDS_WITH_TEXT:
|
||||
builder.append(" LIKE '%");
|
||||
builder.append(viewFilter.getFilterData());
|
||||
builder.append(adaptFilterData(viewFilter.getFilterData()));
|
||||
builder.append("'");
|
||||
break;
|
||||
|
||||
case ViewFilter.CONTAINS_TEXT:
|
||||
builder.append(" LIKE '%");
|
||||
builder.append(viewFilter.getFilterData());
|
||||
builder.append(adaptFilterData(viewFilter.getFilterData()));
|
||||
builder.append("%'");
|
||||
break;
|
||||
|
||||
case ViewFilter.NOT_CONTAINS_TEXT:
|
||||
builder.append(" NOT LIKE '%");
|
||||
builder.append(viewFilter.getFilterData());
|
||||
builder.append(adaptFilterData(viewFilter.getFilterData()));
|
||||
builder.append("%'");
|
||||
break;
|
||||
|
||||
case ViewFilter.EQUALS_TEXT:
|
||||
builder.append(" LIKE '");
|
||||
builder.append(viewFilter.getFilterData());
|
||||
builder.append(adaptFilterData(viewFilter.getFilterData()));
|
||||
builder.append("'");
|
||||
break;
|
||||
|
||||
|
@ -194,18 +194,18 @@ public class GameView implements Comparable
|
|||
}
|
||||
else
|
||||
{
|
||||
builder.append(viewFilter.getFilterData());
|
||||
builder.append(adaptFilterData(viewFilter.getFilterData()));
|
||||
}
|
||||
break;
|
||||
|
||||
case ViewFilter.BEFORE:
|
||||
builder.append(" < ");
|
||||
builder.append(viewFilter.getFilterData());
|
||||
builder.append(adaptFilterData(viewFilter.getFilterData()));
|
||||
break;
|
||||
|
||||
case ViewFilter.AFTER:
|
||||
builder.append(" > ");
|
||||
builder.append(viewFilter.getFilterData());
|
||||
builder.append(adaptFilterData(viewFilter.getFilterData()));
|
||||
break;
|
||||
default:
|
||||
logger.debug("Unexpected value: {}", viewFilter.getOperator());
|
||||
|
@ -242,25 +242,25 @@ public class GameView implements Comparable
|
|||
{
|
||||
case ViewFilter.BEGINS_WITH_TEXT:
|
||||
builder.append(" LIKE '");
|
||||
builder.append(viewFilter.getFilterData());
|
||||
builder.append(adaptFilterData(viewFilter.getFilterData()));
|
||||
builder.append("%'");
|
||||
break;
|
||||
|
||||
case ViewFilter.ENDS_WITH_TEXT:
|
||||
builder.append(" LIKE '%");
|
||||
builder.append(viewFilter.getFilterData());
|
||||
builder.append(adaptFilterData(viewFilter.getFilterData()));
|
||||
builder.append("'");
|
||||
break;
|
||||
|
||||
case ViewFilter.CONTAINS_TEXT:
|
||||
builder.append(" LIKE '%");
|
||||
builder.append(viewFilter.getFilterData());
|
||||
builder.append(adaptFilterData(viewFilter.getFilterData()));
|
||||
builder.append("%'");
|
||||
break;
|
||||
|
||||
case ViewFilter.EQUALS_TEXT:
|
||||
builder.append(" LIKE '");
|
||||
builder.append(viewFilter.getFilterData());
|
||||
builder.append(adaptFilterData(viewFilter.getFilterData()));
|
||||
builder.append("'");
|
||||
break;
|
||||
|
||||
|
@ -276,17 +276,17 @@ public class GameView implements Comparable
|
|||
|
||||
case ViewFilter.IS:
|
||||
builder.append(" = ");
|
||||
builder.append(viewFilter.getFilterData());
|
||||
builder.append(adaptFilterData(viewFilter.getFilterData()));
|
||||
break;
|
||||
|
||||
case ViewFilter.BEFORE:
|
||||
builder.append(" < ");
|
||||
builder.append(viewFilter.getFilterData());
|
||||
builder.append(adaptFilterData(viewFilter.getFilterData()));
|
||||
break;
|
||||
|
||||
case ViewFilter.AFTER:
|
||||
builder.append(" > ");
|
||||
builder.append(viewFilter.getFilterData());
|
||||
builder.append(adaptFilterData(viewFilter.getFilterData()));
|
||||
break;
|
||||
default:
|
||||
logger.debug("Unexpected value: {}", viewFilter.getOperator());
|
||||
|
@ -301,6 +301,11 @@ public class GameView implements Comparable
|
|||
}
|
||||
this.sqlQuery = builder.toString();
|
||||
}
|
||||
|
||||
private String adaptFilterData(String data)
|
||||
{
|
||||
return data.replaceAll("'", "''");
|
||||
}
|
||||
|
||||
public int getGameViewId()
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue