original_string: public static function getArchiveData($archiveIds, $recordNames, $archiveDataType, $idSubtable)
      {
          $chunk = new Chunk();
  
          // create the SQL to select archive data
          $loadAllSubtables = $idSubtable == Archive::ID_SUBTABLE_LOAD_ALL_SUBTABLES;
          if ($loadAllSubtables) {
              $name = reset($recordNames);
  
              // select blobs w/ name like "$name_[0-9]+" w/o using RLIKE
              $nameEnd = strlen($name) + 1;
              $nameEndAppendix = $nameEnd + 1;
              $appendix = $chunk->getAppendix();
              $lenAppendix = strlen($appendix);
  
              $checkForChunkBlob  = "SUBSTRING(name, $nameEnd, $lenAppendix) = '$appendix'";
              $checkForSubtableId = "(SUBSTRING(name, $nameEndAppendix, 1) >= '0'
                                      AND SUBSTRING(name, $nameEndAppendix, 1) <= '9')";
  
              $whereNameIs = "(name = ? OR (name LIKE ? AND ( $checkForChunkBlob OR $checkForSubtableId ) ))";
              $bind = array($name, $name . '%');
          } else {
              if ($idSubtable === null) {
                  // select root table or specific record names
                  $bind = array_values($recordNames);
              } else {
                  // select a subtable id
                  $bind = array();
                  foreach ($recordNames as $recordName) {
                      // to be backwards compatibe we need to look for the exact idSubtable blob and for the chunk
                      // that stores the subtables (a chunk stores many blobs in one blob)
                      $bind[] = $chunk->getRecordNameForTableId($recordName, $idSubtable);
                      $bind[] = self::appendIdSubtable($recordName, $idSubtable);
                  }
              }
  
              $inNames     = Common::getSqlStringFieldsArray($bind);
              $whereNameIs = "name IN ($inNames)";
          }
  
          $getValuesSql = "SELECT value, name, idsite, date1, date2, ts_archived
                                  FROM %s
                                  WHERE idarchive IN (%s)
                                    AND " . $whereNameIs;
  
          // get data from every table we're querying
          $rows = array();
          foreach ($archiveIds as $period => $ids) {
              if (empty($ids)) {
                  throw new Exception("Unexpected: id archive not found for period '$period' '");
              }
  
              // $period = "2009-01-04,2009-01-04",
              $date = Date::factory(substr($period, 0, 10));
  
              $isNumeric = $archiveDataType == 'numeric';
              if ($isNumeric) {
                  $table = ArchiveTableCreator::getNumericTable($date);
              } else {
                  $table = ArchiveTableCreator::getBlobTable($date);
              }
  
              $sql      = sprintf($getValuesSql, $table, implode(',', $ids));
              $dataRows = Db::fetchAll($sql, $bind);
  
              foreach ($dataRows as $row) {
                  if ($isNumeric) {
                      $rows[] = $row;
                  } else {
                      $row['value'] = self::uncompress($row['value']);
  
                      if ($chunk->isRecordNameAChunk($row['name'])) {
                          self::moveChunkRowToRows($rows, $row, $chunk, $loadAllSubtables, $idSubtable);
                      } else {
                          $rows[] = $row;
                      }
                  }
              }
          }
  
          return $rows;
      }
code: public static function getArchiveData($archiveIds, $recordNames, $archiveDataType, $idSubtable)
      {
          $chunk = new Chunk();
  
          // create the SQL to select archive data
          $loadAllSubtables = $idSubtable == Archive::ID_SUBTABLE_LOAD_ALL_SUBTABLES;
          if ($loadAllSubtables) {
              $name = reset($recordNames);
  
              // select blobs w/ name like "$name_[0-9]+" w/o using RLIKE
              $nameEnd = strlen($name) + 1;
              $nameEndAppendix = $nameEnd + 1;
              $appendix = $chunk->getAppendix();
              $lenAppendix = strlen($appendix);
  
              $checkForChunkBlob  = "SUBSTRING(name, $nameEnd, $lenAppendix) = '$appendix'";
              $checkForSubtableId = "(SUBSTRING(name, $nameEndAppendix, 1) >= '0'
                                      AND SUBSTRING(name, $nameEndAppendix, 1) <= '9')";
  
              $whereNameIs = "(name = ? OR (name LIKE ? AND ( $checkForChunkBlob OR $checkForSubtableId ) ))";
              $bind = array($name, $name . '%');
          } else {
              if ($idSubtable === null) {
                  // select root table or specific record names
                  $bind = array_values($recordNames);
              } else {
                  // select a subtable id
                  $bind = array();
                  foreach ($recordNames as $recordName) {
                      // to be backwards compatibe we need to look for the exact idSubtable blob and for the chunk
                      // that stores the subtables (a chunk stores many blobs in one blob)
                      $bind[] = $chunk->getRecordNameForTableId($recordName, $idSubtable);
                      $bind[] = self::appendIdSubtable($recordName, $idSubtable);
                  }
              }
  
              $inNames     = Common::getSqlStringFieldsArray($bind);
              $whereNameIs = "name IN ($inNames)";
          }
  
          $getValuesSql = "SELECT value, name, idsite, date1, date2, ts_archived
                                  FROM %s
                                  WHERE idarchive IN (%s)
                                    AND " . $whereNameIs;
  
          // get data from every table we're querying
          $rows = array();
          foreach ($archiveIds as $period => $ids) {
              if (empty($ids)) {
                  throw new Exception("Unexpected: id archive not found for period '$period' '");
              }
  
              // $period = "2009-01-04,2009-01-04",
              $date = Date::factory(substr($period, 0, 10));
  
              $isNumeric = $archiveDataType == 'numeric';
              if ($isNumeric) {
                  $table = ArchiveTableCreator::getNumericTable($date);
              } else {
                  $table = ArchiveTableCreator::getBlobTable($date);
              }
  
              $sql      = sprintf($getValuesSql, $table, implode(',', $ids));
              $dataRows = Db::fetchAll($sql, $bind);
  
              foreach ($dataRows as $row) {
                  if ($isNumeric) {
                      $rows[] = $row;
                  } else {
                      $row['value'] = self::uncompress($row['value']);
  
                      if ($chunk->isRecordNameAChunk($row['name'])) {
                          self::moveChunkRowToRows($rows, $row, $chunk, $loadAllSubtables, $idSubtable);
                      } else {
                          $rows[] = $row;
                      }
                  }
              }
          }
  
          return $rows;
      }
