| Цитата | 
|---|
swerg написал: Скобли фигурные лишние
     table.ins ert(arrtotal,{ .......          }) | 
спасибо, действительно... глупая ошибка
можно тогда еще один вопрос? подобным образом я хочу экспортировать таблицу обезличенных сделок в базу скриптом. я проходу по таблице all_trades (сделки получаю по нескольким инструментам)
формирую массив вида datetime[ticker][price]["1025"] = value  также и для 1026 (сделки на покупку продажу)
затем в циклах обхожу массив и добавляю в базу данных все это дело раз в (%setinterval%) 
скрипт вроде работает но даты добавляются как-то рандомно т.е я вижу в базе данных сначала сделки  за 23 часа потом за 12, за 15 , потом 13 и так далее и я вообще не уверен записал он все или частично
скрипт:
Скрытый текст  | 
|---|
 | Код | 
|---|
 -- Подключение драйвера (библиотеки):
local is_run = true
luasql = require "luasql.mysql"
env = luasql.mysql()
con = assert (env:connect('footprint', 'root', '', 'localhost','3306'))
arrmain  = {};
arrprices={}
arrtickers={}
arrtotal={}
local function has_value (tab, val)
    for index, value in ipairs(tab) do
        if val ue == val then
            return true
        end
    end
    return false
end
function main()
local number_of_rows = getNumberOf('all_trades')    
for i = 1,number_of_rows-1 do
    qbuy=0
    qsell=0
    datetime = {}
    all_trade_item = getItem('all_trades', i)
    datetime.year = all_trade_item.datetime.year
    datetime.month = all_trade_item.datetime.month
    datetime.day = all_trade_item.datetime.day
    datetime.hour = all_trade_item.datetime.hour
    datetime.min = all_trade_item.datetime.min
    datetime.sec = all_trade_item.datetime.sec
 
    posixTime = os.time(datetime) 
    if i==1 then
    nextposixTime = posixTime + 10 -- +10 sec    
    datetime2 =  os.date("*t",posixTime);
    posixTime1 =  tostring(datetime2.year)
    .."-"
    ..tostring(datetime2.month)
    .."-"
    ..tostring(datetime2.day)
    .." "
    ..tostring(datetime2.hour)
    ..":"
    ..tostring(datetime2.min)
    ..":"
    ..tostring(datetime2.sec);
   
    arrtotal[posixTime1] = {}   
    else     
    if (posixTime >= nextposixTime) then
    nextposixTime = posixTime + 10 -- +10 sec
    datetime2 =  os.date("*t",posixTime);
    posixTime1 =  tostring(datetime2.year)
    .."-"
    ..tostring(datetime2.month)
    .."-"
    ..tostring(datetime2.day)
    .." "
    ..tostring(datetime2.hour)
    ..":"
    ..tostring(datetime2.min)
    ..":"
    ..tostring(datetime2.sec);
    arrtotal[posixTime1] = {}  
    
    end
end
    if all_trade_item.sec_code then --TICKER
        ticker = all_trade_item.sec_code
        if has_value(arrtickers, ticker) then
             ticker=ticker --если нашли в массивае arrtickers слово ticker
            else
                table.insert(arrtickers,ticker)
                arrtotal[posixTime1][ticker] = {}
        end 
    end
    
    if all_trade_item.price then --price
        price = all_trade_item.price
        if arrtotal[posixTime1] == nil then arrtotal[posixTime1] = {} end --NE NUZHNO
        if arrtotal[posixTime1][ticker] == nil then arrtotal[posixTime1][ticker] = {} end -- NE NUZHNO
    if has_value(arrprices,price) then
        price=price
        if arrtotal[posixTime1][ticker][price] == nil then
            arrtotal[posixTime1][ticker][price] = {}
        end -- if arrtotal[ticker][price] == nil
        else
            table.insert(arrprices,price)   
            arrtotal[posixTime1][ticker][price] = {} -- тоже добавление в конец
        end -- else get item price
    end --if getItem("all_trades",i).price
    if all_trade_item.flags then operation= all_trade_item.flags end
    
    --operation = all_trade_item.flags
    if  all_trade_item.qty then
        quanity =  all_trade_item.qty
        if operation==1026 then
          qbuy = quanity
          if arrtotal[posixTime1][ticker][price]["1026"] == nil then arrtotal[posixTime1][ticker][price]["1026"] = 0 end
            arrtotal[posixTime1][ticker][price]["1026"] = arrtotal[posixTime1][ticker][price]["1026"]  + qbuy
        end
        if operation==1025 then  
            qsell = quanity 
            if arrtotal[posixTime1][ticker][price]["1025"] == nil then arrtotal[posixTime1][ticker][price]["1025"] = 0 end
            arrtotal[posixTime1][ticker][price]["1025"] = arrtotal[posixTime1][ticker][price]["1025"] + qsell
        end
      
    end -- if  getItem("all_trades",i).qty
   
end -- main for !!!!
message(tostring(#arrtotal))
a=nil
b=a[1]
for datekey,dateval in pairs(arrtotal) do  --date
    for tickerkey, tickerval in pairs(dateval) do --ticker
        for pricekey, priceval in pairs(tickerval) do --price    
            for opkey, opval in pairs(priceval) do --1025 1026
                res = assert(con:execute(string.format("INS ERT IN TO sdelki(price,quanity,operation,ticker,datetime) VALUES('%f','%d','%d','%s','%s')", pricekey,opval,opkey,tickerkey,datekey )));
            end
        end
    end
end
end -- function main |  
  | 
подскажите что я делаю не так?