Posts

how to find the execution time for partcular code blocks in ColdFusion

For finding the execution time of particular code blocks, we can use the ColdFusion function GetTickCount().  Without enabling the debugging information in the Administrator, we ca use the metho d GetTickCount() for finding the time used for executing a partcul ar code block. For example,  <cfset t1 = GetTickCount()> code block begin s.. ------------------------------------- code bloc k ends. <cfset  t2= GetTickCount()> <cfset t otal=t2-t1> <cfoutput> Time take n for execution was #total#</cfoutput >    

ColdFusion code to find the datasources in the server

<cfscript> adminObj = createObject("component","cfide.adminapi.administrator"); createObject("component","cfide.adminapi.administrator").login("CF admin password"); myObj = createObject("component","cfide.adminapi.datasource"); </cfscript> <cfdump var="#myObj.getDatasources()#">

Coldfusion code to get the mappings in the server

To find the mappings in the server, we can use the following code.     <cfset  mappings = StructNew()>     <cfset ServiceFactory = createObject("java","coldfusion.server.ServiceFactory")>         <cfset mappings = ServiceFactory.runtimeService.getMappings()>        <cfdump var="#mappings#">

Blank space validation in ColdFusion cfinput

For validating a required input field for blank space, we can use the attribute 'Validate="noblanks"  in the cfinput tag. For example, <cfform name="test" method="post" action="" > Name:<cfinput type="text" name="firstname"  required="yes" validate="noblanks"  message="Please Enter Your firstname"> <cfinput type=" submit" name="submit" value="Submit"> </cfform>

MySql queries to find highest, second highest etc. values

Image
If we have a table 'account' with fields 'accountid' and 'balance', 1. Query to find highest balance from 'account' is:  select balance from account order by balance desc limit 0,1; 2.  Query to find second highest balance from 'account' is:    select balance from account order by balance desc limit 1,1;   3.  Query to find third highest balance from 'account' is: select balance from account order by balance desc limit 2,1;     

Deleting records using coldfusion ORM

For deleting the records, we can use the ORM function, EntityDelete(). For example, if we have an entity 'userDetails' as below: <cfcomponent persistent="true" table="Userdetails">     <cfproperty name="id" fieldType="id" ormtype="int" column="id" >     <cfproperty name="userfirstname">     <cfproperty name="userlastname">     <cfproperty name="address">     <cfproperty name="description"> </cfcomponent> For deleting the particular record, the code is given below: <cfscript> udetails= EntityLoadByPK( " Userdetails ", 1 ); EntityDelete( udetails ); </cfscript>

Ordering records using Coldfusion ORM

Image
If we have the entity as follows; component persistent="true" table=" Userdetails" {     property name="id" fieldType="id" ormtype="int" column="id" ;     property name="userfirstname"  ;     property name="userlastname";     property name="address";     property name="description"; } For ordering the records, we can use the code as follows: <cfscript> mydetails = EntityLoad( "Userdetails", {}, "id desc" ); writeDump( mydetails); </cfscript> Output: