Uploaded image for project: 'In-Portal CMS'
  1. In-Portal CMS
  2. INP-1009

Improvements to kDBConnection class (iterator, kDBConnectionDebug class)

    XMLWordPrintable

    Details

    • Type: Feature Request
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 5.2.0-B2
    • Fix Version/s: 5.2.0-B3
    • Component/s: Database
    • Labels:
      None

      Description

      In-Portal has nice kDBConnection class, that we use in every day operations that require database interaction.

      Among all it has following most important methods, that you can use:

      • Query - runs sql statement and returns 2-dimensional array with a results
      • GetRow - runs sql statement and returns first row only as 1-dimensional array
      • GetCol - runs sql statement and returns first field from each resulting row
      • GetOne - runs sql statement and returns first column from first row as a string
        All of above functions work very well when you don't have thousands rows in database tables you operate.

      In case if you have big tables, then idea to create an array of all selected rows inside kDBConnection::Query method (memory allocation #1) and then returning it to calling function (memory allocation #2) isn't a good idea since you get 2x memory allocation as you would normally get when using code from PHP documentation:

      $rs = mysql_query($sql);

      while ( $row = mysql_fetch_array($rs) )

      { ... }

      mysql_free_result($rs);

      To solve this problem I created kDBConnection::GetIterator method, that allocates memory only where you actually iterate the data you get from Query method:

      $rows = $this->Conn->GetIterator($sql);
      $row_count = count($rows);

      foreach ($rows as $index => $row) { ... }

      I also created kDBConnectionDebug class, which is kDBConnection class descendant with Query & GetIterator methods overridden to collect additional statistics while in debug mode. Before kDBConnectionDebug class Query method always called _debugQuery method in first lines of Query method, which was slowing whole DB querying process a bit.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                alex Alex
                Reporter:
                alex Alex
                Developer:
                Alex
              • Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: