动软MySQL存储过程模板
<#@ template language="c#" HostSpecific="True" #>
<#@ output extension= ".cs" #>
<#
TableHost host = (TableHost)(Host);
host.Fieldlist.Sort(CodeCommon.CompareByintOrder);
int columnCount=host.Fieldlist.Count;
string IdentityStr="id";
string specStr="datetime";
foreach (ColumnInfo c in host.Fieldlist)
{
if(c.IsIdentity)
{
IdentityStr=c.ColumnName.ToString().ToLower();
break;
}
}
#>
DROP procedure IF EXISTS <#= host.GetDALClass(host.TableName) #>_GetMaxId;
CREATE PROCEDURE <#= host.GetDALClass(host.TableName) #>_GetMaxId()
BEGIN
SELECT MAX(Id) FROM <#= host.GetDALClass(host.TableName) #>;
END;
DROP procedure IF EXISTS <#= host.GetDALClass(host.TableName) #>_Exists;
CREATE PROCEDURE <#= host.GetDALClass(host.TableName) #>_Exists
($_Id int)
BEGIN
SELECT count(1) FROM <#= host.GetDALClass(host.TableName) #> WHERE Id=$_Id ;
END;
DROP procedure IF EXISTS <#= host.GetDALClass(host.TableName) #>_ADD;
CREATE PROCEDURE <#= host.GetDALClass(host.TableName) #>_ADD(
<#int updateI=1; foreach (ColumnInfo c in host.Fieldlist)
{ if(c.IsIdentity) { #>OUT $_<#= c.ColumnName.ToString().ToLower()#> <#=c.TypeName#> (<#=c.Length#>)<#if (updateI!=columnCount){#>,<#}#><# } else{ #><#if(c.TypeName==specStr){#>$_<#= c.ColumnName.ToString().ToLower()#> <#=c.TypeName#><#}else{#>$_<#= c.ColumnName.ToString().ToLower()#> <#=c.TypeName#>(<#=c.Length#>)<#}#><#if (updateI!=columnCount){#>,<#}#><#} updateI++;} #>)
BEGIN
INSERT INTO <#= host.GetDALClass(host.TableName) #>(<#updateI=1; foreach (ColumnInfo c in host.Fieldlist)
{ if(c.IsIdentity) { updateI++;continue;} #><#= c.ColumnName.ToString().ToLower()#><#if (updateI!=columnCount){#>,<#}#>
<# updateI++;} #>
)VALUES(
<# updateI=1; foreach (ColumnInfo c in host.Fieldlist)
{ if(c.IsIdentity) { updateI++;continue;} #>
$_<#= c.ColumnName.ToString().ToLower()#><#if (updateI!=columnCount){#>,<#}#>
<# updateI++;} #>
);
set $_<#=IdentityStr#>=last_insert_id();
END;
DROP procedure IF EXISTS <#= host.GetDALClass(host.TableName) #>_Update;
CREATE PROCEDURE <#= host.GetDALClass(host.TableName) #>_Update(
<#updateI=1; foreach (ColumnInfo c in host.Fieldlist)
{ #>
<#if(c.TypeName==specStr){#>
$_<#= c.ColumnName.ToString().ToLower()#> <#=c.TypeName#>
<#}else{#>
$_<#= c.ColumnName.ToString().ToLower()#> <#=c.TypeName#>(<#=c.Length#>)
<#}#>
<#if (updateI!=columnCount){#>,<#}#>
<# updateI++;} #>)
BEGIN
UPDATE <#= host.GetDALClass(host.TableName) #> SET
<#updateI=1; foreach (ColumnInfo c in host.Fieldlist)
{ if(c.IsIdentity) { updateI++;continue;}#>
<#= c.ColumnName.ToString().ToLower()#>=$_<#= c.ColumnName.ToString().ToLower()#><#if (updateI!=columnCount){#>,<#}#>
<#updateI++; } #>
WHERE Id=$_Id ;
END;
DROP procedure IF EXISTS <#= host.GetDALClass(host.TableName) #>_Delete;
CREATE PROCEDURE <#= host.GetDALClass(host.TableName) #>_Delete(
$_Id int)
BEGIN
DELETE from <#= host.GetDALClass(host.TableName) #>
WHERE Id=$_Id ;
END;
DROP procedure IF EXISTS <#= host.GetDALClass(host.TableName) #>_GetModel;
CREATE PROCEDURE <#= host.GetDALClass(host.TableName) #>_GetModel(
$_Id int)
BEGIN
SELECT
<# updateI=1;foreach (ColumnInfo c in host.Fieldlist)
{ #>
<#= c.ColumnName.ToString().ToLower()#><#if (updateI!=columnCount){#>,<#}#>
<#updateI++; } #>
FROM <#= host.GetDALClass(host.TableName) #>
WHERE Id=$_Id ;
END;
DROP procedure IF EXISTS <#= host.GetDALClass(host.TableName) #>_GetColumnInfo;
CREATE PROCEDURE <#= host.GetDALClass(host.TableName) #>_GetColumnInfo(
$_Id int,
$_ColumnName varchar(20))
BEGIN
set @sqlStr=CONCAT('SELECT ',$_ColumnName , ' FROM <#= host.GetDALClass(host.TableName) #> WHERE Id= ',$_Id);
PREPARE count_stmt FROM @sqlStr;
EXECUTE count_stmt;
END;
DROP procedure IF EXISTS <#= host.GetDALClass(host.TableName) #>_GetList;
CREATE PROCEDURE <#= host.GetDALClass(host.TableName) #>_GetList()
BEGIN
SELECT
<# updateI=1;foreach (ColumnInfo c in host.Fieldlist)
{ #>
<#= c.ColumnName.ToString().ToLower()#><#if (updateI!=columnCount){#>,<#}#>
<#updateI++; } #>
FROM <#= host.GetDALClass(host.TableName) #>;
END;
动软MySQL存储过程模板的更多相关文章
- mysql存储过程模板
CREATE DEFINER=`root`@`localhost` PROCEDURE `SP_test`(IN `nodeCode` varchar(100),IN `id` varchar(36) ...
- 动软Model 模板 生成可空类型字段
动软代码 生成可空类型 <#@ template language="c#" HostSpecific="True" #> <#@ outpu ...
- 动软模板系列二(Model层模板)
动软模板其实和CodeSmith的模板差不多 实现的原理是一样的,但是CodeSmith貌似只支持表生成,而且不够“国人化”,所以打算研究下动软的模板,如果熟练掌握后想必以后开发项目效率可以提高很多了 ...
- 【动软.Net代码生成器】连接MySQL生成C#的POCO实体类(Model)
首先是工具的下载地址: 动软.Net代码生成器 该工具官网自带完整教程: 文档:http://www.maticsoft.com/help/ 例子:http://www.maticsoft.com/h ...
- 动软生成的WCP DAO层模板(不使用接口)
本实战是博主初次学习Java,分析WCP源码时,学习HibernateTools部分的实战,由于初次接触,难免错误,仅供参考,希望批评指正. 开发环境: Eclipse Version: Photon ...
- 动软代码生成器 可用于生成Entity层,可更改模板 /codesmith 也可以
动软代码生成器官方下载地址:http://www.maticsoft.com/download.aspx 教程:http://jingyan.baidu.com/article/219f4bf7dfd ...
- 手把手教你用动软.NET代码生成器实例教程
动软实战攻略 手把手教你用动软 文档编号:20110421 版权所有 © 2004-2011 动软 在线帮助:http://help.maticsoft.com 目录 一. 产品介绍 ...
- C# 嵌入dll 动软代码生成器基础使用 系统缓存全解析 .NET开发中的事务处理大比拼 C#之数据类型学习 【基于EF Core的Code First模式的DotNetCore快速开发框架】完成对DB First代码生成的支持 基于EF Core的Code First模式的DotNetCore快速开发框架 【懒人有道】在asp.net core中实现程序集注入
C# 嵌入dll 在很多时候我们在生成C#exe文件时,如果在工程里调用了dll文件时,那么如果不加以处理的话在生成的exe文件运行时需要连同这个dll一起转移,相比于一个单独干净的exe,这种形 ...
- 动软商城系统可免费下载了,专业批发分销商城系统,ASP.NET商城系统
动软商城系统是一套集CMS资讯+品牌Shop商城+WAP商城+APP手机客户端+SNS用户互动社区于一体的全新电商营销解决方案.主要为企业树立企业品牌形象,实现独立网络推广,充分集成网站SEO.企业微 ...
随机推荐
- TextMate 小小心得
在Vim.Emacs之间纠结了很久之后,却选择了TextMate P.S. 为何Emacs和Vim被称为两大神器 中文的资料不是很多,一狠心,找了James Edward Gray II的TextMa ...
- Openstack Neutron 允许VM流量转发
neutron port-update <port-id> --port-security-enabled=False --no-security-groups
- ASP.NET MVC 如何解决“上下文的模型已在数据库创建后发生更改”问题
问题描述:支持"XXContext"(泛指之类的数据库上下文模型)上下文的模型已在数据库创建后发生更改.请考虑使用 Code First 迁移更新数据库. 问题解决:坑爹的MVC会 ...
- tcpdump for android L 5.x with pie support
由于使用了NDK编译的可执行文件在应用中调用,在4.4及之前的版本上一直没出问题. 最近由于要测试在Android L上的运行情况发现,当运行该可执行文件时,报如下错误: error: only po ...
- Visual Studio 2013 (vs2013)中“向前定位”,“向后定位”按钮
Visual Studio 2013 (vs2013)中默认的界面中似乎没有向前向后定位这个非常实用的功能,下面是把它们找出来的方法: 方法1:右键-->工具栏空白处-->最下面,自定义- ...
- Excel保护工作表
最近见到一个Excel文件,其中的表不能选中,不能编辑,今天研究了一下 明白了其设置方法 excel中开始--格式--保护工作表--去掉所有勾选,输入保护密码 即可
- 用原生DOM 遍历页面节点
代码丢失,直接上图:
- JS中数组Array的用法示例介绍 (转)
new Array() new Array(len) new Array([item0,[item1,[item2,...]]] 使用数组对象的方法: var objArray=new Array() ...
- How can I fix “Compilation unit name must end with .java, or one of the registered Java-like extensions”?
How can I fix “Compilation unit name must end with .java, or one of the registered Java-like extensi ...
- [Android Pro] 通过包名启动应用
Intent intent = packageManager.getLaunchIntentForPackage(WEIXIN_PKGNAME); intent.setFlags(Intent.FLA ...