progs:fblutil
Toto je starší verze dokumentu!
FBLUtil
Klonovani mezi DB
function CloneTable(db1, TableName, db2) local t = db1:GetTable(TableName) local flds = "" for i, v in ipairs(t) do local s = string.format("%s %s", v.Field, v.Typ) if flds ~= "" then flds = flds .. ", " end flds = flds .. s end db2:Execute(string.format("CREATE TABLE %s (%s)", TableName, flds)) db2:Commit() end function CloneIndices(db1, TableName, db2) local t = db1:GetIndices(TableName) for i, v in ipairs(t) do db2:Execute(string.format("CREATE %s INDEX %s ON %s (%s)", v.Opts, v.Name, TableName, v.Fields)) if v.Inactive then db2:Execute(string.format("ALTER INDEX %s INACTIVE", v.Name)) end end db2:Commit() end function ExportAndDiff(DB, TableName, flds) local n = DB:ExportTable(Tmp..FName1, ";", "UTF-8", "base64", string.format("select %s from %s", flds, TableName)) local err, name, num = os.execute(string.format("diff %s %s >/dev/null 2>&1", Tmp..FName0, Tmp..FName1)) --LUA5.1 vraci cislo, >=5.2 vraci true nebo nil print("Diff", err, name, num) if (type(err) == "number" and err ~= 0) or not err then error(string.format("ERROR: Diff table %s (%s)", TableName, tostring(err))) end return n end local t = os.time() print("Test DataPumpTo") CloneTable(db1, TableName, db2) local n = db1:DataPumpTo(string.format("select * from %s", TableName), db2, string.format("insert into %s", TableName)) db2:Commit() CloneIndices(db1, TableName, db2) print(string.format("Done %d rows in %ds", n, os.difftime(os.time(), t))) local n = ExportAndDiff(db2, TableName, flds) assert(TableRows == n) db2:Execute(string.format("drop table %s", TableName)) db2:Commit()
progs/fblutil.1579251441.txt.gz · Poslední úprava: 2020/01/17 08:57 autor: Karel Petrů