Esempio n. 1
0
 /** Update the content of the file */
 public function Insert($append = false)
 {
     if (!$this->BuildId || !is_numeric($this->BuildId)) {
         add_log('BuildId not set', 'CoverageFileLog::Insert()', LOG_ERR, 0, $this->BuildId, CDASH_OBJECT_COVERAGE, $this->FileId);
         return false;
     }
     if (!$this->FileId || !is_numeric($this->FileId)) {
         add_log('FileId not set', 'CoverageFileLog::Insert()', LOG_ERR, 0, $this->BuildId, CDASH_OBJECT_COVERAGE, $this->FileId);
         return false;
     }
     pdo_begin_transaction();
     $update = false;
     if ($append) {
         // Load any previously existing results for this file & build.
         $update = $this->Load(true);
     }
     $log = '';
     foreach ($this->Lines as $lineNumber => $code) {
         $log .= $lineNumber . ':' . $code . ';';
     }
     foreach ($this->Branches as $lineNumber => $code) {
         $log .= 'b' . $lineNumber . ':' . $code . ';';
     }
     if ($log != '') {
         if ($update) {
             $sql_command = 'UPDATE';
             $sql = "UPDATE coveragefilelog SET log='{$log}'\n                WHERE buildid=" . qnum($this->BuildId) . ' AND
             fileid=' . qnum($this->FileId);
         } else {
             $sql_command = 'INSERT';
             $sql = 'INSERT INTO coveragefilelog (buildid,fileid,log) VALUES ';
             $sql .= '(' . qnum($this->BuildId) . ',' . qnum($this->FileId) . ",'" . $log . "')";
         }
         pdo_query($sql);
         add_last_sql_error("CoverageFileLog::{$sql_command}()");
     }
     pdo_commit();
     $this->UpdateAggregate();
     return true;
 }
