{"action":"opened","issue":{"url":"https://api.github.com/repos/glpi-project/glpi/issues/865","repository_url":"https://api.github.com/repos/glpi-project/glpi","labels_url":"https://api.github.com/repos/glpi-project/glpi/issues/865/labels{/name}","comments_url":"https://api.github.com/repos/glpi-project/glpi/issues/865/comments","events_url":"https://api.github.com/repos/glpi-project/glpi/issues/865/events","html_url":"https://github.com/glpi-project/glpi/issues/865","id":169422187,"number":865,"title":"$DB->list_tables() also lists views","user":{"login":"SylvieCozic","id":15051513,"avatar_url":"https://avatars.githubusercontent.com/u/15051513?v=3","gravatar_id":"","url":"https://api.github.com/users/SylvieCozic","html_url":"https://github.com/SylvieCozic","followers_url":"https://api.github.com/users/SylvieCozic/followers","following_url":"https://api.github.com/users/SylvieCozic/following{/other_user}","gists_url":"https://api.github.com/users/SylvieCozic/gists{/gist_id}","starred_url":"https://api.github.com/users/SylvieCozic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SylvieCozic/subscriptions","organizations_url":"https://api.github.com/users/SylvieCozic/orgs","repos_url":"https://api.github.com/users/SylvieCozic/repos","events_url":"https://api.github.com/users/SylvieCozic/events{/privacy}","received_events_url":"https://api.github.com/users/SylvieCozic/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2016-08-04T16:52:35Z","updated_at":"2016-08-04T16:52:35Z","closed_at":null,"body":"Hello GLPi team,\r\n\r\nFor some particular plugins we use views in the glpi database.\r\n\r\nBut we have an issue when the `$DB->list_tables()` function is called as it's not only returning all tables but also all views.\r\n\r\nFor example, if I want to migrate lets say to 9.1 RC2 :) then\r\n`install\\update.php` will call `DBmysql::optimize_tables($migration);`\r\n`optimize_tables` function will call `$result = $DB->list_tables();`\r\nand `$query = \"OPTIMIZE TABLE `\".$table.\"` ;\";` will crash when trying to \"optimize\" my views.\r\n\r\nTo avoid this I changed the list_tables function :\r\n\r\n```\r\n   function list_tables($table=\"glpi_%\") {\r\n--      return $this->query(\"SHOW TABLES LIKE '\".$table.\"'\");\r\n++\t  return $this->query(\"SELECT TABLE_NAME FROM information_schema.`TABLES` WHERE TABLE_SCHEMA = (SELECT DATABASE()) AND TABLE_TYPE != 'VIEW' AND TABLE_NAME LIKE '\".$table.\"'\");\r\n   }\r\n\r\n```\r\n\r\nI change this function since glpi 0.83.7 but I am maybe not the only one needing this.\r\n\r\nTo reproduce the case, just :\r\n- create a fake view on any \"recent\" version of glpi\r\n- execute a \"SHOW TABLES\" --> the view is listed\r\n- execute a \"SELECT TABLE_NAME FROM information_schema.`TABLES` WHERE TABLE_SCHEMA = (SELECT DATABASE()) AND TABLE_TYPE != 'VIEW'\" --> only tables are listed\r\n- just try and execute an \"OPTIMIZE\" on the view ^^\r\n\r\nIt is maybe not the best way to list tables. I just couldn't find a better way. \r\n\r\nRegards,\r\n\r\n_Sylvie_\r\n"}}
{"actor":{"display_login":"SylvieCozic"}}