From 4d404d8853bf869665de41f29f43874432e7af30 Mon Sep 17 00:00:00 2001 From: Karl Blomster Date: Tue, 14 Dec 2021 18:22:58 +0100 Subject: [PATCH] generator: support MySQL 5.7 MySQL 5.7 does not support CTE's. Refactor the table column metadata query to avoid the CTE. --- generator/mysql/query_set.go | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/generator/mysql/query_set.go b/generator/mysql/query_set.go index a409eb7..85c4278 100644 --- a/generator/mysql/query_set.go +++ b/generator/mysql/query_set.go @@ -32,15 +32,14 @@ WHERE table_schema = ? and table_type = ?; func (m mySqlQuerySet) GetTableColumnsMetaData(db *sql.DB, schemaName string, tableName string) []metadata.Column { query := ` -WITH primaryKeys AS ( - SELECT k.column_name - FROM information_schema.table_constraints t - JOIN information_schema.key_column_usage k USING(constraint_name,table_schema,table_name) - WHERE table_schema = ? AND table_name = ? AND t.constraint_type='PRIMARY KEY' -) SELECT COLUMN_NAME AS "column.Name", IS_NULLABLE = "YES" AS "column.IsNullable", - (EXISTS(SELECT 1 FROM primaryKeys AS pk WHERE pk.column_name = columns.column_name)) AS "column.IsPrimaryKey", + (EXISTS( + SELECT 1 + FROM information_schema.table_constraints t + JOIN information_schema.key_column_usage k USING(constraint_name,table_schema,table_name) + WHERE table_schema = ? AND table_name = ? AND t.constraint_type='PRIMARY KEY' AND k.column_name = columns.column_name + )) AS "column.IsPrimaryKey", IF (COLUMN_TYPE = 'tinyint(1)', 'boolean', IF (DATA_TYPE='enum',