From f5f614978061cb291ee8a82a91f8f7b56035208b Mon Sep 17 00:00:00 2001 From: java-tester-x Date: Sat, 23 Mar 2013 18:15:14 +0200 Subject: [PATCH 1/3] Implement support of Oracle driver --- laravel/database/connection.php | 3 + laravel/database/connectors/oracle.php | 56 +++++++ laravel/database/query/grammars/oracle.php | 139 ++++++++++++++++++ laravel/database/schema.php | 3 + laravel/database/schema/grammars/oracle.php | 8 + {public => www}/.htaccess | 0 {public => www}/bundles/.gitignore | 0 {public => www}/css/.gitignore | 0 {public => www}/favicon.ico | 0 {public => www}/img/.gitignore | 0 {public => www}/index.php | 0 {public => www}/js/.gitignore | 0 {public => www}/laravel/css/style.css | 0 {public => www}/laravel/img/logoback.png | Bin .../laravel/js/modernizr-2.5.3.min.js | 0 {public => www}/laravel/js/prettify.js | 0 {public => www}/laravel/js/scroll.js | 0 17 files changed, 209 insertions(+) create mode 100644 laravel/database/connectors/oracle.php create mode 100644 laravel/database/query/grammars/oracle.php create mode 100644 laravel/database/schema/grammars/oracle.php rename {public => www}/.htaccess (100%) rename {public => www}/bundles/.gitignore (100%) rename {public => www}/css/.gitignore (100%) rename {public => www}/favicon.ico (100%) rename {public => www}/img/.gitignore (100%) rename {public => www}/index.php (100%) rename {public => www}/js/.gitignore (100%) rename {public => www}/laravel/css/style.css (100%) rename {public => www}/laravel/img/logoback.png (100%) rename {public => www}/laravel/js/modernizr-2.5.3.min.js (100%) rename {public => www}/laravel/js/prettify.js (100%) rename {public => www}/laravel/js/scroll.js (100%) diff --git a/laravel/database/connection.php b/laravel/database/connection.php index 938ae97f92b..17a209ae7a5 100644 --- a/laravel/database/connection.php +++ b/laravel/database/connection.php @@ -92,6 +92,9 @@ protected function grammar() case 'pgsql': return $this->grammar = new Query\Grammars\Postgres($this); + case 'oracle': + return $this->grammar = new Query\Grammars\Oracle($this); + default: return $this->grammar = new Query\Grammars\Grammar($this); } diff --git a/laravel/database/connectors/oracle.php b/laravel/database/connectors/oracle.php new file mode 100644 index 00000000000..c600a6affb4 --- /dev/null +++ b/laravel/database/connectors/oracle.php @@ -0,0 +1,56 @@ +options($config)); + + return $connection; + } + +} \ No newline at end of file diff --git a/laravel/database/query/grammars/oracle.php b/laravel/database/query/grammars/oracle.php new file mode 100644 index 00000000000..f30282a261b --- /dev/null +++ b/laravel/database/query/grammars/oracle.php @@ -0,0 +1,139 @@ +insert($query, $values)." RETURNING $column"; + } + + /** + * Compile a SQL SELECT statement from a Query instance. + * + * @param Query $query + * @return string + */ + public function select(Query $query) + { + $sql = parent::components($query); + + // SQL Server does not currently implement an "OFFSET" type keyword, so we + // actually have to generate the ANSI standard SQL for doing offset like + // functionality. OFFSET is in SQL Server 2012, however. + if ($query->offset > 0) + { + return $this->ansi_offset($query, $sql); + } + + // Once all of the clauses have been compiled, we can join them all as + // one statement. Any segments that are null or an empty string will + // be removed from the array before imploding. + return $this->concatenate($sql); + } + + /** + * Compile the SELECT clause for a query. + * + * @param Query $query + * @return string + */ + protected function selects(Query $query) + { + if ( ! is_null($query->aggregate)) return; + + $select = ($query->distinct) ? 'SELECT DISTINCT ' : 'SELECT '; + + return $select.$this->columnize($query->selects); + } + + /** + * Generate the ANSI standard SQL for an offset clause. + * + * @param Query $query + * @param array $components + * @return array + */ + protected function ansi_offset(Query $query, $components) + { + // An ORDER BY clause is required to make this offset query work, so if + // one doesn't exist, we'll just create a dummy clause to trick the + // database and pacify it so it doesn't complain about the query. + if ( ! isset($components['orderings'])) + { + $components['orderings'] = 'ORDER BY 1'; + } + + // We need to add the row number to the query so we can compare it to + // the offset and limit values given for the statement. So we'll add + // an expression to the select for the row number. + $orderings = $components['orderings']; + + $components['selects'] .= ", ROW_NUMBER() OVER ({$orderings}) AS RowNum"; + + unset($components['orderings']); + + $start = $query->offset + 1; + + // Next we need to calculate the constraint that should be placed on + // the row number to get the correct offset and limit on the query. + // If there is not a limit, we'll just handle the offset. + if ($query->limit > 0) + { + $finish = $query->offset + $query->limit; + + $constraint = "BETWEEN {$start} AND {$finish}"; + } + else + { + $constraint = ">= {$start}"; + } + + // We're finally ready to build the final SQL query so we'll create + // a common table expression with the query and select all of the + // results with row numbers between the limit and offset. + $sql = $this->concatenate($components); + + return "SELECT * FROM ($sql) TempTable WHERE RowNum {$constraint}"; + } + + /** + * Compile the LIMIT clause for a query. + * + * @param Query $query + * @return string + */ + protected function limit(Query $query) + { + return ''; + } + + /** + * Compile the OFFSET clause for a query. + * + * @param Query $query + * @return string + */ + protected function offset(Query $query) + { + return ''; + } + +} \ No newline at end of file diff --git a/laravel/database/schema.php b/laravel/database/schema.php index c37fcd6363b..9f0344e9c90 100644 --- a/laravel/database/schema.php +++ b/laravel/database/schema.php @@ -186,6 +186,9 @@ public static function grammar(Connection $connection) case 'sqlite': return new Schema\Grammars\SQLite($connection); + + case 'oracle': + return new Schema\Grammars\Oracle($connection); } throw new \Exception("Schema operations not supported for [$driver]."); diff --git a/laravel/database/schema/grammars/oracle.php b/laravel/database/schema/grammars/oracle.php new file mode 100644 index 00000000000..16a7f5a439a --- /dev/null +++ b/laravel/database/schema/grammars/oracle.php @@ -0,0 +1,8 @@ + Date: Sat, 23 Mar 2013 18:18:49 +0200 Subject: [PATCH 2/3] Change laravel catalog structure --- paths.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/paths.php b/paths.php index 37c5b1edf3b..dbc20221789 100644 --- a/paths.php +++ b/paths.php @@ -50,7 +50,7 @@ // -------------------------------------------------------------- // The path to the public directory. // -------------------------------------------------------------- -$paths['public'] = 'public'; +$paths['public'] = 'www'; // *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*- // END OF USER CONFIGURATION. HERE BE DRAGONS! From fc31a3e1ada3706fdc797f4912a3681c70edd5e2 Mon Sep 17 00:00:00 2001 From: java-tester-x Date: Sat, 23 Mar 2013 22:41:58 +0200 Subject: [PATCH 3/3] Update oracle.php --- laravel/database/connectors/oracle.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/laravel/database/connectors/oracle.php b/laravel/database/connectors/oracle.php index c600a6affb4..0b856bf0e2c 100644 --- a/laravel/database/connectors/oracle.php +++ b/laravel/database/connectors/oracle.php @@ -6,6 +6,17 @@ */ class Oracle extends Connector { + /** + * The PDO connection options. + * + * @var array + */ + protected $options = array( + PDO::ATTR_CASE => PDO::CASE_UPPER, + PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, + PDO::ATTR_ORACLE_NULLS => PDO::NULL_NATURAL, + ); + /** * Establish a PDO database connection. * @@ -53,4 +64,4 @@ public function connect($config) return $connection; } -} \ No newline at end of file +}