function execute() { set_error_handler('exception_error_handler'); $results = false; $msg = array('text' => $this->type() == 'SELECT' ? 'no records' : 'no errors', 'type' => 'good'); try { $results = DB::getConn()->query($this->query, E_USER_NOTICE); } catch (Exception $e) { $msg = array('text' => htmlentities($e->getMessage()), 'type' => 'error'); } restore_error_handler(); $fields = new DataObjectSet(); $records = new DataObjectSet(); if (isset($results) && $results instanceof SS_Query) { foreach ($results as $result) { $record = new DBP_Record(); $data = array(); foreach ($result as $field => $val) { if (!$fields->find('Label', $field)) { $fields->push(new DBP_Field($field)); } $data[$field] = strlen($val) > 64 ? substr($val, 0, 63) . '<span class="truncated">…</span>' : $val; } $record->Data($data); $records->push($record); } } return array('Query' => $this->query, 'Fields' => $fields, 'Records' => $records, 'Message' => $msg); }