/**
  * Executes a prepared statement.
  *
  * Returns a boolean value indicating success.
  * Overridden for query counting and logging.
  *
  * @param  string  $parameters
  * @return boolean
  */
 public function execute($parameters = null)
 {
     $return = $this->statement->execute($parameters);
     if ($this->connection->useDebug) {
         $sql = $this->getExecutedQueryString();
         $this->connection->log($sql);
         $this->connection->setLastExecutedQuery($sql);
         $this->connection->incrementQueryCount();
     }
     return $return;
 }
Beispiel #2
0
 public function build($dsn = null, $user = null, $pass = null, $adapter = null)
 {
     if (null === $dsn) {
         $dsn = 'sqlite::memory:';
     }
     if (null === $adapter) {
         $adapter = new \Propel\Runtime\Adapter\Pdo\SqliteAdapter();
     }
     $pdo = new PdoConnection($dsn, $user, $pass);
     $con = new ConnectionWrapper($pdo);
     $con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
     $this->buildSQL($con);
     $this->buildClasses();
     $name = $this->getDatabase()->getName();
     Propel::getServiceContainer()->setAdapter($name, $adapter);
     Propel::getServiceContainer()->setConnection($name, $con);
     return $con;
 }
Beispiel #3
0
 public function build($dsn = null, $user = null, $pass = null, $adapter = null, array $classTargets = null)
 {
     if (null === $dsn) {
         $dsn = 'sqlite::memory:';
     }
     if (null === $adapter) {
         $adapter = new SqliteAdapter();
     }
     if (null === $classTargets) {
         $classTargets = $this->classTargets;
     }
     $pdo = new PdoConnection($dsn, $user, $pass);
     $con = new ConnectionWrapper($pdo);
     $con->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_WARNING);
     $adapter->initConnection($con, []);
     $this->buildSQL($con);
     $this->buildClasses($classTargets);
     $name = $this->getDatabase()->getName();
     Propel::getServiceContainer()->setAdapter($name, $adapter);
     Propel::getServiceContainer()->setConnection($name, $con);
     return $con;
 }
Beispiel #4
0
 protected function checkMySQLConfigurations(ConnectionWrapper $con)
 {
     // todo add cache for this test
     $result = $con->query("SELECT VERSION() as version, @@SESSION.sql_mode as session_sql_mode");
     if ($result && ($data = $result->fetch(\PDO::FETCH_ASSOC))) {
         $sessionSqlMode = explode(',', $data['session_sql_mode']);
         if (empty($sessionSqlMode[0])) {
             unset($sessionSqlMode[0]);
         }
         $canUpdate = false;
         // MariaDB is not impacted by this problem
         if (false === strpos($data['version'], 'MariaDB')) {
             // MySQL 5.6+ compatibility
             if (version_compare($data['version'], '5.6.0', '>=')) {
                 // add NO_ENGINE_SUBSTITUTION
                 if (!in_array('NO_ENGINE_SUBSTITUTION', $sessionSqlMode)) {
                     $sessionSqlMode[] = 'NO_ENGINE_SUBSTITUTION';
                     $canUpdate = true;
                     Tlog::getInstance()->addWarning("Add sql_mode NO_ENGINE_SUBSTITUTION. Please configure your MySQL server.");
                 }
                 // remove STRICT_TRANS_TABLES
                 if (($key = array_search('STRICT_TRANS_TABLES', $sessionSqlMode)) !== false) {
                     unset($sessionSqlMode[$key]);
                     $canUpdate = true;
                     Tlog::getInstance()->addWarning("Remove sql_mode STRICT_TRANS_TABLES. Please configure your MySQL server.");
                 }
                 // remove ONLY_FULL_GROUP_BY
                 if (($key = array_search('ONLY_FULL_GROUP_BY', $sessionSqlMode)) !== false) {
                     unset($sessionSqlMode[$key]);
                     $canUpdate = true;
                     Tlog::getInstance()->addWarning("Remove sql_mode ONLY_FULL_GROUP_BY. Please configure your MySQL server.");
                 }
             }
         }
         if (!empty($canUpdate)) {
             if (null === $con->query("SET SESSION sql_mode='" . implode(',', $sessionSqlMode) . "';")) {
                 throw new \RuntimeException('Failed to set MySQL global and session sql_mode');
             }
         }
     } else {
         Tlog::getInstance()->addWarning("Failed to get MySQL version and sql_mode");
     }
 }
 /**
  * {@inheritDoc}
  */
 public function log($msg)
 {
     if ($this->isSlowOnly && !$this->getProfiler()->isSlow()) {
         return;
     }
     $msg = $this->getProfiler()->getProfile() . $msg;
     return parent::log($msg);
 }
 /**
  * Logs the method call or SQL using the Propel::log() method or a registered logger class.
  *
  * @uses      self::getLogPrefix()
  * @see       self::setLogger()
  *
  * @param     string   $msg  Message to log.
  * @param     integer  $level  Log level to use; will use self::setLogLevel() specified level by default.
  * @param     string   $methodName  Name of the method whose execution is being logged.
  * @param     array    $debugSnapshot  Previous return value from self::getDebugSnapshot().
  */
 public function log($msg, $level = null, $methodName = null)
 {
     if ($this->isSlowOnly && !$this->getProfiler()->isSlow()) {
         return;
     }
     $msg = $this->getProfiler()->getProfile() . $msg;
     return parent::log($msg, $level, $methodName);
 }
Beispiel #7
0
 /**
  * Creates a Connection instance.
  *
  * @param \Propel\Runtime\Connection\ConnectionInterface $connection
  */
 public function __construct(ConnectionInterface $connection)
 {
     $connection = new TraceablePDO($connection);
     parent::__construct($connection);
 }