<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="de">
	<id>https://www.verzauberte-welten.de/index.php?action=history&amp;feed=atom&amp;title=Modul%3ACargoUtil</id>
	<title>Modul:CargoUtil - Versionsgeschichte</title>
	<link rel="self" type="application/atom+xml" href="https://www.verzauberte-welten.de/index.php?action=history&amp;feed=atom&amp;title=Modul%3ACargoUtil"/>
	<link rel="alternate" type="text/html" href="https://www.verzauberte-welten.de/index.php?title=Modul:CargoUtil&amp;action=history"/>
	<updated>2026-04-05T20:33:58Z</updated>
	<subtitle>Versionsgeschichte dieser Seite in Verzauberte Welten e.V.</subtitle>
	<generator>MediaWiki 1.39.8</generator>
	<entry>
		<id>https://www.verzauberte-welten.de/index.php?title=Modul:CargoUtil&amp;diff=4393&amp;oldid=prev</id>
		<title>imported&gt;Oetterer am 11. März 2022 um 09:48 Uhr</title>
		<link rel="alternate" type="text/html" href="https://www.verzauberte-welten.de/index.php?title=Modul:CargoUtil&amp;diff=4393&amp;oldid=prev"/>
		<updated>2022-03-11T09:48:56Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Neue Seite&lt;/b&gt;&lt;/p&gt;&lt;div&gt;local p = {}&lt;br /&gt;
local getArgs = require('Module:Arguments').getArgs&lt;br /&gt;
local classDebug = require('Module:Debug/class')&lt;br /&gt;
local _TT = require('Module:TableTools')&lt;br /&gt;
local cargo&lt;br /&gt;
if mw.ext and mw.ext.cargo then&lt;br /&gt;
	cargo = mw.ext.cargo&lt;br /&gt;
