A U-Bend In The Tubes

Friday, July 24, 2009

M$-SQL Server GO Keyword is a badly thought out piece of shite.

Just a quick one. The database for my company’s main software product uses M$-SQL, since every two bit company in the universe has a license for it kicking about somewhere, and while adding my changes to the migration script I discovered that the ‘GO’ keyword makes declared variables go out of scope, thus:

DECLARE @ID uniqueidentifier

SELECT @id = FOO.id
    FROM DataEntityExtractors FOO
    WHERE FOO.id = 'id'
GO

PRINT @ID
---------------

Error: Must declare the scalar variable "@ID".
SQLState:  S1000
ErrorCode: 137
Error occured in:
PRINT @ID

To make it work you need to move the ‘GO’ to a point in the script where you don’t need the variables anymore:

DECLARE @ID uniqueidentifier

SELECT @id = FOO.id
    FROM DataEntityExtractors FOO
    WHERE FOO.id = 'id'

PRINT @ID
GO

Is a version of the first query that will work.

Goddamn I hate M$-SQL. Hate it so very, very much. No idea why you need to second guess the query compiler before you can get stuff to work.

Meh.

posted by Bradshaw at 15:24  

Wednesday, July 22, 2009

I hate the Hibernate elements keyword

Not much going on in Bradshaw land at the moment. Working on a whole heap of logically interesting bugs that just use standard-ass java constructs, so there’s not much to update. I just spent an hour shouting at Hibernate over something I really should have known before, but somehow managed to avoid learning.

If you want to do an ‘IN’ query on an object that has a Collection as a field you need to use the “elements” keyword: thus.

SELECT
  foo
FROM
  Foo foo
WHERE
  :bar in elements(foo.barList)

Woo!

posted by Bradshaw at 10:43  

Wednesday, July 1, 2009

Fixing Linux terminals after ‘cat’-ing a binary file

Not really a development thing, but whatever…

Everyone who uses Linux on the command line will hit this one at one point or another – You ‘cat’ something, discover it’s a binary file, then discover it’s completely fucked your terminal, thus:

screwedbinaryterminal

Not so very long ago I used to close and restart the terminal, for I am very, very lazy. Then I discovered what the fix was because I am awesome.

There are two solutions to this problem:

1. Use the ‘reset” shell command

% reset [return]

OR

2. Issue the following set of commands (working blind)

% cat [return]
% [ctrl o] [return]
% [ctrl d] [return]

Shazzam:

fixedbinaryterminal
Just for the record, if you feel like breaking it again, run the same set of commands listed above, replacing Ctrl-o with Ctrl-n

posted by Bradshaw at 11:14  

Powered by WordPress