<cfsilent>
<!--- 20181209 v0.3 --->
<!---v0.3 добавлен атрибут cfSqlType--->
<!---v0.4 добавлен атрибут container for json---> 
<!---v0.5 добавлен атрибут type и трансляция в CF_SQL_---> 
<!--- 20210326 v0.8 formatter --->	

<cffunction name="passThrough"	
	returntype="any" 
	output="false"
	hint="just return argument">	
	<cfargument name="x" type="ANY" required="true"/>
	<cfreturn #ARGUMENTS.x#/>	
</cffunction>
	
<cfif thisTag.executionMode IS "end" OR !thisTag.hasEndTag>
	<cfassociate basetag="cf_field_set" datacollection="fieldsArray"/>

	<cfparam name="ATTRIBUTES.expression" default=""/>
	<cfparam name="ATTRIBUTES.title" default=""/>
	<cfparam name="ATTRIBUTES.name" default=""/>	
	<cfparam name="ATTRIBUTES.type" default="string"/>	
	<cfparam name="ATTRIBUTES.cfSqlType" default="#getCfSqlType(ATTRIBUTES.type)#"/>
	<cfparam name="ATTRIBUTES.container" default=""/>
	<cfparam name="ATTRIBUTES.formatter" default=#passThrough#/>

	<cfif ATTRIBUTES.expression IS "">
		<cfset ATTRIBUTES.expression=thisTag.generatedContent/>
	</cfif>

	<cfif ATTRIBUTES.name IS "">
		<cfset regex="([[:word:]]+)[[:space:]]*$"/>
		<cfset matches=REFindNoCase(regex, ATTRIBUTES.expression, 1, true)/>
		<cfif arrayLen(matches.pos) GT 1>
			<cfset ATTRIBUTES.name=mid(ATTRIBUTES.expression, matches.pos[2], matches.len[2])/>
		</cfif>
	</cfif>
</cfif>

<cffunction name="getCfSqlType">
	<!---Translate CF type understandable by isValid to CF_SQL_*--->
	<cfargument name="type"/>

		<cfswitch expression=#ARGUMENTS.type#>
			<cfcase value="string">
				<cfreturn "CF_SQL_VARCHAR"/>
			</cfcase>
			<cfcase value="integer">
				<cfreturn "CF_SQL_INTEGER"/>
			</cfcase>
			<cfcase value="boolean">
				<cfreturn "CF_SQL_BIT"/>
			</cfcase>
			<cfcase value="numeric">
				<cfreturn "CF_SQL_NUMERIC"/>
			</cfcase>
			<cfcase value="date,time">
				<cfreturn "CF_SQL_TIMESTAMP"/>
			</cfcase>
			<cfdefaultcase>
				<cfthrow type="custom" message="Unsupported type" detail="Type #ARGUMENTS.type# not supported"/>
			</cfdefaultcase>
		</cfswitch>

</cffunction>
</cfsilent>