October 2007 Blog Posts
UPDATE:
After i've been proven wrong in the comments below I have to say this:
Go take a read of this article to see how circular references are really handled.
While Delegate.GetInvocationList() really is a great and usefull thing and it could be used in clearing up events,
there's no need for it since you can do that as easily by simply unsubscribin from the event when
you want to dispose your class.
You can read this post on, but know that this example is WRONG, except for the last part about
Observer pattern and WeakEvent pattern.
Maybe you should read this post since...
Until recently i've been sure that there are 2 date formats that are completly locale insensitive. Those 2 i thought were locale insensitive are yyyy-mm-dd HH:mm:ss.fff and yyyymmdd HH:mm:ss.fff. And i was proven wrong a few days ago! The only locale insensitive date format is yyyymmdd HH:mm:ss.fff you can easily test this with this script: DECLARE @t1 table (date DATETIME)
SET DATEFORMAT ymd
INSERT INTO @t1 ( date )
VALUES ( '2007-10-22 10:15:3.83' )
-- this fails
SET DATEFORMAT ymd
INSERT INTO @t1 ( date )
VALUES ( '2007-22-10 10:15:3.83' )
SET DATEFORMAT ymd
INSERT INTO @t1 ( date )
VALUES ( '20071022 10:15:3.83' )
SET...
I can't believe these properties aren't already natively implemented. Come on Microsoft... we do live in the year 2007 you know!!
I know that you can do this using P/Invoke and SendMessage but i wanted a nice managed way of finding
the current line and column of the Caret position in a multiline TextBox.
After a bit of experimenting i've come up with this extended class:
public class TextBoxEx : TextBox
{
public TextBoxEx()
{ }
public void GoTo(int line, int column)
{
if (line...
Often you can see a request made by people to help them separate data in thier character based columns to numeric and non-numeric part.
Most often the answer they get is very simple: Use IsNumeric built in function.
But there's a very little known fact about this function though:
It DOES NOT behave the way you think it does!
You don't believe me? Let's see with an example. How many rows do you think this will return:
DECLARE @t1 TABLE (title varchar(20))
INSERT INTO @t1
SELECT '123d45' UNION ALL
SELECT '123e45' UNION ALL
SELECT '12 3456' UNION ALL
SELECT '123456' UNION ALL
SELECT '5532.673'
SELECT *
FROM ...
First let's look at the difference assuming we want to delete the whole table like truncate does.
Truncate:
- deallocates the data pages in a table and only this deallocation is stored in transaction log
- aquires only table and page locks for the whole table. since no row locks are used less memory is required (lock is a pure memory object)
- resets identity column if there is one
- removes ALL pages. NO empty pages are left behind in a table
- fast(er)
- doesn't fire delete triggers
Delete:
- removes one row at the time and every deleted row is stored in the transaction log
- aquires table and/or page and...
In long running scripts it's usefull to notify the client of the progress. Here's a simple solution.
Let's create a simple "long running" script:
-- this will return all 3 results to the client after 20 seconds (full execution time)
SELECT 1
WAITFOR DELAY '00:00:10'
SELECT 2
WAITFOR DELAY '00:00:10'
SELECT 3
But what if you want to notify the client when each select happened?
RAISERROR to the rescue:
SELECT 1
-- flush message to client
RAISERROR (N'After 1', -- Message text
10, -- Severity
1) -- State
...