GeoService-Xr에서 DBMS를 대상으로 Query 문을 호출하는 코드를 정리해 둡니다. GET 방식과 POST 방식 모두 적용할 수 있는데요. 먼저 POST 방식에 대한 예는 다음과 같습니다.
sql = "SELECT USER_ID, SEC_NUM, NAM, EMAIL from web_user_man";
url = "http://168.192.76.103:8080/Xr?sql|BzSewage|1";
$.ajax({
url: url,
type: "POST",
crossDomain: true,
data: sql,
dataType: "text",
success: function (response) {
response = response.substr(0, response.length - 1); // data 문자열 끝에 \0 문자를 제거
response = JSON.parse(response);
// ...
},
error: function (xhr, status) {
alert("ajax error");
}
});
아래는 위와 동일한 SQL 문에 대해 GET 방식으로 호출한 예입니다.
sql = "SELECT USER_ID, SEC_NUM, NAM, EMAIL from web_user_man";
url = "http://168.192.76.103:8080/Xr?sql|" + encodeURIComponent(sql) + "|BzSewage|1";
$.ajax({
url: url,
type: "GET",
crossDomain: true,
dataType: "text",
success: function (response) {
response = response.substr(0, response.length - 1); // data 문자열 끝에 \0 문자를 제거
response = JSON.parse(response);
// ...
},
error: function (xhr, status) {
alert("ajax error");
}
});
이런 방식은 개발 단계에서 별도의 서버설정없이 바로 SQL 문을 실행할 수 있는데요. 최종적으로는 SQL 문을 이처럼 코드 단에 담기 보다는 GeoService-Xr의 SQL 실행 서비스의 방식으로 변경해 소스코드를 배포해야 합니다.