summaryrefslogtreecommitdiff
path: root/src/Query/FirebirdBuilder.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/Query/FirebirdBuilder.php')
-rwxr-xr-xsrc/Query/FirebirdBuilder.php109
1 files changed, 109 insertions, 0 deletions
diff --git a/src/Query/FirebirdBuilder.php b/src/Query/FirebirdBuilder.php
new file mode 100755
index 0000000..98d2b18
--- /dev/null
+++ b/src/Query/FirebirdBuilder.php
@@ -0,0 +1,109 @@
+<?php
+
+namespace Xgrz\Firebird\Query;
+
+use Illuminate\Database\Query\Builder as QueryBuilder;
+use Illuminate\Support\Collection;
+
+class FirebirdBuilder extends QueryBuilder
+{
+ /**
+ * Determine if any rows exist for the current query.
+ *
+ * @return bool
+ */
+ public function exists()
+ {
+ return parent::count() > 0;
+ }
+
+ /**
+ * Add a from stored procedure clause to the query builder.
+ *
+ * @param string $procedure
+ * @param array $values
+ * @return \Illuminate\Database\Query\Builder|static
+ */
+ public function fromProcedure(string $procedure, array $values = [])
+ {
+ $compiledProcedure = $this->grammar->compileProcedure($this, $procedure, $values);
+
+ // Remove any expressions from the values array, as they will have
+ // already been evaluated by the grammar's parameterize() function.
+ $values = array_filter($values, function($value) {
+ return ! $this->grammar->isExpression($value);
+ });
+
+ $this->fromRaw($compiledProcedure, array_values($values));
+
+ return $this;
+ }
+
+ public function where($column, $operator = NULL, $value = NULL, $boolean = 'and')
+ {
+ // detect is not search
+ if (! str($operator)->contains('like', true)) {
+ return parent::where($column, $operator, $value, $boolean);
+ }
+
+ // when is search covert to upper case column and value at database level
+ $wrapped = $this->grammar->wrap($column);
+ return $boolean === 'and'
+ ? parent::whereRaw("UPPER($wrapped) LIKE UPPER(?)", [$value])
+ : parent::orWhereRaw("UPPER($wrapped) LIKE UPPER(?)", [$value]);
+ }
+
+ /**
+ * Retrieve column values from rows represented as objects.
+ *
+ * @param array $queryResult
+ * @param string $column
+ * @param string $key
+ * @return Collection
+ */
+ protected function pluckFromObjectColumn($queryResult, $column, $key)
+ {
+ $results = [];
+ $column = strtoupper($column);
+ $key = strtoupper($key);
+
+ foreach ($queryResult as $item) {
+ if (is_null($key)) {
+ foreach ($queryResult as $row) {
+ $results[] = $row->$column;
+ }
+ } else {
+ foreach ($queryResult as $row) {
+ $results[$row->$key] = $row->$column;
+ }
+ }
+ }
+
+ return new Collection($results);
+ }
+
+ /**
+ * Retrieve column values from rows represented as arrays.
+ *
+ * @param array $queryResult
+ * @param string $column
+ * @param string $key
+ * @return Collection
+ */
+ protected function pluckFromArrayColumn($queryResult, $column, $key)
+ {
+ $results = [];
+
+ if (is_null($key)) {
+ foreach ($queryResult as $row) {
+ $results[] = $row[$column];
+ }
+ } else {
+ foreach ($queryResult as $row) {
+ $results[$row[$key]] = $row[$column];
+ }
+ }
+
+ return new Collection($results);
+ }
+}