TableInfoMapper.xml 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  3. <mapper namespace="com.zkqy.system.mapper.TableInfoMapper">
  4. <resultMap id="mysqlTableInfoResult" type="com.zkqy.system.entity.TableInfo">
  5. <result property="fieldName" column="fieldName"></result>
  6. <result property="fieldType" column="fieldType"></result>
  7. <result property="isNull" column="isNull" javaType="boolean"></result>
  8. <result property="isPrimary" column="isPrimary" javaType="boolean"></result>
  9. <result property="fieldDescription" column="fieldDescription"></result>
  10. <result property="fieldLength" column="fieldLength"></result>
  11. <result property="isAuto" column="isAuto" javaType="boolean"></result>
  12. </resultMap>
  13. <select id="tableInfoList" resultType="com.zkqy.system.entity.vo.TableInfoVO">
  14. select table_name tableName,create_time createTime,table_comment tableComment from information_schema.tables
  15. where table_schema=#{databaseName}
  16. <if test="map.tableName != null and map.tableName != ''">and table_name like concat('%', #{map.tableName},
  17. '%')
  18. </if>
  19. <if test="map.tableComment != null and map.tableComment !=''">and table_comment like concat('%',
  20. #{map.tableComment}, '%')
  21. </if>
  22. order by createTime asc
  23. </select>
  24. <select id="sqlServerTableInfoList" resultType="com.zkqy.system.entity.vo.TableInfoVO">
  25. select
  26. a.name AS tableName,
  27. a.create_date AS createTime,
  28. CONVERT ( NVARCHAR ( 100 ), isnull( g.[value], '' ) ) AS tableComment
  29. from ${databaseName}.sys.tables a
  30. LEFT JOIN sys.extended_properties g ON ( a.object_id = g.major_id AND g.minor_id = 0 )
  31. where a.type = 'U'
  32. <if test="map.tableName != null and map.tableName != ''">and a.name like concat('%', #{map.tableName}, '%')</if>
  33. <if test="map.tableComment != null and map.tableComment !=''">and CONVERT ( NVARCHAR ( 100 ), isnull( g.[value],
  34. '' ) ) like concat('%', #{map.tableComment}, '%')
  35. </if>
  36. order by createTime asc
  37. </select>
  38. <select id="dmTableInfoList" resultType="com.zkqy.system.entity.vo.TableInfoVO">
  39. select a.object_name as tableName,
  40. b.comment$ as tableComment,
  41. a.created as createTime
  42. from dba_objects a
  43. left join SYSTABLECOMMENTS b
  44. on b.tvname = a.object_name and a.owner = b.schname
  45. where a.object_type = 'TABLE'
  46. and a.owner = #{databaseName}
  47. <if test="map.tableName != null and map.tableName != ''">and a.object_name like concat('%', #{map.tableName},
  48. '%')
  49. </if>
  50. <if test="map.tableComment != null and map.tableComment !=''">and b.comment$ like concat('%',
  51. #{map.tableComment}, '%')
  52. </if>
  53. order by createTime asc
  54. </select>
  55. <select id="mysqlTableFieldInfo" resultMap="mysqlTableInfoResult">
  56. SELECT column_name fieldName,
  57. IF
  58. (is_nullable = 'NO', TRUE, FALSE) isNull,
  59. data_type fieldType,
  60. character_maximum_length fieldLength,
  61. IF
  62. (column_key = 'PRI', TRUE, FALSE) isPrimary,
  63. column_comment fieldDescription,
  64. if(extra = 'auto_increment', true, false) isAuto
  65. FROM information_schema.COLUMNS
  66. WHERE table_name = #{tableName}
  67. AND table_schema = #{dataBaseName}
  68. ORDER BY ordinal_position asc;
  69. </select>
  70. <select id="sqlserverTableFieldInfo" resultMap="mysqlTableInfoResult">
  71. SELECT fieldName = a.name,
  72. isAuto = case when COLUMNPROPERTY(a.id, a.name, 'IsIdentity') = 1 then 1 else 0 end,
  73. isPrimary = case
  74. when exists(SELECT 1
  75. FROM sysobjects
  76. where xtype = 'PK'
  77. and parent_obj = a.id
  78. and name in (SELECT name
  79. FROM sysindexes
  80. WHERE indid in
  81. (SELECT indid FROM sysindexkeys WHERE id = a.id AND colid = a.colid)))
  82. then 1
  83. else 0 end,
  84. fieldType = b.name,
  85. fieldLength = COLUMNPROPERTY(a.id, a.name, 'PRECISION'),
  86. isNull = case when a.isnullable = 1 then 0 else 1 end,
  87. fieldDescription = isnull(g.[value], '')
  88. FROM syscolumns a
  89. left join
  90. systypes b
  91. on
  92. a.xusertype = b.xusertype
  93. inner join
  94. sysobjects d
  95. on
  96. a.id = d.id and d.xtype = 'U' and d.name<![CDATA[ <>]]> 'dtproperties'
  97. left join
  98. syscomments e
  99. on
  100. a.cdefault = e.id
  101. left join
  102. sys.extended_properties g
  103. on
  104. a.id = G.major_id and a.colid = g.minor_id
  105. left join
  106. sys.extended_properties f
  107. on
  108. d.id = f.major_id and f.minor_id = 0
  109. where d.name = #{tableName}
  110. order by a.id, a.colorder
  111. </select>
  112. <select id="dmTableFieldInfo" resultMap="mysqlTableInfoResult">
  113. SELECT a.table_name As tableName
  114. , c.comments As tableComment
  115. , a.column_name As fieldName
  116. , b.comments As fieldDescription
  117. , a.data_type As fieldType
  118. , a.data_length As fieldLength
  119. , (case when d.column_position = 1 then 1 else 0 end) As isPrimary
  120. , (case when (e.nullable = 'N') then 1 else 0 end) as isNull
  121. , (case when f.info2 = 1 then 1 else 0 end) as isAuto
  122. FROM all_tab_cols a
  123. LEFT JOIN all_col_comments b
  124. ON b.table_name = a.table_name AND b.column_name = a.column_name AND a.owner = b.schema_name
  125. LEFT JOIN all_tab_comments c ON c.table_name = b.table_name AND c.owner = b.owner
  126. LEFT JOIN (SELECT dcc.table_name,
  127. dcc.column_name,
  128. dcc.column_position,
  129. dcc.index_owner,
  130. dc.constraint_name
  131. FROM all_ind_columns dcc
  132. JOIN all_constraints dc
  133. ON dcc.index_name = dc.index_name AND dc.constraint_type = UPPER('p') AND
  134. dcc.index_owner = dc.owner) d
  135. ON d.table_name = a.table_name AND d.column_name = a.column_name AND d.index_owner = a.owner
  136. LEFT JOIN all_tab_columns e
  137. ON a.table_name = e.table_name AND a.owner = e.owner and a.column_name = e.column_name
  138. LEFT JOIN (SELECT f1.owner, f1.object_name As table_name, f0.name, f0.info2
  139. FROM syscolumns f0
  140. INNER JOIN dba_objects f1
  141. ON f1.object_type = 'TABLE' AND info2 = 1 AND f1.object_id = f0.id) f
  142. ON f.name = a.column_name AND f.table_name = a.table_name AND f.owner = a.owner
  143. WHERE a.owner = UPPER(#{dataBaseName})
  144. and a.table_name = #{tableName}
  145. ORDER BY a.table_name ASC, a.column_id ASC;
  146. </select>
  147. </mapper>