else&lt;br /&gt;
	cargo = {}&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function prepareQueryParam(query)&lt;br /&gt;
	classDebug:log(21, 'entering CargoUtil.prepareQueryParam', 'CargoUtil')&lt;br /&gt;
	if query.tables and #query.tables &amp;gt; 0 and query.fields and #query.fields &amp;gt; 0 then&lt;br /&gt;
		if type(query.tables) == 'table' then&lt;br /&gt;
			query.tables = table.concat(query.tables, ', ')&lt;br /&gt;
		end&lt;br /&gt;
		if not query.joins then&lt;br /&gt;
			query.joins = query.join&lt;br /&gt;
		end&lt;br /&gt;
		if query.joins and type(query.joins) == 'table' then&lt;br /&gt;
			query.joins = table.concat(query.joins, ', ')&lt;br /&gt;
		end&lt;br /&gt;
		if type(query.fields) == 'table' then&lt;br /&gt;
			query.fields = table.concat(query.fields, ', ')&lt;br /&gt;
		end&lt;br /&gt;
		if query.where and type(query.where) == 'table' then&lt;br /&gt;
			if query.where[1] then	-- sequence assumed&lt;br /&gt;
				query.where = table.concat(query.where, ' AND ')&lt;br /&gt;
			else&lt;br /&gt;
				local where = ''&lt;br /&gt;
				for k, v in pairs(query.where) do&lt;br /&gt;
					where = where .. k .. '=' .. v .. ' AND '&lt;br /&gt;
				end&lt;br /&gt;
				query.where = where .. '1 '&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
		if query.group and type(query.group) == 'table' then&lt;br /&gt;
			query.group = table.concat(query.group, ', ')&lt;br /&gt;
		end&lt;br /&gt;
		if query.having and type(query.having) == 'table' then&lt;br /&gt;
			if query.having[1] then	-- sequence assumed&lt;br /&gt;
					query.having = table.concat(query.having, ', ')&lt;br /&gt;
			else&lt;br /&gt;
				local having = ''&lt;br /&gt;
				for k, v in pairs(query.having) do&lt;br /&gt;
					having = having .. k .. '=' .. v .. ', '&lt;br /&gt;
				end&lt;br /&gt;
				query.having = mw.ustring.sub(having, 1, -3)&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
		if query.order and type(query.order) == 'table' then&lt;br /&gt;
			query.order = table.concat(query.order, ', ')&lt;br /&gt;
		end&lt;br /&gt;
		return query&lt;br /&gt;
	else&lt;br /&gt;
		if tables and #tables &amp;gt; 0 then&lt;br /&gt;
			error('Argument query.tables is missing or empty! (calling from ' .. tostring(self) .. ')', 2)&lt;br /&gt;
		else&lt;br /&gt;
			error('Argument query.fields is missing or empty! (calling from ' .. tostring(self) .. ')', 2)&lt;br /&gt;
		end&lt;br /&gt;
		return nil&lt;br /&gt;
	end	&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function p.attach(dbtable)&lt;br /&gt;
	classDebug:log(21, 'entering CargoUtil.attach', 'CargoUtil.attach')&lt;br /&gt;
	classDebug:log(22, ' with table &amp;quot;' .. dbtable .. '&amp;quot;')&lt;br /&gt;
	local frame = mw.getCurrentFrame()&lt;br /&gt;
	local ret = false&lt;br /&gt;
	ret = frame:callParserFunction('#cargo_attach:_table=' .. dbtable)&lt;br /&gt;
	return ret&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function p.declare(dbtable, dbfields)&lt;br /&gt;
	classDebug:log(21, 'entering CargoUtil.declare', 'CargoUtil.declare')&lt;br /&gt;
	classDebug:log(22, ' with table &amp;quot;' .. dbtable .. '&amp;quot; and fields ' ..&lt;br /&gt;
		(type(dbfields) == &amp;quot;string&amp;quot; and '&amp;quot;' .. dbfields .. '&amp;quot;' or 'of type ' .. type(dbfields)), 'CargoUtil.declare')&lt;br /&gt;
	if type(dbfields) == &amp;quot;table&amp;quot; then&lt;br /&gt;
		classDebug:log(23, ' datatable: ' .. _TT.printTable(dbfields), 'CargoUtil.declare')&lt;br /&gt;
	end&lt;br /&gt;
	local frame = mw.getCurrentFrame()&lt;br /&gt;
	local ret = false&lt;br /&gt;
	if type(dbfields) == &amp;quot;string&amp;quot; then&lt;br /&gt;
		ret = frame:callParserFunction('#cargo_declare:_table=' .. dbtable, dbfields)&lt;br /&gt;
	elseif type(dbfields) == &amp;quot;table&amp;quot; then&lt;br /&gt;
		ret = frame:callParserFunction{name = '#cargo_declare:_table=' .. dbtable, args = dbfields}&lt;br /&gt;
	end&lt;br /&gt;
	return ret&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function p.query(query, attributes, retainBlanks)&lt;br /&gt;
	classDebug:log(21, 'entering CargoUtil.query', 'CargoUtil.query')&lt;br /&gt;
	classDebug:log(23, ' with query: ' .. (query and _TT.printTable(query) or 'NONE'), 'CargoUtil.query')&lt;br /&gt;
	classDebug:log(23, ' with attributes: ' .. (attributes and _TT.printTable(attributes) or 'NONE'), 'CargoUtil.query')&lt;br /&gt;
	local attributes = attributes or {}&lt;br /&gt;
	if type(attributes) ~= 'table' then&lt;br /&gt;
		attributes = {attributes}&lt;br /&gt;
	end&lt;br /&gt;
	-- CargoUtil.query() allows for query.paramters (like table, where, etc) to be tables. cargo.query only takes strings. remedy this here&lt;br /&gt;
	local query = prepareQueryParam(query)&lt;br /&gt;
	local args = {&lt;br /&gt;
		where = query.where,&lt;br /&gt;
		join = query.joins,&lt;br /&gt;
		groupBy = query.group,&lt;br /&gt;
		having = query.having,&lt;br /&gt;
		orderBy = query.order,&lt;br /&gt;
		limit = attributes.limit&lt;br /&gt;
	}&lt;br /&gt;
	local result = cargo.query(query.tables, query.fields, args)&lt;br /&gt;
