Skip to content

Commit

Permalink
Merge pull request #39 from souzaleo97/master
Browse files Browse the repository at this point in the history
Insert datatype numeric for primaryKey
  • Loading branch information
nunomazer authored Jan 23, 2019
2 parents e16fa52 + ec3b92d commit d40cece
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 4 deletions.
13 changes: 13 additions & 0 deletions Database/Schema/BlueprintSybase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace Uepg\LaravelSybase\Database\Schema;

use Illuminate\Database\Schema\Blueprint;

class BlueprintSybase extends Blueprint
{
public function numeric($column, $total=8, $autoIncrement=false)
{
return $this->addColumn('numeric', $column, compact('total', 'autoIncrement'));
}
}
21 changes: 17 additions & 4 deletions Database/Schema/SybaseGrammar.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<?php namespace Uepg\LaravelSybase\Database\Schema;
<?php

namespace Uepg\LaravelSybase\Database\Schema;

use Illuminate\Database\Schema\Grammars\Grammar;
use Illuminate\Support\Fluent;
use Illuminate\Database\Schema\Blueprint;
use Uepg\LaravelSybase\Database\Schema\BlueprintSybase as Blueprint;

class SybaseGrammar extends Grammar {

Expand All @@ -18,7 +20,7 @@ class SybaseGrammar extends Grammar {
*
* @var array
*/
protected $serials = array('bigInteger', 'integer');
protected $serials = array('bigInteger', 'integer', 'numeric');

/**
* Compile the query to determine if a table exists.
Expand Down Expand Up @@ -371,9 +373,20 @@ protected function typeDouble(Fluent $column)
*/
protected function typeDecimal(Fluent $column)
{
return "decimal({$column->total}, {$column->places})";
return "decimal({$column->total}, {$column->places})";
}

/**
* Create the column definition for a numeric type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
protected function typeNumeric(Fluent $column)
{
return "numeric({$column->total}, 0)";
}

/**
* Create the column definition for a boolean type.
*
Expand Down
16 changes: 16 additions & 0 deletions Database/SybaseConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Doctrine\DBAL\Driver\PDOSqlsrv\Driver as DoctrineDriver;
use Illuminate\Database\Query\Processors\SqlServerProcessor;
use Uepg\LaravelSybase\Database\Query\SybaseGrammar as QueryGrammar;
use Uepg\LaravelSybase\Database\Schema\BlueprintSybase;
use Uepg\LaravelSybase\Database\Schema\SybaseGrammar as SchemaGrammar;
use Illuminate\Database\Connection;
use Illuminate\Database\Query\Builder;
Expand Down Expand Up @@ -521,4 +522,19 @@ public function getFetchMode()
{
return $this->fetchMode;
}

/**
* @return \Illuminate\Database\Schema\Builder
*/
public function getSchemaBuilder()
{
if (is_null($this->schemaGrammar)) {
$this->useDefaultSchemaGrammar();
}
$builder = new \Illuminate\Database\Schema\Builder($this);
$builder->blueprintResolver(function ($table, $callback) {
return new BlueprintSybase($table, $callback);
});
return $builder;
}
}
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,24 @@ The file is usualy found in `/etc/freetds/freetds.conf`. Set the configuration a
[global]
# TDS protocol version
tds version = 5.0

### Setting to use numeric data type
In the migration file you must replace include `use Illuminate\Database\Schema\Blueprint;` with include `use Uepg\LaravelSybase\Database\Schema\BlueprintSybase as Blueprint;`

Example:
```php
use Illuminate\Database\Migrations\Migration;
//use Illuminate\Database\Schema\Blueprint;
use Uepg\LaravelSybase\Database\Schema\BlueprintSybase as Blueprint;

class CreateTable extends Migration
{
public function up()
{
Schema::create('table_name', function (Blueprint $table) {
$table->numeric('column_name', length, autoIncrement);
});
}
}

```

0 comments on commit d40cece

Please sign in to comment.