Posts

Showing posts from April, 2013

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:

Simple ORM concepts in coldfusion

Image
ORM (Object Relational Mapping ) helps us to develop applications without writing repetitive SQL statements for select, update, insert and delete operations. For configuring ORM, we should have a datasource in the server. Also we need to enable ORM in our Application.cfc file. So the Application.cfc will look like, component {        this.name = "ORMtest";   //Name of the Application        this.datasource = "DatasourceName";  //setting datasource        this.ormenabled = true;  //Enabling ORM        this.ormsettings.dbcreate = "update";  //Allows coldfusion to update database } For each tables in the database, we have to create different components or cfcs, which are called Entities. For example, if we have a table called 'Userdetails' , we can create a cfc 'userdetails.cfc', and  we need to map the objects to tables. component persistent="true" table=" Userdetails" {     property name="id" fieldType

Remove non ASCII characters in coldfusion

The following code will remove the non ascii or illegal characters from a string. <cfset str=" Please enter string "> <cfset a=reReplace(str, "[^\x20-\x7E]", "", "ALL")> <cfoutput>#a#</cfoutput>