Skip to content

Commit d40cece

Browse files
authored
Merge pull request #39 from souzaleo97/master
Insert datatype numeric for primaryKey
2 parents e16fa52 + ec3b92d commit d40cece

File tree

4 files changed

+67
-4
lines changed

4 files changed

+67
-4
lines changed

Database/Schema/BlueprintSybase.php

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace Uepg\LaravelSybase\Database\Schema;
4+
5+
use Illuminate\Database\Schema\Blueprint;
6+
7+
class BlueprintSybase extends Blueprint
8+
{
9+
public function numeric($column, $total=8, $autoIncrement=false)
10+
{
11+
return $this->addColumn('numeric', $column, compact('total', 'autoIncrement'));
12+
}
13+
}

Database/Schema/SybaseGrammar.php

+17-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
<?php namespace Uepg\LaravelSybase\Database\Schema;
1+
<?php
2+
3+
namespace Uepg\LaravelSybase\Database\Schema;
24

35
use Illuminate\Database\Schema\Grammars\Grammar;
46
use Illuminate\Support\Fluent;
5-
use Illuminate\Database\Schema\Blueprint;
7+
use Uepg\LaravelSybase\Database\Schema\BlueprintSybase as Blueprint;
68

79
class SybaseGrammar extends Grammar {
810

@@ -18,7 +20,7 @@ class SybaseGrammar extends Grammar {
1820
*
1921
* @var array
2022
*/
21-
protected $serials = array('bigInteger', 'integer');
23+
protected $serials = array('bigInteger', 'integer', 'numeric');
2224

2325
/**
2426
* Compile the query to determine if a table exists.
@@ -371,9 +373,20 @@ protected function typeDouble(Fluent $column)
371373
*/
372374
protected function typeDecimal(Fluent $column)
373375
{
374-
return "decimal({$column->total}, {$column->places})";
376+
return "decimal({$column->total}, {$column->places})";
375377
}
376378

379+
/**
380+
* Create the column definition for a numeric type.
381+
*
382+
* @param \Illuminate\Support\Fluent $column
383+
* @return string
384+
*/
385+
protected function typeNumeric(Fluent $column)
386+
{
387+
return "numeric({$column->total}, 0)";
388+
}
389+
377390
/**
378391
* Create the column definition for a boolean type.
379392
*

Database/SybaseConnection.php

+16
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Doctrine\DBAL\Driver\PDOSqlsrv\Driver as DoctrineDriver;
77
use Illuminate\Database\Query\Processors\SqlServerProcessor;
88
use Uepg\LaravelSybase\Database\Query\SybaseGrammar as QueryGrammar;
9+
use Uepg\LaravelSybase\Database\Schema\BlueprintSybase;
910
use Uepg\LaravelSybase\Database\Schema\SybaseGrammar as SchemaGrammar;
1011
use Illuminate\Database\Connection;
1112
use Illuminate\Database\Query\Builder;
@@ -521,4 +522,19 @@ public function getFetchMode()
521522
{
522523
return $this->fetchMode;
523524
}
525+
526+
/**
527+
* @return \Illuminate\Database\Schema\Builder
528+
*/
529+
public function getSchemaBuilder()
530+
{
531+
if (is_null($this->schemaGrammar)) {
532+
$this->useDefaultSchemaGrammar();
533+
}
534+
$builder = new \Illuminate\Database\Schema\Builder($this);
535+
$builder->blueprintResolver(function ($table, $callback) {
536+
return new BlueprintSybase($table, $callback);
537+
});
538+
return $builder;
539+
}
524540
}

README.md

+21
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,24 @@ The file is usualy found in `/etc/freetds/freetds.conf`. Set the configuration a
5959
[global]
6060
# TDS protocol version
6161
tds version = 5.0
62+
63+
### Setting to use numeric data type
64+
In the migration file you must replace include `use Illuminate\Database\Schema\Blueprint;` with include `use Uepg\LaravelSybase\Database\Schema\BlueprintSybase as Blueprint;`
65+
66+
Example:
67+
```php
68+
use Illuminate\Database\Migrations\Migration;
69+
//use Illuminate\Database\Schema\Blueprint;
70+
use Uepg\LaravelSybase\Database\Schema\BlueprintSybase as Blueprint;
71+
72+
class CreateTable extends Migration
73+
{
74+
public function up()
75+
{
76+
Schema::create('table_name', function (Blueprint $table) {
77+
$table->numeric('column_name', length, autoIncrement);
78+
});
79+
}
80+
}
81+
82+
```

0 commit comments

Comments
 (0)