Login or Sign Up to become a member!

EXPERTS, INFORMATION, IDEAS & KNOWLEDGE

Social bookmarker Add this

Your profile

Search

September 2008
Mon Tue Wed Thu Fri Sat Sun
 << <   > >>
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30          

XML Feeds

All the LessThanDot Journals

What is deferred name resolution and why do you need to care?

by SQLDenis


Permalink 08 Sep 2008 08:23 , Categories: Data Modelling & Design Tags: gotcha, howto, sql server, t-sql, tip, trick

So I posted a teaser in the puzzles forum. Without running this, try to guess what will happen?

  1. DECLARE @x INT
  2.  
  3. SET @x = 1
  4.  
  5. IF (@x = 0)
  6. BEGIN
  7.     SELECT 1 AS VALUE INTO #temptable
  8. END
  9. ELSE
  10. BEGIN
  11.    SELECT 2 AS VALUE INTO #temptable
  12. END
  13.  
  14. SELECT * FROM #temptable –what does this return

This is the error you get
Server: Msg 2714, Level 16, State 1, Line 12
There is already an object named ‘#temptable’ in the database.

You can do something like this to get around the issue with the temp table

  1. DECLARE @x INT
  2.  
  3. SET @x = 1
  4.  
  5. CREATE TABLE #temptable (VALUE INT)
  6. IF (@x = 0)
  7. BEGIN
  8.     INSERT #temptable
  9.     SELECT 1
  10. END
  11. ELSE
  12. BEGIN
  13.     INSERT #temptable
  14.     SELECT 2
  15. END
  16.  
  17. SELECT * FROM #temptable –what does this return

So what is thing called Deferred Name Resolution? Here is what is explained in Books On Line

When a stored procedure is created, the statements in the procedure are parsed for syntactical accuracy. If a syntactical error is encountered in the procedure definition, an error is returned and the stored procedure is not created. If the statements are syntactically correct, the text of the stored procedure is stored in the syscomments system table.

When a stored procedure is executed for the first time, the query processor reads the text of the stored procedure from the syscomments system table of the procedure and checks that the names of the objects used by the procedure are present. This process is called deferred name resolution because objects referenced by the stored procedure need not exist when the stored procedure is created, but only when it is executed.

In the resolution stage, Microsoft SQL Server 2000 also performs other validation activities (for example, checking the compatibility of a column data type with variables). If the objects referenced by the stored procedure are missing when the stored procedure is executed, the stored procedure stops executing when it gets to the statement that references the missing object. In this case, or if other errors are found in the resolution stage, an error is returned.

So what is happening is that beginning with SQL server 7 deferred name resolution was enabled for real tables but not for temporary tables. If you change the code to use a real table instead of a temporary table you won’t have any problem
Run this to see what I mean

  1. DECLARE @x INT
  2.  
  3. SET @x = 1
  4.  
  5. IF (@x = 0)
  6. BEGIN
  7.     SELECT 1 AS VALUE INTO temptable
  8. END
  9. ELSE
  10. BEGIN
  11.    SELECT 2 AS VALUE INTO temptable
  12. END
  13.  
  14. SELECT * FROM temptable –what does this return

What about variables? Let’s try it out, run this

  1. DECLARE @x INT
  2.  
  3. SET @x = 1
  4.  
  5. IF (@x = 0)
  6. BEGIN
  7.     DECLARE @i INT
  8.     SELECT @i = 5
  9. END
  10. ELSE
  11. BEGIN
  12.    DECLARE @i INT
  13.    SELECT @i = 6
  14. END
  15.  
  16. SELECT @i

And you get the follwing error
Server: Msg 134, Level 15, State 1, Line 13
The variable name ‘@i’ has already been declared. Variable names must be unique within a query batch or stored procedure.

Now why do you need to care about deferred name resolution? Let’s take another example from a blogpost I made a while back: Do you depend on sp_depends (no pun intended)

First create this proc

  1. CREATE PROC SomeTestProc
  2. AS
  3. SELECT dbo.somefuction(1)
  4. GO

