From 86702ec437ecb114dddf27ad8f4fa6d166bb77e3 Mon Sep 17 00:00:00 2001 From: North Date: Thu, 25 Oct 2012 00:32:48 +0300 Subject: [PATCH] [CardRepository] Fixed searching for Strings containing apostrophe --- .../src/mage/cards/repository/CardCriteria.java | 15 ++++++++------- .../src/mage/cards/repository/CardRepository.java | 5 +++-- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/Mage.Sets/src/mage/cards/repository/CardCriteria.java b/Mage.Sets/src/mage/cards/repository/CardCriteria.java index 7382af53f9..99f7790c6b 100644 --- a/Mage.Sets/src/mage/cards/repository/CardCriteria.java +++ b/Mage.Sets/src/mage/cards/repository/CardCriteria.java @@ -28,6 +28,7 @@ package mage.cards.repository; import com.j256.ormlite.stmt.QueryBuilder; +import com.j256.ormlite.stmt.SelectArg; import com.j256.ormlite.stmt.Where; import java.sql.SQLException; import java.util.ArrayList; @@ -158,11 +159,11 @@ public class CardCriteria { Where where = qb.where(); int clausesCount = 0; if (name != null) { - where.like("name", '%' + name + '%'); + where.like("name", new SelectArg('%' + name + '%')); clausesCount++; } if (rules != null) { - where.like("rules", '%' + rules + '%'); + where.like("rules", new SelectArg('%' + rules + '%')); clausesCount++; } @@ -175,7 +176,7 @@ public class CardCriteria { } for (CardType type : types) { - where.like("types", '%' + type.name() + '%'); + where.like("types", new SelectArg('%' + type.name() + '%')); } if (!types.isEmpty()) { where.or(types.size()); @@ -183,21 +184,21 @@ public class CardCriteria { } for (CardType type : notTypes) { - where.not().like("types", '%' + type.name() + '%'); + where.not().like("types", new SelectArg('%' + type.name() + '%')); clausesCount++; } for (String superType : supertypes) { - where.like("supertypes", '%' + superType + '%'); + where.like("supertypes", new SelectArg('%' + superType + '%')); clausesCount++; } for (String subType : notSupertypes) { - where.not().like("supertypes", '%' + subType + '%'); + where.not().like("supertypes", new SelectArg('%' + subType + '%')); clausesCount++; } for (String subType : subtypes) { - where.like("subtypes", '%' + subType + '%'); + where.like("subtypes", new SelectArg('%' + subType + '%')); clausesCount++; } diff --git a/Mage.Sets/src/mage/cards/repository/CardRepository.java b/Mage.Sets/src/mage/cards/repository/CardRepository.java index bce60392dd..471682a8aa 100644 --- a/Mage.Sets/src/mage/cards/repository/CardRepository.java +++ b/Mage.Sets/src/mage/cards/repository/CardRepository.java @@ -31,6 +31,7 @@ import com.j256.ormlite.dao.Dao; import com.j256.ormlite.dao.DaoManager; import com.j256.ormlite.jdbc.JdbcConnectionSource; import com.j256.ormlite.stmt.QueryBuilder; +import com.j256.ormlite.stmt.SelectArg; import com.j256.ormlite.support.ConnectionSource; import com.j256.ormlite.table.TableUtils; import java.io.File; @@ -123,7 +124,7 @@ public enum CardRepository { public CardInfo findCard(String setCode, int cardNumber) { try { QueryBuilder queryBuilder = cardDao.queryBuilder(); - queryBuilder.where().eq("setCode", setCode).and().eq("cardNumber", cardNumber); + queryBuilder.where().eq("setCode", new SelectArg(setCode)).and().eq("cardNumber", cardNumber); List result = cardDao.query(queryBuilder.prepare()); if (!result.isEmpty()) { return result.get(0); @@ -149,7 +150,7 @@ public enum CardRepository { public List findCards(String name) { try { QueryBuilder queryBuilder = cardDao.queryBuilder(); - queryBuilder.where().eq("name", name); + queryBuilder.where().eq("name", new SelectArg(name)); return cardDao.query(queryBuilder.prepare()); } catch (SQLException ex) {