Module:SchemaDiagram

--[[ Example for debug console:

mw.logObject( p._parse_sql( [===[ CREATE TABLE /*_*/user ( user_id int unsigned NOT NULL PRIMARY KEY AUTO_INCREMENT,  user_name varchar(255) binary NOT NULL default ,  user_real_name varchar(255) binary NOT NULL default ,  user_password tinyblob NOT NULL,  user_newpassword tinyblob NOT NULL,  user_newpass_time binary(14),  user_email tinytext NOT NULL,  user_touched binary(14) NOT NULL default ,  user_token binary(32) NOT NULL default ,  user_email_authenticated binary(14),  user_email_token binary(32),  user_email_token_expires binary(14),  user_registration binary(14),  user_editcount int,  user_password_expires varbinary(14) DEFAULT NULL

) /*$wgDBTableOptions*/; ]===] ) )

]]

function parse_sql(sql) local legal_states = { root = { create = true, root = true, },		create = { create = true, create_table = true, root = true, },		create_table = { create_table = true, table_field_start = true, },		table_field_start = { table_field_type = true, table_field_start = true, create = true, create_table_goto_semi = true, },		table_field_type = { table_field_attrib = true, table_field_goto_closeparen = true, },		table_field_goto_closeparen = { table_field_goto_closeparen = true, table_field_attrib = true, },		table_field_attrib = { table_field_attrib_not = true, table_field_attrib = true, table_field_start = true, create = true, },		table_field_attrib_not = { table_field_attrib = true, },		create_table_goto_semi = { create_table_goto_semi = true, root = true, },	}	local state = "root"

local parsed_tables = {} local parsed_current = { table_name = nil, table_fields = nil, field_name = nil, -- Required keys: 'type' -- Optional keys: 'primary', 'nullable'. field_attribs = nil }

-- Inspired by http://lua-users.org/wiki/SwitchStatement local parser = { -- outer-most state ["root"] = function (token) if token == "CREATE" then return "create" end

-- ignore anything else return "root" end, -- seen "CREATE" ["create"] = function (token) -- expect "TABLE" for "CREATE TABLE" if token == "TABLE" then return "create_table" end -- expect ";" (end of CREATE statement) if token == ";" then record_table_commit_maybe return "root" end -- expect "INDEX" for "CREATE INDEX" (ignored) -- expect "UNIQUE" for "CREATE UNIQUE INDEX" (ignored) -- expect "/*$wgDBTableOptions*/" (ignored) return "create" end, -- seen "CREATE TABLE" ["create_table"] = function (token) -- expect "/*_*/ '			.. ' '	end

for table_name, table_fields in pairs( parsed_tables ) do		if not shown_table_names[table_name] then mw.log( "table not in layout: " .. table_name ) if warn_incomplete_layout then mw.addWarning( "Database table '" .. table_name .. "' is not in the current layout." ) end end end

return result_html .. ' ' end

p._parse_sql = parse_sql

return p