I made a little update to the CFAir compiler package. I tweaked the generated application to be a little more complicated, and CFAir still works on it. There’s a screenshot to the right (If you’re own my site.)
Tag: ColdFusion
I’ve posted my Squidhead Presentation that I gave last night at the Philly CFUG.
I made some changes to the CFAIR compiler project.
- Added some documentation
- Fixed a bug that caused the first run of the app to not create an air file.
- Made sure that images referenced by ColdFusion CSS are imported
Additionally I added a screenshot of the image to the RIAForge site.
So check out CF Air Compiler, and please let me know what you think of it. Is this worth developing further? Or should I just wait for Centaur? Anybody have any suggestions or ideas on how to proceed?
I was inspired by Ben Forta’s post on creating AIR application from ColdFusion. I felt like there had to be a better way than just copying the source of ColdFusion generated HTML files. So I started working with it and came up with a proof of concept project on RIAForge: CF Air Compiler.
I wrote a simple application called “testapp” that just binds a CFGrid to the results of a CFC call that returns a CFFeed of coldfusionbloggers. This is the application that will be packaged into an Air application.
I used CFHttp to grab the ColdFusion page outputted as HTML and move them to a repository. Then I used ReMatch to find all of the used CFIDE javascript files, css files, and images, and copy them to the repository. Then I used ReMatch to grab all of the cfc calls and convert them to fully qualified url calls.
The second part was a little easier. All it required was wrapping the adt.bat in a CFC wrapper. It just has two methods: certificate and package. They correspond to the options for the adt.bat file. I used that to compile the application into AIR.
There were a few challenges with it. I haven’t figured out a way to get to the images used in CSS. I could just grab them indiscriminately, but I want to do a little better, expect an update after I think about it for a bit. Also the CF JavaScript evidently tries to do some things that violate the security model of the Air Runtime. It required wrapping the ColdFusion generated html in an iframe. To read more about the issue, you can check out the Air Wiki.
It’s not perfect code, but I figured I would at least get it out there and maybe someone smarter could take it a little further. Check it out, please feel free to offer suggestions and criticism.
Over the past two weeks I’ve been struggling with adding support for Oracle in Squidhead. (Expect a release early next week.) Oracle was more different from both Microsoft SQL and MySQL than they were from each other. It got me thinking about the three and their various pros and cons for code generation, and their pros and cons for me doing code generation with stored procedures. I figured it could make a good blog article. (Or someone could see my post and say “Hey you didn’t have to do all that because of the blah command!”)
Microsoft SQL
This was the first one I started with, so the others are being compared to it. It comes with the built in stored procedure sp_help, which is absolutely brilliant. It gave more information for tables than I ever needed. It also gives most of the information for a stored procedure that I need. Although there are a few things lacking which made me have to resort to using sp_helptext, and then parsing the actual stored procedure. I had to do this to get the number of result sets that a stored procedure returns. (Because if a stored procedure returns more than one record set, Squidhead writes the method to return a structure of queries instead of just a query. ) Also I had to do this to get the metadata of the arguments being passed to a stored procedure.
MySql
Of the three this was the easiest to do. I had a flash one night (“just implement sp_help’s queries in MqSQL”) and it took me less than 24 hours to add it. Nonetheless I still had to query a lot of system tables directly to get the results I wanted.
There are few other limitations that bug me, but they aren’t related to code generation. Things like stored procedures not being able to take default values in their inputs, and views not being able to contain subqueries. I’m sure as those features mature though, we’ll see better results there.
Oracle
Finally, we reach Oracle. It took me a week of hair pulling, keyboard slamming and muttered curses to get it right. But finally I did.
What I didn’t like:
One has to create a cursor to contain output recordsets for a stored procedure. That’s so different than the other systems that I wanted to kill someone. Although, I must confess it makes counting output record sets much easier.
That everything is limited to a name length of 30 characters. So I had to get creative with how to deal with stored procedures with names like usp_entryToComment_list_foreign_key_labels. The solution I came up with was to abbreviate them and rename them higher up in the Squdihead stack so that the functions have the “correct” names.
What I liked:
Packages. Packages are sort of like classes or CFC’s for Oracle operations. The encapsulate code into discreet chunks. I basically create a package for every table so my stored procs have names like ENTRYPKG.READ which is better in my mind than usp_entry_read as that’s just a way I use to group and sort stored procedures anyway.
The sheer amount of data in the various data dictionaries. I don’t have to parse any code strings to get any metadata. That’s much easier.
“CREATE OR REPLACE.” Truly awesome. Cuts down on the amount of steps I have to do to recreate a stored proc or package. I wish I had known it exists for MySQL.
Conclusion
It’s kinda funny, and it may be cognitive dissonance talking, but of the three, I really like Oracle the best for code creation and metadata. Overall, I still lean towards Microsoft Sql as it is the one I know the best. Also whatever your thoughts on Microsoft Sql Server Management Studio, it’s so much better than SQL developer for Oracle. But that’s a completely different topic.
I’ll be doing a presentation and little demo of Squidhead at the Philadelphia Area CFUG meeting on Tuesday November 13th.
I’ll be going over the reason behind the application and what it can do. As for the demo, have you seen my Facebook in 17 minutes demo? Well, I’ll be doing that, in about half the time. (I’ve made some improvements to Squidhead in the interim.)
Inspired by Sean’s example, I asked myself, “Why doesn’t Squidhead have a mailing list?”
“I don’t know,” I replied.
So now I have one. Feel to join and pester myself and the 2 other people that will join.
Squidhead has gone through a little resurgence since I got back from MAX. It’s happened for two main reasons.
- I’m using to it to build a more complex application
- I talked to a few people about it, and they actually liked it
But it occurs to me that I could/should do a better job explaining why you might want to give it a longer look.
Squidhead might be for you if:
- You or your organization requires a generator that uses stored procedures instead of inline SQL calls
- You or your organization prefers using foreign keys and wants a generator that can use them to discover business logic
- You want to fool around with code generation but don’t the like MVC code that many of the others use.
Squidhead might give you an excuse to:
- Work with Ant, because of the build.xml files it creates for itself.
- Experiment with Unit Testing, because it builds its own CFUnit Tests and runs yours too
Squidhead isn’t for you if:
- You find the name “Squidhead” ridiculous.
- You’re already using a more established generated or framework
If you’re interested, here are some resources for you:
Um, hey, did some of you try and download the Flash version of the video? Um, yeah, and did it crash your browser, and possibly crash your computer?
Sorry about that.
I’ve fixed the Flash version and it shouldn’t do that anymore. I should have gone with Flash Video encoder in Flash CS3 from the get go.
A reader left a comment in one of my posts about the Selling ColdFusion outside of the Community, stating that I had to answer this before I could sell outside of the community. I figured it was worth a blog post instead of a comment.
Simply stated, I use ColdFusion because it is the most productive language I have ever worked in. I have done more, in less time with ColdFusion, than I have ever achieved in any other language.
Over the course of years at my job I have had to do work in ColdFusion, Perl, Php, C++, Python, and Java. I don’t claim to know any of them; I just had to work in them. None of them have allowed me to build things as fast or as easily as ColdFusion.
Those languages I stated before, of all of them, I used Perl the most. I’ve spent more time figuring out how to do the few things I really know in Perl, than I spent learning ColdFusion. Part of that is Perl itself, part of that is the sheer sadistic joy that Perl programmers take in making even their sample code undecipherable to the non-initiated, but most of it can be attributed to ColdFusion’s true ease of absorption.
I remember something a student interviewing for a co-op position said to me:
I wish I hadn’t learned ColdFusion first. It made me expect all languages to be that easy to learn.
Some, (like this recent post from Kyle Hayes) have termed this a weakness with ColdFusion. But that should be considered strength of the language, people want to work in it; people expect other languages to be so accessible. These features should be embraced in the rush to get more users in the door, not thrown away.
There you have my 2 cents, please feel free to disagree.