Help

You are currently browsing articles tagged Help.

I ran into an interesting problem the other day that I think is worth sharing.  Fans of the pluggable factory design pattern, inversion of control, etc will be interested to know that these methods do not work very well when compiled into static libraries.  Sounds obvious but what may not be so obvious is why.

I stumbled onto this problem when I changed one of my exe projects to a static library so I could setup two exe’s, one for unit tests, the other for releasing.  (Which by the way is a wonderful way to unit test an exe project)  Most of my projects these days use some form of inversion of control so I had static variables creating maker classes which would register themselves with the factory.  As explained in one of my previous articles here.

When I changed my project to a static library and linked it to a separate exe project my maker classes stopped registering themselves.  Why does this happen?  Well after a bit of a research I found out that when you link in a static library, the linker only links code into your project that you actually use.  All extra code is left uninitialized and put in a corner to sit while the big boss code runs.  A very interesting side effect of static linking.

Anyway, to fix this problem in visual studio you need to set “Use Library Dependency Inputs” in Linker options on your exe project.  This will make the linker link in all the object files themselves, instead of selectively linking them as needed.  I am researching some way to do this per library, because as of right now if you set this it will link ALL libraries like that.

In linux it would seem the option is -z allextract, but I have not tested this one.

If you need your static objects from a static library to be initiated like normal, this should do the trick.

Tags: , , ,

User defined types in Microsoft SQL are really handy.  Using these objects you can construct queries like

select duration.minutes from cdrs;
select duration.seconds from cdrs;

You can also program them to read weird string inputs that other data types can not handle.  Recently I wrote a custom data type to read a duration field of the format minutes:seconds.tenths; so standard input went something like ’002:34.2.’

Writing a custom data type is actually very simple.  You just open a new sql data type project in Visual Studio and VS will integrate nicely with your sql server; even going so far as to upload the data type for you and run tests.  There are numerous tutorials online for programming a data type however so I will not cover that aspect.

Like I said I recently created a data type for my data parsing.  I put it into my table but soon found that assigning my specific data processing user permissions to the object was harder than you would expect.  I kept getting the error

[Microsoft][ODBC SQL Server Driver][SQL Server]EXECUTE permission denied on object 'data_type', database 'db', schema 'dbo'. (SQL-42000)

Trying

grant execute on [data_type] to cdr;

returned ‘object not found.’  Ms sql’s security assignment tool did not help either, it never did ‘find’ the object I created.

I eventually found my way to this msdn page which at least revealed the secret missing keyword.  To set the permission on the object use this query

grant execute on TYPE::[dbo].[data_type] to cdr;

Tags: , , , ,

Charles Solar is Stephen Fry proof thanks to caching by WP Super Cache