Skip to content

Commit

Permalink
Merge pull request #42 from afgloeden/master
Browse files Browse the repository at this point in the history
Changes related to PSR's
  • Loading branch information
nunomazer authored Apr 10, 2019
2 parents d40cece + 661abda commit 7146ba5
Show file tree
Hide file tree
Showing 12 changed files with 1,171 additions and 874 deletions.
12 changes: 12 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 4
trim_trailing_whitespace = true

[*.md]
trim_trailing_whitespace = false
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
/vendor/
/vendor
274 changes: 141 additions & 133 deletions Database/Query/SybaseGrammar.php
Original file line number Diff line number Diff line change
@@ -1,142 +1,150 @@
<?php namespace Uepg\LaravelSybase\Database\Query;
<?php

namespace Uepg\LaravelSybase\Database\Query;

use Illuminate\Database\Query\Builder;
use Illuminate\Database\Query\Grammars\Grammar;

class SybaseGrammar extends Grammar {
/**
* All of the available clause operators.
*
* @var array
*/
protected $operators = [
'=', '<', '>', '<=', '>=', '!<', '!>', '<>', '!=',
'like', 'not like', 'between', 'ilike',
'&', '&=', '|', '|=', '^', '^=',
];

protected $builder;

public function getBuilder(){
return $this->builder;
}

/**
* Compile a select query into SQL.
*
* @param \Illuminate\Database\Query\Builder
* @return string
*/
public function compileSelect(Builder $query)
{
$this->builder = $query;
$components = $this->compileComponents($query);

return $this->concatenate($components);
}

/**
* Compile the "select *" portion of the query.
*
* @param \Illuminate\Database\Query\Builder $query
* @param array $columns
* @return string
*/
protected function compileColumns(Builder $query, $columns)
{
if (!is_null($query->aggregate)) {
return;
}

$select = $query->distinct ? 'select distinct ' : 'select ';

// If there is a limit on the query, but not an offset, we will add the
// top clause to the query, which serves as a "limit" type clause
// within the SQL Server system similar to the limit keywords available
// in MySQL.
if ($query->limit > 0 && $query->offset <= 0) {
$select .= 'top ' . $query->limit . ' ';
}

return $select . $this->columnize($columns);
}

/**
* Compile the "from" portion of the query.
*
* @param \Illuminate\Database\Query\Builder $query
* @param string $table
* @return string
*/
protected function compileFrom(Builder $query, $table)
{
$from = parent::compileFrom($query, $table);

if (is_string($query->lock)) {
return $from . ' ' . $query->lock;
}

if (!is_null($query->lock)) {
return $from . ' with(rowlock,' .
($query->lock ? 'updlock,' : '') . 'holdlock)';
}

/**
* All of the available clause operators.
*
* @var array
*/
protected $operators = array(
'=', '<', '>', '<=', '>=', '!<', '!>', '<>', '!=',
'like', 'not like', 'between', 'ilike',
'&', '&=', '|', '|=', '^', '^=',
);

protected $Builder;
public function getBuilder(){
return $this->Builder;
return $from;
}

/**
* Compile the "limit" portions of the query.
*
* @param \Illuminate\Database\Query\Builder $query
* @param int $limit
* @return string
*/
protected function compileLimit(Builder $query, $limit)
{
return '';
}

/**
* Compile the "offset" portions of the query.
*
* @param \Illuminate\Database\Query\Builder $query
* @param int $offset
* @return string
*/
protected function compileOffset(Builder $query, $offset)
{
return '';
}

/**
* Compile a truncate table statement into SQL.
*
* @param \Illuminate\Database\Query\Builder $query
* @return array
*/
public function compileTruncate(Builder $query)
{
return [
'truncate table ' . $this->wrapTable($query->from) => array()
];
}

/**
* Get the format for database stored dates.
*
* @return string
*/
public function getDateFormat()
{
return 'Y-m-d H:i:s.000';
}

/**
* Wrap a single string in keyword identifiers.
*
* @param string $value
* @return string
*/
protected function wrapValue($value)
{
if ($value === '*') {
return $value;
}


/**
* Compile a select query into SQL.
*
* @param \Illuminate\Database\Query\Builder
* @return string
*/

public function compileSelect(Builder $query)
{
$this->Builder = $query;
$components = $this->compileComponents($query);

return $this->concatenate($components);
}
/**
* Compile the "select *" portion of the query.
*
* @param \Illuminate\Database\Query\Builder $query
* @param array $columns
* @return string
*/
protected function compileColumns(Builder $query, $columns)
{
if ( ! is_null($query->aggregate)) return;

$select = $query->distinct ? 'select distinct ' : 'select ';

// If there is a limit on the query, but not an offset, we will add the top
// clause to the query, which serves as a "limit" type clause within the
// SQL Server system similar to the limit keywords available in MySQL.
if ($query->limit > 0 && $query->offset <= 0)
{
$select .= 'top '.$query->limit.' ';
}

return $select.$this->columnize($columns);
}

/**
* Compile the "from" portion of the query.
*
* @param \Illuminate\Database\Query\Builder $query
* @param string $table
* @return string
*/
protected function compileFrom(Builder $query, $table)
{
$from = parent::compileFrom($query, $table);

if (is_string($query->lock)) return $from.' '.$query->lock;

if ( ! is_null($query->lock))
{
return $from.' with(rowlock,'.($query->lock ? 'updlock,' : '').'holdlock)';
}

return $from;
}

/**
* Compile the "limit" portions of the query.
*
* @param \Illuminate\Database\Query\Builder $query
* @param int $limit
* @return string
*/
protected function compileLimit(Builder $query, $limit)
{
return '';
}

/**
* Compile the "offset" portions of the query.
*
* @param \Illuminate\Database\Query\Builder $query
* @param int $offset
* @return string
*/
protected function compileOffset(Builder $query, $offset)
{
return '';
}

/**
* Compile a truncate table statement into SQL.
*
* @param \Illuminate\Database\Query\Builder $query
* @return array
*/
public function compileTruncate(Builder $query)
{
return array('truncate table '.$this->wrapTable($query->from) => array());
}

/**
* Get the format for database stored dates.
*
* @return string
*/
public function getDateFormat()
{
return 'Y-m-d H:i:s.000';
}

/**
* Wrap a single string in keyword identifiers.
*
* @param string $value
* @return string
*/
protected function wrapValue($value)
{
if ($value === '*') return $value;

return '['.str_replace(']', ']]', $value).']';
}

return '[' . str_replace(']', ']]', $value) . ']';
}
}
12 changes: 7 additions & 5 deletions Database/Query/SybaseProcessor.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<?php

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
namespace Uepg\LaravelSybase\Database\Query;

use Illuminate\Database\Query\Processors\Processor;

class SybaseConnector extends Processor
{
//
}
13 changes: 10 additions & 3 deletions Database/Schema/BlueprintSybase.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,15 @@

class BlueprintSybase extends Blueprint
{
public function numeric($column, $total=8, $autoIncrement=false)
public function numeric($column, $total = 8, $autoIncrement = false)
{
return $this->addColumn('numeric', $column, compact('total', 'autoIncrement'));
return $this->addColumn(
'numeric',
$column,
compact(
'total',
'autoIncrement'
)
);
}
}
}
Loading

0 comments on commit 7146ba5

Please sign in to comment.