&lt;br /&gt;
	local ret = {}&lt;br /&gt;
	for num, row in pairs(result) do&lt;br /&gt;
		local newRow = {}&lt;br /&gt;
		for key, value in pairs(row) do&lt;br /&gt;
			if mw.ustring.len(mw.text.trim(value)) &amp;gt; 0 or retainBlanks then&lt;br /&gt;
				newRow[key] = value&lt;br /&gt;
				-- cargo interprets underscored (_) as spaces in fieldnames (keys). so copy the entry&lt;br /&gt;
				if mw.ustring.find(key, ' ') then&lt;br /&gt;
					local newKey = mw.ustring.gsub(key, ' ', '_')&lt;br /&gt;
					if not newRow[newKey] then&lt;br /&gt;
						newRow[newKey] = newRow[key]&lt;br /&gt;
					end&lt;br /&gt;
				end&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
		ret[num] = newRow&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	return ret&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function p.rawquery(query, attributes)&lt;br /&gt;
	classDebug:log(21, 'entering CargoUtil.rawquery', 'CargoUtil.rawquery')&lt;br /&gt;
	classDebug:log(23, ' with query: ' .. (query and _TT.printTable(query) or 'NONE'), 'CargoUtil.rawquery')&lt;br /&gt;
	classDebug:log(23, ' with attributes: ' .. (attributes and _TT.printTable(attributes) or 'NONE'), 'CargoUtil.rawquery')&lt;br /&gt;
	local query = prepareQueryParam(query)&lt;br /&gt;
	local frame = mw.getCurrentFrame()&lt;br /&gt;
	local tables = query.tables&lt;br /&gt;
	local arguments = attributes or {}&lt;br /&gt;
	arguments.fields = query.fields&lt;br /&gt;
	arguments['join on'] = query.joins&lt;br /&gt;
	arguments.where = query.where&lt;br /&gt;
	arguments['group by'] = query.group&lt;br /&gt;
	arguments.having = query.having&lt;br /&gt;
	arguments['order by'] = query.order&lt;br /&gt;
	classDebug:log(24, ' calling parser function with tables: ' .. tables .. ' and arguments: ' .. _TT.printTable(arguments))&lt;br /&gt;
	return frame:callParserFunction{ name='#cargo_query:tables=' .. tables, args = arguments }&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function p.store(dbtable, data)&lt;br /&gt;
	classDebug:log(21, 'entering CargoUtil.store')&lt;br /&gt;
	classDebug:log(22, ' with table &amp;quot;' .. dbtable .. '&amp;quot; and data ' ..&lt;br /&gt;
		(type(data) == &amp;quot;string&amp;quot; and '&amp;quot;' .. data .. '&amp;quot;' or 'of type ' .. type(data)))&lt;br /&gt;
	if type(data) == &amp;quot;table&amp;quot; then&lt;br /&gt;
		classDebug:log(23, ' datatable: ' .. _TT.printTable(data))&lt;br /&gt;
	end&lt;br /&gt;
	local ret = false&lt;br /&gt;
	if type(data) == &amp;quot;table&amp;quot; then&lt;br /&gt;
		for k, v in pairs(data) do&lt;br /&gt;
			if type(v) == 'boolean' then&lt;br /&gt;
				data[k] = v and 1 or 0&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
		local frame = mw.getCurrentFrame()&lt;br /&gt;
		ret = frame:callParserFunction{name = '#cargo_store:_table=' .. dbtable, args = data}&lt;br /&gt;
	end&lt;br /&gt;
	return ret&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
return p&lt;/div&gt;</summary>
		<author><name>imported&gt;Oetterer</name></author>
	</entry>
</feed>