Обновить Application.cfc

This commit is contained in:
naeel 2026-02-17 08:47:22 +03:00
parent 76e099150d
commit 9c7e4efdd9

View File

@ -1,9 +1,7 @@
<cfcomponent displayname="Application" output="true"> <cfcomponent displayname="Application" output="true">
<cfset this.Name = "nubes-crud-final" />
<cfset this.Name = "nubes-crud-demo" />
<cfset this.sessionmanagement = "Yes" /> <cfset this.sessionmanagement = "Yes" />
<cfset this.datasource = "testds" /> <cfset this.datasource = "testds" />
<cfset getDS(this.datasource) /> <cfset getDS(this.datasource) />
<cffunction name="getDS" access="private" returntype="void"> <cffunction name="getDS" access="private" returntype="void">
@ -12,59 +10,34 @@
<cfset var ds = {} /> <cfset var ds = {} />
<cfloop list="class,connectionString,database,driver,host,port,type,url,username,password,bundleName,bundleVersion,connectionLimit,liveTimeout,validate" item="field"> <cfloop list="class,connectionString,database,driver,host,port,type,url,username,password,bundleName,bundleVersion,connectionLimit,liveTimeout,validate" item="field">
<cfset var envVal = system.getEnv("#arguments.dsname#_#field#") /> <cfset var envVal = system.getEnv("#arguments.dsname#_#field#") />
<cfif isDefined("envVal") AND len(envVal)> <cfif isDefined("envVal") AND len(envVal)><cfset ds[field] = envVal /></cfif>
<cfset ds[field] = envVal />
</cfif>
</cfloop> </cfloop>
<cfset this.datasources[arguments.dsname] = ds /> <cfset this.datasources[arguments.dsname] = ds />
</cffunction> </cffunction>
<cffunction name="OnRequest" access="public" returntype="void" output="true"> <cffunction name="OnRequest" access="public" returntype="void" output="true">
<cfargument name="template" type="string" required="true" /> <cfargument name="template" type="string" required="true" />
<cfset request.DS = this.datasource /> <cfset request.DS = this.datasource />
<cfset setEncoding("FORM", "UTF-8")>
<cfset setEncoding("URL", "UTF-8")>
<cfif structKeyExists(form, "crud_action")> <cfif structKeyExists(form, "crud_action")>
<cftry> <cftry>
<cfswitch expression="#form.crud_action#"> <cfswitch expression="#form.crud_action#">
<cfcase value="insert"> <cfcase value="insert">
<cfquery datasource="#request.DS#"> <cfquery datasource="#request.DS#">INSERT INTO nubes_test_table (test_data) VALUES (<cfqueryparam value="#form.txt_content#" cfsqltype="cf_sql_varchar">)</cfquery>
INSERT INTO nubes_test_table (test_data)
VALUES (<cfqueryparam value="#form.txt_content#" cfsqltype="cf_sql_varchar">)
</cfquery>
</cfcase> </cfcase>
<cfcase value="update"> <cfcase value="update">
<cfquery datasource="#request.DS#"> <cfquery datasource="#request.DS#">UPDATE nubes_test_table SET test_data = <cfqueryparam value="#form.txt_content#" cfsqltype="cf_sql_varchar"> WHERE id = <cfqueryparam value="#form.id#" cfsqltype="cf_sql_integer"></cfquery>
UPDATE nubes_test_table
SET test_data = <cfqueryparam value="#form.txt_content#" cfsqltype="cf_sql_varchar">
WHERE id = <cfqueryparam value="#form.id#" cfsqltype="cf_sql_integer">
</cfquery>
</cfcase> </cfcase>
<cfcase value="delete"> <cfcase value="delete">
<cfquery datasource="#request.DS#"> <cfquery datasource="#request.DS#">DELETE FROM nubes_test_table WHERE id = <cfqueryparam value="#form.id#" cfsqltype="cf_sql_integer"></cfquery>
DELETE FROM nubes_test_table
WHERE id = <cfqueryparam value="#form.id#" cfsqltype="cf_sql_integer">
</cfquery>
</cfcase> </cfcase>
</cfswitch> </cfswitch>
<cfcatch><cfset request.db_error = cfcatch.message /></cfcatch> <cfcatch><cfset request.db_error = cfcatch.message /></cfcatch>
</cftry> </cftry>
</cfif> </cfif>
<cftry> <cftry>
<cfquery datasource="#request.DS#"> <cfquery datasource="#request.DS#">CREATE TABLE IF NOT EXISTS nubes_test_table (id SERIAL PRIMARY KEY, test_data TEXT, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP);</cfquery>
CREATE TABLE IF NOT EXISTS nubes_test_table (
id SERIAL PRIMARY KEY,
test_data TEXT,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
</cfquery>
<cfcatch><cfset request.db_error = cfcatch.message /></cfcatch> <cfcatch><cfset request.db_error = cfcatch.message /></cfcatch>
</cftry> </cftry>
<cfinclude template="#arguments.template#" /> <cfinclude template="#arguments.template#" />
</cffunction> </cffunction>
</cfcomponent> </cfcomponent>