Example #1
0
 $_T->printFooter(false);
 // The false prevents the footer to actually close the <BODY> and <HTML> tags.
 // Now we're still in the <BODY> so the progress bar can add <SCRIPT> tags as much as it wants.
 flush();
 // Now, start with ALTER TABLE if necessary, since that will take the longest time and ends a transaction anyway.
 // If it fails directly after this, one can always just redo the add. LOVD will detect properly that it needs to be added to the ACTIVE_COLS table, then.
 if (!$zData['active_checked']) {
     $sSQL = 'ALTER TABLE ' . $aTableInfo['table_sql'] . ' ADD COLUMN `' . $zData['id'] . '` ' . $zData['mysql_type'];
     $dStart = time();
     $q = $_DB->exec($sSQL, false);
     if ($q === false) {
         $sError = $_DB->formatError();
         // Save the PDO error before it disappears.
         $tPassed = time() - $dStart;
         $sMessage = $tPassed < 2 ? '' : ' (fail after ' . $tPassed . ' seconds - disk full maybe?)';
         lovd_queryError(LOG_EVENT . $sMessage, $sSQL, $sError);
     }
 }
 $_BAR->setProgress(80);
 $_BAR->setMessage('Enabling column...');
 $_DB->beginTransaction();
 if (!$zData['active']) {
     $sSQL = 'INSERT INTO ' . TABLE_ACTIVE_COLS . ' VALUES (?, ?, NOW())';
     $_DB->query($sSQL, array($zData['id'], $_AUTH['id']));
 }
 // Write to log...
 if (!$zData['active']) {
     lovd_writeLog('Event', LOG_EVENT, 'Added column ' . $zData['id'] . ' (' . $zData['head_column'] . ') to ' . $aTableInfo['table_name'] . ' table');
 }
 $_BAR->setProgress(90);
 $_BAR->setMessage('Registering column settings...');
Example #2
0
 function loadEntry($nID = false)
 {
     // Loads and returns an entry from the database.
     global $_DB, $_T;
     if (empty($nID)) {
         // We were called, but the class wasn't initiated with an ID. Fail.
         lovd_displayError('LOVD-Lib', 'Objects::(' . $this->sObject . ')::loadEntry() - Method didn\'t receive ID');
     }
     if ($this->sSQLPreLoadEntry !== '') {
         // $sSQLPreLoadEntry is defined, execute it.
         $_DB->query($this->sSQLPreLoadEntry);
     }
     // Build query.
     if ($this->sSQLLoadEntry) {
         $sSQL = $this->sSQLLoadEntry;
     } else {
         $sSQL = 'SELECT * FROM ' . constant($this->sTable) . ' WHERE id = ?';
     }
     $q = $_DB->query($sSQL, array($nID), false);
     if ($q) {
         $zData = $q->fetchAssoc();
     }
     if (!$q || !$zData) {
         $sError = $_DB->formatError();
         // Save the PDO error before it disappears.
         $_T->printHeader();
         if (defined('PAGE_TITLE')) {
             $_T->printTitle();
         }
         if ($sError) {
             lovd_queryError($this->sObject . '::loadEntry()', $sSQL, $sError);
         }
         lovd_showInfoTable('No such ID!', 'stop');
         $_T->printFooter();
         exit;
     } else {
         $this->nID = $nID;
     }
     $zData = $this->autoExplode($zData);
     return $zData;
 }
 function loadAll($nID = false)
 {
     // Loads all variantOnTranscript entries from the database.
     global $_DB, $_T;
     if (empty($nID)) {
         // We were called, but the class wasn't initiated with an ID. Fail.
         lovd_displayError('LOVD-Lib', 'Objects::(' . $this->sObject . ')::loadEntry() - Method didn\'t receive ID');
     }
     $q = $_DB->query($this->sSQLLoadEntry, array($nID, $this->sObjectID), false);
     if ($q) {
         $z = $q->fetchAllAssoc();
     }
     if (!$q || !$z) {
         $sError = $_DB->formatError();
         // Save the PDO error before it disappears.
         $_T->printHeader();
         if (defined('PAGE_TITLE')) {
             $_T->printTitle();
         }
         if ($sError) {
             lovd_queryError($this->sObject . '::loadEntry()', $sSQL, $sError);
         }
         lovd_showInfoTable('No such ID!', 'stop');
         $_T->printFooter();
         exit;
     }
     $zData = array();
     foreach ($z as $aVariantOnTranscript) {
         $aVariantOnTranscript = $this->autoExplode($aVariantOnTranscript);
         foreach ($this->aColumns as $sColClean => $aCol) {
             $sCol = $aVariantOnTranscript['transcriptid'] . '_' . $sColClean;
             if ($aCol['form_type'][2] == 'select' && $aCol['form_type'][3] > 1) {
                 $zData[$sCol] = explode(';', $aVariantOnTranscript[$sColClean]);
             } else {
                 $zData[$sCol] = $aVariantOnTranscript[$sColClean];
             }
         }
         $zData[$aVariantOnTranscript['transcriptid'] . '_effectid'] = $aVariantOnTranscript['effectid'];
         $zData[$aVariantOnTranscript['transcriptid'] . '_position_c_start'] = $aVariantOnTranscript['position_c_start'];
         $zData[$aVariantOnTranscript['transcriptid'] . '_position_c_start_intron'] = $aVariantOnTranscript['position_c_start_intron'];
         $zData[$aVariantOnTranscript['transcriptid'] . '_position_c_end'] = $aVariantOnTranscript['position_c_end'];
         $zData[$aVariantOnTranscript['transcriptid'] . '_position_c_end_intron'] = $aVariantOnTranscript['position_c_end_intron'];
     }
     return $zData;
 }
