- 1
- 2
- 3
if @OWNER_PHONE <> @OLD_PHONE set @PHONE = @OWNER_PHONE
if @PHONE <> @OLD_PHONE set @OWNER_PHONE = @PHONE
set @PHONE = @OWNER_PHONE
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
Всего: 22
0
if @OWNER_PHONE <> @OLD_PHONE set @PHONE = @OWNER_PHONE
if @PHONE <> @OLD_PHONE set @OWNER_PHONE = @PHONE
set @PHONE = @OWNER_PHONE
+1
declare @NL table
(ARTICLE_ID int primary key,
M int,
DS datetime,
DD datetime,
RAS money,
REST money,
NWS money,
NWA money,
LD_AMOUNT money,
LD_DATE datetime,
IS_NL bit,
SCC_ID int,
IS_NOT_MARKDOWN bit)
Double Side,Single Density / Double Side, Double Density — это понятно. Но почему datetime?
0
while exists (
select
C.CONTRAGENT_NAME,
PR.PHONE
from CONTRAGENTS C
inner join CONTRAGENT_PROPERTIES PR on PR.CONTRAGENT_ID = C.CONTRAGENT_ID
except select NAME,PHONE from IMPORT_SOURCE)
begin
declare @IDENTITIES table (CONTRAGENT_ID int)
insert CONTRAGENTS (
CONTRAGENT_NAME,
…)
output inserted.CONTRAGENT_ID into @IDENTITIES
select distinct
NAME,
…
from IMPORT_SOURCE
insert CONTRAGENT_PROPERTIES (
…,
PHONE,
…)
select
…,
S.PHONE
…
from @IDENTITIES I
inner join CONTRAGENTS C on C.CONTRAGENT_ID = I.CONTRAGENT_ID
cross apply (
select top 1
from IMPORT_SOURCE S
left join (
select
C.CONTRAGENT_NAME,
PR.PHONE
from CONTRAGENTS C
inner join CONTRAGENT_PROPERTIES PR on PR.CONTRAGENT_ID = C.CONTRAGENT_ID
) TX on TX.CONTRAGENT_NAME = S.NAME and TX.PHONE = S.PHONE
where TX.CONTRAGENT_NAME is null)
end
Импорт. В источнике за ключевые поля нужно было взять NAME и PHONE, которые в целевой базе — в разных таблицах. Курсоры — слишком долго.
−50
select
0 as IS_WRK,
case when DD.DELIVERY_DET_ID is null then 1 else 0 end NW,
0 as NH,
round(WO.AMOUNT * AD.PRICE_BASE*100.0/(100.0+AD.NDS), 2)*AMM.CURS*CDS.CURRENCY_KOEF/CDV.CURRENCY_KOEF as SUMM_NO_NDS,
round(WO.AMOUNT * AD.PRICE_BASE, 2)*AMM.CURS*CDS.CURRENCY_KOEF/CDV.CURRENCY_KOEF as SUMM_VV,
case
when DD.DELIVERY_DET_ID is null
then
( isnull(round(WO.AMOUNT * A.PRICE_IN *
(select CURRENCY_KOEF from CURRENCY_DAILY (nolock) where CURRENCY_GROUP_ID =
(select CURRENCY_GROUP_ID from CURRENCY_GROUP (nolock) where CURRENCY_DATE =
(select max(CURRENCY_DATE) from CURRENCY_GROUP (nolock) where CURRENCY_DATE <= AD.DATE_ACTION)) and CURRENCY_ID = @Currency)
/
(select CURRENCY_KOEF from CURRENCY_DAILY (nolock) where CURRENCY_GROUP_ID =
(select CURRENCY_GROUP_ID from CURRENCY_GROUP (nolock) where CURRENCY_DATE =
(select max(CURRENCY_DATE) from CURRENCY_GROUP (nolock) where CURRENCY_DATE <= AD.DATE_ACTION)) and CURRENCY_ID = A.CURRENCY_ID), 2),0)
)
else
( /* 08.04.2015 - 4700 BEGIN */
ISNULL ( round(WO.AMOUNT *case @Currency
when DM.CURRENCY_ID then DD.PRICE_NO_NDS
when @CurrencyBase then DD.PRICE_BASE*(100.0/(100.0+DD.NDS))
else DD.PRICE_BASE*(100.0/(100.0+DD.NDS))*CDS.CURRENCY_KOEF
end, 2), 0)
/* 08.04.2015 - 4700 END */
)
end
as IN_NO_NDS,
case
when DD.DELIVERY_DET_ID is null
then
( isnull(round(WO.AMOUNT * A.PRICE_IN *
(select CURRENCY_KOEF from CURRENCY_DAILY (nolock) where CURRENCY_GROUP_ID =
(select CURRENCY_GROUP_ID from CURRENCY_GROUP (nolock) where CURRENCY_DATE =
(select max(CURRENCY_DATE) from CURRENCY_GROUP (nolock) where CURRENCY_DATE <= AD.DATE_ACTION)) and CURRENCY_ID = @Currency)
/
(select CURRENCY_KOEF from CURRENCY_DAILY (nolock) where CURRENCY_GROUP_ID =
(select CURRENCY_GROUP_ID from CURRENCY_GROUP (nolock) where CURRENCY_DATE =
(select max(CURRENCY_DATE) from CURRENCY_GROUP (nolock) where CURRENCY_DATE <= AD.DATE_ACTION)) and CURRENCY_ID = A.CURRENCY_ID), 2),0)
)
else
( /* 08.04.2015 - 4700 BEGIN */
ISNULL(round(WO.AMOUNT *case @Currency
when DM.CURRENCY_ID then DD.PRICE
when @CurrencyBase then DD.PRICE_BASE
else DD.PRICE_BASE*(100.0/(100.0+DD.NDS))*CDS.CURRENCY_KOEF
end, 2), 0)
/* 08.04.2015 - 4700 END */
)
end
as IN_VV,
AD.USER_WRITER as WRITER,
AD.ACCOUNT_ID
from ACCOUNT_DETAIL as AD (nolock)
inner join @AM as AM on AM.ACCOUNT_ID = AD.ACCOUNT_ID
inner join ARTICLE as A (nolock) on A.ARTICLE_ID = AD.ARTICLE_ID
left join #_WRITEOUT_TEMP_REST_ as WO on WO.ACCOUNT_DET_ID = AD.ACCOUNT_DET_ID
left join DELIVERY_DETAIL as DD (nolock) on WO.ROOT_ID = DD.DELIVERY_DET_ID
left join DELIVERY_MASTER as DM (nolock) on DM.DELIVERY_MST_ID = DD.DELIVERY_MST_ID
inner join ACCOUNT_MASTER AMM (nolock) on AMM.ACCOUNT_ID=AM.ACCOUNT_ID
inner join CURRENCY_DAILY CDV (nolock) on ((CDV.CURRENCY_GROUP_ID = AMM.CURRENCY_GROUP_ID)and(CDV.CURRENCY_ID = AMM.CURRENCY_ID))
inner join CURRENCY_DAILY CDS (nolock) on ((CDS.CURRENCY_GROUP_ID = AMM.CURRENCY_GROUP_ID)and(CDS.CURRENCY_ID = @Currency))
where
AD.IS_WRITEOUT = 0 and AD.OUT = 1
and (@Articles = '' and @ArticleGroups = '' or charindex(',' + convert(varchar, A.ARTICLE_ID) + ',', @Articles) > 0
or charindex(',' + convert(varchar, A.GROUP_ID) + ',', @ArticleGroups) > 0)
Xzibit.jpg
−54
type
TheCurrency = class(TObject)
id: Integer;
name: String;
end;
TheWHouse = class(TObject)
id: Integer;
name: String;
end;
TheProvider = class(TObject)
id: Integer;
name: String;
end;
TheNds = class(TObject)
nds: Double;
end;
−49
dep_id:=-1;
next_day:=1;
cds.First;
while not (cds.Eof) do
begin
if (dep_id <> cds.FieldByName('DEP_ID').AsInteger) then
begin
dep_id := cds.FieldByName('DEP_ID').AsInteger;
//переходим на новую страницу, печатаем шапку
//...
row:=7;
next_day :=1;
end;
if (DS_Parametes.FieldByName('DATE').AsString <> FieldByName('RS_DATE').AsString) and (next_day <> 5) then
next_day := 2;
if (next_day < 3) then
begin
//Печатаем шапку дня
//...
if (DS_Parametes.FieldByName('DATE').AsString <> cds.FieldByName('RS_DATE').AsString) then
begin
WS.Cells[Row,01]:= 'Завтра, '+ cds.FieldByName('RS_DATE').AsString;
next_day :=5;
end
else
begin
WS.Cells[Row,01]:= cds.FieldByName('RS_DATE').AsString;
next_day :=4;
end;
inc(row);
end;
//Ну и дальше печатаем строчки таблицы
//...
inc(row);
cds.next;
end;
next_day := 4
+5
Action doItWrong;
var filename = "sdf";
using (var fileStream = new FileStream(filename,FileMode.Create))
{
doItWrong=()=>
{
for(int i = 0; i < 10; i++)
{
fileStream.WriteByte(255);
}
};
}
doItWrong();
Интересно, почему такое вообще не запрещают компилировать?
0
WriteBuffer = enc.GetBytes("$ FETCH " + number + " BODY[HEADER]\r\n");
netStream.Write(WriteBuffer, 0, WriteBuffer.Length);
ListMessage = strReader.ReadLine();
//...
while ((ListMessage.IndexOf("$ OK ") == -1) && (ListMessage.IndexOf("$ BAD ") == -1))
{
//Типа там читаем всякие заголовки и прочие бла-бла
if (ListMessage.IndexOf("filename=") > -1)
{
temp = ListMessage.Replace("filename=", "");
temp = temp.Trim();
file_name = temp;
is_file = 1; temp = ""; is_att = 1;
}
//...
ListMessage = strReader.ReadLine();
continue;
}
//...
WriteBuffer = enc.GetBytes("$ FETCH " + number + " BODY[TEXT]\r\n");
netStream.Write(WriteBuffer, 0, WriteBuffer.Length);
ListMessage = strReader.ReadLine();
temp = "";
end_file = 0;
body = "";
if (ListMessage.IndexOf("$ BAD ") == -1) ListMessage = strReader.ReadLine();
if (ListMessage == "")
is_body = 0;
else
is_body = 1;
while ((ListMessage.IndexOf("$ OK ") == -1) && (ListMessage.IndexOf("$ BAD ") == -1))
{
if (is_body == 1)
{
if (ListMessage == "")
is_body = 0;
else
body = body + ListMessage;
}
if ((is_att == 1) && (end_file == 0))
{
if (is_file == 1)
{
if (ListMessage.IndexOf("--") > -1)
end_file = 1;
else
temp = temp + ListMessage;
}
if (ListMessage == "")
{
is_file = 1;
}
}
if (ListMessage.IndexOf("Content-Disposition: attachment;") > -1)
{
is_att = 1;
}
//...
ListMessage = strReader.ReadLine();
continue;
}
if (is_att==0)
{
//А тут ничего интересного, просто декодирование из Base64 и сохранение в файл
}
Следите за булями (точнее, их суррогатами).
ЗЫ: да, я уже выкладывал кусок из того же модуля, и там уже были некоторые куски, которые попали и сюда тоже.
0
public static IEnumerable fGetPostIMAP(string port, int port2, string username, string password, string startCount, string path)
{
Stopwatch swatch = new Stopwatch();
swatch.Start();
int Delay = 10;
System.IO.StreamWriter sw = null;
System.Net.Sockets.TcpClient tcpc = null;
int bytes = -1;
int is_file = 0;
int is_att = 0;
byte[] buffer;
StringBuilder sb = new StringBuilder();
//...
string UID = "";
string From;
try
{
//...
if (ListMessage.IndexOf("filename=") > -1)
{
temp = ListMessage.Replace("filename=", "");
temp = temp.Trim();
file_name = temp;
is_file = 1; temp = ""; is_att = 1;
}
//...
if (is_file == 1)
{
if (ListMessage.IndexOf("--") > -1)
end_file = 1;
else
temp = temp + ListMessage;
}
if (ListMessage == "")
{
is_file = 1;
}
//...
}
catch (Exception ex)
{
rows.Add(new object[] { "ERROR:" });
rows.Add(new object[] { ex.Message });
}
finally
{
if (sw != null)
{
sw.Close();
sw.Dispose();
}
if (tcpc != null)
{
tcpc.Close();
}
}
return rows;
}
Делфи головного мозга просвечивает в каждой строчке. Даже использованием 0/1 вместо булева типа не скрыть дельфишной сути.
−49
CASE CMD[1] OF
//...
3005,3031,3032:
begin
if (varastype(cmd[2],varinteger)=1) THEN exit;
if (varastype(cmd[2],varinteger)=5) THEN result:=write_elem_spr_3031_3032(cmd);
end;
//...
end;
//...
function TRDM_admin.write_elem_spr_3031_3032(cmd: OleVariant): OleVariant;
begin
if (varastype(cmd[1],varinteger)=3031) then
begin
if write_CS.fieldbyname('OLD_ID').AsVariant<>null then
s:=inttostr(write_CS.fieldbyname('OLD_ID').AsInteger) else
s:='null';
end;
if (varastype(cmd[1],varinteger)=3032) then
begin
if write_CS.fieldbyname('TEMPLATE_ROLE_ID').AsVariant<>null then
s:=inttostr(write_CS.fieldbyname('TEMPLATE_ROLE_ID').AsInteger) else
s:='null';
if write_CS.fieldbyname('TYPE_DOLGN').AsVariant<>null then
s1:=inttostr(write_CS.fieldbyname('TYPE_DOLGN').AsInteger) else
s1:='null';
end;
if id_element>0 then // элемент существует - готовимся к записи
begin
if (varastype(cmd[1],varinteger)=3005) then
begin
write_Query.SQL.Add({запрос});
end;
if (varastype(cmd[1],varinteger)=3031) then
begin
write_Query.SQL.Add({запрос});
end;
if (varastype(cmd[1],varinteger)=3032) then
begin
write_Query.SQL.Add({запрос});
end;
//несколько строк малозначащего кода
end else
begin
if (varastype(cmd[1],varinteger)=3005) then
read_spr_Query.SelectSQL.Add('select gen_id(GEN_TAB_LPU_ID,1) from rdb$database');
if (varastype(cmd[1],varinteger)=3031) then
read_spr_Query.SelectSQL.Add('select gen_id(GEN_TAB_STRUCT_ID,1) from rdb$database');
if (varastype(cmd[1],varinteger)=3032) then
read_spr_Query.SelectSQL.Add('select gen_id(GEN_SPR_DOLGN_ID,1) from rdb$database');
//Ещё несколько малозначащих строк
if (varastype(cmd[1],varinteger)=3005) then
write_Query.SQL.Add({запрос});
if (varastype(cmd[1],varinteger)=3031) then
begin
write_Query.SQL.Add({запрос});
struct_lpu_id:=write_CS.fieldbyname('lpid').AsInteger;
end;
if (varastype(cmd[1],varinteger)=3032) then
begin
write_Query.SQL.Add({запрос});
end;
//Ещё несколько малозначащих строк
end;
if (varastype(cmd[1],varinteger)=3031) then
begin
//Ещё много строк
end;
write_IBT.Commit;
end;
Очевидно, объединяя сущности 3005, 3031 и 3032 в одном методе, автор хотел показать, что они взаимосвязаны.