Thursday, June 24, 2010

How to get the primary key of a record added to the table with coldfusion

Many people use database tables with autonumber primary keys. These are columns (typically

named “id”) that the database will provide a value for by simply adding one to the last highest value.

So if the last record inserted had an ID value of 5, the next will be 6. (Note that this isn’t always true.

You can’t assume the next value will be one over the last highest value.) If you need to find out what

value was used for the primary key, ColdFusion provides a simple way to do that.

To use this feature, you first must provide the result attribute to your cfquery tag. This tells

ColdFusion to save information about the query to the variable named by the result attribute.

“foo” result=“result”>

insert into people(name,email)

values(“Paris Hilton”, “trash@celebs.com”)

After running this query a structure named result will be created. Most of the keys of this structure

are set, including the sql of the query, recordcount, and other values, however there is a special key

that will store the value of the primary key assigned to the insertion. Unfortunately, this key value

will vary depending on the database. For SQL Server, the value will be in the IDENTITYCOL key.

For Oracle, the value will be in the ROWID key. For Sybase, the value will be in the

SYB_IDENTITY key. For Informix, the value will be in the SERIAL_COL key. For MySQL, the

value will be in the GENERATED_KEY key.

Using the above query as an example and assuming MySQL, you can display the primary key value

like so:

The ID of the row I just inserted was #result.generated_key#.

Logical architecture of a Fusebox application

Logical architecture of a Fusebox application

The logical architecture of a Fusebox app resembles a hub and spoke system, with all actions returning to the hub (the Fusebox). This sort of structure is also known as a circuit application. fusebox

Figure 1 Fusebox App Structure

A circuit application is usually a single directory of files and generally does a few related tasks such as search. The overall application is called the home application, which is made up of many circuit applications. This is where Fusebox gets its name. Just like an electrical Fusebox, it is set up as a group of circuits (”fuses”) that are ready to send the user to whichever part of the application his or her next click requires. Each of these fuses has a name, called a fuseaction. Fuseactions are used to turn on the appropriate switches to cause the required action. So the Fuseaction is the key to the application?without a fuseaction, the application will only do the default fuseaction.

INDEX.CFM and the FuseactionThe home application is ALWAYS engendered in a file called INDEX.CFM, which is placed in the root directory of your application. Every link on the website will always be to this file! When creating the user interface for the application, each URL link or form will be to INDEX.CFM and then contain the name of the fuseaction that will do the work necessary if it is activated. For a URL, the fuseaction will be contained in the query string, for instance: http://localhost/INDEX.CFM?fuseaction=search. For a form, the usual method of placing the fuseaction is to call the INDEX.CFM file in the form?s action field, but then include a hidden form field with the fuseaction:

Now, The question is for internal workings of the INDEX.CFM file. It will use CFINCLUDEs to combine files together to create a working application. But how does ColdFusion use the fuseaction to know which files to combine? This is done using CFCASE/CFSWITCH. The CFCASE/CFSWITCH tags perform a similar function to a CFIF statement with a bunch of CFELSEIFs. But, using CFSWITCH/CFCASE will run much faster than a similar series of CFIF/CFELSEIF. When there are many ELSEIF’s, the logic is exactly the same. For example, here is a logical statement using CFIF/CFELSEIF:

“Wooof” “Meeooow” “Moooooo” [[Silence]]

Using CFCASE/CFSWITCH, the same statement would be:

“Wooof” “Meeooow” “Moooooo” [[silence]]

Since CFSWITCH/CFCASE is faster, it is the method used in the Fusebox architecture. INDEX.CFM will contain CFSWITCH/CFCASE to determine what the user wants to do. Think of the INDEX.CFM as basically one big switch statement and each CFCASE contains the information on what to do for a particular fuseaction. Therefore, the EXPRESSION= parameter of the CFSWITCH will be equal to your Fuseaction variable. An example: fuseaction=search might run a search and then display the results. In this case, the opening CFSWITCH statement should assign #FUSEACTION# to be the variable to be used, as in:

This means that basically, a fuseaction is the equivalent of a single CFCASE statement in your INDEX.CFM. Have a look at this code:

Suppose a user clicks on the following link:

registration

Using the example code above, when ColdFusion executes our CFSWITCH using the “registration” fuseaction, it will first display our HTML header block, then it will include the registration form itself and then finally the HTML footer. The rest of the CFCASES will be ignored.

Article Inspired from : fusionauthority

Coldfusion and It’s Advantages

ColdFusion is a rapid scripting environment server for creating dynamic Internet Applications. ColdFusion Markup Language (CFML) is an easy-to-learn tag-based scripting language, with connectivity to enterprise data and powerful built-in search and charting capabilities. ColdFusion enables developers to easily build and deploy dynamic websites, content publishing systems, self-service applications, commerce sites, and more.

coldfusionmx.JPGcoldfusionmx_arch.JPG

