コード例 #1
0
ファイル: Query.php プロジェクト: vrtulka23/daiquiri
 /**
  * Querys the database with a plain text query.
  * @param string $sql the sql string
  * @param bool $plan flag for plan creation
  * @param string $table result table
  * @param array $options for further options that are handeled by the queue
  * @return array $response 
  */
 public function query($sql, $plan = false, $table, $options = array())
 {
     // init error array
     $errors = array();
     // check if there is a name for the new table
     if (empty($table)) {
         $tablename = false;
     } else {
         $tablename = $table;
     }
     // get group of the user
     $usrGrp = Daiquiri_Auth::getInstance()->getCurrentRole();
     if ($usrGrp !== null) {
         $options['usrGrp'] = $usrGrp;
     } else {
         $options['usrGrp'] = "guest";
     }
     // if plan type direct, obtain query plan
     if ($this->_processor->supportsPlanType("QPROC_SIMPLE") === true and $plan === false) {
         $plan = $this->_processor->getPlan($sql, $errors);
         if (!empty($errors)) {
             return array('status' => 'error', 'errors' => $errors);
         }
     } else {
         // if plan type is AlterPlan and no plan is available, throw error
         if ($this->_processor->supportsPlanType("QPROC_ALTERPLAN") === true and $plan === false) {
             $errors['planError'] = 'Query plan required. If you end up here, something went badly wrong';
             return array('status' => 'error', 'errors' => $errors);
         }
         // split plan into lines
         $processing = new Query_Model_Resource_Processing();
         $noMultilineCommentSQL = $processing->removeMultilineComments($plan);
         $multiLines = $processing->splitQueryIntoMultiline($noMultilineCommentSQL, $errors);
         $plan = $multiLines;
     }
     // process sql string
     $job = $this->_processor->query($sql, $errors, $plan, $tablename);
     if (!empty($errors)) {
         return array('status' => 'error', 'errors' => $errors);
     }
     // before submission, see if user has enough quota
     if ($this->_checkQuota($this->_queue, $usrGrp)) {
         $errors['quotaError'] = 'Your quota has been reached. Drop some tables to free space or contact the administrators';
         return array('status' => 'error', 'errors' => $errors);
     }
     // submit job
     $statusId = $this->_queue->submitJob($job, $errors, $options);
     if (!empty($errors)) {
         return array('status' => 'error', 'errors' => $errors);
     }
     // return with success
     return array('status' => 'ok', 'job' => $job);
 }