Rob Gonda's Blog

Microsoft SQL Server Database Publishing Wizard

The SQL Server Database Publishing Wizard enables the deployment of SQL Server databases into a hosted environment on either a SQL Server 2000 or 2005 server. It generates a single SQL script file which can be used to recreate a database (both schema and data) in a shared hosting environment where the only connectivity to a server is through a web-based control panel with a script execution window. If supported by the hosting service provider, the Database Publishing Wizard can also directly upload databases to servers located at the shared hosting provider.

AjaxCFC for jQuery Alpha3 Release

I just updated the SVN with the 3rd alpha release of AjaxCFC for jQuery. For those of you not familiarized with source control repositories, I included the code into the main AjaxCFC download (thank Rey Bango for reminding me four times a day), available at RIAForge and my blog. You can also just click here.

This release includes several small fixes in the JavaScript and upgrade to the latest CFJSON. Thanks to Larry Reinhard for pointing it out.

The code seems to be really stable; I haven't got many bug reports, au contraire, Jacob Munson, from CFQuickDocs, said he dropped it into his code w/o any complications, maintaining all existing functionality.

I shall wrap up some documentation and officially release it for production.

SEO Advice needed

A couple of days ago I thought Google loved me. Immediately after I posted an entry, all the keywords for this entry showed up in the very first place in Google; but my happiness did not last. My blog get aggregated by a few large itechnology portals and after a few days, Google spidered their copy of my entry. Immediately after this event, they took my place in Google and took me completely out of it. It seems like their post has more authority than mine, the content is the same (its aggregated), therefore, theirs stay, and mine goes.

Is there anything I can do about this? I'd like to keep the aggregators, but somehow claim ownership of the article. Is that mutually exclusive? Is that what micro-ids are all about? Any help would be appreciated.

Leverage SQL Session at the South Florida CFUG

I will be speaking this coming February 22nd at the South Florida CFUG. For this month I chose a topic that will benefit you regardless of your programming language of preference, and should hopefully allow to you take back something that you can apply immediately.

Topic:      Leverage the power of SQL
Description:     Many developers don't realize the power of SQL to perform data related tasks and computations. Learn how to utilize triggers, stored procedures, constraints, and user-defined-functions to their full potential, and see the huge impact this could have in your organization or day-to-day coding.

Tell your friends.

ColdFusion Vs. SQL UUID

A few days ago I blogged about database level data integrity and promised a follow up concentrating in uuids.

A UUID stands for Universally Unique Identifier. The intent of UUIDs is to enable distributed systems to uniquely identify information without significant central coordination. Thus, anyone can create a UUID and use it to identify something with reasonable confidence that the identifier will never be unintentionally used by anyone for anything else. Information labelled with UUIDs can therefore be later combined into a single database without needing to resolve name conflicts. The most widespread use of this standard is in Microsoft's Globally Unique Identifiers (GUIDs) which implement this standard (source: wikipedia).

A UUID is essentially a 16-byte (128-bit) number. In its canonical form a UUID may look like this:

    xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx (8-4-4-4-12)

However, for some reason ColdFusion's UUID looks like

    xxxxxxxx-xxxx-xxxx-xxxxxxxxxxxxxxxx (8-4-4-16)

Microsoft SQL has a native datatype called uniqueidentifier, which represents the 36-characters GUID. Many ColdFusion developers choose not to use the GUID because it cannot be implicitly validated by ColdFusion and it cannot be seamlessly moved to a different database like mysql, postgre, oracle.

The most widely adopted solution is to use a 35-character primary key and insert a ColdFusion UUID, nonetheless, how do you validate a proper uuid at the database level? What if you want the database to generate the primary key? If the key gets altered, it will fail ColdFusions implicit UUID datatype validation.

The solution is to add some constraints in the database level.

Is it really simple to generate a UUID, since all it takes it just to remove the 4th hyphen.

CREATE FUNCTION dbo.newUUID(@GUID varchar(36))
RETURNS varchar(35)
AS
BEGIN
 RETURN left(@GUID, 23) + right(@GUID,12)
END


Note that due to limitations and not being able to invoke a newID() function inside a user defined function, we need to pass the GUID. Now, that said, we can add a default value to our primary keys and let SQL Server generate them for us:

Default Value: dbo.newUUID(newid())


