|
|
|
Помогите с SQL
|
|||
|---|---|---|---|
|
#18+
Добрый день, всем кто зашел в эту тему... ребята у меня такая проблема... меня грузанули SQL, в котором я мягко говоря не разбираюсь... Выдали код, где судя по всему есть проблемы... слишком медленно происходит чтение из базы... я где-то на уровне подсознания понимаю, что загрузка из базы написанна каряво... Если, кто заметил ошибку.. или есть совет.. напишите.. ------------ вот то что мне выдали ----------- function hExcel.resetQuery : integer; var ss, s1, s2, s0, str, strOne : string; tm1, tm2, dt, ddt : tTime; IniFile : tIniFile; jj, ii, iValue : integer; dd, d1, d2 : real; sMonth0, sMonth1, sMonth2, sMonth3 : string; begin dt:=strToTime('00:15:00'); ddt:=strToTime('00:00:05'); ss:=ApplicationPath+'data.ini'; IniFile := TIniFile.Create(ss); fMain.ADOQueryTicks.close; fMain.ADOQueryTicks.CursorLocation := clUseServer ; ss:=dateToStr(currentDay); str:='20'+copy(ss, 7, 2)+'-'+copy(ss, 4, 2)+'-'+copy(ss, 1, 2); if sReadTimeOld<>'' then sReadTimeOld:=IniFile.readString('main', 'timeRead', '00:00:01.000') else begin sReadTimeOld:=str+' '+timeToStr(Time-dt)+'.000'; iTag:=0; end; s1:=sReadTimeOld; jj:=Pos(' ', s1); ss:=Copy(s1, jj+1, 44); tm1:=strtoTime(ss)-ddt; delete(s1, jj, 55); s1:=s1+' '+TimeToStr(tm1)+'.000'; ss:=timeToStr(Time); s2:=str+' '+ss+'.000'; sReadTimeOld:=s2; ss:=timeToStr(Time+ddt); s2:=str+' '+ss+'.000'; s0:=str+' 00:00:01.000'; str:=' and dt>'''+s1+''' and dt<'''+s2+''''; strOne:=' and dt>'''+s0+''' and dt<'''+s2+''''; tm1:=time; fMain.ADOQueryTicks.SQL.clear; Запрос последнего значения 1 fMain.ADOQueryTicks.SQL.add( 'select top 1 realtime_tick.* from realtime_tick'+ ' where'+ ' realtime_tick.region_ID = 150 AND'+ ' realtime_tick.sec_id = 1 AND'+ ' realtime_tick.ticker = ''UKX'' '+ str+ ' order by DT DESC'); fMain.ADOQueryTicks.Open; if fMain.ADOQueryTicks.recordCount>0 then sMonth0:=fMain.ADOQueryTicks.fields[iValue].text; ss:=fMain.ADOQueryTicks.fields[4].text; jj:=Pos(' ', ss); if jj<>0 then delete(ss, 1, jj); if ss<>'' then begin fMain.labelTimeRef.caption:=ss; fTablo.labelTimeRef.caption:=ss; end; fMain.ADOQueryTicks.close; Запрос последнего значения 2 fMain.ADOQueryTicks.SQL.clear; fMain.ADOQueryTicks.SQL.add( 'select top 1 realtime_tick.* from realtime_tick'+ ' where'+ ' realtime_tick.region_ID = 150 AND'+ ' realtime_tick.sec_id = 3 AND'+ ' realtime_tick.field_id = 2 '+ str+ ' order by DT DESC'); fMain.ADOQueryTicks.Open; if fMain.ADOQueryTicks.recordCount>0 then sMonth1:=fMain.ADOQueryTicks.fields[iValue].text; try if sToMonth0='FTSE' then d1:=strToFloat(sMonth0); if sToMonth0='FUT' then d1:=strToFloat(sMonth1); if sToMonth1='FTSE' then d2:=strToFloat(sMonth0); if sToMonth1='FUT' then d2:=strToFloat(sMonth1); dd:=(d1+d2)/2; sMonth2:=format('%.1f', [dd]); sMonth3:=format('%.1f', [dd]); except sMonth2:=''; sMonth3:=''; end; ss:=fMain.ADOQueryTicks.fields[4].text; jj:=Pos(' ', ss); if jj<>0 then delete(ss, 1, jj); if ss<>'' then begin fMain.labelTimeFutRef.caption:=ss; fTablo.labelTimeFutRef.caption:=ss; end; fMain.ADOQueryTicks.close; if sMonth0<>'' then begin if sToMonth0='FTSE' then fMain.EdMainFTSE.text:=sMonth0; if sToMonth1='FTSE' then fMain.EdMainFUT.text:=sMonth0; if sToMonth2='FTSE' then fMain.EdMainMonth2.text:=sMonth0; if sToMonth3='FTSE' then fMain.EdMainMonth3.text:=sMonth0; end; if sMonth1<>'' then begin if sToMonth0='FUT' then fMain.EdMainFTSE.text:=sMonth1; if sToMonth1='FUT' then fMain.EdMainFUT.text:=sMonth1; if sToMonth2='FUT' then fMain.EdMainMonth2.text:=sMonth1; if sToMonth3='FUT' then fMain.EdMainMonth3.text:=sMonth1; end; if sMonth2<>'' then begin if Pos('AV',sToMonth0)=1 then fMain.EdMainFTSE.text:=sMonth2; if Pos('AV',sToMonth1)=1 then fMain.EdMainFUT.text:=sMonth2; if Pos('AV',sToMonth2)=1 then fMain.EdMainMonth2.text:=sMonth2; if Pos('AV',sToMonth3)=1 then fMain.EdMainMonth3.text:=sMonth2; end; if sMonth3<>'' then begin if Pos('AV',sToMonth0)=1 then fMain.EdMainFTSE.text:=sMonth3; if Pos('AV',sToMonth1)=1 then fMain.EdMainFUT.text:=sMonth3; if Pos('AV',sToMonth2)=1 then fMain.EdMainMonth2.text:=sMonth3; if Pos('AV',sToMonth3)=1 then fMain.EdMainMonth3.text:=sMonth3; end; fTablo.EdMainFTSE.text:=fMain.EdMainFTSE.text; fTablo.EdMainFUT.text:=fMain.EdMainFUT.text; fTablo.EdMainMonth2.text:=fMain.EdMainMonth2.text; fTablo.EdMainMonth3.text:=fMain.EdMainMonth3.text; fMain.ADOQueryTicks.SQL.clear; if iTag=0 then begin fMain.ADOQueryTicks.SQL.add(' SELECT realtime_tick.*'+ ' FROM realtime_tick INNER JOIN'+ ' instruments ON realtime_tick.region_ID = instruments.region_ID'+ ' AND realtime_tick.sec_id = instruments.sec_id'+ ' AND realtime_tick.ticker = instruments.ticker'+ ' WHERE (instruments.region_ID = 150 AND instruments.sec_id = 2'+ ' AND instruments.ticker LIKE ''ESX%'' '+str+ ' AND ( realtime_tick.field_id = 6 or realtime_tick.field_id = 4))'+' order by DT DESC'); end; if iTag=1 then begin fMain.ADOQueryTicks.SQL.add(' SELECT realtime_tick.*'+ ' FROM realtime_tick INNER JOIN'+ ' instruments ON realtime_tick.region_ID = instruments.region_ID'+ ' AND realtime_tick.sec_id = instruments.sec_id'+ ' AND realtime_tick.ticker = instruments.ticker'+ ' WHERE (instruments.region_ID = 150 AND instruments.sec_id = 2'+ ' AND instruments.ticker LIKE ''ESX%'' '+strOne+ ' AND ( realtime_tick.field_id = 2))'+' order by DT DESC'); end; if iTag>1 then begin Запрос квот fMain.ADOQueryTicks.SQL.add(' SELECT realtime_tick.*'+ ' FROM realtime_tick INNER JOIN'+ ' instruments ON realtime_tick.region_ID = instruments.region_ID'+ ' AND realtime_tick.sec_id = instruments.sec_id'+ ' AND realtime_tick.ticker = instruments.ticker'+ ' WHERE instruments.region_ID = 150 AND instruments.sec_id = 2'+ ' AND ( realtime_tick.field_id = 6 or realtime_tick.field_id = 4 or realtime_tick.field_id = 2)'+ ' AND instruments.ticker LIKE ''ESX%'''+str+' order by DT DESC'); end; fMain.ADOQueryTicks.Open; result:=fMain.ADOQueryTicks.recordCount; IniFile.WriteString('main', 'timeRead', sReadTimeOld); IniFile.free; isExcelData:=false; inc(iTag); tm1:=time-tm1; fMain.LabelInfo.caption:='TQ='+timeToStr(tm1); fMain.LabelInfo.refresh; end; ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 08.11.2004, 19:26 |
|
||
|
Помогите с SQL
|
|||
|---|---|---|---|
|
#18+
Как мне кажется, ни ADO, ни Excel, ни Delphi к теме mySQL отношения не имеют. Кроме того, высокой производительности от этих составных (ADO, Excel, Delphi) ожидать и не приходится. Да и "слишком медленно", это сколько и на какой машине? P.S. если вопрос про SQL, то имело смысл вычленить его из общего кода. Длинный код мало кто читает. Заодно, было бы неплохо его как следует отформатировать. Успехов! ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 09.11.2004, 10:25 |
|
||
|
|

start [/forum/topic.php?fid=47&msg=32772912&tid=1854642]: |
0ms |
get settings: |
7ms |
get forum list: |
9ms |
check forum access: |
2ms |
check topic access: |
2ms |
track hit: |
156ms |
get topic data: |
9ms |
get forum data: |
2ms |
get page messages: |
45ms |
get tp. blocked users: |
1ms |
| others: | 212ms |
| total: | 445ms |

| 0 / 0 |
