1. document, private TABLE 2개를 join 하는 이유는 private 테이블에만 존재하는 값이 1 일때 해당 게시물만 출력하는 코드입니다.

2. private 테이블은 document 와 동일한 컬럼이 2개가 있습니다.

    module_srl, upload_target_srl (document_srl 동일) ...

    그리고 private 컬럼 1,0 으로 구분되어 있습니다.

 

private 1 에 해당하는 document 목록을 뽑아 오려고.. 아래 처럼 하고 있는데..

당췌 ㅠ_- 비개발자이다 보니.. 한계가..

 

코드 완성 부탁 좀 드리겠습니다.

 

 

 

<query id="getAllDocuments2Private" action="select">
    <tables>
        <table name="documents" alias="documents" >
         <table name="private" alias="private" type="left join" />
             <conditions>
                 <condition operation="equal" column="private.upload_target_srl" default="documents.document_srl" notnull="notnull" />
             </conditions>
         </table>
    </tables>
    
<columns>
<column name="documents.*" />
</columns>

  <conditions>
   <condition operation="in" column="documents.module_srl" var="module_srl" filter="number" />
<condition operation="equal" column="private.is_private" default="1" pipe="and" />
<condition operation="equal" column="category_srl" var="category_srl" pipe="and" />
    </conditions>
<navigation>
<index var="sort_index" default="documents.list_order" order="order_type" />
<list_count var="list_count" default="20" />
<page_count var="page_count" default="1" />
<page var="page" default="1" />
</navigation>
</query>

 

  • ?
    쿼리 하나만 보여주시는 것보다 private 테이블 구조와 private 테이블에 데이터를 넣는 코드를 보여주셔야 뭔가 답이 나올 것 같은데요? 남이 짜놓은 SELECT 쿼리만 보고 모듈을 뚝딱 완성시키는 건 어렵거든요 @_@
  • ? profile

    <query id="getAllDocuments2" action="select">
    <tables>
    <table name="documents" />
    </tables>
    <columns>
    <column name="*" />
    </columns>
    <conditions>
    <condition operation="in" column="module_srl" var="module_srl" filter="number" />
    <condition operation="equal" column="category_srl" var="category_srl" pipe="and" />
    </conditions>
    <navigation>
    <index var="sort_index" default="list_order" order="order_type" />
    <list_count var="list_count" default="20" />
    <page_count var="page_count" default="1" />
    <page var="page" default="1" />
    </navigation>
    </query>

    백승찬님의 선택된 게시판의 전체 게시물 뽑아오는 위젯 기본 쿼리 코드 입니다.
    + 이 기본 위젯에서 비공개 체크된 게시물만 뽑아 오고 싶었습니다.
    따로 제작된 addon 으로 게시물 등록하면 xe_private TABLE에 공개/비공개를 Insert 하도록 되어 있습니다.
    upload_target_srl, module_srl, member_srl, is_private 4개의 column 값이 있습니다. is_private 1:0 으로 들어갑니다.

  • ?

    <table name="documents" alias="documents" > 끝에 슬래시(/)가 빠져있네요.

    <table name="documents" alias="documents" />

     

    XML 파일에서는 태그를 열었으면 반드시 태그를 닫아주셔야 됩니다.
    <table> 태그 안에는 아무 내용도 없으니 그냥 열고 닫아도 됩니다.

     

    <table name="private" alias="private" type="left join" />

     

    <table> 태그 안에 태그가 있는 경우에는 열고 바로 닫으면 안 됩니다.

     

    <table name="private" alias="private" type="left join">

     

    이렇게 고치셔야 할 듯 합니다.

  • profile
    SELECT documents . *
    FROM xe_documents AS documents
    LEFT JOIN xe_private AS private ON private.upload_target_srl = documents.document_srl
    WHERE documents.is_directshare = 'Y'
    AND private.is_private = '1'
    LIMIT 0 , 30

     

    phpmyadmin 에서는 위 쿼리가 아주 잘 출력됩니다.

     

    XE Query 는 잘 모르겠지만.. 아래가 잘 못 된건가요?

    <query id="getAllDocuments2Private" action="select">
        <tables>
            <table name="documents" alias="documents" />
            <table name="torrents" alias="torrents" type="left join">
                <conditions>
                    <condition operation="equal" column="torrents.upload_target_srl" default="documents.document_srl" />
                </conditions>
            </table>
        </tables>
        <columns>
            <column name="documents.*" />
        </columns>
        <conditions>
    
            <condition operation="equal" column="documents.is_directshare" default="Y" pipe="and" />
            <condition operation="equal" column="torrents.is_private" default="1" pipe="and" />
        </conditions>
    <navigation>
    <index var="sort_index" default="documents.list_order" order="order_type" />
    <list_count var="list_count" default="20" />
    <page_count var="page_count" default="1" />
    <page var="page" default="1" />
    </navigation>
    </query>

     

  • profile ?
    $output = executeQuery('[모듈명].getAllDocuments2Private', $args);
    debugPrint($output);

    오타가 있거나 XML Query 문법에 맞지 않는 경우 잘못된 쿼리가 만들어져서 아무 에러가 없는 것처럼 보이는 경우가 있습니다. 쿼리 실행 결과를 한 번 보셔야 할 것 같네요. executeQuery()를 실행한 결과는 생성된 쿼리문과 함께 반환됩니다.
    $output->_query 이 값이 XML 쿼리를 실제 실행한 SQL문입니다.