About every 2 months or so someone asks about reliably returning the primary key record from an insert query. The problem they are trying to solve usually has to do with additional inserts into related tables. For example, if you are adding a new user and you want to set group permissions as well - but group permissions require inserting into another table. One way to do it is to do an insert, then do a second query that pulls back the "max(id)" and uses another qualifier - like an email address. This requires 2 connections to the database, but it is a very common method. If you are using SQL server and your primary key is an "identity" type field then you have another option. You can insert and get back the identity value in the same query. This is preferred because of SQL treats a single query statement as an implicit transaction - meaning you are assured of data integrity, and that you will return the right value. Here's the way it works.Read More
Here's a "gotcha" tip. I have a dev server that had 512 megs of RAM on it. I had the JVM heap sizes configured at 256 meg minimum and 384 meg maximum. Today I added some memory to bring it up to 1 gig. I wanted to change the minimum heap to 512 and the maximum heap to 768. Naturally I set both of them to these new values and hit "submit". I got an error that the "minimum" cannot exceed the maximum. Apparently, the code takes care of minimum first. That means it took my value of 512 and compared it to the "old" maximum value of 384 - causing the error.
To fix this I had to set each value independently - starting with the max value. I set the max value to 768 without touching the Min value. Then I set the min value. I thought that was the end and I went happily to restart the CF service to implement my changes. Naturally the service wouldn't start. I examined the coldfusion-err log in the and it said that I could not start the JVM because I was using conflicting garbage collection switches.
Indeed I had change GC type based on some excellent tips from robi sens blog (from UseParallelGC to UseConcMarkSweepGC). Due to the error (I'm guessing) the system had added the UseParallelGC back into my jvm.config file.
So, if you are going to use the cold fusion admin ap to make JVM changes make sure and backup your jvm.config file (found in the runtime/bin directory on a standard installation).
Web services are great - but they are not a magic bullet. You have to become familiar will all their little quirks to use them effectively. This is a nice tip I picked up on the email list for BACFUG (I love the retro logo). Sometimes you might have a CFC that you are calling as a webservice like this:
While I love the CF Administrator, there's one feature that is slightly hidden. I don't need it often, but when I do it is usually an emergency and I have to click around till I remember where it is. It's that little form that says "purge data for clients that remain unvisited for n number of days. To find it, log into the CF Administrator and click on "client variables". If you are using the registry or a data source you will see that the word "registry" or the name of your data source is a link. Click on the link and you will find the form. Also note that there is an important tech note and hot fix for client variables if you are using them. Also note that most CF Gurus concerned with scalability recommend that you not use the registry to store client variables. Use a data source instead - and please people, not Access, ok?
I am always rhapsodizing on the benefits of CFQUERYPARAM. But what if you needed to not use CFQUERYPARAM? Is it possible to get the benefits of the tag without actually needing to USE the tag? Why yes it is! In order to explain let's look under the covers of how an SQL statement is prepared when you use binding. How about a little lesson from Classis ASP?Read More
The new Application.cfc file (as of Coldfusion MX 7) is a great "step up" for the framework. In case you are not familar with it, here's a rundown. You replace the venerable old "application.cfm" file in the root of your application with an "application.cfc" file. It works in a similar way, but there are some extra features and some gotchas. Basically there are 8 function calls that are made by 8 different events that are a part of any application. To put it another way, when certain things happen within the application it fires 8 possible events - which in turn call these functions.Read More