now create this function

  1. CREATE FUNCTION somefuction(@id INT)
  2. RETURNS INT
  3. AS
  4. BEGIN
  5. SELECT @id = 1
  6. RETURN @id
  7. END
  8. Go

now run this

  1. SP_DEPENDS ’somefuction’

result: Object does not reference any object, and no objects reference it.

Most people will not create a proc before they have created the function. So when does this behavior rear its ugly head? When you script out all the objects in a database, if the function or any objects referenced by an object are created after the object that references them then sp_depends won’t be 100% correct

SQL Server 2005 makes it pretty easy to do it yourself

  1. SELECT specific_name,*
  2. FROM information_schema.routines
  3. WHERE object_definition(OBJECT_ID(specific_name)) LIKE ‘%somefuction%’
  4. AND routine_type = ‘procedure’
3 comments »Send a trackback » 49 views

CentOS, Postfix, MySQL and a Typo

by damber


Permalink 05 Sep 2008 16:06 , Categories: Linux, RHEL Tags: centos, linux, mail server, mysql, postfix, typo

A little lesson in typo-trauma

Today I finally got round to doing some admin on my primary home server, which (amongst many things) is my main mail server. After dusting a few cobwebs away, checking nobody had broken any of the furniture and such, I decided to run yum to get the latest updates (it had been almost a month since the last time I checked 88| but still, at least now it was about to be updated to all the shiny sparkly new things that CentOS had released for me…

And it did, it came up with about 5 or 6 updates, including an update to postfix. Great. So, it finished in about a minute or two and I went on about my evening. All was happy in the land of the ignorant.

Ignorant, that is, until I decided to send an email to my dear old mum to give her an update on the list of laptops I was recommending for her (I know, I’m so thoughtful :D). At which point my squirrelmail (webmail) froze.. you see, I’m currently re-decorating my study, so have moved my main workstation into another room, and as such it’s not in use.. and my other non-work laptop is, er, recovering from, er, how do you say it? A little ‘rinse’ in the bath… so, work laptop it is, and webmail access only…

I thought maybe it was my damn windows wifi connection at first because it has been such a problem the last few days.. (I can’t wait to get back to my linux environments, this windows only stuff is giving me a serious heart condition.) Anyway, after a prod and a poke it seemed that it might be the mail server…

Determining the problem

So, I checked the mail server logs and discovered…

  1. [root@phantom ~]# tail /var/log/maillog
  2. phantom postfix/smtpd[8736]: fatal: unsupported dictionary type: mysql

mmmm… now, that looks familiar.. wasn’t that a problem I faced when setting up this mail server? The problem that centos repositories only provide the standard postfix rpm which doesn’t have mysql support compiled in? But, it has been working for ages.. why is it failing now ? Hold on.. let me check what exactly was updated again recently…

  1. [root@phantom ~]# tail /var/log/yum.log
  2. Updated: postfix - 2:2.3.3-2.1.el5_2.i386

Ahhhh… bugger.:'(

Path of enlightenment

OK… now I’m thinking that some stupid numpty has released the wrong rpm in the wrong repository, because I know that I set things up originally to exclude the main repositories for postfix updates and only get it from the centosplus repository. Of course I did. I’m sure. I think. mmmmm… ok, let me check…

  1. [root@phantom ~]# vi /etc/yum.repos.d/CentOS-Base.repo
  2. #released updates
  3. [updates]
  4. name=CentOS-$releasever - Updates
  5. mirrorlist=http://mirrorlist.centos.org/?release=$releasever&amp;arch=$basearch&amp;repo=updates
  6. #baseurl=http://mirror.centos.org/centos/$releasever/updates/$basearch/
  7. gpgcheck=1
  8. gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5
  9. priority=1
  10. exclude=kernel* posfix*   <<<<<<——looky at what we have here..
  11. [centosplus]
  12. name=CentOS-$releasever - Plus
  13. mirrorlist=http://mirrorlist.centos.org/?release=$releasever&amp;arch=$basearch&amp;repo=centosplus
  14. #baseurl=http://mirror.centos.org/centos/$releasever/centosplus/$basearch/
  15. gpgcheck=1
  16. enabled=1
  17. gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5
  18. priority=2
  19. includepkgs=kernel* postfix*

Ooops. Can you spot it? :yes: Yep, exactly - every entry apart from the updates was excluding “postfix", whilst the updates were excluding “posfix".. :no:

Fixing the shame..

That, my friend, is the scourge of bugs everywhere.. the humble typo. ah well. Lesson learnt.. now just to download the previous centosplus package for postfix with mysql built in and re-install it (and fix that damn typo):

  1. [root@phantom ~]# wget http://www.mirrorservice.org/sites/mirror.centos.org/5.2/centosplus/i386/RPMS/postfix-2.3.3-2.el5.centos.mysql_pgsql.i386.rpm
  2. [root@phantom ~]# rpm -Uvh —-replacepkgs —-force postfix-2.3.3-2.el5.centos.mysql_pgsql.i386.rpm
  3. [root@phantom ~]# sed -i ’s/posfix/postfix/g’ /etc/yum.repos.d/CentOS-Base.repo

phew… mail server back up and working again. I thought for a brief second that it was going to be a major problem, but, thankfully, a download + install to rollback and a correction of a typo later.. and I’m back up and running :-) A lesson in scrutiny of important configuration data has been learnt..:lalala: until the next time.. ;D

