Skip to content

Commit

Permalink
adding newline to files, adding multiple insert support
Browse files Browse the repository at this point in the history
  • Loading branch information
jfelder committed Oct 3, 2014
1 parent 556244e commit ddd69f3
Show file tree
Hide file tree
Showing 10 changed files with 62 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ after_script:
matrix:
allow_failures:
- php: hhvm
fast_finish: true
fast_finish: true
2 changes: 1 addition & 1 deletion phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@
<directory suffix=".php">./tests/</directory>
</testsuite>
</testsuites>
</phpunit>
</phpunit>
2 changes: 1 addition & 1 deletion src/Jfelder/OracleDB/Connectors/OracleConnector.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,4 @@ protected function getDsn(array $config)

return $rv;
}
}
}
2 changes: 1 addition & 1 deletion src/Jfelder/OracleDB/OCI_PDO/OCI.php
Original file line number Diff line number Diff line change
Expand Up @@ -427,4 +427,4 @@ public function setExecuteMode($mode)

throw new OCIException($this->setErrorInfo('0A000', '9999', "Invalid commit mode specified: {$mode}"));
}
}
}
8 changes: 3 additions & 5 deletions src/Jfelder/OracleDB/OCI_PDO/OCIException.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@ class OCIException extends PDOException
/**
* Create a new query exception instance.
*
* @param string $sql
* @param array $bindings
* @param array $previous
* @return void
* @param string $e
*
*/
public function __construct($e)
{
Expand All @@ -20,4 +18,4 @@ public function __construct($e)
$this->message = "SQLSTATE[$e[0]] " . $e[2];
}

}
}
2 changes: 1 addition & 1 deletion src/Jfelder/OracleDB/OCI_PDO/OCIStatement.php
Original file line number Diff line number Diff line change
Expand Up @@ -548,4 +548,4 @@ private function setErrorInfo($code=null, $error=null, $message = null)

return $this->error;
}
}
}
2 changes: 1 addition & 1 deletion src/Jfelder/OracleDB/OracleConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ protected function getDefaultPostProcessor()
return new Query\Processors\OracleProcessor;
}

}
}
8 changes: 4 additions & 4 deletions src/Jfelder/OracleDB/OracleDBServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ public function boot()

/**
* Register the service provider.
*
* @return void
*/
*
* @throws \ErrorException
*/
public function register()
{
$this->package('jfelder/oracledb');
Expand Down Expand Up @@ -73,4 +73,4 @@ public function provides()
return array();
}

}
}
49 changes: 48 additions & 1 deletion src/Jfelder/OracleDB/Query/Grammars/OracleGrammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,54 @@ public function compileSelect(Builder $query)
return trim($this->concatenate($components));
}

/**

/**
* Compile an insert statement into SQL.
*
* @param \Illuminate\Database\Query\Builder $query
* @param array $values
* @return string
*/
public function compileInsert(Builder $query, array $values)
{
// Essentially we will force every insert to be treated as a batch insert which
// simply makes creating the SQL easier for us since we can utilize the same
// basic routine regardless of an amount of records given to us to insert.
$table = $this->wrapTable($query->from);

if ( ! is_array(reset($values)))
{
$values = array($values);
}

// If there is only one record being inserted, we will just use the usual query
// grammar insert builder because no special syntax is needed for the single
// row inserts in Oracle. However, if there are multiples, we'll continue.
$count = count($values);

if ($count == 1)
{
return parent::compileInsert($query, reset($values));
}

$columns = $this->columnize(array_keys(reset($values)));

$rows = array();

// Oracle requires us to build the multi-row insert as multiple inserts with
// a select statement at the end. So we'll build out this list of columns
// and then join them all together with select to complete the queries.
$parameters = $this->parameterize(reset($values));

for ($i=0; $i<$count; $i++)
{
$rows[] = "into {$table} ({$columns}) values ({$parameters}) ";
}

return "insert all ".implode($rows)." select 1 from dual";
}

/**
* Compile an insert and get ID statement into SQL.
*
* @param \Illuminate\Database\Query\Builder $query
Expand Down
2 changes: 1 addition & 1 deletion src/Jfelder/OracleDB/Query/Processors/OracleProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,4 @@ private function bindType($param)
return $param;
}

}
}

0 comments on commit ddd69f3

Please sign in to comment.