?????????????У??????????????LUA?????????
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 ")
for k??v in pairs(tbl_prop) do
fp_out:write("-- triggers of " .. k .. " ")
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(" ")
end
fp_out:write(" ")
end
end
???????? ??????????
????????????????Tab_Version_Tab???????????仯??????????仯????????????????????????????????????????У???????????????????????????
????1. ???????????????????
????2. ??natural join?????????????????????????
????SELECT COUNT(*) FROM table_local NATURAL JOIN table_tmp;
????????????????????????????????
????MySQL??DBLINK???????????????????Щ??