protected function reportException($message, $e) { $this->logger->fatal("{$message}: " . get_class($e)); if ($this->logger->wouldLog('error')) { $this->logger->error($e->getMessage()); } }
/** * Parse SQL with types from sql in the form of "INSERT INTO testPreparedStatement(id, name) VALUES(?int, ?varchar)" * @param string $sql * @param array $lobs names of clob and blob fields from query * @return boolean */ protected function parseSQL($sql, array $lobs = array()) { if (empty($this->DBM)) { $this->log->error("Prepare failed: Database object missing"); return false; } if (empty($sql)) { $this->log->error("Prepare failed: empty SQL statement"); return false; } $this->sqlText = $sql; $this->log->info("Parse Query: {$sql}"); // Build fieldDefs array and replace ?SugarDataType placeholders with a single ?placeholder $cleanedSql = ""; $nextParam = strpos($sql, "?"); if ($nextParam == 0) { $cleanedSql = $sql; } else { // parse the sql string looking for params $row = 0; while ($nextParam > 0) { $cleanedSql .= substr($sql, 0, $nextParam + 1); // we want the ? $sql = substr($sql, $nextParam + 1); // strip leading chars // scan for termination of SugarDataType $sugarDataType = ""; for ($i = 0; $i < strlen($sql) and strpos(",) ", substr($sql, $i, 1)) === false; $i++) { if (strpos(",) ", substr($sql, $i, 1)) == false) { $sugarDataType .= substr($sql, $i, 1); } } if ($sugarDataType === "") { // no type, default to varchar $sugarDataType = 'varchar'; } // insert the fieldDef $this->fieldDefs[$row]['type'] = $sugarDataType; if ($this->DBM->isTextType($sugarDataType)) { if (empty($lobs)) { $this->log->fatal('Name of lob field is not specified: ' . $this->sqlText); return false; } $this->lobFields[$row] = array_shift($lobs); } $sql = substr($sql, $i); // strip off the SugarDataType $nextParam = strpos($sql, "?"); // look for another param $row++; } // add the remaining sql $cleanedSql .= $sql; } $this->parsedSQL = $cleanedSql; return true; }