Home
А я брахаць ня ўмею, дык і завыў [entries|archive|friends|userinfo]
Абу Антось

[ userinfo | livejournal userinfo ]
[ archive | journal archive ]

Трохзначная лёгіка наносіць удар у адказ. / Three-valued logic strikes back [Feb. 6th, 2009|09:55 am]
[Tags|, ]
[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)
Link

Хозяйке на заметку [Jan. 22nd, 2009|02:06 pm]
[Tags|]

Прошло 52 года с создания транслятора формул, более известного как FORTRAN. Однако даже в наши дни
великий и могучий дотнет не умеет по умолчанию парсить экспоненты. Лечится, правда, тривиально:
вместо decimal.TryParse(Value, out decValue) надо добавлять немного шаманских заклинаний и писать decimal.TryParse(Value, Globalization.NumberStyles.Float, Globalization.CultureInfo.CurrentCulture, out decValue)
Link

Граблі strike back [Aug. 6th, 2007|04:05 pm]
[Tags|, ]

Why would this code
StartDelay := GetTickCount();

repeat
   Application.ProcessMessages;
until (abs((GetTickCount() - StartDelay))) >= PauseLength;

suddenly stop working? Because )
Link6 comments|Leave a comment

Funny bug [Jul. 17th, 2007|04:17 pm]
[Tags|, , ]

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
Link14 comments|Leave a comment

Граблі [Apr. 7th, 2007|03:22 pm]
[Tags|, ]
[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
Link

Граблі [Apr. 7th, 2007|03:22 pm]
[Tags|, ]
[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.
Link2 comments|Leave a comment

SQL Server stinks! [Apr. 13th, 2006|11:01 am]
[Tags|, ]

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)
Link2 comments|Leave a comment

CircumCHAR(1)ion [Dec. 21st, 2005|03:56 pm]
[Tags|, , ]

Толькі што змарнаваў амаль паўгадзіны, спрабаваў зразумець, чаму мая функцыя ў 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!
LinkLeave a comment

AVG - integer division [Aug. 31st, 2005|11:49 am]
[Tags|, ]

http://community.livejournal.com/ru_programming/278230.html
Link

Zen of Visual Basic [Mar. 18th, 2005|07:30 pm]
[Tags|, , ]

Dim Everything As Object

If Everything Is Nothing Then
   MsgBox "Everything Is Nothing"
End If
LinkLeave a comment

Access SQL <> SQL Server SQL -2 [Jan. 14th, 2005|06:45 am]
[Tags|, ]
[Current Music |Pitchshifter - The Remix War]

Раз пайшла такая п'янка, распавяду пра баг, што мне найболей запомніўся. непраграмістым не чытаць )
Link3 comments|Leave a comment

Access SQL <> SQL Server SQL [Jan. 13th, 2005|10:00 am]
[Tags|, ]

А вы ведалі, што вось такі запыт:
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.Key
Current mood: recovering from a botched attempt to downgrade an SQL Server-based app to an Access-based one.
Link2 comments|Leave a comment

[Праграмізм] Dontcha just L-U-V Perl? [Dec. 23rd, 2004|03:06 pm]
[Tags|, , ]
[Current Music |Sisters of Mercy - Vision Thing]

#!/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 ???
Адказ )
Link2 comments|Leave a comment

Сiненькi сьцiплы бульточак [Aug. 12th, 2002|05:33 pm]
[Tags|, , ]
[Current Music |Pere Ubu - St. Arkansas]

Каля паловы часу application developer'а йдзе не на ўласна распрацоўку праграм, а на барацьбу з чужым кодам - third-party APIs, controls, etc. Пры гэтым у мяне, здаецца, з ростам квалiфiкацыi гэты адсотак расьце, бо даюць правiць усё больш кавалкаў, да якiх другiя проста ня ведаюць як падступiцца.
далей гiсторыя пра VB, майкрасофтаўскiя й шэрыданаўскiя чэкбоксы )
Link2 comments|Leave a comment

За што я не люблю Perl [Apr. 26th, 2002|02:03 pm]
[Tags|, , ]
[Current Music |Clan of Xymox - Clan of Xymox]

За тое, што ён не вiдавочны )
Link14 comments|Leave a comment

navigation
[ viewing | most recent entries ]

Advertisement