4 comments »Send a trackback » 214 views

F# Developer Center

by SQLDenis


Permalink 05 Sep 2008 11:48 , Categories: Microsoft Technologies Tags: f#, functional programming

Microsoft has launched the F# Developer Center

Here you can learn everything about Microsoft’s functional programming language F# (pronounced F sharp). There are links to forums, blogs, projects on codeplex, code gallery samples, videos and much more.

Also check out the Getting Started with F# section, here you can download the latest F# CTP and three sample chapters of the Expert F# book are also available for preview

Leave a comment »Send a trackback » 55 views

Get A Free SQL Server 2008 Ebook

by SQLDenis


Permalink 04 Sep 2008 08:32 , Categories: Data Modelling & Design Tags: book, products, red gate, tools

Download a trial version of Red Gate’s SQL Toolbelt 2008 and get Brad’s Sure Guide to SQL Server 2008 for free

Products included in the SQL Toolbelt 2008:

SQL Compare Pro
SQL Data Compare Pro
SQL Packager Pro
SQL Prompt Pro
SQL Doc Pro
SQL Backup Pro
SQL Data Generator
SQL Dependency Tracker
SQL Refactor
SQL Multi Script
SQL Comparison SDK

I have been using Red Gate’s products since 2002 and must say that they have saved me tons of work/time many times.

Here is the link to the site: Brad’s Sure Guide to SQL Server 2008

1 comment »Send a trackback » 226 views

Django 1.0 Released

by SQLDenis


Permalink 03 Sep 2008 20:18 , Categories: Web Design, Graphics & Styling Tags: django, jython, orm, python

Yes it is true, Django 1.0 has been released today. Here is a part of the announcement:

No, you’re not hallucinating, it’s really here.

Around three years ago, Adrian, Simon, Wilson and I released some code to the world. Our plan was to hack quietly on it for a bit, release a solid 1.0 release, and then really get the ball rolling.

Well.

What happened, of course, was that an amazing community sprung up literally overnight — our IRC channel had over a hundred people in it the day after release, and it’s never been that “empty” since.

I really can’t stress enough how amazing our community of users and developers are. About half of the code that’s gone into Django over the past three years has been contributed by someone other than a core committer. Since our last stable release, we’ve made over 4,000 code commits, fixed more than 2,000 bugs, and edited, added, or removed around 350,000 lines of code. We’ve also added 40,000 lines of new documentation, and greatly improved what was already there.

Django 1.0 represents a the largest milestone in Django’s development to date: a web framework that a group of perfectionists can truly be proud of. Without this amazing community, though, it would have never happened.

Read the release notes here: http://docs.djangoproject.com/en/dev/releases/1.0/

Download Django 1.0 here http://www.djangoproject.com/download/

And of course congratulations to the team :-)

Leave a comment »Send a trackback » 110 views

:: Next >>