<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="BoardComment">


	<select id="BoardComment.selectCommentList" parameterType="boardCommentVO" resultType="boardCommentVO">
		<![CDATA[
           SELECT
           		COMMENTS.BC_SEQ AS SEQ,
				COMMENTS.BC_NAME AS USERNAME,
				COMMENTS.BC_CONTENT AS CONTENT,
				COMMENTS.BC_REGDATE AS REGDATE,
				COMMENTS.BC_BD_SEQ AS PARENTSEQ,
				COMMENTS.BC_IP AS IP,
				COMMENTS.BC_MB_ID AS USERID, 
				#{id} ID
           FROM
           		H3_BD_${id}_COMT COMMENTS
           WHERE
           	 	BC_BD_SEQ = #{parentSeq}
           ORDER BY
           	 	BC_BD_SEQ DESC
	  	]]>
	</select>
	
	
	<select id="BoardComment.selectBoardComment" parameterType="boardCommentVO" resultType="boardCommentVO">
		<![CDATA[	
			SELECT
           		COMMENTS.BC_SEQ AS SEQ,
				COMMENTS.BC_NAME AS USERNAME,
				COMMENTS.BC_CONTENT AS CONTENT,
				COMMENTS.BC_REGDATE AS REGDATE,
				COMMENTS.BC_BD_SEQ AS PARENTSEQ,
				COMMENTS.BC_IP AS IP,
				COMMENTS.BC_MB_ID AS USERID, 
				#{id} ID
			FROM 
				H3_BD_${id}_COMT COMMENTS
			WHERE
				BC_SEQ = #{seq}
		]]>
	</select>
	
	
	<insert id="BoardComment.insertBoardComment" parameterType="boardCommentVO">
		INSERT INTO 
			H3_BD_${id}_COMT (
				 BC_NAME, BC_CONTENT, BC_REGDATE, BC_BD_SEQ, BC_IP, BC_MB_ID
      ) VALUES (
          #{userName}, #{content}, NOW(), #{parentSeq}, #{ip}, #{userId}
      )
      <selectKey resultType="int" keyProperty="seq" order="AFTER">
        SELECT currval(#{id}||'_bc_seq') as seq
	    </selectKey>
	</insert>
	
	
	<delete id="BoardComment.deleteBoardComment" parameterType="boardCommentVO">
	<![CDATA[
		DELETE 
		FROM
			H3_BD_${id}_COMT
		WHERE 
			BC_SEQ = #{seq}
	]]>
	</delete>
	
	
	<delete id="BoardComment.deleteBoardCommentAll" parameterType="boardCommentVO">
	<![CDATA[
		DELETE 
		FROM
			H3_BD_${id}_COMT
		WHERE 
			BC_BD_SEQ = #{parentSeq}
	]]>
	</delete>
	
	
</mapper>
