Skip to content

Commit

Permalink
Merge pull request #1 from emericklaw/formatting
Browse files Browse the repository at this point in the history
Formatting update to spaces
  • Loading branch information
emericklaw authored Jan 17, 2022
2 parents 684c2b9 + 849d686 commit 9a06180
Show file tree
Hide file tree
Showing 5 changed files with 737 additions and 733 deletions.
264 changes: 132 additions & 132 deletions src/emericklaw/SQLAnywhere/SQLAnywhereConnection.php
Original file line number Diff line number Diff line change
@@ -1,139 +1,139 @@
<?php namespace emericklaw\SQLAnywhere;
<?php

namespace emericklaw\SQLAnywhere;

use Illuminate\Database\Connection;
use \emericklaw\SQLAnywhereClient;

class SQLAnywhereConnection extends Connection {

/**
* Create a new database connection instance.
*
* @param PDO $pdo
* @param string $database
* @param string $tablePrefix
* @param array $config
* @return void
*/
public function __construct(SQLAnywhereClient $pdo, $database = '', $tablePrefix = '', array $config = array())
{
$this->pdo = $pdo;

// First we will setup the default properties. We keep track of the DB
// name we are connected to since it is needed when some reflective
// type commands are run such as checking whether a table exists.
$this->database = $database;

$this->tablePrefix = $tablePrefix;

$this->config = $config;

// We need to initialize a query grammar and the query post processors
// which are both very important parts of the database abstractions
// so we initialize these to their default values while starting.
$this->useDefaultQueryGrammar();

$this->useDefaultPostProcessor();
}

/**
* Run a select statement against the database.
*
* @param string $query
* @param array $bindings
* @return array
*/
public function select($query, $bindings = array(), $useReadPdo = true)
{
// new version since Laravel 5.4
// /vendor/laravel/framework/src/Illuminate/Database/Connection.php
// --> function: select(...)
return $this->run($query, $bindings, function($query, $bindings)
{
if ($this->pretending()) return array();

// For select statements, we'll simply execute the query and return an array
// of the database result set. Each element in the array will be a single
// row from the database table, and will either be an array or objects.
$statement = $this->getReadPdo()->prepare($query);

$statement->execute($this->prepareBindings($bindings));

return $statement->fetchAll();
});
}

/**
* Run a select statement against the database and returns a generator.
*
* @param string $query
* @param array $bindings
* @param bool $useReadPdo
* @return \Generator
*/
public function cursor($query, $bindings = [], $useReadPdo = true)
{
$statement = $this->run($query, $bindings, function ($query, $bindings) use ($useReadPdo) {
if ($this->pretending()) {
return [];
}

// First we will create a statement for the query. Then, we will set the fetch
// mode and prepare the bindings for the query. Once that's done we will be
// ready to execute the query against the database and return the cursor.
$statement = $this->getReadPdo()->prepare($query);

$statement->execute($this->prepareBindings($bindings));

return $statement;
});

while ($record = $statement->fetch()) {
yield $record;
}
}

/**
* Run an SQL statement and get the number of rows affected.
*
* @param string $query
* @param array $bindings
* @return int
*/
public function affectingStatement($query, $bindings = array())
{
return $this->run($query, $bindings, function($query, $bindings)
{
if ($this->pretending()) return 0;

// For update or delete statements, we want to get the number of rows affected
// by the statement and return that back to the developer. We'll first need
// to execute the statement and then we'll use PDO to fetch the affected.
$statement = $this->getPdo()->prepare($query);

$statement->execute($this->prepareBindings($bindings));

return $statement->affectedRows();
});
}

/**
* Get the default query grammar instance.
*
* @return Illuminate\Database\Query\Grammars\Grammars\Grammar
*/
protected function getDefaultQueryGrammar()
{
class SQLAnywhereConnection extends Connection
{

/**
* Create a new database connection instance.
*
* @param PDO $pdo
* @param string $database
* @param string $tablePrefix
* @param array $config
* @return void
*/
public function __construct(SQLAnywhereClient $pdo, $database = '', $tablePrefix = '', array $config = [])
{
$this->pdo = $pdo;

// First we will setup the default properties. We keep track of the DB
// name we are connected to since it is needed when some reflective
// type commands are run such as checking whether a table exists.
$this->database = $database;

$this->tablePrefix = $tablePrefix;

$this->config = $config;

// We need to initialize a query grammar and the query post processors
// which are both very important parts of the database abstractions
// so we initialize these to their default values while starting.
$this->useDefaultQueryGrammar();

$this->useDefaultPostProcessor();
}

/**
* Run a select statement against the database.
*
* @param string $query
* @param array $bindings
* @return array
*/
public function select($query, $bindings = [], $useReadPdo = true)
{
// new version since Laravel 5.4
// /vendor/laravel/framework/src/Illuminate/Database/Connection.php
// --> function: select(...)
return $this->run($query, $bindings, function ($query, $bindings) {
if ($this->pretending()) return [];

// For select statements, we'll simply execute the query and return an array
// of the database result set. Each element in the array will be a single
// row from the database table, and will either be an array or objects.
$statement = $this->getReadPdo()->prepare($query);

$statement->execute($this->prepareBindings($bindings));

return $statement->fetchAll();
});
}

/**
* Run a select statement against the database and returns a generator.
*
* @param string $query
* @param array $bindings
* @param bool $useReadPdo
* @return \Generator
*/
public function cursor($query, $bindings = [], $useReadPdo = true)
{
$statement = $this->run($query, $bindings, function ($query, $bindings) use ($useReadPdo) {
if ($this->pretending()) {
return [];
}

// First we will create a statement for the query. Then, we will set the fetch
// mode and prepare the bindings for the query. Once that's done we will be
// ready to execute the query against the database and return the cursor.
$statement = $this->getReadPdo()->prepare($query);

$statement->execute($this->prepareBindings($bindings));

return $statement;
});

while ($record = $statement->fetch()) {
yield $record;
}
}

/**
* Run an SQL statement and get the number of rows affected.
*
* @param string $query
* @param array $bindings
* @return int
*/
public function affectingStatement($query, $bindings = [])
{
return $this->run($query, $bindings, function ($query, $bindings) {
if ($this->pretending()) return 0;

// For update or delete statements, we want to get the number of rows affected
// by the statement and return that back to the developer. We'll first need
// to execute the statement and then we'll use PDO to fetch the affected.
$statement = $this->getPdo()->prepare($query);

$statement->execute($this->prepareBindings($bindings));

return $statement->affectedRows();
});
}

/**
* Get the default query grammar instance.
*
* @return Illuminate\Database\Query\Grammars\Grammars\Grammar
*/
protected function getDefaultQueryGrammar()
{
return $this->withTablePrefix(new SQLAnywhereQueryGrammar);
}

/**
* Get the default schema grammar instance.
*
* @return Illuminate\Database\Schema\Grammars\Grammar
*/
protected function getDefaultSchemaGrammar()
{
}

/**
* Get the default schema grammar instance.
*
* @return Illuminate\Database\Schema\Grammars\Grammar
*/
protected function getDefaultSchemaGrammar()
{
return $this->withTablePrefix(new SQLAnywhereSchemaGrammar);
}

}
}
63 changes: 33 additions & 30 deletions src/emericklaw/SQLAnywhere/SQLAnywhereConnector.php
Original file line number Diff line number Diff line change
@@ -1,46 +1,49 @@
<?php namespace emericklaw\SQLAnywhere;
<?php

namespace emericklaw\SQLAnywhere;

use Illuminate\Database\Connectors\Connector;
use Illuminate\Database\Connectors\ConnectorInterface;
use Illuminate\Support\Arr;
use \emericklaw\SQLAnywhereClient;

class SQLAnywhereConnector extends Connector implements ConnectorInterface {
class SQLAnywhereConnector extends Connector implements ConnectorInterface
{

/**
* Establish a database connection.
*
* @param array $options
* @return PDO
*/
public function connect(array $config)
{
return $this->createConnection(array(), $config, array());
}
/**
* Establish a database connection.
*
* @param array $options
* @return PDO
*/
public function connect(array $config)
{
return $this->createConnection([], $config, []);
}


/**
* Create a new PDO connection.
*
* @param array $config
* @param array $options
* @return SQLAnywhere
*/
public function createConnection($dsn, array $config, array $options)
{
$autocommit = Arr::get($config, 'autocommit');
$persintent = Arr::get($config, 'persintent');
/**
* Create a new PDO connection.
*
* @param array $config
* @param array $options
* @return SQLAnywhere
*/
public function createConnection($dsn, array $config, array $options)
{
$autocommit = Arr::get($config, 'autocommit');
$persintent = Arr::get($config, 'persintent');

return new SQLAnywhereClient($this->getDsn($config), $autocommit, $persintent);
}
return new SQLAnywhereClient($this->getDsn($config), $autocommit, $persintent);
}

/**
/**
* Create a DSN string from a configuration.
*
* @param array $config
* @return string
*/
protected function getDsn(array $config)
protected function getDsn(array $config)
{
// First we will create the basic DSN setup as well as the port if it is in
// in the configuration options. This will give us the basic DSN we will
Expand All @@ -53,12 +56,12 @@ protected function getDsn(array $config)
// Sample: UID=test;PWD=test;ENG=dbserv;DBN=dbname;COMMLINKS=TCPIP{HOST=192.168.100.100:2638}
$dsn = "uid={$username};pwd={$password};dbn={$database};commlinks=tcpip{host={$host}:{$port}}";
if (isset($charset)) {
$dsn.= ";charset={$charset}";
$dsn .= ";charset={$charset}";
}
if (isset($dbserver)) {
$dsn.= ";ENG={$dbserver}";
$dsn .= ";ENG={$dbserver}";
}

return $dsn;
return $dsn;
}
}
Loading

0 comments on commit 9a06180

Please sign in to comment.