Hello, in a plugin, I am trying to show the database size but cannot get the statement to work. In phpMyAdmin it works fine, but the syntax is confusing in Kanboard.
I noticed in Kanboard, SQLite has a function for the database size which is fine, but using PicoDB for MySQL and Postgres is not working.
public function databaseSize()
{
// SELECT table_schema "myppworkspace", ROUND(SUM(data_length + index_length) / 1024 / 1024, 1) "DB Size in MB" FROM information_schema.tables WHERE table_schema = 'myppworkspace' GROUP BY table_schema;
if (DB_DRIVER === 'postgres') {
return $this->db->execute('');
} elseif (DB_DRIVER === 'mysql') {
return $this->db->execute('
SELECT
table_schema AS "Database",
ROUND(
SUM(data_length + index_length) / 1024 / 1024,
1
) "MB"
FROM
information_schema.tables
WHERE
table_schema = "myppworkspace";
');
}
}
Errors:
PHP Fatal error: Uncaught Error: Object of class PDOStatement could not be converted to string
Kanboard cant seem to find WHERE table_schema = myppworkspace; - I have tried "myppworkspace" and 'myppworkspace' and also just myppworkspace. Like I said in phpMyAdmin it works and I get the total MB for the database.
I tried to build the query, but I only got as far as return $this->db->table('information_schema.tables') because I cannot find a way to do the ROUND and SUM function.
oh I see, but then why does it work in phpMyAdmin? I will try without renaming
EDIT: na it doesnt work… I tried by removing the line, and then by removing the AS
I get Internal Error: SQL Error: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'myppworkspace' in 'where clause'
I added you both as contributors and was going to mention you both in the initial release so GitHub adds your mentions. I have added you for write access too… check how I formatted it
I left the original code, but in the tooltip it is formatted raw and in the page, it is half rounded up in MB
Check my code, if the code is worng then I will do the suggested amendment, otherwise I think I already formatted it before your comment today
Maybe it was not clear. It is nothing wrong there, but the conversion to megabyte could do once before using the final result, instead of twice, once for each sub-result. That’s all.