Mephisto
March 17th, 2022, 17:52
Hi there,
I encounter an issue with DB access. I need to migrate same DB entries to new DB entries.
I first catch the data I want to migrate from the DB and write it to it's new location. This works fine if I comment out the "DB.deleteChild" entries at the end of my code. If the "DB.deleteChild" entries are active, the "DB.getValue" part fails to acquire any data. I assume for some reason the deletion happens before I can grab the data from the DB even so the grabbing happens code wise before the deletion.
Happy to provide the ruleset code and the DB I want to migrate in a PM.
function migrateNPC6(nodeNPC)
-- Get nodes for migration
for _, nodeAction in pairs (DB.getChildren(nodeNPC, "actions")) do
-- Get values from DB.
nHandling = DB.getValue(nodeAction, "atk_handling", 0)
nBonus = DB.getValue(nodeAction, "atk_modifier", 0)
nType = DB.getValue(nodeAction, "atk_type", 0)
sQualities = DB.getValue(nodeAction, "desc", "")
sName = DB.getValue(nodeAction, "name", "")
-- Migrate values from old to new DB entries
DB.setValue(nodeAction, "wpn_handling", "number", nHandling)
DB.setValue(nodeAction, "atk_bonus", "number", nBonus)
DB.setValue(nodeAction, "wpn_name", "string", sName)
DB.setValue(nodeAction, "wpn_qualities", "string", sQualities)
DB.setValue(nodeAction, "wpn_type", "number", nType)
Debug.console("sName", sName)
Debug.console("sQualities", sQualities)
Debug.console("wpn_name", DB.getValue(nodeAction, "wpn_name", ""))
Debug.console("wpn_qualities", DB.getValue(nodeAction, "wpn_qualities", ""))
-- Delete old migrated DB entries
DB.deleteChild(nodeAction, "atk_handling")
DB.deleteChild(nodeAction, "atk_modifier")
DB.deleteChild(nodeAction, "atk_type")
DB.deleteChild(nodeAction, "desc")
DB.deleteChild(nodeAction, "name")
end
end
I encounter an issue with DB access. I need to migrate same DB entries to new DB entries.
I first catch the data I want to migrate from the DB and write it to it's new location. This works fine if I comment out the "DB.deleteChild" entries at the end of my code. If the "DB.deleteChild" entries are active, the "DB.getValue" part fails to acquire any data. I assume for some reason the deletion happens before I can grab the data from the DB even so the grabbing happens code wise before the deletion.
Happy to provide the ruleset code and the DB I want to migrate in a PM.
function migrateNPC6(nodeNPC)
-- Get nodes for migration
for _, nodeAction in pairs (DB.getChildren(nodeNPC, "actions")) do
-- Get values from DB.
nHandling = DB.getValue(nodeAction, "atk_handling", 0)
nBonus = DB.getValue(nodeAction, "atk_modifier", 0)
nType = DB.getValue(nodeAction, "atk_type", 0)
sQualities = DB.getValue(nodeAction, "desc", "")
sName = DB.getValue(nodeAction, "name", "")
-- Migrate values from old to new DB entries
DB.setValue(nodeAction, "wpn_handling", "number", nHandling)
DB.setValue(nodeAction, "atk_bonus", "number", nBonus)
DB.setValue(nodeAction, "wpn_name", "string", sName)
DB.setValue(nodeAction, "wpn_qualities", "string", sQualities)
DB.setValue(nodeAction, "wpn_type", "number", nType)
Debug.console("sName", sName)
Debug.console("sQualities", sQualities)
Debug.console("wpn_name", DB.getValue(nodeAction, "wpn_name", ""))
Debug.console("wpn_qualities", DB.getValue(nodeAction, "wpn_qualities", ""))
-- Delete old migrated DB entries
DB.deleteChild(nodeAction, "atk_handling")
DB.deleteChild(nodeAction, "atk_modifier")
DB.deleteChild(nodeAction, "atk_type")
DB.deleteChild(nodeAction, "desc")
DB.deleteChild(nodeAction, "name")
end
end