Archive for December, 2010

Filtering DOM elements with jQuery

Thursday, December 30th, 2010

A few days back I was asked to build a scrolling div full of checkboxes populated via a database query record set that could be filtered. To accomplish this, I’ve often used AJAX in the past to hit a CF component that would run a SELECT statement containing a WHERE clause that looked for a record LIKE my existing value. This would return back the filtered item.

In this case however, I was working with a very large dataset and it was not appropriate to make an AJAX call to filter the dataset, and much less to do so on each key press to simulate live filtering. So I decided to filter on the client side and leave CF and AJAX out of the equation all-together. Naturally, I open the jQuery docs and start looking for something along the lines of a regular expression. As usual jQuery makes things even simpler than I could have imagined.

The jQuery selectors page shows multiple ways of selecting elements. One way is to use the ‘contains’ selector that essentially looks at the value of an attribute and checks if the substring exists in any of the available values. Once we know which elements are like and not like the substring (a.k.a. the filter criteria) we can use the jQuery show() and hide() functions to perform the filter visually for the user.

Let’s look at an example.

(more…)

ORA-00923: FROM keyword not found where expected

Wednesday, December 15th, 2010

This is a general reference to an error I received today when executing an Oracle statement. Essentially the statement was fairly complicated containing a number of subqueries. As such receiving ‘ORA-00923: FROM keyword not found where expected’ as an error in a statement was somewhat frustrating. As it turns out, not only is it a somewhat useless user facing error, it didn’t even turn out to have anything to do with the FROM clause.

After much debugging, a co-worker determined that the issue was a duplicate column reference in the SELECT clause. After determining the point of failure I decided to write up a simple test to determine if this error would be thrown in a statement far less complicated than the one being worked on at the time.

What I learned is rather interesting. This error is only thrown when a column is duplicated, in which the duplicate is contained within the all symbol (*). So on the assumption that the employee_table contains three columns – employee_id, employee_name, and employee_email – let’s take the following example that would throw this error when run against Oracle.

Throws: ORA-00923: FROM keyword not found where expected

SELECT *, employee_name
FROM employee_table

If I were to write out the columns and duplicate the columns I would get a different error. The following example would throw an ambiguous column reference.

Throws: ORA-00918: column ambiguously defined

SELECT employee_id, employee_name, employee_email, employee_name
FROM employee_table

While the above examples are no-brainers, the particular query I was working on was a very complex SQL statement with CF wrappers and Oracle functions and all kinds of good stuff. So under these conditions finding duplicate columns can be very tricky and unfortunately Oracle doesn’t do much to help. So I guess the lesson is that if you get either of these errors check for any duplicating columns. Note that my literal test did contain a JOIN, which may have something to do with the second error listed. That particular statement might throw a different error.

Query Of Queries runtime error. The aggregate function [SUM(expression)] cannot operate on an operand of type [VARCHAR].

Tuesday, December 14th, 2010

I ran into the above error today when trying to run a SUM() function on a query retrieved from a database using the Coldfusion Query of Queries sweetness. While the error itself is fairly explanatory I couldn’t figure out where my column being summed was being typed as a string as opposed to an integer. As such I began reading up in the Coldfusion docs on how to type data columns via a Query of Queries. It turns out that it’s very doable with a Cast() function. So while not using Cast() would throw the above error, using it to cast the column data type as an Integer resolved the issue.

Won’t work while My_Total is a type string (VARCHAR)

SELECT SUM(My_String_Column) AS My_Total
FROM Some_Table

Will work while My_Total is a type string (VARCHAR)

SELECT SUM(Cast(My_String_Column AS INTEGER)) AS My_Total
FROM Some_Table

So, fairly straight-forward usage. Any column can be cast as a number of data types on the fly within the Query of Queries. Just as a side-note, I did resolve the actual issue after discovering the Cast() function. Essentially, I typed my return variable in my Oracle Function as an NVARCHAR2. Hence my value was returning as a string. Once I changed my return data type I no longer needed the Cast() function in my Query of Queries. Nonetheless, it’s pretty cool functionality provided by Coldfusion.

What am I using to redesign/organize my blog?

Monday, December 13th, 2010

So I haven’t posted much lately because I’ve been in the beginning phases of redesigning and re-organizing my blog.  The entire concept of ‘pukkared’ came out of a freelancing development business my wife and I ran for a couple years.  Since, we’ve both gotten full-time jobs doing what we love that keeps us employed, usually, well-beyond full-time.  Once we decided to officially drop the freelancing stage of our life we dropped our website and I moved the concept of ‘pukkared’ over to my blog.  While I love the design and always believed it was, within the marketing realm, an excellent design, I have never thought that it fit my blog very well.  As such, I have decided it’s time to redesign, and more importantly re-organize my content into something that makes sense within the given audience and context.

I thought I would quickly post some of the tools I’m using to develop the new blog since some of them I’ve just found and are pretty freakin’ cool.  The list I’ll cover is WordPress (obviously), Balsamiq (for wireframing), and Kuler (color organization).

WordPress.  I never cease to be completely astounded at how perfect the WordPress program is.  I can usually find something to complain about with most any software I use for more than an hour, but I can’t say that I would change anything about WordPress. I’ve been using WordPress for a long time, but have always used its customization options within the default settings.  Essentially, I’ve never taken the opportunity to dig into the code and truly customize within WordPress, until now.  While I have no problems with PHP as a scripting language, I personally despise the way it is used to write dynamic HTML.  And there seems to be a lot of this in WordPress (as with any PHP program I’m sure).  Looking at a mix of PHP and HTML gives me an almost instant headache.  Beyond that, I like that WordPress comes fully equipped with tons of pre-built functions that can be called to do most anything you want making the general code base incredibly flexible.  Overall, coding WordPress is a real pleasure.  Beyond digging into the backend of WordPress, it is an incredible piece of software for most any type of web publishing.  wordpress

(more…)