To validate a proper UUID is a little more complicated, since SQL has no native isUUID or isGUID function. I chose to use a regular expression, but guess what? SQL Server 2000 has no regular expression capabilities.

So step one is to create a regular expression evaluator function

CREATE FUNCTION dbo.find_regular_expression
    (
        @source varchar(5000),
        @regexp varchar(1000),
        @ignorecase bit = 0
    )
RETURNS bit
AS
    BEGIN
        DECLARE @hr integer
        DECLARE @objRegExp integer
        DECLARE @objMatches integer
        DECLARE @objMatch integer
        DECLARE @count integer
        DECLARE @results bit
       
        EXEC @hr = sp_OACreate 'VBScript.RegExp', @objRegExp OUTPUT
        IF @hr <> 0 BEGIN
            SET @results = 0
            RETURN @results
        END
        EXEC @hr = sp_OASetProperty @objRegExp, 'Pattern', @regexp
        IF @hr <> 0 BEGIN
            SET @results = 0
            RETURN @results
        END
        EXEC @hr = sp_OASetProperty @objRegExp, 'Global', false
        IF @hr <> 0 BEGIN
            SET @results = 0
            RETURN @results
        END
        EXEC @hr = sp_OASetProperty @objRegExp, 'IgnoreCase', @ignorecase
        IF @hr <> 0 BEGIN
            SET @results = 0
            RETURN @results
        END   
        EXEC @hr = sp_OAMethod @objRegExp, 'Test', @results OUTPUT, @source
        IF @hr <> 0 BEGIN
            SET @results = 0
            RETURN @results
        END
        EXEC @hr = sp_OADestroy @objRegExp
        IF @hr <> 0 BEGIN
            SET @results = 0
            RETURN @results
        END
    RETURN @results
    END


Now that we have this, all we need is the UUID regEx pattern and call this function.

CREATE FUNCTION dbo.isUUID (@uuid varchar(35)) 
RETURNS bit AS 
BEGIN

DECLARE @uuidRegex varchar(50)
SET @uuidRegex = '^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{16}$'

RETURN dbo.find_regular_expression(@uuid,@uuidRegex ,0)

END


Alright! now we have a isUUID function, which you can easily invoke from everywhere... open a sql script and execute

SELECT [dbo].[isUUID]('D929E4FB-537C-495F-BB3F31B8E42C0FBB')


Now that we tested it and know how it works, all we need is to add a constraint to your primary key:

Open your table in design mode, click constraints, new, and add this line:

([dbo].[isUUID]([ID]) = 1)


where ID is the name of the primary key.

So you learned how to generate a UUID, default your primary key to use one, validate a UUID regEx, and add a constraint to enforce db data integrity.

cf.Objective() posts speakers list

The speakers list is now up at the cf.Objective() site. I couldn't assist last year, but I heard nothing but great stories, so I'm really happy to make it this year. Sessions and topics will be posted shortly, but registration is already open. Trust me, no matter what are the final topics, just look at the speakers, you know it will be good. Hope to see you all there.

Framework Conference highlights

The frameworks conference was great... big applause to Liz and the Teratech team for putting it together. Like in most conferences, I only made it to a selected number of sessions, however, I learned a lot from the speakers at the bar.

The two sessions I enjoyed the most were Hal Helm's Interface Driven Architecture, and Chris Scott's Intro to Aspect Oriented Programming.

The food was great; we had food available from 8am till 6pm ... We had a foosball tournament and the prize was two Flex 2.0 licenses... too bad the tables were even worse than the beat-up one at my office :)

My session was on object factories, providing some history and evolution in CF programming, and examples taking apart Ray Camden's Galleon forums and showing alternative ways to wire dependencies together. Ray assisted my presso and it seems like I could have made a difference; that's great!.

I'll post my slides and code shortly, plus a bonus video or two, showing what speakers really do at these conferences.

cfcUnit 1.2 beta 1 now with Ant

After a long wait, Paul announced the beta release of cfcUnit 1.2, which now finally includes Ant support. cfcUnit allows you to perform tests on very specific functionality of your components (units), and now they can be funny automated with your builds by being invoked by Ant right from within Eclipse. I know Paul has been working on this for a long time under Sean's pressure, so you know this code must be good. You can get the latest release at sourceforge.

This blog is running version 5.9.003. Contact Blog Owner