Google App Engine 용 JDO : 견적을 피합니다
-
19-09-2019 - |
문제
JDO (Google App Engine)에서 쿼리 매개 변수를 어떻게 탈출합니까?
예를 들어, 변수 이름에 안전하지 않은 숯이 단일 따옴표로 포함될 수있는 경우 다음 스 니펫을 안전하게 만드는 방법 ( ')
PersistenceManager pm = ...;
String query = "select from Person where name='"+name+"'";
List<Shortened> shortened = (List<Shortened>) pm.newQuery(query).execute();
해결책
대신 쿼리 매개 변수를 사용하면 쿼리 자체에 값을 포함하는 것보다 훨씬 안전합니다. GAE 문서의 예는 다음과 같습니다.
Query query = pm.newQuery("select from Employee " +
"where lastName == lastNameParam " +
"order by hireDate desc " +
"parameters String lastNameParam");
List<Employee> results = (List<Employee>) query.execute("Smith");
제휴하지 않습니다 StackOverflow