diff --git a/Database/Schema/BlueprintSybase.php b/Database/Schema/BlueprintSybase.php new file mode 100644 index 0000000..26050e5 --- /dev/null +++ b/Database/Schema/BlueprintSybase.php @@ -0,0 +1,13 @@ +addColumn('numeric', $column, compact('total', 'autoIncrement')); + } +} \ No newline at end of file diff --git a/Database/Schema/SybaseGrammar.php b/Database/Schema/SybaseGrammar.php index c248587..9fbc775 100644 --- a/Database/Schema/SybaseGrammar.php +++ b/Database/Schema/SybaseGrammar.php @@ -1,8 +1,10 @@ -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. * diff --git a/Database/SybaseConnection.php b/Database/SybaseConnection.php index 7f33dd4..005e1af 100644 --- a/Database/SybaseConnection.php +++ b/Database/SybaseConnection.php @@ -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; @@ -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; + } } diff --git a/README.md b/README.md index e8514eb..50f36d0 100644 --- a/README.md +++ b/README.md @@ -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); + }); + } +} + +```