Getting a good nights sleep – ORM with NHibernate

Posted by on Friday 28th September 2007 | Tagged as: .NET, Community, Database, Development, Links, SQL, Talks / Presentations

Getting a good nights sleep - ORM with NHibernate

Last night I gave a presentation to the Liverpool Geekup group about NHibernate, thanks to everyone who came along – you were all a very nice audience. The slides from the presentation entitled Getting a Good Nights Sleep – ORM with NHibernate are available as a PDF, here. There are a number of links in the slides, but here is a more comprehensive list of links that people may find useful or interesting

A few SQL Tricks and Tips

Posted by on Wednesday 11th July 2007 | Tagged as: Database, Development, SQL

 

Undocumented Stored Procedure 1 – sp_MSForEachDB

 There are a number of reasons that you might need to run the same (or similar) bits of SQL against a number of similar databases.  I find myself doing this when I update some part of an application that runs against a number of individual client databases on the same server.  In my case, the databases are consistently named in the format ‘client’ + ‘ApplicationName – i.e. ReflectivePerspectiveBLOG

sp_MSForEachDB is a built in SQL Server stored procedure which is undocumented in Books Online, but helps us out in this situation, allowing us to run a command on each database on the server

EXEC sp_MSForEachDB @command1 = '

use [?]

if (db_name() like '%BLOG')

BEGIN

     --Perform our operation

     update foo set bar = 1 where wibble=2

END

'

Undocumented Stored Procedure 2 – sp_MSForEachTable

 Another related stored proceedure is sp_MSForEachTable – this one allows you to do things to each table in the database:

EXEC sp_MSForEachTable @command1 = '

       select top 10 * from ?

'

SET vs SELECT to initialize variables

There are two ways of allocating values to variables in TSQL – SET and SELECT.  Many people get into the habit of using SET to initialize their variables, like so

SET @foo = 1

SET @bar = 2

SET @wibble = 3

For performance purposes this is quite in-efficient as each use of SET is the equivaent of a SELECT statement.

SELECT, on the other hand has the advantage that it is able to set multiple variables at once:

SELECT @foo = 1, @bar = 2, @wibble=3

This single select statement is the equivalent of one of the SET statements above.  The performance advantages of this increase when allocating values to variables from database tables:

SET @foo = (select foo from table where 1=1)

SET @bar = (select bar from table where 1=1)

does the same as the following statement, but only executes the query against the database once.

SELECT @foo = foo, @bar = bar from table where 1=1

Table Variables

Table variables are very useful and often forgotten about feature of SQL Server.  You can use them much as you might a temporary table, however they have the added benefit that they will clean up after them selves, so you don’t have to remember to do the drop table #foo.

You can create Table Variables like so:

declare @tableVar table (col1 int, col2 int)

and from then on you can use them much as you would any other table

insert into @tableVar (col1, col2) values(1,2)
select * from @tableVar
Technorati Tags: , , ,

Yahoo HackDay – Flickr Face Ball

Posted by on Sunday 17th June 2007 | Tagged as: .NET, C#, Community, Photography, Software

OK, the time has come to unveil my Hack for Yahoo Hack Day.  Face Ball is the ‘Crazy new game at Flickr HQ‘, and images have been popping up all over flickr as other join in.  Well now, you too can join in the fun, and just like Thom Shannon, make your own Face Ball images without risk of injury or special equipment.

Flickr Face Ball is a .NET 2 Windows Forms application that allows you to select images from you Flickr photo stream by tagging them as ‘ToFaceBall’, and add one of three different face ball images to the original photo, uploading the results to your Flickr account.

 

So, how do you get involved in this craze:

  1. Ensure you are running Windows with the .NET 2 framework – sorry Mac guys – this one probably isn’t for you.
  2. Download the Zip File
  3. Tag a few suitable images on your Flickr photo stream with the tag ‘ToFaceBall’
  4. Extract the .zip and run FlickrFaceBall.exe
  5. Enter your Flickr user account name into the box provided and click ‘Fetch From Flickr’
  6. Wait patiently while it loads the images.
  7. Choose an Image from the thumbnail strip at the bottom of the screen, choose a ball from the pallet on the left, and click on the image to position it.
    Face Ball picks on the BT Internet Van in the carpark
  8. When you have achieved the look you want, click save, enter a title and description, followed by Authenticate.
  9. When prompted in your browser, please allow the application to upload the images.
  10. Finally, click upload, and (hopefully) your creation will be be uploaded to your flickr stream.
    image 

Credits:

FlickrFaceBall uses the Flickr.NET API Implementation – I have only good things to say about this library – it just works 😉

Thom Shannon for providing the inspiration for the Hack, and also providing the PSD of face ball images.

Finally, to the original source of the Face Ball images – photo1 and photo2

Please Note: This program is hack quality code – It’s not been tested much, and if it breaks your computer, flickr account, or anything else, its your own responsibility.

 

« Prev - Next »