Example #4
0
 $sSQLFailed = '';
 foreach ($aUpdates as $sVersion => $aSQL) {
     $_BAR->setMessage('To ' . $sVersion . '...');
     // Also set update_checked_date to NULL, so LOVD will again check for updates as soon as possible.
     $aSQL[] = 'UPDATE ' . TABLE_STATUS . ' SET version = "' . $sVersion . '", updated_date = NOW(), update_level = 0, update_checked_date = NULL';
     // Loop needed queries...
     foreach ($aSQL as $i => $sSQL) {
         $i++;
         if (!$nSQLFailed) {
             $q = $_DB->query($sSQL, false, false);
             // This means that there is no SQL injection check here. But hey - these are our own queries.
             if (!$q) {
                 $nSQLFailed++;
                 // Error when running query.
                 $sError = $_DB->formatError();
                 lovd_queryError('RunUpgradeSQL', $sSQL, $sError, false);
                 $sSQLFailed = 'Error!<BR><BR>\\n\\n' . 'Error while executing query ' . $i . ':\\n' . '<PRE style="background : #F0F0F0;">' . htmlspecialchars($sError) . '</PRE><BR>\\n\\n' . 'This implies these MySQL queries need to be executed manually:<BR>\\n' . '<PRE style="background : #F0F0F0;">\\n<SPAN style="background : #C0C0C0;">' . sprintf('%' . strlen(count($aSQL)) . 'd', $i) . '</SPAN> ' . htmlspecialchars($sSQL) . ';\\n';
             } else {
                 $nSQLDone++;
                 $nSQLDonePercentage = floor(100 * $nSQLDone / $nSQL);
                 // Don't want to show 100% when an error occurs at 99.5%.
                 if ($nSQLDonePercentage != $nSQLDonePercentagePrev) {
                     $_BAR->setProgress($nSQLDonePercentage);
                     $nSQLDonePercentagePrev = $nSQLDonePercentage;
                 }
                 flush();
                 usleep(1000);
             }
         } else {
             // Something went wrong, so we need to print out the remaining queries...
             $nSQLFailed++;
Example #5
0
File: PDO.php Project: LOVDnl/LOVD3
 function execute($aSQL = array(), $bHalt = true, $bTrim = false)
 {
     // Wrapper around PDOStatement::execute().
     global $_DB;
     try {
         if ($aSQL === (array) $aSQL) {
             // Believe it or not, faster than is_array().
             // lovd_queryDB() allowed the passing of arrays in the arguments.
             foreach ($aSQL as $nKey => $Arg) {
                 if ($Arg === (array) $Arg) {
                     // Believe it or not, faster than is_array().
                     // We handle arrays gracefully.
                     $aSQL[$nKey] = implode(';', $bTrim ? array_map('trim', $Arg) : $Arg);
                 } elseif ($Arg === NULL) {
                     $this->bindValue($nKey + 1, $Arg, PDO::PARAM_INT);
                 } elseif ($bTrim) {
                     $aSQL[$nKey] = trim($aSQL[$nKey]);
                 }
             }
         }
         // There is no else, we will catch the exception thrown by parent::execute().
         parent::execute($aSQL);
     } catch (PDOException $e) {
         // Incorrect SQL, too few parameters, ...
         if ($bHalt) {
             try {
                 @$_DB->rollBack();
                 // In case we were in a transaction. // FIXME; we can know from PHP >= 5.3.3.
             } catch (PDOException $eNoTransaction) {
             }
             // lovd_queryError() will call lovd_displayError() which will halt the system.
             lovd_queryError(defined('LOG_EVENT') ? LOG_EVENT : 'Unknown', $this->queryString, 'Error in PDOStatement::execute() while executing prepared query: ' . $e->getMessage());
         } else {
             return false;
         }
     }
     return true;
 }