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