inleft
2022-02-09 9bcb19959eeb9da9bde2561e7278f6d0a55eb151
commit | author | age
9bcb19 1 <?xml version="1.0" encoding="UTF-8"?>
I 2 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
3 <mapper namespace="vip.xiaonuo.generate.modular.mapper.CodeGenerateMapper">
4
5     <resultMap id="informationResult" type="vip.xiaonuo.generate.modular.result.InformationResult">
6         <result column="table_name" property="tableName" />
7         <result column="create_time" property="createTime" />
8         <result column="update_time" property="updateTime" />
9         <result column="table_comment" property="tableComment" />
10     </resultMap>
11
12     <resultMap id="inforMationColumnsResult" type="vip.xiaonuo.generate.modular.result.InforMationColumnsResult">
13         <result column="column_name" property="columnName" />
14         <result column="data_type" property="dataType" />
15         <result column="column_comment" property="columnComment" />
16         <result column="column_key" property="columnKey" />
17     </resultMap>
18
19     <!-- 查询指定库中所有表 mysql -->
20     <select id="selectInformationTable" parameterType="String" resultMap="informationResult" databaseId = "mysql">
21         select table_name,create_time,update_time,table_comment
22         from information_schema.tables
23         where
24             table_schema = '${dbName}'
25     </select>
26
27     <!-- 查询指定库中所有表 oracle -->
28     <select id="selectInformationTable" parameterType="String" resultMap="informationResult" databaseId = "oracle">
29         select table_name, comments as table_comment
30         from user_tab_comments
31     </select>
32
33     <!-- 查询指定库中所有表 mssql -->
34     <select id="selectInformationTable" parameterType="String" resultMap="informationResult" databaseId = "mssql">
35         SELECT DISTINCT
36             d.name as table_name,
37             f.value as table_comment
38         FROM
39             syscolumns a
40                 LEFT JOIN systypes b ON a.xusertype= b.xusertype
41                 INNER JOIN sysobjects d ON a.id= d.id
42                 AND d.xtype= 'U'
43                 AND d.name != 'dtproperties'
44                 LEFT JOIN syscomments e ON a.cdefault= e.id
45                 LEFT JOIN sys.extended_properties g ON a.id= G.major_id
46                 AND a.colid= g.minor_id
47                 LEFT JOIN sys.extended_properties f ON d.id= f.major_id
48                 AND f.minor_id= 0
49     </select>
50
51     <!-- 查询指定库中所有表 pgsql -->
52     <select id="selectInformationTable" parameterType="String" resultMap="informationResult" databaseId = "pgsql">
53         SELECT
54             relname AS TABLE_NAME,
55             col_description ( C.oid, 0 ) AS TABLE_COMMENT
56         FROM
57             pg_class C
58         WHERE
59             relkind = 'r'
60           AND relname NOT LIKE'pg_%'
61           AND relname NOT LIKE'sql_%'
62         ORDER BY
63             relname
64     </select>
65
66     <!-- 查询指定库中所有表 达梦数据库 -->
67     <select id="selectInformationTable" parameterType="String" resultMap="informationResult" databaseId = "dm">
68         select table_name, comments as table_comment
69         from user_tab_comments
70     </select>
71
72     <!-- 查询指定库中所有表 人大金仓数据库 -->
73     <select id="selectInformationTable" parameterType="String" resultMap="informationResult" databaseId = "kingbasees">
74         select table_name, comments as table_comment
75         from user_tab_comments
76     </select>
77
78     <!-- 查询指定表中所有字段 mysql -->
79     <select id="selectInformationColumns" parameterType="String" resultMap="inforMationColumnsResult" databaseId = "mysql">
80         select
81             column_name,data_type,column_comment,column_key
82         from information_schema.columns
83         where
84             table_schema = '${dbName}' and table_name = '${tableName}';
85     </select>
86
87     <!-- 查询指定表中所有字段 oracle -->
88     <select id="selectInformationColumns" parameterType="String" resultMap="inforMationColumnsResult" databaseId = "oracle">
89         select
90             a.column_name as column_name,
91             a.data_type as data_type,
92             b.comments as column_comment,
93             case
94                 when c.position>0 then 'PRI'
95                 else ''
96                 end column_key
97         from
98                 (select * from user_tab_columns where table_name='${tableName}') a
99                     left join
100                 (select * from user_col_comments where table_name='${tableName}') b
101                 on a.column_name=b.column_name
102                     left join
103             (
104                 select table_name,column_name,position from user_cons_columns
105                 where
106                     table_name='${tableName}'
107                   and constraint_name=(select constraint_name
108                                        from
109                                            user_constraints where table_name='${tableName}' and constraint_type='P')
110                   and owner='${dbName}'
111             ) c
112             on a.column_name=c.column_name
113         order by a.column_id
114     </select>
115
116     <!-- 查询指定表中所有字段 mssql -->
117     <select id="selectInformationColumns" parameterType="String" resultMap="inforMationColumnsResult" databaseId = "mssql">
118         SELECT
119             C.name AS column_name,
120             T.name AS data_type,
121             isnull( ETP.value, '' ) AS column_comment,
122             CASE
123
124                 WHEN EXISTS (
125                         SELECT
126                             1
127                         FROM
128                             sysobjects
129                         WHERE
130                             xtype = 'PK'
131                           AND parent_obj = c.id
132                           AND name IN ( SELECT name FROM sysindexes WHERE indid IN ( SELECT indid FROM sysindexkeys WHERE id = c.id AND colid = c.colid ) )
133                     ) THEN
134                     'PRI' ELSE ''
135                 END AS column_key
136         FROM
137             syscolumns C
138                 INNER JOIN systypes T ON C.xusertype = T.xusertype
139                 LEFT JOIN sys.extended_properties ETP ON ETP.major_id = c.id
140                 AND ETP.minor_id = C.colid
141                 AND ETP.name = 'MS_Description'
142                 LEFT JOIN syscomments CM ON C.cdefault= CM.id
143         WHERE
144             C.id = object_id( '${tableName}' )
145     </select>
146
147     <!-- 查询指定表中所有字段 pgsql -->
148     <select id="selectInformationColumns" parameterType="String" resultMap="inforMationColumnsResult" databaseId = "pgsql">
149         SELECT
150             t1.*,
151             COALESCE(t2.pk_name, '') AS column_key
152         FROM
153             (
154                 SELECT A
155                            .attname AS COLUMN_NAME,
156                        pg_type.typname AS data_type,
157                        col_description ( A.attrelid, A.attnum ) AS column_comment
158                 FROM
159                     pg_class AS C,
160                     pg_attribute
161                         AS A INNER JOIN pg_type ON pg_type.oid = A.atttypid
162                 WHERE
163                     C.relname = '${tableName}'
164                   AND A.attrelid = C.oid
165                   AND A.attnum > 0
166             ) t1
167                 LEFT JOIN (
168                 SELECT
169                     pg_attribute.attname AS COLUMN_NAME,
170                     CASE WHEN pg_constraint.conname ISNULL THEN '' ELSE 'PRI' END AS pk_name
171                 FROM
172                     pg_constraint
173                         INNER JOIN pg_class ON pg_constraint.conrelid = pg_class.oid
174                         INNER JOIN pg_attribute ON pg_attribute.attrelid = pg_class.oid
175                         AND pg_attribute.attnum = pg_constraint.conkey [ 1 ]
176                         INNER JOIN pg_type ON pg_type.oid = pg_attribute.atttypid
177                 WHERE
178                     pg_class.relname = '${tableName}'
179                   AND pg_constraint.contype = 'p'
180             ) t2 ON t1.COLUMN_NAME = t2.COLUMN_NAME
181     </select>
182
183     <!-- 查询指定表中所有字段 达梦数据库 -->
184     <select id="selectInformationColumns" parameterType="String" resultMap="inforMationColumnsResult" databaseId = "dm">
185         select
186             a.column_name as column_name,
187             a.data_type as data_type,
188             b.comments as column_comment,
189             case
190                 when c.position>0 then 'PRI'
191                 else ''
192                 end column_key
193         from
194                 (select * from user_tab_columns where table_name='${tableName}') a
195                     left join
196                 (select * from user_col_comments where table_name='${tableName}') b
197                 on a.column_name=b.column_name
198                     left join
199             (
200                 select table_name,column_name,position from user_cons_columns
201                 where
202                     table_name='${tableName}'
203                   and constraint_name=(select constraint_name
204                                        from
205                                            user_constraints where table_name='${tableName}' and constraint_type='P')
206                   and owner='${dbName}'
207             ) c
208             on a.column_name=c.column_name
209         order by a.column_id
210     </select>
211
212     <!-- 查询指定表中所有字段 人大金仓数据库 -->
213     <select id="selectInformationColumns" parameterType="String" resultMap="inforMationColumnsResult" databaseId = "dm">
214         select
215             a.column_name as column_name,
216             a.data_type as data_type,
217             b.comments as column_comment,
218             case
219                 when c.position>0 then 'PRI'
220                 else ''
221                 end column_key
222         from
223                 (select * from user_tab_columns where table_name='${tableName}') a
224                     left join
225                 (select * from user_col_comments where table_name='${tableName}') b
226                 on a.column_name=b.column_name
227                     left join
228             (
229                 select table_name,column_name,position from user_cons_columns
230                 where
231                     table_name='${tableName}'
232                   and constraint_name=(select constraint_name
233                                        from
234                                            user_constraints where table_name='${tableName}' and constraint_type='P')
235                   and owner='${dbName}'
236             ) c
237             on a.column_name=c.column_name
238         order by a.column_id
239     </select>
240
241 </mapper>