Filed under: .Net Graphics
July 29, 2005 • 1:11 am 0
Giving credit
July 26, 2005 • 10:00 am 0
Knowing the DBMS
I traced the issue to code other than my own (again – whew! – it’s hard being an outsider and lacking the experience of the large institutional platform which everyone else has been living and breathing) – this time to logic which was updating the database in a batch update utility. The problem apparently was an assumption that the code would update correctly because of the position of the boolean check in the conditional statement. There was a two-fold problem to this logic, since the base assumption that the check would short-circuit was incorrect was complicated by the indeterminate (exluding use of the ORDER BY clause, that is) order of results of a SELECT statement. The programmer didn’t seem to know either of these things, which reinforces my belief that _every expert enterprise developer needs to have a firm grasp on database storage and retrieval fundamentals_ as well as near-expert depth of the peculiarities of the chosen vendor specifics. I’m not sure how other platforms do it, but SQL Server doesn’t short circuit OR statements (but it does AND statements). The docs try to lead us astray on this one, but a simple test shows us everything:
CREATE TABLE #Test ( myValue nvarchar(20) )
INSERT INTO #Test VALUES ( 'Test1' )
INSERT INTO #Test VALUES ( 'Test2' )
INSERT INTO #Test VALUES ( 'Test3' )
--The entire "OR" statement is evaluated, and not short circuited, even thought the first value is true (1/0 will return an error)
SELECT * FROM #Test WHERE myValue LIKE 'Test%' OR 1/0 = 1
--The "AND" statement is short-circuted, since T-SQL 8.0 does this for "AND" (1/0 will return an error) SELECT * FROM #Test WHERE 1 = 2 AND 1/0 = 1
--Test 1 will be returned first, even though it is listed 2nd, because the way the inserts happened, and how the loader retrieves the rows into the page buffers, and then how the query engine reads the buffers…
SELECT * FROM #Test WHERE myValue = 'Test2' OR myValue = 'Test' + '1'
Filed under: Getting Data
July 26, 2005 • 9:24 am 0
Another switch
Filed under: Software Engineering
July 26, 2005 • 8:30 am 0
Passed 70-300
Filed under: Software Engineering
July 14, 2005 • 8:05 pm 0
SqlCommand.ExecuteReader deficiency
.Net exceptions have two purposes: signal that there was an exceptional situation when executing program flow which needs to be handled using routines that are separate from the main program flow (usually the catch block), and the other is to allow decisions to be made about how to handle what handled and take some appropriate action based on the type of the exception. HRESULTS did the same thing, but exceptions are more elegant because the exception code is outside the main program flow. Now, imagine if all you had was the Exception type (or HRESULT 0x80004005) – we would know that an exception occured, but the program would only have one recourse which would maintain program runtime integrity – exit. Since we don’t have information on the exception, we wouldn’t know if it was an input validation error or something more critical, like an access violation or that the system was out of memory. Strongly typed exceptions allow corrective action or graceful degradation of program execution in a reliable fashion. While most of the .Net Framework provides excellent variety of strongly typed exceptions which allow good programming structure and responsiveness, there is one notable exception: the ExecuteReader method in the SqlCommand class. Check out the docs: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemDataSqlClientSqlCommandClassExecuteReaderTopic2.asp
Notice that when a statement can’t be executed, a plain old generic Exeption is thrown! How are we supposed to know that this is what really happened, and not some other error like OutOfMemoryException or ExecutionEngineException which apparently can happen at any time? One might say, "Well, those are all subclasses of SystemException, so just trap that and handle it differently." However, there are many, many SystemExceptions, so should we differentiate in our catch statement among all of them, some of them, or what? Obviously, this is a serious oversight, since SQL code which doesn’t run is a quite common occurance. Perhaps this is fixed in 2.0….
Filed under: Software Engineering