コード例 #1
0
ファイル: Driver.php プロジェクト: Dren-x/mobit
 /**
  * {@inheritdoc}
  */
 public function connect(array $params, $username = null, $password = null, array $driverOptions = array())
 {
     if (isset($driverOptions['userDefinedFunctions'])) {
         $this->_userDefinedFunctions = array_merge($this->_userDefinedFunctions, $driverOptions['userDefinedFunctions']);
         unset($driverOptions['userDefinedFunctions']);
     }
     try {
         $pdo = new PDOConnection($this->_constructPdoDsn($params), $username, $password, $driverOptions);
     } catch (PDOException $ex) {
         throw DBALException::driverException($this, $ex);
     }
     foreach ($this->_userDefinedFunctions as $fn => $data) {
         $pdo->sqliteCreateFunction($fn, $data['callback'], $data['numArgs']);
     }
     return $pdo;
 }
コード例 #2
0
ファイル: Client.php プロジェクト: xxspartan16/BMS-Market
    /**
     * @TODO: move to "SqlitePlatform" and rename to "registerExtraFunctions"?
     *
     * @param PDOConnection $sqliteConnection
     *
     * @return Client
     */
    private function registerSqliteFunctions(PDOConnection $sqliteConnection)
    {
        $sqliteConnection->sqliteCreateFunction('EXTRACTVALUE', function ($string, $expression) {
            $dom = new \DOMDocument('1.0', 'UTF-8');
            $dom->loadXML($string);
            $xpath = new \DOMXPath($dom);
            $list = $xpath->evaluate($expression);

            if (!is_object($list)) {
                return $list;
            }

            // @TODO: don't know if there are expressions returning more then one row
            if ($list->length > 0) {
                // @TODO: why it can happen that we do not have a type? https://github.com/phpcr/phpcr-api-tests/pull/132
                $type = is_object($list->item(0)->parentNode->attributes->getNamedItem('type'))
                    ? $list->item(0)->parentNode->attributes->getNamedItem('type')->value
                    : null;
                $content = $list->item(0)->textContent;

                switch ($type) {
                    case 'long':
                        return (int) $content;
                        break;
                    case 'double':
                        return (double) $content;
                        break;
                    default:
                        return $content;
                }
            }

            // @TODO: don't know if return value is right
            return null;
        }, 2);

        $sqliteConnection->sqliteCreateFunction('CONCAT', function () {
            return implode('', func_get_args());
        });

        return $this;
    }