<?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="dataflowExecution">

  <!--
    information_schema 방식 (TableManagementService.getPrimaryKeys 와 동일)
    tableName 파라미터: 사전에 sanitize() 처리된 값만 전달할 것
  -->
  <select id="selectPrimaryKeys" parameterType="map" resultType="string">
    SELECT
        KCU.COLUMN_NAME
    FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS TC
    JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE KCU
        ON TC.CONSTRAINT_NAME = KCU.CONSTRAINT_NAME
    WHERE TC.TABLE_NAME = #{table_name}
      AND TC.CONSTRAINT_TYPE = 'PRIMARY KEY'
    ORDER BY KCU.ORDINAL_POSITION
  </select>

  <!-- 외부 DB 연결 정보 조회 (external_db_connections 테이블) -->
  <select id="selectExternalConnection" parameterType="map" resultType="map">
    SELECT
        ID
        , CONNECTION_NAME
        , DB_TYPE
        , HOST
        , PORT
        , DATABASE_NAME
        , USERNAME
        , PASSWORD
        , CONNECTION_TIMEOUT
    FROM EXTERNAL_DB_CONNECTIONS
    WHERE ID = #{connection_id}
  </select>

</mapper>
