| Трохзначная лёгіка наносіць удар у адказ. / Three-valued logic strikes back |
[Feb. 6th, 2009|09:55 am] |
| [ | Tags | | | code, sql | ] |
| [ | Current Music |
| | Лаэртский - Карлица | ] |
Аналітыкі адлавілі багафічу. IN працуе як звычайнае параўнаньне з кожным значэньнем са сьпіса ( x IN(a,b,c) == (x=a OR x=b OR x=c) ), таму калі ў сьпісе значэньняў у IN трапляецца NULL, x=NULL неазначана і рэзультат нечакана пусты. Лечыцца дадаткам IS NOT NULL у падзапыце.
CREATE TABLE #temp(i int, flag bit NOT NULL)
INSERT INTO #temp VALUES(1, 1)
INSERT INTO #temp VALUES(2, 0)
INSERT INTO #temp VALUES(NULL, 0)
--returns 2 and NULL
SELECT i FROM #temp WHERE flag=0
--returns 1
SELECT i FROM #temp WHERE flag=1
--you would expect this to return 1, just like the query before, but it returns nothing!
SELECT i FROM #temp WHERE i not in (SELECT i FROM #temp WHERE flag=0)
--this corrected query returns 1, as it should
SELECT i FROM #temp WHERE i not in (SELECT i FROM #temp WHERE flag=0 AND i IS NOT NULL)
|
|
|
| Хозяйке на заметку |
[Jan. 22nd, 2009|02:06 pm] |
Прошло 52 года с создания транслятора формул, более известного как FORTRAN. Однако даже в наши дни великий и могучий дотнет не умеет по умолчанию парсить экспоненты. Лечится, правда, тривиально: вместо decimal.TryParse(Value, out decValue) надо добавлять немного шаманских заклинаний и писать decimal.TryParse(Value, Globalization.NumberStyles.Float, Globalization.CultureInfo.CurrentCulture, out decValue) |
|
|
| Граблі strike back |
[Aug. 6th, 2007|04:05 pm] |
Why would this code
StartDelay := GetTickCount();
repeat
Application.ProcessMessages;
until (abs((GetTickCount() - StartDelay))) >= PauseLength;
suddenly stop working? ( Because ) |
|
|
| Funny bug |
[Jul. 17th, 2007|04:17 pm] |
You would think that "next line" after the condition that raises an error would be the line after "End If", not the one right after "Then"...
On Error Resume Next
Dim c As Collection
'comment out to show the bug
'Set c = New Collection
'c.Add "Shit"
'since c wasn't initialized, accessing it's property raises an error
'you'd think that Resume Next will go to the line after End If, but...
If c.Count > 0 Then
MsgBox "Shit happened"
End If
|
|
|
| Граблі |
[Apr. 7th, 2007|03:22 pm] |
| [ | Tags | | | code, sql | ] |
| [ | Current Mood |
| | working | ] |
| [ | Current Music |
| | Moe Tucker - Dogs Under Stress | ] |
Наступілі на граблі, бо трэба чытаць весь TFM, а не толькі першы сказ UPDATE (column) Tests for an INSERT or UPDATE action to a specified column (ага, падумалі суворыя тэхаскія парні, вось гэтае UPDATE() нам і падкажа, ці ўстаўляюць значэньне ў поле) and is not used with DELETE operations. More than one column can be specified. Because the table name is specified in the ON clause, do not include the table name before the column name in an IF UPDATE clause. To test for an INSERT or UPDATE action for more than one column, specify a separate UPDATE(column) clause following the first one. Aле фіг вам, сказалі мелкасофтаўцы, бо IF UPDATE will return the TRUE value in INSERT actions because the columns have either explicit values or implicit (NULL) values inserted.
Imported event Original |
|
|
| Граблі |
[Apr. 7th, 2007|03:22 pm] |
| [ | Tags | | | code, sql | ] |
| [ | Current Mood |
| | working | ] |
| [ | Current Music |
| | Moe Tucker - Dogs Under Stress | ] |
Наступілі на граблі, бо трэба чытаць весь TFM, а не толькі першы сказ UPDATE (column) Tests for an INSERT or UPDATE action to a specified column (ага, падумалі суворыя тэхаскія парні, вось гэтае UPDATE() нам і падкажа, ці ўстаўляюць значэньне ў поле) and is not used with DELETE operations. More than one column can be specified. Because the table name is specified in the ON clause, do not include the table name before the column name in an IF UPDATE clause. To test for an INSERT or UPDATE action for more than one column, specify a separate UPDATE(column) clause following the first one. Aле фіг вам, сказалі мелкасофтаўцы, бо IF UPDATE will return the TRUE value in INSERT actions because the columns have either explicit values or implicit (NULL) values inserted. |
|
|
| SQL Server stinks! |
[Apr. 13th, 2006|11:01 am] |
SELECT Round(59999.0 * 0.155,2) 9299.8500 - correct
SELECT Round(Cast(59999.0 as money) * Cast(0.155 as float),2) 9299.8400000000001 - wrong!
Fix: SELECT Round(Cast(Cast(59999.0 as money) * Cast(0.155 as float) as money) ,2) |
|
|
| CircumCHAR(1)ion |
[Dec. 21st, 2005|03:56 pm] |
Толькі што змарнаваў амаль паўгадзіны, спрабаваў зразумець, чаму мая функцыя ў SQL Server выдавала лабуду. Тый-жа самы запыт, калі яго пусьціць напрасткі, працаваў як трэба. Пікантнасьць дадавала тая абставіна, што функцыі Transact-SQL Debugger дебагіць нельга, толькі працэдуры. Ў рэзультаце знайшоў - памылкова апісаў параметр як CHAR(1) замест CHAR(10) (дрыгнула рука маладога хірурга), а сэрвер, замест таго каб пакрыўдзіцца, што-ж ты, гад, апранаеш дзіцячыя гольфікі на здаровага бугая, паслухмяна абразаў значэньне. І гэта пры тым, што яшчэ 8 год таму ў InterBase магчыма было аб'яўляць свае дамэны!
Just wasted almost half an hour trying to understand why my SQL Server function was returning garbage. The same query, when ran directly, was working as expected. Bonus insult points to MSFT for making it impossible to debug functions with Transact-SQL Debugger (stored procedures only). Finally found the gotcha - mistakenly declared an input parameter as CHAR(1) instead of CHAR(10). Instead of screaming in my face, SQL Server was obediently circumcising the value. And boy, back in 1998 InterBase allowed me to create problem-specific domains! |
|
|
| Zen of Visual Basic |
[Mar. 18th, 2005|07:30 pm] |
Dim Everything As Object
If Everything Is Nothing Then
MsgBox "Everything Is Nothing"
End If
|
|
|
| Access SQL <> SQL Server SQL |
[Jan. 13th, 2005|10:00 am] |
А вы ведалі, што вось такі запыт:
SELECT A.Field, B.Field, C.Field
FROM A LEFT JOIN B ON A.Key=B.Key
LEFT JOIN C ON A.Key=C.Keyпрацуе ў SQL Server'ы, але выдае памылку ў Access'ы? Дык ведайце. Лечыцца проста:
FROM (A LEFT JOIN B ON A.Key=B.Key)
LEFT JOIN C ON A.Key=C.KeyCurrent mood: recovering from a botched attempt to downgrade an SQL Server-based app to an Access-based one. |
|
|
| [Праграмізм] Dontcha just L-U-V Perl? |
[Dec. 23rd, 2004|03:06 pm] |
#!/usr/bin/perl -w
use strict;
#...
sub process {
my $str=shift;
# my $rest;
($a, $b, $rest) = split(/\s+/,$str,3);
if (defined($a)){
print OUT "$a\t";
}
if (defined($b)){
print OUT "$b\n";
}
if (!defined($rest)){
return (0);
}
process($rest);
}
Калі не прыбраць значок камэнтара перад my $rest; , то Пэрл, натуральна лаецца на неаб'яўленую зьменлівую $rest . Пытаньне: чаму Пэрл ня лаецца на неаб'яўленыя $a і $b ??? ( Адказ ) |
|
|
| navigation |
| [ |
viewing |
| |
most recent entries |
] |
| |
|
|