local file_in = "d:\\sync_tables.sql" local file_out = "d:\\sync_trigs.sql" local tbl_prop = {} local fp = io.open(file_in, "r") if fp then while true do s1 = fp:read("*l") if not s1 then break end _,_,s2 = string.find(s1, "\"([%w%_]+)\"") if s2 then tbl_prop[s2] = 1 end end end local sql_prep = [[ drop trigger if exists trig_$OP_$TAB; delimiter | create trigger trig_$OP_$TAB after $OP on $TAB for each row begin update Tab_Version_Tab set TrigVersion=UNIX_TIMESTAMP() where Tab_Name = '$TAB'; end; | delimiter ; ]] local tbl_rep = {"insert", "update", "delete"} local fp_out = io.open(file_out, "w") if fp_out then fp_out:write("use xopensdb\n") for k,v in pairs(tbl_prop) do fp_out:write("-- triggers of " .. k .. "\n") for k1,v1 in pairs(tbl_rep) do local sql_out = sql_prep sql_out = string.gsub( sql_out, "$TAB", k); sql_out = string.gsub( sql_out, "$OP", v1); fp_out:write(sql_out) fp_out:write("\n") end fp_out:write("\n") end end |