被GROUP_CONCAT坑得好惨啊

原本是想偷懒写一个存储过程,来生成实体类

CREATE DEFINER=`root`@`%` PROCEDURE `CreateModel`(IN `TableName` varchar(50),In `TableDescription` varchar(50))
BEGIN


Set 

@hh = CHAR(10 using utf8),

@tab = char(9 using utf8),

@t2=(select GROUP_CONCAT(CONCAT(

@tab,@tab,'/// <summary>',@hh,
@tab,@tab,'/// ',Column_Comment,@hh,
@tab,@tab,'/// </summary>',@hh,
(case Column_Key when 'PRI' then CONCAT(@tab,@tab,'[SugarColumn(IsPrimaryKey = true, IsIdentity = true)]',@hh) else '' end),
@tab,@tab,'public ',
case 
when column_type like 'int%' then 'int'
when column_type like '%char%' then 'string'
when column_type like '%bit%' then 'bool'
when column_type like '%text%' then 'string'
when column_type like '%date%' then 'DateTime'
when column_type like '%tinyint%' then 'byte'
when column_type like '%decimal%' then 'decimal'

else column_type end,

' ',Column_Name,' ',' { get; set; } ',@hh,@hh) SEPARATOR ' ') from information_schema.columns
where table_schema = 'db'
and table_name = TableName);

			SET @t1 = CONCAT('using System;',@hh,
			'using SqlSugar;',
			@hh,@hh,
			'namespace APIHost.Domain.Entity',@hh,
			'{',
			@hh,@tab,'#region',' ',TableDescription,
			@hh,@tab,'/// <summary>',
			@hh,@tab,'/// ',TableDescription,
			@hh,@tab,'/// </summary>',
			@hh,@tab,'[SugarTable("',TableName,'", TableDescription = "',TableDescription,'")]',
			@hh,@tab,'public class ',TableName,-- ' : dbbase',
			@hh,@tab,'{',@hh,
			@t2,
			@hh,@tab,'}',
			@hh,@tab,'#endregion',
			@hh,'}');
			
			Select @t1;

END

于是找了一个简单的表,写好存储过程,一切正常,一路复制粘贴几十个文件。

最后生成一下,结果一堆错,发现好多类都不全,无语了。

搞了半天才发现GROUP_CONCAT的数据缺半截。

必须设置下它的长度,再执行,就正常了。又要重新复制粘贴,为毛要用mysql。。。烦

SET SESSION  group_concat_max_len = 10240;
show VARIABLES like 'group_concat_max_len'

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值