1
My faith works for nothing in this world
The SQL is like this:
-- Function used to return the remaining space of a chosen folder. --
DELIMITER $$
CREATE FUNCTION tamanhoRestante (_idPasta INT)
RETURNS INT
BEGIN
DECLARE lpasTamanho INT;
DECLARE lpasUsado INT;
-- Aqui é verificado o tamanho TOTAL da pasta escolhida. --
SELECT tamanho FROM pasta WHERE idPasta = _idPasta INTO lpasTamanho;
-- E agora a verificação de todos os arquivos alocados nesta pasta. --
IF(SELECT COUNT(*) FROM usuario JOIN usuario_has_pasta WHERE idUsuario = usuario_has_pasta.Usuario_idUsuario > 0) THEN
SELECT SUM(arquivo.tamanho) FROM arquivo JOIN Pasta_has_Arquivo JOIN Pasta WHERE idArquivo = Arquivo_idArquivo AND Pasta_idPasta = _idPasta INTO lpasUsado;
ELSE SET lpasUsado = 0;
END IF;
-- Agora faz-se o retorno do tamanho total da pasta subtraindo o total utilizado --
RETURN lpasTamanho - lpasUsado;
END
$$
DELIMITER ;
In this test, the lpasTotal = Tamanho
total of the selected folder, and lpasUsado
is the sum of the size of all files linked to this folder (via a ternary Pasta_has_Arquivo
).
The lpasTamanho
in the test has size 100, and the lpasTamanho
I did the test with 0 and 50, but in both returns Null :/
Can anyone help me with that? I can’t find the mistake.
Add in question the result of the select of the tables by doing the favor
– Sorack
The select is quite confused. But to feed the variable from select do something like this: SELECT size INTO lpasSize FROM folder WHERE idPasta = _idPasta;
– Reginaldo Rigo
I believe this one link solves your problem, see how INTO is done.
– Marco Souza
what you can also do is use the SET in the INTO login.
– Marco Souza
Thanks for the personal answers! The problem is not the select, I took his test and it is ok, the problem is in the second part, the SUM.. :/
– Kauan Nagashi