code_tokens: public static function getArchiveData ( $ archiveIds , $ recordNames , $ archiveDataType , $ idSubtable ) { $ chunk = new Chunk ( ) ; // create the SQL to select archive data $ loadAllSubtables = $ idSubtable == Archive :: ID_SUBTABLE_LOAD_ALL_SUBTABLES ; if ( $ loadAllSubtables ) { $ name = reset ( $ recordNames ) ; // select blobs w/ name like "$name_[0-9]+" w/o using RLIKE $ nameEnd = strlen ( $ name ) + 1 ; $ nameEndAppendix = $ nameEnd + 1 ; $ appendix = $ chunk -> getAppendix ( ) ; $ lenAppendix = strlen ( $ appendix ) ; $ checkForChunkBlob = "SUBSTRING(name, $nameEnd, $lenAppendix) = '$appendix'" ; $ checkForSubtableId = "(SUBSTRING(name, $nameEndAppendix, 1) >= '0'
                                      AND SUBSTRING(name, $nameEndAppendix, 1) <= '9')" ; $ whereNameIs = "(name = ? OR (name LIKE ? AND ( $checkForChunkBlob OR $checkForSubtableId ) ))" ; $ bind = array ( $ name , $ name . '%' ) ; } else { if ( $ idSubtable === null ) { // select root table or specific record names $ bind = array_values ( $ recordNames ) ; } else { // select a subtable id $ bind = array ( ) ; foreach ( $ recordNames as $ recordName ) { // to be backwards compatibe we need to look for the exact idSubtable blob and for the chunk // that stores the subtables (a chunk stores many blobs in one blob) $ bind [ ] = $ chunk -> getRecordNameForTableId ( $ recordName , $ idSubtable ) ; $ bind [ ] = self :: appendIdSubtable ( $ recordName , $ idSubtable ) ; } } $ inNames = Common :: getSqlStringFieldsArray ( $ bind ) ; $ whereNameIs = "name IN ($inNames)" ; } $ getValuesSql = "SELECT value, name, idsite, date1, date2, ts_archived
                                  FROM %s
                                  WHERE idarchive IN (%s)
                                    AND " . $ whereNameIs ; // get data from every table we're querying $ rows = array ( ) ; foreach ( $ archiveIds as $ period => $ ids ) { if ( empty ( $ ids ) ) { throw new Exception ( "Unexpected: id archive not found for period '$period' '" ) ; } // $period = "2009-01-04,2009-01-04", $ date = Date :: factory ( substr ( $ period , 0 , 10 ) ) ; $ isNumeric = $ archiveDataType == 'numeric' ; if ( $ isNumeric ) { $ table = ArchiveTableCreator :: getNumericTable ( $ date ) ; } else { $ table = ArchiveTableCreator :: getBlobTable ( $ date ) ; } $ sql = sprintf ( $ getValuesSql , $ table , implode ( ',' , $ ids ) ) ; $ dataRows = Db :: fetchAll ( $ sql , $ bind ) ; foreach ( $ dataRows as $ row ) { if ( $ isNumeric ) { $ rows [ ] = $ row ; } else { $ row [ 'value' ] = self :: uncompress ( $ row [ 'value' ] ) ; if ( $ chunk -> isRecordNameAChunk ( $ row [ 'name' ] ) ) { self :: moveChunkRowToRows ( $ rows , $ row , $ chunk , $ loadAllSubtables , $ idSubtable ) ; } else { $ rows [ ] = $ row ; } } } } return $ rows ; }
docstring: Queries and returns archive data using a set of archive IDs.
  
  @param array $archiveIds The IDs of the archives to get data from.
  @param array $recordNames The names of the data to retrieve (ie, nb_visits, nb_actions, etc.).
  Note: You CANNOT pass multiple recordnames if $loadAllSubtables=true.
  @param string $archiveDataType The archive data type (either, 'blob' or 'numeric').
  @param int|null|string $idSubtable  null if the root blob should be loaded, an integer if a subtable should be
  loaded and 'all' if all subtables should be loaded.
  @throws Exception
  @return array
docstring_tokens: Queries and returns archive data using a set of archive IDs .