28 Feb 2007, 12:07pm
Uncategorized:
by toni

leave a comment

SQL 2005 as an antipattern

After 1 month and an half working on the strange combination of EJBs and SQL 2005 I can say that not only EJBs are an antipattern but also the bloody SQL server of Microsoft.

We had so many troubles doing an automated backup and restore of a database, the last one was a permission problem that you can fix using a stored procedure (oh my God I wrote that I am using a stored procedure from Microsoft running on  Microsoft RDBMS!) that it’s shipped with that kind of RDBMS. Is very nice the code, Action=Auto_Fix.

How much easier and safer is to backup a MySql server(*)?

This problem was just the last one, and I need to yell out a bit.

STG Forums :: View topic – SQL login problems after a backup/restore
To fix this problem, run the following SQL commands:
Code:
Exec sp_change_users_login @Action = ‘Auto_Fix’, @UserNamePattern = ‘tsmith’

That’s what happens with some folks without knowledge of what are good programming practices write a RDMS. I just wanna paste here the code (part of) of the Stored Procedure. It’s SQLserver two thousand five and someone still write shit code like this:

– ERROR IF NOT AUTO_FIX –
if @Action <> ‘AUTO_FIX’
begin
raiserror(15286,-1,-1,@ActionIn)
return (1)
end

– HANDLE AUTO_FIX –
– CHECK PERMISSIONS –
if not is_srvrolemember(‘sysadmin’) = 1
begin
dbcc auditevent (130, 14, 0, NULL, @UserNamePattern, NULL, NULL, NULL, NULL, NULL)
raiserror(15247,-1,-1)
return (1)
end
else
begin
dbcc auditevent (130, 14, 1, NULL, @UserNamePattern, NULL, NULL, NULL, NULL, NULL)
end

– VALIDATE PARAMS –
if @UserNamePattern IS Null or @LoginName IS NOT Null
begin
raiserror(15600,-1,-1,’sys.sp_change_users_login’)
return (1)
end

– LOOP THRU ORPHANED USERS –
select @exec_stmt = ‘declare ms_crs_110_Users cursor global for
select name from sysusers
where name = N’ + quotename( @UserNamePattern , ””)+ ‘
and   issqluser = 1
and   sid is not NULL
and   len(sid) < = 16
and   suser_sname(sid) is null'
EXEC (@exec_stmt)
open ms_crs_110_Users
fetch next from ms_crs_110_Users into @110name

while (@@fetch_status = 0)
begin
if exists (select * from sys.server_principals where
name = @110name              -- match login name
and type in ('C', 'K'))            -- check if it is a certificate or asymmetric key login
begin
raiserror(15291,-1,-1, 'login', @110name)
deallocate ms_crs_110_Users
return (1)
end

-- IS NAME ALREADY IN USE? --
if not exists(select * from master.dbo.syslogins where loginname = @110name)
begin
-- VALIDATE PARAMS --
if @Password IS Null
begin
raiserror(15600,-1,-1,'sys.sp_change_users_login')
deallocate ms_crs_110_Users
return (1)
end

-- ADD LOGIN --
EXEC @ret = sys.sp_addlogin @110name, @Password, @dbname
if @ret <> 0 or suser_sid(@110name) is null
begin
raiserror(15497,16,1,@110name)
deallocate ms_crs_110_Users
return (1)
end
select @FixMode = ’1AddL’
raiserror(15293,-1,-1,@110name)
end
else
begin
– REPORT ERROR & CONTINUE IF DUPLICATE SID IN DB –
select @FixMode = ’2UpdU’
raiserror(15292,-1,-1,@110name)
end

select @loginsid = suser_sid(@110name)
if not exists (select * from sysusers where sid = @loginsid)
begin
– LOCK USER –
BEGIN TRANSACTION
EXEC %%Owner(Name = @110name).Lock(Exclusive = 1)
– UPDATE SYSUSERS ROW –
if @@error = 0
begin
EXEC %%UserOrGroup(Name = @110name).SetSID(SID = @loginsid,
IsExternal = 0, IsGroup = 0) — may fail
if @@error <> 0
begin
ROLLBACK TRANSACTION
deallocate ms_crs_110_Users
raiserror(15063,-1,-1)
return (1)
end
end
COMMIT TRANSACTION

if @FixMode = ’1AddL’
select @cfixesaddlogin = @cfixesaddlogin + 1
else
select @cfixesupdate = @cfixesupdate + 1
end
else
raiserror(15331,-1,-1,@110name)

fetch next from ms_crs_110_Users into @110name
end — loop
close ms_crs_110_Users
deallocate ms_crs_110_Users

– REPORT AND RETURN SUCCESS –
raiserror(15295,-1,-1,@cfixesupdate)
raiserror(15294,-1,-1,@cfixesaddlogin)
return (0) — sp_change_users_login

(*) Go here if you don’t confide in me, I did that many times, with cron, from ant, never had ANY problems.

26 Feb 2007, 9:33am
Uncategorized:
by toni

5 comments

Bluetooth support on virtual machines w/ Parallels Desktop for Mac? – Parallels Support Forum

I am developing with a friend a small client server bluetooth application (an opensource project, perhaps more information here soon) and the target environment is Windows. So I’m using Parallels(*), in coherence mode with bluetooth and so on :-)

Bluetooth support on virtual machines w/ Parallels Desktop for Mac? – Parallels Support Forum
Yes, you may use built-in bluetooth adapter, but you need drivers for it.

The easiest way to get those drivers is:
1. Download and install latest Apple Boot Camp from http://www.apple.com/macosx/bootcamp/
2. Browse to Macintosh HD->Applications->Utilities
3. Right-click the “Boot Camp Assistant” and select “Show Package Contents”.
4. Go to Contents->Resources and click the DiskImage.dmg to mount it.
5. Find the “Install Macintosh Drivers for Windows XP.exe” and copy inside your VM.
6. Run the file. In a short while, all necessary drivers will be installed. Reboot

PS: We can’t redistribute Apple software, that is why you don’t have bluetooth drivers by default.

(*) I had also some strange problems with my upgrade to 3170 RC3,  the screen was black at startup, fortunately the Parallels forum rocks and I found that you simply have to start WinXP in “safe” mode, then reinstall the Paralllels tools, not from the menu, but mounting that from the parallels installation, then you’ll find them mounted on the D: letter of your Parallels winXP.

22 Feb 2007, 6:21pm
work:
by toni

leave a comment

ChadFowler.com XML* and J2EE*: Commodity Skills

ChadFowler.com XML and J2EE: Commodity Skills

Very interesting post of Chad Fowler.

In which technology I should Invest my time?

Usually I invest my time in the technologies that I like more, I did that in the past for Java, then Java Micro Edition, at the moment I have a strong interest for what’s going on around Ruby. I don’t care so much about money. But it’s interesting to see that looks like it’s trendy now to go for Ruby :-)
If you search for J2EE* with Google Trends you will see that India is the Country number one searching for that.

If you search for Ruby on Rails you will find a lot of searches from USA & Canda.

The offshore market has injected its low-cost programmers into a relatively narrow set of technologies. Java and .NET programmers are a dime a dozen in India. India has a lot of Oracle DBAs as well. Less mainstream technologies are very much underrepresented by the offshore development shops. When choosing a technology set to focus your career on, you should understand the effects of increased supply and lower prices on your career prospects.

As a .NET programmer, you may find yourself competing with tens of thousands of more people in the job market than you would if you were, for example, a Python programmer. This would result in the average cost of a .NET programmer decreasing significantly, possibly driving demand higher (i.e., creating more .NET jobs). So, you’d be likely to find jobs available, but the jobs wouldn’t pay all that well. The supply of Python programmers might be much smaller than that of .NET programmers with a demand to match.

(*)I hate J2EE and XML, but this is another, old, story.

19 Feb 2007, 12:34pm
work:
by toni

leave a comment

post #200

I have a lot of draft posts, I think is time to post some of those.

- Sa cosa stavo pensando? Io stavo pensando una cosa molto triste, cioé che io, anche in una società più decente di questa, mi troverò sempre con una minoranza di persone. Ma non nel senso di quei film dove c’è un uomo e una donna che si odiano, si sbranano su un’isola deserta perché il regista non crede nelle persone. Io credo nelle persone, però non credo nella maggioranza delle persone. Mi sa che mi troverò sempre a mio agio e d’accordo con una minoranza…e quindi…

- Do you know what I am thinking about? I’m thinking about a very sad thing, that is that me, even in a better society that this, I’ll always see myself in minority of people. Not in the sense of that kind of films where there are one man and one woman hating each others, they fights against each others in a desert island because the director doesn’t trust in people. I believe in people, but I don’t believe in the majority of people. I think that I’ll find myself at ease on with a minority… and so…

My tentative translation, quoting Nanni Moretti in Caro Diario (Dear Diary)

And so… I’ll continue to develop with test driven, test first, agile practices, scrum perhaps even behavior driven and domain driven and why not interface driven? The importance is to be driven!

But more than this fancy things I’ll always search for happiness, fun & learning at work.