首页 > 数据库技术 > 详细

根据数据库的表结构的类型返回其对应的简写类型

时间:2015-11-12 17:49:28      阅读:378      评论:0      收藏:0      [点我收藏+]
首先感谢QQ群的各位大大:
 
 
原始的自己打的代码:
%
% Column_Type:二进制的MySQL的数据类型
% 输入值有:<<"int(11)">>,<<"decimal(10,2)">>,<<"varchar(XX)">>,<<"float">>
%	返回值对应的为 int ,decimal ,varchar ,float
%
%
get_column_type(Column_Type)->
	case 
		re:run(Column_Type,"int",[caseless]) 
		of
		{match,_} ->
			integer;
		_ ->
			case re:run(Type,"decimal",[caseless])
			 of
				{match,_} ->
					decimal;
				_ ->
					case re:run(Type,"varchar",[caseless]) 
						of
						{match,_} ->
							varchar;

						_->
							case re:run(Type,"float",[caseless]) 
								of
									{match,_} ->
										float;
									_->
										binary
								end
						end
			end
	end.

又长又丑还一层层的嵌套,看着头疼。。。。

 
 
方案一:
 
技术分享
 
方案二:
-define(COLUMN_TYPES,[{"int",integer},{"varchar",varchar}]).

get_column_type(ColumnType)	-> 
    get_column_type(ColumnType,?COLUMN_TYPES).

get_column_type(ColumnType,[Column_KeyValue|COLUMN_TYPES])	->
	{MatchKey,Type} = Column_KeyValue,
    case 
		re:run(ColumnType, MatchKey,[caseless])
		of 
			{match,_}	
				->		 
					Type;
			_
				-> 
				get_column_type(ColumnType,COLUMN_TYPES)
	end;

get_column_type(_ColumnType,_)->	
	unknown.            

 

 
 

根据数据库的表结构的类型返回其对应的简写类型

原文:http://www.cnblogs.com/ribavnu/p/4959379.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!