Connecting ColdFusion 10 to FoxPro 9

My company has a legacy application built in FoxPro 9 which contains a table that I need to extract data from on a recurring basis. I have never worked with FoxPro. Apparently in FoxPro each table has a corresponding .dbf file. For this example we will say that the table file is persons.dbf, which resides at C:\legacyapp\data\.

The first step for connecting ColdFusion to the FoxPro database was to find an acceptable driver. I initially tried to use some ODBC drivers but abandoned this route. Not only was it just not working, but I do my development on a Mac (whereas production is Windows) and I really wanted a solution that did not involve a Windows and a Mac configuration.

So the following steps describe how I set up a jdbc connection to FoxPro 9 from ColdFusion.

  1. Download the StelsDBF JDBC Driver
  2. Place the dbfdriver.jar file in {ColdFusion-Home}/cfusion/lib aka C:\ColdFusion10\cfusion\lib\
  3. Restart the ColdFusion services
  4. Login to the CFADMIN and set up a Data Source
    • For ‘Data Source Name’ enter ‘legacyapp’
    • For ‘Driver’ select ‘Other’
    • Click ‘Add’
    • For JDBC URL enter ‘jdbc:jstels:dbf:c:/legacyapp/data’
    • For Driver Class enter ‘jstels.jdbc.dbf.DBFDriver2’
    • Click ‘Submit’
  5. When using cfquery to select data use the file name as the table name:
    SELECT 
        LASTNAME, FIRSTNAME
    FROM
        persons
    

It was actually not too bad to set up once I located the driver.

Clean Up Google Drive Icon Files

I had a Git repo that I was storing on Google Drive (Yes that probably was not a great idea, but it was a lazy way of sharing some pdfs in the repo with a non-technical coworker). The Google Drive app on the Mac uses an “Icon” file to indicate sync statuses of folders.  Unfortunately this kept screwing up the repo by also putting “Icon” files in all the folders in the .git directory.  Having the repo was more important than it being in Google Drive so I moved the folder out of Google Drive.  Once the folder was moved the “Icon” files remained and the repo was still throwing an error when I tried to code in Adobe Brackets.

Here is how I cleaned up all the Google Drive “Icon” files.

WARNING: BE SURE YOU DON’T HAVE FILES NAMED WITH “Icon” AS THE FIRST 4 LETTERS OR THIS WILL DELETE THEM.

  1. Open terminal
  2. Change directories into the folder that was once in Google Drive
  3. Issue the following terminal command:
    find . -name 'Icon*' -type f -delete

Now the repo is back to normal.

SQL Server SELECT into existing table

This morning I needed to add a single record to an existing table in database1 from an existing table in database2. Here’s how I was able to do it:

INSERT INTO database1.dbo.tablename
     SELECT *  
     FROM 
          database2.dbo.tablename
     WHERE 
          ID='4d08aeb0bedd01452dfef3eabc2816dcc75533c8'

Please note that the databases use a SHA-1 Hash for the ID field. If you use an IDENTITY field in SQL you’d have to take some extra steps to briefly allow inserting an IDENTITY field.

Using a ColdFusion Ternary Operator for an Optional Tag Attribute

Today I had to write a script to process a form and send an email as part of the processing. The form allows the user to specify an email address to bcc, but it’s not required. I’m a big fan of using the Ternary Operator for doing either/or stuff like css classes. So I decided to extend that fandom to set the bcc attribute of the <cfmail> tag if the email specified in the form was valid.

Assumptions for this example:

1. You have validated form.bccEmail as a valid email.
2. You have a default mail server specified in Application.cfc or CFADMIN.
3. You may see more utility in using the Ternary Operator for other conditional cases.

The “magic” is in the bcc attribute below:

    
	    Message Body here...
    

ColdFusion function returns space before value

I had an annoying issue this morning where a function I wrote that rounds and formats values for use in an internal financial app kept sticking a single space before the value returned. This was obviously not good for a financial app. After spending 10-15 minutes tearing the function’s innards apart it turns out what was going on in the function was not the cause. The cause was simple.

In a tag based ColdFusion function you need to be sure to include the ‘output=”no”‘ attribute.

 
     ... MAGIC STUFF HERE ...

ColdFusion 9 SELECT IN query using ormExecuteQuery()

For some reason this took me some effort to figure out. Maybe others will find it useful.


CategoryList = '1,2,3';
Categories = ormExecuteQuery("from Category where Id IN (:IdList)",{IdList=ListToArray(CategoryList)});

If you know a better way please drop me a comment. I posted this in the Adobe Coldfusion forum for a few days but didn’t get anything.

CAPTCHA Fails

I was buying some software this morning and got the following CAPTCHA at checkout. CLASSIC.

Yup. For real. My other favorite was one I received while working on an application at the office.

Good stuff.

Mac Diff/Merge Utility for Dreamweaver

If you have done web development on a PC in Dreamweaver you have probably used WinMerge to check for differences between local and remote files.  Since I moved to the Mac a few years ago I have been neglectful in finding a similar tool for the Mac.  Thanks to some changes in my current day job I now have a larger team and more of a need for getting my act together on this.

The tool I have decided on in a free one called DiffMerge.  Part 1 of the install is the typical Mac install (drag a file to the Applications folder).  Part 2 is a little more detailed (but dead simple).  There is a readme.txt file in the installer image with instructions for copying 2 files to facilitate command line usage (You will need this for Dreamweaver).

Once you have done the installation and followed the readme.txt fire up Dreamweaver and click Dreamweaver > Preferences > File compare and set the path to your equivalent of the screenshot below:

DiffMerge for Dreamweaver on the Mac

Save, Format, View Dreamweaver Checked Out By Report

I wrote a post a while back about a file I created to format Dreamweaver search results for printing. Recently the need arose for me to apply that same formatting to Dreamweaver’s “Checked Out By” report.

Here is what your report will look like:

Checked Out By Report View

Download the search_results.zip file here. It contains the files to transform both “Search Results” and the “Checked Out By” report.

*** UPDATED 2/27/2015 ***

As a security measure Chrome blocks access to local files. You must open Chrome from the command line with a flag to allow access to local files.

Follow these steps to allow local file access in Chrome on the Mac:

  • If you have Chrome open, close it
  • Open a terminal window
  • Execute the command:
    open /Applications/Google Chrome.app --args --allow-file-access-from-files
  • Once Chrome opens select ‘File > Open File’ and browse to your local xml file
  • Voilà