No edit summary |
No edit summary |
||
Line 14: | Line 14: | ||
local countFields = 'COUNT(*)=total' | local countFields = 'COUNT(*)=total' | ||
local countArgs = { | local countArgs = { | ||
format = ' | format = 'list', | ||
limit = 1 | limit = 1 | ||
} | } | ||
Line 32: | Line 32: | ||
local args = { | local args = { | ||
format = table, | format = 'table', | ||
fields = queryFields, | fields = queryFields, | ||
limit = 1, | limit = 1, |
Revision as of 06:55, 27 December 2023
Documentation for this module may be created at Module:RandomCargoRecord/doc
local p = {} local cargo = mw.ext.cargo function p.randomCargoRecord(frame) local getArgs = require('Module:Arguments').getArgs local args = getArgs(frame); local tableName = args[1] if tableName == nil or tableName == "" then hasErrors = true return string.format("<code>tableName</code> parameter is required") end local countFields = 'COUNT(*)=total' local countArgs = { format = 'list', limit = 1 } local countResults = cargo.query(tableName, countFields, countArgs) for r = 1, #countResults do local result = countResults[r] local total = result.total end if total == nil or total == "" then return string.format("<code>total</code> could not be calculated from table %s", tableName) end local number = require('Module:Random').number local queryFields = 'game,link' local countOffset = number(1, total) local args = { format = 'table', fields = queryFields, limit = 1, offset = countOffset } local result = cargo.query(tableName, fields, args) for r = 1, #results do local result = results[r] return string.format("<h1>%s</h1>", result.link) end end return p