CREATE DEFINER=`username`@`servername` PROCEDURE `sp_name_of_procedure`(
IN NAMEOFTHETABLE VARCHAR(40),
IN RECORDSPERPAGE INT
)
BEGIN
set @q1 := concat("SELECT * FROM DATABASE.",NAMEOFTHETABLE );
set @q2 := concat("SELECT count(*) FROM DATABASE.",NAMEOFTHETABLE ,"AS TOTALRECORDS");
prepare s2 from @q2;
execute s2;
set @q1 := concat(@q1,' LIMIT ',TOTALRECORDS,',',RECORDSPERPAGE );
prepare s1 from @q1;
execute s1;
deallocate prepare s1;
deallocate prepare s2;
END
I am needing to view some logs in a table, and it needs to be dynamic script so i can use this to view any of the logs without having to make static stored procedures for each table. Do not worry, validation is being taken care of server and client side. I can pull the Recordset, and I can get it to limit how many to pull, but I need it to offset at the END of the Recordset, so for example, if I wanted to just view the last 100 logs of a table.
It seems I might have to actually make 2 different recordsets to do this, because by setting the cursor type to go backwards, I can not get q2 to run to caluclate how many records I have to set that as the offset. I can't use MAX because the keys are all different in each table, so a COUNT(*) is easiest method I would think. But I get this error:
ODBC driver does not support the requested properties.
EDIT - ( TLDR : The recordset needed to be flipped by MYSQL instead of letting ASP Classic do it )
But I guess my question after explaining everything is, is there a way to tell the LIMIT command to just go to the last record without calculating that number beforehand? And if not, is my assumption that I should make 2 stored procedures and have one cursor type run first that allows for the count, then run the second stored procedure to plug in that count to OFFSET the records towards the end of the list? Maybe I answered my own question on how to do this, but perhaps someone has some information on LIMIT and OFFSET that will throw me to the end of the recordset without having to count the amount of records first? Thanks in advance! (side note - I know COUNT isn't efficient, and * isn't, but I need dynamic use and at the moment I am literally only using 2% of the CPU load.
UPDATE - This question is different than the offered suggestions as they were using pagination, and this particular script is designed to dump an exact amount of records to the screen per user form request, and won't exactly need to go forward or backwards.