ü Develop and manage applications quickly and easily—ColdFusion lets you condense complex and powerful business logic into fewer lines of code that can be reused, helping you to save time and reduce errors. It provides insight into applications across servers and helps you maintain a consistent configuration across clusters to more efficiently manage your environment. Using ColdFusion , you can improve application performance with more granular control over code, templates, and applications. And speed up application development with the tight integration between ColdFusion and Adobe ColdFusion Builder™ software, the new Eclipse™ based IDE.

ü Rapidly build rich interfaces for new and existing ColdFusion applications—By leveraging the unique integration between ColdFusion and the products in the Adobe Flash Platform, you can accelerate the development of RIAs and interfaces, from client to server. Built-in support for Ajax controls enables you to easily create rich interfaces using Ajax and to build more compelling and intuitive applications. New controls include mapping, multimedia player, multifile upload, accordion navigation, progress indicator, confirmations, alerts, buttons, and sliders. In addition, you can now leverage the power of ColdFusion enterprise services via AMF or SOAP without writing a single line of CFML.

ü Integrate ColdFusion applications with enterprise technologies—Using the enterprise services in ColdFusion , you can easily access data from an existing infrastructure. It’s also easy to build a hub application for enterprise personnel by including Microsoft Exchange enterprise messaging, calendaring, a contact list, and task management. You can expose data from Microsoft Office SharePoint web services to a ColdFusion application and dynamically generate office documents for reporting, decision making, and presentations. Leverage .NET objects from other applications to build a hub application for multiple enterprise resources. Also integrate with Java™ objects, IMAP, and more.

coldfusionmx_adv.JPG

coldfusionmx_arch_comp.JPG

Sources: • Sun Developer Network overview of Java SE security• MSDN, “How To: Use Regular Expressions to Constrain Input in ASP.NET”• PHP.NET Manual—“Security” section• Adobe white paper—Rapid application development for J2EE using Adobe ColdFusion 8• Adobe white paper—ColdFusion 8 developer security guidelines


ColdFusion Magic:- Join between oracle and sql server Using resultset

Yes, it is possible to JOIN result sets from different datasources

One unique use for Query of Queries is to JOIN recordsets from separate queries. By extension, this means you can JOIN recordsets from different datasources as well.

Let’s assume that my datasource for customers is an Oracle database, but the database for customer orders is SQL Server. I realize this is a bit contrived, but we all know how strange the corporate operating environment can be. Using Query of Queries, you can run a JOIN on the two recordsets.

In this example, I’m grabbing orders for a specific customer. First, we’ll look at the getCustomerOrders query, which will provide the second recordset that we’ll use in our JOIN along with the getCustomers recordset:


select
orderID,
customerID,
orderAmount
from
customerOrders

This would produce a recordset like the one shown in Figure 1.

fig1.JPG

JOIN query(Figure 1)

Now, let’s JOIN these separate result sets:


select
getCustomers.customerID,
getCustomers.customerName,
getCustomerOrders.orderID,
getCustomerOrders.orderAmount
from
getCustomers, getCustomerOrders
where
getCustomerOrders.customerID = getCustomers.customerID
AND getCustomerOrders.customerID = 91

The resulting recordset can be seen in Figure 2.

fig2.JPG

JOIN Query of Query(Figure 2)

This ability to relate records in separate queries can be a useful approach to certain programming challenges.

Vulnerability affects ColdFusion MX 7 and ColdFusion 8

A vulnerability has been reported in Adobe ColdFusion, which potentially can be exploited by malicious people to hijack user sessions.

The vulnerability is caused due to an unspecified error when using CFID or CFTOKEN and can be exploited to e.g. hijack a user’s session on an application built using ColdFusion.

NOTE: This vulnerability does not affect customers using J2EE session management.

The vulnerability affects ColdFusion MX 7 and ColdFusion 8.

Issue


ColdFusion manages sessions by keying on cookie values for CFID and CFTOKEN, by default. It has been found that ColdFusion will accept empty string values for either or both of these variables. If an application accidentally stored empty values to CFID and CFTOKEN, all users could share the same session data.

Solution


This update will cause ColdFusion to create a new session if CFID and/or CFTOKEN values are empty strings.
ColdFusion 8

You use the ColdFusion 8 Administrator to install hot fixes. The installation process is the same for all platforms and installation choices.

  1. Download hf800-70523.zip (6.25K) and extract the hf800-70523.jar file.
  2. Open the ColdFusion 8 Administrator and select the System Information page.
  3. Next to the Update File field, select the Browse Button and browse to the extracted file. Select the file and click Submit.
  4. Restart ColdFusion.

The ColdFusion 8.0 hot fix JAR file does not need to be retained after installing it with the ColdFusion Administrator. The file has been copied into the correct location.

The ColdFusion 8.0 hot fix JAR file will appear as a new entry in the System Information list.

Hot fixes are installed in the cf_root\lib\updates directory. To uninstall a hot fix, delete the JAR file from the updates directory that are being replaced by the cumulative update, after stopping the ColdFusion 8 application server.

