mirror of
https://github.com/correl/mage.git
synced 2024-12-26 19:16:54 +00:00
[CardRepository] Fixed searching for Strings containing apostrophe
This commit is contained in:
parent
021a00400d
commit
86702ec437
2 changed files with 11 additions and 9 deletions
|
@ -28,6 +28,7 @@
|
||||||
package mage.cards.repository;
|
package mage.cards.repository;
|
||||||
|
|
||||||
import com.j256.ormlite.stmt.QueryBuilder;
|
import com.j256.ormlite.stmt.QueryBuilder;
|
||||||
|
import com.j256.ormlite.stmt.SelectArg;
|
||||||
import com.j256.ormlite.stmt.Where;
|
import com.j256.ormlite.stmt.Where;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -158,11 +159,11 @@ public class CardCriteria {
|
||||||
Where where = qb.where();
|
Where where = qb.where();
|
||||||
int clausesCount = 0;
|
int clausesCount = 0;
|
||||||
if (name != null) {
|
if (name != null) {
|
||||||
where.like("name", '%' + name + '%');
|
where.like("name", new SelectArg('%' + name + '%'));
|
||||||
clausesCount++;
|
clausesCount++;
|
||||||
}
|
}
|
||||||
if (rules != null) {
|
if (rules != null) {
|
||||||
where.like("rules", '%' + rules + '%');
|
where.like("rules", new SelectArg('%' + rules + '%'));
|
||||||
clausesCount++;
|
clausesCount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -175,7 +176,7 @@ public class CardCriteria {
|
||||||
}
|
}
|
||||||
|
|
||||||
for (CardType type : types) {
|
for (CardType type : types) {
|
||||||
where.like("types", '%' + type.name() + '%');
|
where.like("types", new SelectArg('%' + type.name() + '%'));
|
||||||
}
|
}
|
||||||
if (!types.isEmpty()) {
|
if (!types.isEmpty()) {
|
||||||
where.or(types.size());
|
where.or(types.size());
|
||||||
|
@ -183,21 +184,21 @@ public class CardCriteria {
|
||||||
}
|
}
|
||||||
|
|
||||||
for (CardType type : notTypes) {
|
for (CardType type : notTypes) {
|
||||||
where.not().like("types", '%' + type.name() + '%');
|
where.not().like("types", new SelectArg('%' + type.name() + '%'));
|
||||||
clausesCount++;
|
clausesCount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (String superType : supertypes) {
|
for (String superType : supertypes) {
|
||||||
where.like("supertypes", '%' + superType + '%');
|
where.like("supertypes", new SelectArg('%' + superType + '%'));
|
||||||
clausesCount++;
|
clausesCount++;
|
||||||
}
|
}
|
||||||
for (String subType : notSupertypes) {
|
for (String subType : notSupertypes) {
|
||||||
where.not().like("supertypes", '%' + subType + '%');
|
where.not().like("supertypes", new SelectArg('%' + subType + '%'));
|
||||||
clausesCount++;
|
clausesCount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (String subType : subtypes) {
|
for (String subType : subtypes) {
|
||||||
where.like("subtypes", '%' + subType + '%');
|
where.like("subtypes", new SelectArg('%' + subType + '%'));
|
||||||
clausesCount++;
|
clausesCount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -31,6 +31,7 @@ import com.j256.ormlite.dao.Dao;
|
||||||
import com.j256.ormlite.dao.DaoManager;
|
import com.j256.ormlite.dao.DaoManager;
|
||||||
import com.j256.ormlite.jdbc.JdbcConnectionSource;
|
import com.j256.ormlite.jdbc.JdbcConnectionSource;
|
||||||
import com.j256.ormlite.stmt.QueryBuilder;
|
import com.j256.ormlite.stmt.QueryBuilder;
|
||||||
|
import com.j256.ormlite.stmt.SelectArg;
|
||||||
import com.j256.ormlite.support.ConnectionSource;
|
import com.j256.ormlite.support.ConnectionSource;
|
||||||
import com.j256.ormlite.table.TableUtils;
|
import com.j256.ormlite.table.TableUtils;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
@ -123,7 +124,7 @@ public enum CardRepository {
|
||||||
public CardInfo findCard(String setCode, int cardNumber) {
|
public CardInfo findCard(String setCode, int cardNumber) {
|
||||||
try {
|
try {
|
||||||
QueryBuilder<CardInfo, Object> queryBuilder = cardDao.queryBuilder();
|
QueryBuilder<CardInfo, Object> queryBuilder = cardDao.queryBuilder();
|
||||||
queryBuilder.where().eq("setCode", setCode).and().eq("cardNumber", cardNumber);
|
queryBuilder.where().eq("setCode", new SelectArg(setCode)).and().eq("cardNumber", cardNumber);
|
||||||
List<CardInfo> result = cardDao.query(queryBuilder.prepare());
|
List<CardInfo> result = cardDao.query(queryBuilder.prepare());
|
||||||
if (!result.isEmpty()) {
|
if (!result.isEmpty()) {
|
||||||
return result.get(0);
|
return result.get(0);
|
||||||
|
@ -149,7 +150,7 @@ public enum CardRepository {
|
||||||
public List<CardInfo> findCards(String name) {
|
public List<CardInfo> findCards(String name) {
|
||||||
try {
|
try {
|
||||||
QueryBuilder<CardInfo, Object> queryBuilder = cardDao.queryBuilder();
|
QueryBuilder<CardInfo, Object> queryBuilder = cardDao.queryBuilder();
|
||||||
queryBuilder.where().eq("name", name);
|
queryBuilder.where().eq("name", new SelectArg(name));
|
||||||
|
|
||||||
return cardDao.query(queryBuilder.prepare());
|
return cardDao.query(queryBuilder.prepare());
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
|
|
Loading…
Reference in a new issue