bencarter78 / odbc

MIT License
24 stars 17 forks source link

Allow grammar classes to be overridden via config #3

Closed mlntn closed 8 years ago

mlntn commented 8 years ago

SQL Server has issues with the default grammar classes. This change allows the grammar to be overwritten via config to use any other grammar classes - including the SQL Server grammar that comes with Laravel/Lumen.

bencarter78 commented 8 years ago

Thanks for the contribution!

underdpt commented 8 years ago

Hi, I think the patch won't use the SchemaGrammar specified in config. This:

    protected function getDefaultSchemaGrammar()
    {
        $class = config('database.connections.odbc.grammar.schema') ?: '\TCK\Odbc\ODBCSchemaGrammar';
        return $this->withTablePrefix( new ODBCSchemaGrammar );
    }

Should be:

    protected function getDefaultSchemaGrammar()
    {
        $class = config('database.connections.odbc.grammar.schema') ?: '\TCK\Odbc\ODBCSchemaGrammar';
        return $this->withTablePrefix( new $class);
    }

Also, it would be good to update the readme for newies like I, to know how to specify the grammar:

        'odbc' => [
            'driver'   => 'odbc',
            'grammar'  => ['query' => '\Illuminate\Database\Query\Grammars\SqlServerGrammar',
                            'schema' => '\Illuminate\Database\Query\Schema\SqlServerGrammar'
                          ],
            'dsn'      => 'odbc:YourDSN;',
            'host'     => '',
            'database' => '',
            'username' => '',
            'password' => '',
        ],
mlntn commented 8 years ago

Yep, I forgot that change. Do you want to create a new pull request and add to the readme?