Esempio n. 2
0
function GetNextSubmission($projectid)
{
    $now_utc = gmdate(FMT_DATETIMESTD);
    // Avoid a race condition when parallel processing.
    pdo_begin_transaction();
    // Get the next submission to process.
    $query_array = pdo_single_row_query("SELECT id, filename, filesize, filemd5sum, attempts\n            FROM submission\n            WHERE projectid='{$projectid}' AND status=0\n            ORDER BY id LIMIT 1 FOR UPDATE");
    add_last_sql_error('GetNextSubmission-1');
    if ($query_array === false || !array_key_exists('id', $query_array)) {
        pdo_rollback();
        return false;
    }
    $submission_id = $query_array['id'];
    $new_attempts = $query_array['attempts'] + 1;
    // Mark it as status=1 (processing) and record started time.
    pdo_query("UPDATE submission SET status=1, started='{$now_utc}', " . "lastupdated='{$now_utc}', attempts={$new_attempts} " . "WHERE id='" . $submission_id . "'");
    add_last_sql_error('GetNextSubmission-2');
    pdo_commit();
    return $query_array;
}
Esempio n. 3
0
 /** Insert a new summary */
 public function Insert($append = false)
 {
     if (!$this->BuildId || !is_numeric($this->BuildId)) {
         echo 'CoverageSummary::Insert(): BuildId not set';
         return false;
     }
     // Add the coverages
     // Construct the SQL query
     if (count($this->Coverages) > 0) {
         $sql = 'INSERT INTO coverage (buildid,fileid,covered,loctested,locuntested,branchstested,branchsuntested,
             functionstested,functionsuntested) VALUES ';
         $i = 0;
         foreach ($this->Coverages as &$coverage) {
             $fullpath = $coverage->CoverageFile->FullPath;
             // GcovTarHandler creates its own coveragefiles, no need to do
             // it again here.
             $fileid = -1;
             if (!empty($coverage->CoverageFile->Crc32)) {
                 $fileid = $coverage->CoverageFile->Id;
             }
             if ($fileid === -1) {
                 // Check if this file already exists in the database.
                 // This could happen if CoverageLog.xml was parsed before Coverage.xml.
                 $coveragefile = pdo_query("SELECT id FROM coveragefile AS cf\n                    INNER JOIN coveragefilelog AS cfl ON (cfl.fileid=cf.id)\n                    WHERE cf.fullpath='{$fullpath}' AND cfl.buildid='{$this->BuildId}'");
                 if (pdo_num_rows($coveragefile) == 0) {
                     // Create an empty file if doesn't exist.
                     pdo_query("INSERT INTO coveragefile (fullpath) VALUES ('{$fullpath}')");
                     $fileid = pdo_insert_id('coveragefile');
                 } else {
                     $coveragefile_array = pdo_fetch_array($coveragefile);
                     $fileid = $coveragefile_array['id'];
                 }
                 $coverage->CoverageFile->Id = $fileid;
             }
             $covered = $coverage->Covered;
             $loctested = $coverage->LocTested;
             $locuntested = $coverage->LocUntested;
             $branchstested = $coverage->BranchesTested;
             $branchsuntested = $coverage->BranchesUntested;
             $functionstested = $coverage->FunctionsTested;
             $functionsuntested = $coverage->FunctionsUntested;
             if (empty($covered)) {
                 $covered = 0;
             }
             if (empty($loctested)) {
                 $loctested = 0;
             }
             if (empty($locuntested)) {
                 $locuntested = 0;
             }
             if (empty($branchstested)) {
                 $branchstested = 0;
             }
             if (empty($branchsuntested)) {
                 $branchsuntested = 0;
             }
             if (empty($functionstested)) {
                 $functionstested = 0;
             }
             if (empty($functionsuntested)) {
                 $functionsuntested = 0;
             }
             $this->LocTested += $loctested;
             $this->LocUntested += $locuntested;
             if ($append) {
                 // UPDATE (instead of INSERT) if this coverage already
                 // exists.
                 pdo_begin_transaction();
                 $row = pdo_single_row_query('SELECT * FROM coverage
                         WHERE buildid=' . qnum($this->BuildId) . ' AND
                         fileid=' . qnum($coverage->CoverageFile->Id) . '
                         FOR UPDATE');
                 if ($row && array_key_exists('1', $row)) {
                     $query = 'UPDATE coverage SET
                         covered=' . qnum($covered) . ',
                         loctested=' . qnum($loctested) . ',
                         locuntested=' . qnum($locuntested) . ',
                         branchstested=' . qnum($branchstested) . ',
                         branchsuntested=' . qnum($branchsuntested) . ',
                         functionstested=' . qnum($functionstested) . ',
                         functionsuntested=' . qnum($functionsuntested) . '
                         WHERE buildid=' . qnum($this->BuildId) . ' AND
                         fileid=' . qnum($coverage->CoverageFile->Id);
                     if (!pdo_query($query)) {
                         add_last_sql_error('CoverageSummary Update Coverage');
                         pdo_rollback();
                         return false;
                     }
                     pdo_commit();
                     continue;
                 }
                 pdo_commit();
             }
             if ($i > 0) {
                 $sql .= ', ';
             } else {
                 $i = 1;
             }
             $sql .= '(' . qnum($this->BuildId) . ',' . qnum($fileid) . ',' . qnum($covered) . ',' . qnum($loctested) . ',' . qnum($locuntested) . ',
                 ' . qnum($branchstested) . ',' . qnum($branchsuntested) . ',' . qnum($functionstested) . ',' . qnum($functionsuntested) . ')';
         }
         if ($i > 0) {
             // Insert into coverage
             if (!pdo_query($sql)) {
                 add_last_sql_error('CoverageSummary Insert Coverage');
                 return false;
             }
         }
         // Add labels
         foreach ($this->Coverages as &$coverage) {
             $coverage->InsertLabelAssociations($this->BuildId);
         }
     }
     $summary_updated = false;
     if ($append) {
         // Check if a coveragesummary already exists for this build.
         pdo_begin_transaction();
         $row = pdo_single_row_query('SELECT loctested, locuntested FROM coveragesummary
                 WHERE buildid=' . qnum($this->BuildId) . '
                 FOR UPDATE');
         if ($row && array_key_exists('loctested', $row)) {
             $previous_loctested = $row['loctested'];
             $previous_locuntested = $row['locuntested'];
             // Recompute how many lines were tested & untested
             // based on all files covered by this build.
             $this->LocTested = 0;
             $this->LocUntested = 0;
             $query = 'SELECT loctested, locuntested FROM coverage
                 WHERE buildid=' . qnum($this->BuildId);
             $results = pdo_query($query);
             if (!$results) {
                 add_last_sql_error('CoverageSummary:GetExistingCoverage');
                 pdo_rollback();
                 return false;
             }
             while ($row = pdo_fetch_array($results)) {
                 $this->LocTested += $row['loctested'];
                 $this->LocUntested += $row['locuntested'];
             }
             // Update the existing record with this information.
             $query = 'UPDATE coveragesummary SET
                 loctested=' . qnum($this->LocTested) . ',
                 locuntested=' . qnum($this->LocUntested) . '
                 WHERE buildid=' . qnum($this->BuildId);
             if (!pdo_query($query)) {
                 add_last_sql_error('CoverageSummary Update');
                 pdo_rollback();
                 return false;
             }
             $summary_updated = true;
             // Record how loctested and locuntested changed as a result
             // of this update.
             $delta_tested = $this->LocTested - $previous_loctested;
             $delta_untested = $this->LocUntested - $previous_locuntested;
         }
         pdo_commit();
     }
     if (!$summary_updated) {
         $query = 'INSERT INTO coveragesummary
             (buildid,loctested,locuntested)
             VALUES (' . qnum($this->BuildId) . ',' . qnum($this->LocTested) . ',' . qnum($this->LocUntested) . ')';
         if (!pdo_query($query)) {
             add_last_sql_error('CoverageSummary Insert');
             return false;
         }
     }
     // If this is a child build then update the parent's summary as well.
     $parent = pdo_single_row_query('SELECT parentid FROM build WHERE id=' . qnum($this->BuildId));
     if ($parent && array_key_exists('parentid', $parent)) {
         $parentid = $parent['parentid'];
         if ($parentid > 0) {
             pdo_begin_transaction();
             $exists = pdo_query('SELECT * FROM coveragesummary
                     WHERE buildid=' . qnum($parentid) . '
                     FOR UPDATE');
             if (pdo_num_rows($exists) == 0) {
                 $query = 'INSERT INTO coveragesummary
                     (buildid,loctested,locuntested)
                     VALUES
                     (' . qnum($parentid) . ',' . qnum($this->LocTested) . ',' . qnum($this->LocUntested) . ')';
             } else {
                 if (!isset($delta_tested)) {
                     $delta_tested = $this->LocTested;
                 }
                 if (!isset($delta_untested)) {
                     $delta_untested = $this->LocUntested;
                 }
                 $query = 'UPDATE coveragesummary SET
                     loctested = loctested + ' . qnum($delta_tested) . ',
                     locuntested = locuntested + ' . qnum($delta_untested) . '
                         WHERE buildid=' . qnum($parentid);
             }
             if (!pdo_query($query)) {
                 add_last_sql_error('CoverageSummary Parent Update');
                 pdo_rollback();
                 return false;
             }
             pdo_commit();
         }
     }
     return true;
 }
Esempio n. 4
0
 public function Insert()
 {
     if (strlen($this->BuildId) == 0 || !is_numeric($this->BuildId)) {
         echo 'BuildUpdate:Insert BuildId not set';
         return false;
     }
     // Avoid a race condition when parallel processing.
     pdo_begin_transaction();
     $buildid = qnum($this->BuildId);
     // Check if this update already exists.
     $query = pdo_query("SELECT updateid FROM build2update\n              WHERE buildid={$buildid} FOR UPDATE");
     $exists = pdo_num_rows($query) == 1;
     if ($exists) {
         $query_array = pdo_fetch_array($query);
         $this->UpdateId = $query_array['updateid'];
         $updateid = qnum($this->UpdateId);
     }
     // Remove previous updates
     if ($exists && !$this->Append) {
         // Parent builds share updates with their children.
         // So if this is a parent build remove any build2update rows
         // from the children here.
         pdo_query("DELETE FROM build2update WHERE buildid IN\n                (SELECT id FROM build WHERE parentid={$buildid})");
         // If the buildupdate and updatefile are not shared
         // we delete them as well.
         $query = pdo_query("SELECT buildid FROM build2update WHERE updateid={$updateid}");
         if (pdo_num_rows($query) == 1) {
             $query = "DELETE FROM buildupdate WHERE id={$updateid}";
             if (!pdo_query($query)) {
                 add_last_sql_error('BuildUpdate Delete', 0, $this->BuildId);
                 pdo_rollback();
                 return false;
             }
             $query = "DELETE FROM updatefile WHERE updateid={$updateid}";
             if (!pdo_query($query)) {
                 add_last_sql_error('BuildUpdate Delete updatefil', 0, $this->BuildId);
                 pdo_rollback();
                 return false;
             }
         }
         $query = "DELETE FROM build2update WHERE buildid={$buildid}";
         if (!pdo_query($query)) {
             add_last_sql_error('Build2Update Delete', 0, $this->BuildId);
             pdo_rollback();
             return false;
         }
         $exists = false;
         $this->UpdateId = '';
         $updateid = '';
     }
     if (!$exists) {
         $this->StartTime = pdo_real_escape_string($this->StartTime);
     }
     $this->EndTime = pdo_real_escape_string($this->EndTime);
     $this->Command = pdo_real_escape_string($this->Command);
     $this->Type = pdo_real_escape_string($this->Type);
     if (strlen($this->Type) > 4) {
         $this->Type = 'NA';
     }
     $this->Status = pdo_real_escape_string($this->Status);
     $this->Revision = pdo_real_escape_string($this->Revision);
     $this->PriorRevision = pdo_real_escape_string($this->PriorRevision);
     $this->Path = pdo_real_escape_string($this->Path);
     $nfiles = count($this->Files);
     $nwarnings = 0;
     foreach ($this->Files as $file) {
         if ($file->Author == 'Local User' && $file->Revision == -1) {
             $nwarnings++;
         }
     }
     if (!$exists) {
         $query = "INSERT INTO buildupdate\n              (starttime,endtime,command,type,status,nfiles,warnings,\n               revision,priorrevision,path)\n              VALUES ('{$this->StartTime}','{$this->EndTime}','{$this->Command}',\n                      '{$this->Type}','{$this->Status}',{$nfiles},{$nwarnings},\n                      '{$this->Revision}','{$this->PriorRevision}','{$this->Path}')";
         if (!pdo_query($query)) {
             add_last_sql_error('BuildUpdate Insert', 0, $this->BuildId);
             pdo_rollback();
             return false;
         }
         $this->UpdateId = pdo_insert_id('buildupdate');
         $updateid = qnum($this->UpdateId);
         $query = "INSERT INTO build2update (buildid,updateid)\n              VALUES ({$buildid},{$updateid})\n              {$this->DuplicateSQL}";
         if (!pdo_query($query)) {
             add_last_sql_error('Build2Update Insert', 0, $this->BuildId);
             pdo_rollback();
             return false;
         }
         // If this is a parent build, make sure that all of its children
         // are also associated with a buildupdate.
         $query = "\n        INSERT INTO build2update (buildid,updateid)\n        SELECT id, '{$this->UpdateId}' FROM build\n        LEFT JOIN build2update ON build.id = build2update.buildid\n        WHERE build2update.buildid IS NULL\n        and build.parentid={$buildid}";
         if (!pdo_query($query)) {
             add_last_sql_error('BuildUpdate Child Insert', 0, $this->BuildId);
             pdo_rollback();
             return false;
         }
     } else {
         $nwarnings += $this->GetNumberOfWarnings();
         $nfiles += $this->GetNumberOfFiles();
         include 'config/config.php';
         if ($CDASH_DB_TYPE == 'pgsql') {
             // pgsql doesn't have concat...
             $query = "UPDATE buildupdate SET\n                  endtime='{$this->EndTime}'," . "command=command || '{$this->Command}',\n                  status='{$this->Status}'," . "nfiles='{$nfiles}',warnings='{$nwarnings}'" . "WHERE id={$updateid}";
         } else {
             $query = "UPDATE buildupdate SET\n                  endtime='{$this->EndTime}',\n                  command=CONCAT(command, '{$this->Command}'),\n                  status='{$this->Status}',\n                  nfiles='{$nfiles}',\n                  warnings='{$nwarnings}'\n                      WHERE id={$updateid}";
         }
         if (!pdo_query($query)) {
             add_last_sql_error('BuildUpdate Update', 0, $this->BuildId);
             pdo_rollback();
             return false;
         }
     }
     foreach ($this->Files as $file) {
         $file->UpdateId = $this->UpdateId;
         $file->Insert();
     }
     pdo_commit();
     return true;
 }
Esempio n. 5
0
 /**
  * Update the tally of configure errors & warnings for this build's
  * parent.
  **/
 public function UpdateParentConfigureNumbers($newWarnings, $newErrors)
 {
     $this->SetParentId($this->LookupParentBuildId());
     if ($this->ParentId < 1) {
         return;
     }
     // Avoid a race condition when parallel processing.
     pdo_begin_transaction();
     $numErrors = 0;
     $numWarnings = 0;
     $parent = pdo_single_row_query('SELECT configureerrors, configurewarnings
             FROM build WHERE id=' . qnum($this->ParentId) . ' FOR UPDATE');
     // Don't let the -1 default value screw up our math.
     if ($parent['configureerrors'] == -1) {
         $parent['configureerrors'] = 0;
     }
     if ($parent['configurewarnings'] == -1) {
         $parent['configurewarnings'] = 0;
     }
     $numErrors = $newErrors + $parent['configureerrors'];
     $numWarnings = $newWarnings + $parent['configurewarnings'];
     pdo_query("UPDATE build SET configureerrors='{$numErrors}',\n                configurewarnings='{$numWarnings}'\n                WHERE id=" . qnum($this->ParentId));
     add_last_sql_error('Build:UpdateParentConfigureNumbers', $this->ProjectId, $this->Id);
     pdo_commit();
 }