<?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="com.fastbee.iot.mapper.TableMapper">
    <!--创建表的 SQL 语句-->
    <update id="createTable" parameterType="java.lang.String">
        CREATE TABLE IF NOT EXISTS `${tableName}`
        (
        `id`       int(0)      NOT NULL AUTO_INCREMENT COMMENT '主键',
        `group_id` int(0)      NULL DEFAULT NULL COMMENT '组号',
        `username` varchar(20) NULL DEFAULT NULL COMMENT '用户名',
        `password` varchar(20) NULL DEFAULT NULL COMMENT '密码',
        PRIMARY KEY (`id`)
        ) ENGINE = InnoDB
        AUTO_INCREMENT = 9
        CHARACTER SET = utf8mb4 COMMENT ='用于测试的用户表';
    </update>

    <select id="getTableByName" resultType="java.lang.String">
        select table_name from information_schema.tables where TABLE_SCHEMA=(select database())
        and table_name = #{tableName}
    </select>

    <select id="getTableNameList" resultType="java.lang.String">
        select table_name from information_schema.tables where TABLE_SCHEMA=(select database())
            and table_name in
            <foreach item="tableName" collection="array" open="(" separator="," close=")">
                #{tableName}
            </foreach>
    </select>

</mapper>
