Ignore:
Timestamp:
Jul 12, 2023, 9:02:24 PM (16 months ago)
Author:
chronos
Message:
  • Modified: Improved client contract generation.
  • Fixed: SQL query logging into file.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Packages/Common/Database.php

    r929 r951  
    4343  public bool $ShowSQLQuery;
    4444  public bool $LogSQLQuery;
     45  public bool $MeasureDuration;
    4546  public string $LogFile;
    4647  public string $Database;
     
    5657    $this->ShowSQLQuery = false;
    5758    $this->LogSQLQuery = false;
     59    $this->MeasureDuration = false;
    5860    $this->LogFile = dirname(__FILE__).'/../../Query.log';
    5961    $this->Database = '';
     
    9395  {
    9496    if (!$this->Connected()) throw new Exception(T('Not connected to database'));
    95     if (($this->ShowSQLQuery == true) or ($this->LogSQLQuery == true)) $QueryStartTime = microtime_float();
     97    $Duration = '';
     98    if ($this->MeasureDuration)
     99    {
     100      $QueryStartTime = microtime_float();
     101    }
    96102    $this->LastQuery = $Query;
    97     if (($this->ShowSQLQuery == true) or ($this->LogSQLQuery == true))
    98     {
    99       $Time = round(microtime_float() - $QueryStartTime, 4);
    100       $Duration = ' ; '.$Time. ' s';
    101     }
    102     if (($this->LogSQLQuery == true) and ($Time != 0))
    103       file_put_contents($this->LogFile, $Query.$Duration."\n", FILE_APPEND);
    104     if ($this->ShowSQLQuery == true)
    105       echo('<div style="border-bottom-width: 1px; border-bottom-style: solid; '.
    106       'padding-bottom: 3px; padding-top: 3px; font-size: 12px; font-family: Arial;">'.$Query.$Duration.'</div>'."\n");
    107103    $Result = new DatabaseResult();
    108104    $Statement = $this->PDO->query($Query);
     
    119115        echo('<div><strong>SQL Error: </strong>'.$this->Error.'<br />'.$Query.'</div>');
    120116        throw new Exception('SQL Error: '.$this->Error.', Query: '.$Query);
     117    }
     118    if ($this->MeasureDuration)
     119    {
     120      $Time = round(microtime_float() - $QueryStartTime, 4);
     121      $Duration = ' ; '.$Time. ' s';
     122    }
     123    if ($this->ShowSQLQuery == true)
     124    {
     125       echo('<div style="border-bottom-width: 1px; border-bottom-style: solid; '.
     126      'padding-bottom: 3px; padding-top: 3px; font-size: 12px; font-family: Arial;">'.$Query.$Duration.'</div>'."\n");
     127    }
     128    if ($this->LogSQLQuery == true)
     129    {
     130      file_put_contents($this->LogFile, $Query.$Duration."\n", FILE_APPEND);
    121131    }
    122132    return $Result;
Note: See TracChangeset for help on using the changeset viewer.