Skip to content

Commit

Permalink
do not force existing snowflake connections to use "native" driver
Browse files Browse the repository at this point in the history
  • Loading branch information
yoramdelangen committed May 23, 2022
1 parent 6a09cde commit ccbdc86
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,11 @@ Or final way and dynamicly:
]
```

When using the PHP `Snowflake_pdo` extension the following options are required:
When using the PHP `pdo_snowflake` extension the following options are required:

```php
'snowflake_pdo' => [
'driver' => 'snowflake',
'driver' => 'snowflake_native',
'account' => '{account_name}.eu-west-1',
'username' => '{username}',
'password' => '{password}',
Expand Down
7 changes: 6 additions & 1 deletion src/Flavours/Snowflake/Connector.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use PDO;
use Closure;
use Exception;
use LaravelPdoOdbc\ODBCConnector;
use LaravelPdoOdbc\Contracts\OdbcDriver;
use LaravelPdoOdbc\Flavours\Snowflake\PDO\Statement;
Expand All @@ -24,12 +25,16 @@ class Connector extends ODBCConnector implements OdbcDriver
public function connect(array $config)
{
$connection = null;
$usingSnowflakeDriver = $config['driver'] === 'snowflake' && extension_loaded('pdo_snowflake');
$usingSnowflakeDriver = $config['driver'] === 'snowflake_native';

// the PDO Snowflake driver was installed and the driver was snowflake, start using snowflake driver.
if ($usingSnowflakeDriver) {
$this->dsnPrefix = 'snowflake';
$this->dsnIncludeDriver = false;

if (!extension_loaded('pdo_snowflake')) {
throw new Exception('Native Snowflake driver pdo_snowflake was not enabled');
}
}

$connection = parent::connect($config);
Expand Down
2 changes: 1 addition & 1 deletion src/ODBCServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use Illuminate\Database\Connection;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\ServiceProvider;
use Illuminate\Database\DatabaseManager;
use LaravelPdoOdbc\Flavours\Snowflake\Connector as SnowflakeConnector;

class ODBCServiceProvider extends ServiceProvider
Expand All @@ -19,6 +18,7 @@ public function register()
{
Connection::resolverFor('odbc', ODBCConnector::registerDriver());
Connection::resolverFor('snowflake', SnowflakeConnector::registerDriver());
Connection::resolverFor('snowflake_native', SnowflakeConnector::registerDriver());
}

/**
Expand Down

0 comments on commit ccbdc86

Please sign in to comment.