Jake Churchill

… on Flex, ColdFusion, FarCry, and much more …

  • Home
  • About
  • Projects

16

Sep

SQLite Administrator Recommendation

Posted by Jake Churchill  Published in SQL

I’ve been doing a lot of work with SQLite and AIR lately and I recently came across a post from Eric Feminella which has helped me tremendously.

The SQLiteadmin program can be downloaded at the end of this page: SQLite Administrator - International Milestone Beta

Instructions for installing on Windows: Unzip and run :)

This is currently only available for Windows so sorry to all you Mac users (including myself)

no comment

13

Mar

MS SQL IF EXISTS Technique

Posted by Jake Churchill  Published in SQL

I’ll be the first to admit that I’m not the greatest when it comes to database design, optimization, even query code when it comes right down to it. Sure, I can do the standard CRUD things withough a problem but really digging into a database is not my cup of tea. So, when I came up with something actually usable, I had to post it :) So, on with the shameless self-promotion…

So, I am using an IF EXISTS … ELSE block for an INSERT/UPDATE query and was having an issue with the message handler. Yeah, I could have added some additional ColdFusion logic, but who wants to do that??? I thought, It’d be really great if the query would give me back the results of what action was actually taken. So, Here’s the original query:

<cfquery name="addUpdate" datasource="#application.CaseInfoDsn#">
	IF EXISTS (		SELECT 	AreaCode
					FROM 	area_codes
					WHERE 	AreaCode = <cfqueryparam cfsqltype="cf_sql_varchar" value="#form.originalAreaCode#">
			  		OR		AreaCode = <cfqueryparam cfsqltype="cf_sql_varchar" value="#form.AreaCode#">	)
		BEGIN
			UPDATE 	area_codes
			SET		AreaCode = <cfqueryparam cfsqltype="cf_sql_varchar" value="#trim(form.AreaCode)#">,
					State_Region = <cfqueryparam cfsqltype="cf_sql_varchar" value="#trim(form.State_Region)#">,
					Description = <cfqueryparam cfsqltype="cf_sql_varchar" value="#trim(form.Description)#">
			WHERE 	AreaCode = <cfqueryparam cfsqltype="cf_sql_varchar" value="#form.originalAreaCode#">
			OR		AreaCode = <cfqueryparam cfsqltype="cf_sql_varchar" value="#form.AreaCode#">

		END
	ELSE
		BEGIN
			INSERT
			INTO 	area_codes
					(
						AreaCode,
						State_Region,
						Description
					)
			VALUES
					(
						<cfqueryparam cfsqltype="cf_sql_varchar" value="#trim(form.AreaCode)#">,
						<cfqueryparam cfsqltype="cf_sql_varchar" value="#trim(form.State_Region)#">,
						<cfqueryparam cfsqltype="cf_sql_varchar" value="#trim(form.Description)#">
					)

		END
</cfquery>

And Here’s my addition:

<cfquery name="addUpdate" datasource="#application.CaseInfoDsn#">
	IF EXISTS (		SELECT 	AreaCode
					FROM 	area_codes
					WHERE 	AreaCode = <cfqueryparam cfsqltype="cf_sql_varchar" value="#form.originalAreaCode#">
			  		OR		AreaCode = <cfqueryparam cfsqltype="cf_sql_varchar" value="#form.AreaCode#">	)
		BEGIN
			UPDATE 	area_codes
			SET		AreaCode = <cfqueryparam cfsqltype="cf_sql_varchar" value="#trim(form.AreaCode)#">,
					State_Region = <cfqueryparam cfsqltype="cf_sql_varchar" value="#trim(form.State_Region)#">,
					Description = <cfqueryparam cfsqltype="cf_sql_varchar" value="#trim(form.Description)#">
			WHERE 	AreaCode = <cfqueryparam cfsqltype="cf_sql_varchar" value="#form.originalAreaCode#">
			OR		AreaCode = <cfqueryparam cfsqltype="cf_sql_varchar" value="#form.AreaCode#">

			SELECT	TOP 1 'upd' AS actionTaken
			FROM	area_codes
		END
	ELSE
		BEGIN
			INSERT
			INTO 	area_codes
					(
						AreaCode,
						State_Region,
						Description
					)
			VALUES
					(
						<cfqueryparam cfsqltype="cf_sql_varchar" value="#trim(form.AreaCode)#">,
						<cfqueryparam cfsqltype="cf_sql_varchar" value="#trim(form.State_Region)#">,
						<cfqueryparam cfsqltype="cf_sql_varchar" value="#trim(form.Description)#">
					)

			SELECT	TOP 1 'ins' AS actionTaken
			FROM	area_codes
		END
</cfquery>

After each action (Insert or Update) I select a random string with a random alias which I can then use for my message handler. Hopefully someone else out there thinks this is cool because I sure do :)

2 comments

Search

Blog Feed

  • Add blog to any reader
  • Comments Rss
July 2009
M T W T F S S
« May    
 12345
6789101112
13141516171819
20212223242526
2728293031  

Subscribe to Blog

Your email:

Subscribe   Unsubscribe

Archives

Categories

  • Browsers (3)
  • CFEclipse (2)
  • ColdFusion (5)
  • CSS (9)
  • Farcry (32)
    • Farcry Examples (2)
    • Farcry Users (1)
  • Flash (1)
  • Flex (14)
  • Javascript (5)
  • Life & Fun (3)
  • Microsoft Office (1)
  • Misc (4)
  • Random Posts (1)
  • SQL (2)

Recent Posts

  • Flex 2 Datagrid not highlighting row (UPDATE)
  • Flex 2 Datagrid not highlighting row
  • Flex Dynamic casting of data
  • Reboot XP PC over Remote Desktop
  • Dynamically instantiate a class

Recent Comments

  • jellyBean on Flex Channel.Connect.Failed error NetConnection.Call.Failed: HTTP: Status 200
  • Wouter Meeuwisse on CSS Browser Hacks
  • Jake Churchill on Flex Channel.Connect.Failed error NetConnection.Call.Failed: HTTP: Status 200
  • coulix on Flex Channel.Connect.Failed error NetConnection.Call.Failed: HTTP: Status 200
  • Jake Churchill on IE menu hover fix

Recent Post

  • Flex 2 Datagrid not highlighting row (UPDATE)
  • Flex 2 Datagrid not highlighting row
  • Flex Dynamic casting of data
  • Reboot XP PC over Remote Desktop
  • Dynamically instantiate a class
  • Flex Custom Preloader without SWF
  • IE menu hover fix
  • Eclipse with plugins
  • Flex Channel.Connect.Failed error NetConnection.Call.Failed: HTTP: Status 200
  • Flex Metadata - Default Property Values

Recent Comments

  • jellyBean in Flex Channel.Connect.Failed error NetConnection.Ca…
  • Wouter Meeuwisse in CSS Browser Hacks
  • Jake Churchill in Flex Channel.Connect.Failed error NetConnection.Ca…
  • coulix in Flex Channel.Connect.Failed error NetConnection.Ca…
  • Jake Churchill in IE menu hover fix
  • nwhysel in IE menu hover fix
  • Jake Churchill » Post Topic &… in Flex 2 Datagrid not highlighting row
  • Jake Churchill in Reboot XP PC over Remote Desktop
  • Jake Churchill in IE6 PNG Transparency Fix
  • oomes in IE6 PNG Transparency Fix
© 2008 Jake Churchill is proudly powered by WordPress
Theme designed by Roam2Rome