Query counter

Wish to see a specific feature/change in future releases? Feel free to post it here, and if it gets enough "likes", we'd definitely include it in future releases!
Post Reply
User avatar
onoehring
AppGini Super Hero
AppGini Super Hero
Posts: 1156
Joined: 2019-05-21 22:42
Location: Germany
Contact:

Query counter

Post by onoehring » 2021-01-11 15:20

Hi,

I would like to have an easier opportunity to get the count of all dabatase queries from time X to time Y. This would make debugging and optimizing sometimes a lot easier.

My suggestion is to set a session variable as a counter and each time the developer uses the sql() or sqlValue() function the counter is increased. The developer can easily reset the counter i.e. clear it in the footer.

Right now I am adding the line

Code: Select all

$_SESSION['countSQLQueries'] ++;
after each line where I am using sql() or sqlValue() which blows up code - and could be omitted easily.

Olaf

pfrumkin
Veteran Member
Posts: 157
Joined: 2020-02-18 17:58
Location: Albuquerque, New Mexico USA

Re: Query counter

Post by pfrumkin » 2021-01-11 17:48

Hi Olaf,

I am not following the value of such a counter. Is it that this way you could tell if your code hit that line to do the query? I add lines of code to write to a file which has several downsides. I am fortunate that our site doesn't have a lot of traffic so these log files don't have contention problems.

Could you implement your own versions of the sql and sqlvalue functions that do the session variable update and make then make the actual sql and sqlvalue calls?

~Paul

User avatar
onoehring
AppGini Super Hero
AppGini Super Hero
Posts: 1156
Joined: 2019-05-21 22:42
Location: Germany
Contact:

Re: Query counter

Post by onoehring » 2021-01-13 07:17

Hi Paul,
Could you implement your own versions of the sql and sqlvalue functions that do the session variable update and make then make the actual sql and sqlvalue calls?
A good idea. Something like this should probably do

Code: Select all

function sqlC($sql, $eo){
  $result = sql($sql, $eo);
  $_SESSION['countSQLQueries'] ++;
  return $result;
}
and

Code: Select all

function sqlValueC($sql){
  $result = sqlValue($sql);
  $_SESSION['countSQLQueries'] ++;
  return $result;
}
PS: I have pages that have hundreds or even thousands of SQL queries to build them. Optimizing and getting a hand on where/what is an issue ;-)

Olaf

Post Reply