spec/builder.cfm
2025-06-02 16:16:51 +03:00

200 lines
8.2 KiB
Plaintext

<!--- примитивный конструктор селектов, чтобы не набирать руками колонки --->
<!--- v0.1 2018.02.27 --->
<cfimport prefix="m" taglib="lib"/>
<cfimport prefix="d" taglib="lib/data"/>
<cfparam name="obj" default=""/>
<cfparam name="ds" default="metadata"/>
<cfparam name="out" default="field_set,bean"/>
<!---<cfswitch expression=#ds#>
<cfcase value="metadata"><cfset request.ds="mms"/></cfcase>
<cfcase value="data"><cfset request.ds="ditcloud"/></cfcase>
<cfdefaultcase><cfset request.ds=""/></cfdefaultcase>
</cfswitch>--->
<cfquery name="qObj" datasource="#request.DS#">
select o.type, o.name from sys.objects o where o.type in ('U','V') order by o.type, o.name
</cfquery>
<!---<cfdump var=#qObj#/>--->
<cfquery name="qCol" datasource="#request.DS#">
select c.name, c.system_type_id, c.max_length, c.is_nullable, c.is_identity from sys.columns c join sys.objects o on (c.object_id=o.object_id) where o.name=<cfqueryparam cfsqltype="cf_sql_varchar" value="#obj#"/>
</cfquery>
<!---<cfdump var=#qCol#/>--->
<form action="" method="post">
<!--- <select name="ds" onchange="submit();">
<option <cfif #ds# EQ "data"> selected</cfif>>data</option>
<option <cfif #ds# EQ "metadata"> selected</cfif>>metadata</option>
</select>--->
<select name="obj">
<cfoutput query="qObj">
<option <cfif #obj# EQ #name#> selected</cfif> value="#name#">
<cfif #trim(qObj.type)# EQ 'U'>(table)<cfelseif #trim(qObj.type)# EQ 'V'>(view)<cfelse></cfif> #name#
</option>
</cfoutput>
</select>
<input type="checkbox" name="out_all" id="out_all" value="1" onchange="; for (var i=0, checkboxes=document.getElementsByName('out'), n=checkboxes.length; i < n ; i++) {checkboxes[i].checked = this.checked;}"/>
<label for="out_all">(все)</label>
<cfloop list="field_set,select,insert,update,bean,grid,detail" item="outformat">
<cfoutput>
<input type="checkbox" name="out" id="#outformat#" value="#outformat#"<cfif structKeyExists(form, "out")><cfif listFind(form.out,outformat)> checked</cfif></cfif>/>
<label for="#outformat#">#outformat#</label>
</cfoutput>
</cfloop>
<input type="submit" name="do" value="Сформировать"/>
</form>
<cfif structKeyExists(form, "do")>
<cfif structKeyExists(form, "out")>
<cfif listFind(form.out,"field_set")>
<pre>
select
&lt;d:field_set titleMapOut="titleMap" lengthOut="fieldCount"&gt;<cfoutput query="qCol">
&lt;d:field title="#name#"&gt;#name#&lt;/d:field&gt;</cfoutput>
&lt;/d:field_set&gt;
from <cfoutput>#obj#</cfoutput>
</pre>
</cfif>
<cfif listFind(form.out,"select")>
<cfset comma="No"/>
<pre>
select <cfoutput query="qCol">
<cfif comma>,<cfelse><cfset comma="Yes"/></cfif>#name#</cfoutput>
from <cfoutput>#obj#</cfoutput>
</pre>
</cfif>
<cfif listFind(form.out,"insert")>
<pre>
insert into <cfoutput>#obj#</cfoutput> (<cfset comma="No"/>
<cfoutput query="qCol"><cfif !is_identity><cfif comma>,<cfelse><cfset comma="Yes"/></cfif>#name#</cfif></cfoutput>
) values (<cfset comma="No"/><cfoutput query="qCol"><cfif !is_identity>
<cfif comma>,<cfelse><cfset comma="Yes"/></cfif>&lt;cfqueryparam cfsqltype="cf_sql_#fieldType(system_type_id)#" value="###name###"/&gt;</cfif></cfoutput>
)
</pre>
</cfif>
<cfif listFind(form.out,"update")>
<cfset comma="No"/>
<pre>
update <cfoutput>#obj#</cfoutput> set <cfoutput query="qCol"><cfif !is_identity>
<cfif comma>,<cfelse><cfset comma="Yes"/></cfif>#name#=&lt;cfqueryparam cfsqltype="cf_sql_#fieldType(system_type_id)#" value="###name###"/&gt;</cfif></cfoutput>
<cfoutput>where #obj#_id=&lt;cfqueryparam cfsqltype="cf_sql_integer" value="###obj#_id##" null=##!isNumeric(#obj#_id)##/&gt;</cfoutput>
</pre>
</cfif>
<cfif listFind(form.out,"bean")>
<pre>
&lt;d:bean readonly=#!pageInfo.writePermitted()# table="<cfoutput>#obj#</cfoutput>" datasource="#request.DS#" output="d" status="status"&gt;<cfoutput query="qCol">
<cfswitch expression=#name#>
<cfcase value="creator_id">&lt;d:param field="creator_id" type="integer" value="##request.usr_id##" skipUpdate/&gt;</cfcase>
<cfcase value="updater_id">&lt;d:param field="updater_id" type="integer" value="##request.usr_id##"/&gt;</cfcase>
<cfcase value="dt_created">&lt;d:param field="dt_created" type="timestamp" value="##Now()##" skipUpdate/&gt;</cfcase>
<cfcase value="dt_updated">&lt;d:param field="dt_updated" type="timestamp" value="##Now()##"/&gt;</cfcase>
<cfdefaultcase>&lt;d:param field="#name#" type="#fieldType(system_type_id)#"<cfif (system_type_id EQ 167) AND (max_length GT 0)> size="#max_length#" preprocessor=##cleanInput##</cfif><cfif (system_type_id EQ 167) AND (max_length LE 0)> preprocessor=##plain2HtmClean##</cfif><cfif "#name#" EQ "#obj#_id"> key autoincrement<cfelseif is_nullable AND listFind("127,104,106,62,59,36,56,108,52,41,58,61,189,48",system_type_id)> forNull=""</cfif><cfif system_type_id EQ 104> default="0" init="0"</cfif>/&gt;</cfdefaultcase>
</cfswitch></cfoutput>
&lt;/d:bean&gt;
</pre>
</cfif>
<cfif listFind(form.out,"grid")>
<pre>
&lt;table class="worktable"&gt;
&lt;thead&gt;
&lt;layout:grid_head titleMap=#titleMap# sortArray=#pageInfo.settings.sort.sortArray#&gt;
<cfoutput query="qCol">&lt;th&gt;&lt;layout:column_head name="#name#"/&gt;&lt;/th&gt;
</cfoutput>
&lt;/layout:grid_head&gt;
&lt;/thead&gt;
&lt;cfoutput query="qRead" maxrows="#pageInfo.recordsPerPage#" startrow="#pageInfo.nStart#"&gt;
&lt;tr&gt;
<cfoutput query="qCol">&lt;td class="c"&gt;##<cfif listFind("58,61,189",system_type_id)>dateFormat(#name#,'DD.MM.YYYY')<cfelse>#name#</cfif>##&lt;/td&gt;
</cfoutput>
&lt;/tr&gt;
&lt;/cfoutput&gt;
&lt;/table&gt;
</pre>
</cfif>
<cfif listFind(form.out,"detail")>
<pre>
&lt;div class="detail"&gt;
<cfoutput query="qCol"><cfif "#name#" NEQ "#obj#_id">
&lt;div class="tr"&gt;
&lt;div class="th"&gt;#name#&lt;/div&gt;
&lt;div class="td"&gt;<cfif ((system_type_id EQ 167) AND (max_length GT 0)) OR listFind("127,106,62,59,36,56,108,52,41,58,61,189,48",system_type_id)>&lt;input type="text" name="#name#" id="#name#" value="<cfelseif ((system_type_id EQ 167) AND (max_length LE 0))>&lt;textarea rows="5" cols="70" name="#name#" id="#name#"&gt;<cfelseif system_type_id EQ 104>&lt;input type="checkbox" name="#name#" id="name" value="1"&lt;cfif (</cfif><!---
--->##<cfif listFind("58,61,189",system_type_id)>dateFormat(d.#name#,'DD.MM.YYYY')<cfelse>d.#name#</cfif>##<cfif ((system_type_id EQ 167) AND (max_length GT 0)) OR listFind("127,106,62,59,36,56,108,52,41,58,61,189,48",system_type_id)>"/&gt;<cfelseif ((system_type_id EQ 167) AND (max_length LE 0))>&lt;/textarea&gt;<cfelseif system_type_id EQ 104> GT 0)&gt; checked&lt;/cfif&gt;/&gt;</cfif><!---
--->&lt;/div&gt;
&lt;/div&gt;
</cfif></cfoutput>
&lt;/div&gt;
</pre>
</cfif>
</cfif>
</cfif>
<cffunction name="fieldType" output="No">
<cfargument name="xtype"/>
<cfswitch expression=#xtype#>
<cfcase value="127"><cfreturn "bigint"/></cfcase>
<cfcase value="104"><cfreturn "integer"/></cfcase><!---bit--->
<cfcase value="175"><cfreturn "char"/></cfcase>
<cfcase value="40"><cfreturn "date"/></cfcase>
<cfcase value="106"><cfreturn "decimal"/></cfcase>
<cfcase value="62"><cfreturn "double"/></cfcase><!---float--cf_sql_double--->
<cfcase value="59"><cfreturn "float"/></cfcase><!---real--cf_sql_float--->
<cfcase value="36"><cfreturn "idstamp"/></cfcase><!---uniqueidentifier--->
<cfcase value="56"><cfreturn "integer"/></cfcase>
<cfcase value="108"><cfreturn "numeric"/></cfcase>
<!---<cfcase value="59"><cfreturn "real"/></cfcase>--->
<cfcase value="52"><cfreturn "smallint"/></cfcase>
<cfcase value="41"><cfreturn "time"/></cfcase>
<cfcase value="58,61,189"><cfreturn "timestamp"/></cfcase><!---smalldatetime,datetime,timestamp--->
<cfcase value="48"><cfreturn "tinyint"/></cfcase>
<cfcase value="165"><cfreturn "varbinary"/></cfcase>
<cfcase value="167,231"><cfreturn "varchar"/></cfcase>
<cfdefaultcase><cfreturn "varchar"/></cfdefaultcase>
</cfswitch>
</cffunction>
<!---
CF_SQL_BIGINT
CF_SQL_BIT
CF_SQL_CHAR
CF_SQL_BLOB
CF_SQL_CLOB
CF_SQL_DATE
CF_SQL_DECIMAL
CF_SQL_DOUBLE
CF_SQL_FLOAT
CF_SQL_IDSTAMP
CF_SQL_INTEGER
CF_SQL_LONGVARCHAR
CF_SQL_MONEY
CF_SQL_MONEY4
CF_SQL_NUMERIC
CF_SQL_REAL
CF_SQL_REFCURSOR
CF_SQL_SMALLINT
CF_SQL_TIME
CF_SQL_TIMESTAMP
CF_SQL_TINYINT
CF_SQL_VARCHAR
--->