ColdFusion MX 7

You use the ColdFusionMX 7 Administrator to install hot fixes. The installation process is the same for all platforms and installation choices.

  1. Download hf702-70523.zip (106K) and extract the hf702-70523.jar file.
  2. Open the ColdFusionMX 7 Administrator and select the System Information page.
  3. Next to the Update File field, select the Browse Button and browse to the extracted file. Select the file and click Submit.
  4. Restart ColdFusion.

The ColdFusionMX 7.02 hot fix JAR file does not need to be retained after installing it with the ColdFusion Administrator. The file has been copied into the correct location.

The ColdFusionMX 7.02 hot fix JAR file will appear as a new entry in the System Information list.

Hot fixes are installed in the cf_root\lib\updates directory. To uninstall a hot fix, delete the JAR file from the updates directory, after stopping the ColdFusionMX 7.02 application server.

For More information use following link

http://kb2.adobe.com/cps/402/kb402805.html

Use Single Sign-On to access ColdFusion applications via SharePoint

SharePoint custom Web Parts let you access multiple ColdFusion applications from the SharePoint server using Single Sign-On (SSO). After signing in, users can access multiple secure ColdFusion applications by accessing ColdFusion services from multiple Web Parts.

To make a ColdFusion application available from SharePoint, use the CFSharepoint SSO WebPart template. This template is a customized version of PageViewer WebPart. It enables you to pass SSO credentials to the ColdFusion application. Download this template from the Adobe website or copy it from the ColdFusion 9 DVD.

Remember these points:

  • Web Parts support only the native single sign-on solution; other pluggable single sign-on services are not supported.
  • Only single sign-on credentials are passed to the ColdFusion application. The ColdFusion application must have the necessary logic to retrieve the credentials and login to the application.

Deploy the CF9SSOWebPart.wsp Web Part for SharePoint Portal Server 2007

To configure single sign-on for SharePoint Server 2007, deploy the CF9SSOWebPart.wsp file to the SharePoint server.

  1. Copy the CF9SSOWebPart.wsp file to the BIN folder within the Web Server extensions. It is normally located at Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\BIN in the SharePoint server.
  2. To deploy the solution to SharePoint, use the command prompt to navigate to Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\BIN and enter the following commands, as required.

    To delete the solution if it is already present:

    STSADM.EXE -o deletesolution -name CF9SSOWebPart.wsp -override

    To add the solution to SharePoint:

    STSADM.EXE -o addsolution -f CF9SSOWebPart.wsp

    To deploy the solution to the configured website by specifying the URL:

    STSADM.EXE -o deploysolution -name CF9SSOWebPart.wsp  -url  -local -allowGacDeployment

    To deploy the solution to all the configured websites:

    STSADM.EXE -o deploysolution -name CF9SSOWebPart.wsp -local -allowGacDeployment

Import the CF9SSOWebPart.wsp Web Part into a Web Part Page

  1. Navigate to the web page on the SharePoint server where you want the Web Part to be accessible.
  2. In the Web Part page, click Site Actions > Site Settings.
  3. In the Site Settings page, click Galleries > Web Parts.
  4. In the Web Part gallery, click Upload in the toolbar pane.
  5. Select the CF9SSOWebPart.wsp Web Part.
  6. Enter the following details in the toolbar pane.
    • URL of the ColdFusion application to access
    • The form field name as the User ID
    • The form field name as the password
    • Name of the SSO application where the credentials are configured

Once the Web Part is deployed, it takes the credentials from the SharePoint Single Sign-On database (based on the application name entered in the Tools Pane). These credentials are transferred to the ColdFusion application through the URL (provided in the Tools Pane) in a FORM containing the specified form fields.

Using cfsharepoint

Sharepoint integration with ColdFusion helps you dynamically manage user lists, views, and groups; work with images and document workspaces; and use search effectively. The cfsharepoint tag lets you create new lists, retrieve list items, and update list items on the SharePoint server.

The following example shows how to create a picture library list called “getpics”.

      < action  ="create new folder" login= "#login#" name="collection1" params="#{strListName=" strparentfolder="">          myimage = filereadbinary(expandpath("Bird.jpg"));      //convert the image into byte array to pass as input for "upload" action.                baseimage = filereadbinary(expandpath("bird.jpg"));  //convert the image into byte array to pass as input for "upload" action.      

To check and ensure that all the updates are made, you can retrieve the list items using code like the following:

      SUCCESS      

Access ColdFusion from SharePoint using custom Web Parts

You can access ColdFusion applications from within SharePoint using custom Web Parts. You can create a custom Web Part using the Page Viewer Web Part template that is shipped, by default, with SharePoint services 2.0 and 3.0, and Microsoft Office SharePoint Portal Server 2003 or 2007.

  1. From the SharePoint Server page, click Modify Shared Page.
  2. Select Add Web

Ref : www.adobe.com