Skip to content

Commit 849d686

Browse files
committed
Formatting update to spaces
1 parent 684c2b9 commit 849d686

5 files changed

+737
-733
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,139 +1,139 @@
1-
<?php namespace emericklaw\SQLAnywhere;
1+
<?php
2+
3+
namespace emericklaw\SQLAnywhere;
24

35
use Illuminate\Database\Connection;
46
use \emericklaw\SQLAnywhereClient;
57

6-
class SQLAnywhereConnection extends Connection {
7-
8-
/**
9-
* Create a new database connection instance.
10-
*
11-
* @param PDO $pdo
12-
* @param string $database
13-
* @param string $tablePrefix
14-
* @param array $config
15-
* @return void
16-
*/
17-
public function __construct(SQLAnywhereClient $pdo, $database = '', $tablePrefix = '', array $config = array())
18-
{
19-
$this->pdo = $pdo;
20-
21-
// First we will setup the default properties. We keep track of the DB
22-
// name we are connected to since it is needed when some reflective
23-
// type commands are run such as checking whether a table exists.
24-
$this->database = $database;
25-
26-
$this->tablePrefix = $tablePrefix;
27-
28-
$this->config = $config;
29-
30-
// We need to initialize a query grammar and the query post processors
31-
// which are both very important parts of the database abstractions
32-
// so we initialize these to their default values while starting.
33-
$this->useDefaultQueryGrammar();
34-
35-
$this->useDefaultPostProcessor();
36-
}
37-
38-
/**
39-
* Run a select statement against the database.
40-
*
41-
* @param string $query
42-
* @param array $bindings
43-
* @return array
44-
*/
45-
public function select($query, $bindings = array(), $useReadPdo = true)
46-
{
47-
// new version since Laravel 5.4
48-
// /vendor/laravel/framework/src/Illuminate/Database/Connection.php
49-
// --> function: select(...)
50-
return $this->run($query, $bindings, function($query, $bindings)
51-
{
52-
if ($this->pretending()) return array();
53-
54-
// For select statements, we'll simply execute the query and return an array
55-
// of the database result set. Each element in the array will be a single
56-
// row from the database table, and will either be an array or objects.
57-
$statement = $this->getReadPdo()->prepare($query);
58-
59-
$statement->execute($this->prepareBindings($bindings));
60-
61-
return $statement->fetchAll();
62-
});
63-
}
64-
65-
/**
66-
* Run a select statement against the database and returns a generator.
67-
*
68-
* @param string $query
69-
* @param array $bindings
70-
* @param bool $useReadPdo
71-
* @return \Generator
72-
*/
73-
public function cursor($query, $bindings = [], $useReadPdo = true)
74-
{
75-
$statement = $this->run($query, $bindings, function ($query, $bindings) use ($useReadPdo) {
76-
if ($this->pretending()) {
77-
return [];
78-
}
79-
80-
// First we will create a statement for the query. Then, we will set the fetch
81-
// mode and prepare the bindings for the query. Once that's done we will be
82-
// ready to execute the query against the database and return the cursor.
83-
$statement = $this->getReadPdo()->prepare($query);
84-
85-
$statement->execute($this->prepareBindings($bindings));
86-
87-
return $statement;
88-
});
89-
90-
while ($record = $statement->fetch()) {
91-
yield $record;
92-
}
93-
}
94-
95-
/**
96-
* Run an SQL statement and get the number of rows affected.
97-
*
98-
* @param string $query
99-
* @param array $bindings
100-
* @return int
101-
*/
102-
public function affectingStatement($query, $bindings = array())
103-
{
104-
return $this->run($query, $bindings, function($query, $bindings)
105-
{
106-
if ($this->pretending()) return 0;
107-
108-
// For update or delete statements, we want to get the number of rows affected
109-
// by the statement and return that back to the developer. We'll first need
110-
// to execute the statement and then we'll use PDO to fetch the affected.
111-
$statement = $this->getPdo()->prepare($query);
112-
113-
$statement->execute($this->prepareBindings($bindings));
114-
115-
return $statement->affectedRows();
116-
});
117-
}
118-
119-
/**
120-
* Get the default query grammar instance.
121-
*
122-
* @return Illuminate\Database\Query\Grammars\Grammars\Grammar
123-
*/
124-
protected function getDefaultQueryGrammar()
125-
{
8+
class SQLAnywhereConnection extends Connection
9+
{
10+
11+
/**
12+
* Create a new database connection instance.
13+
*
14+
* @param PDO $pdo
15+
* @param string $database
16+
* @param string $tablePrefix
17+
* @param array $config
18+
* @return void
19+
*/
20+
public function __construct(SQLAnywhereClient $pdo, $database = '', $tablePrefix = '', array $config = [])
21+
{
22+
$this->pdo = $pdo;
23+
24+
// First we will setup the default properties. We keep track of the DB
25+
// name we are connected to since it is needed when some reflective
26+
// type commands are run such as checking whether a table exists.
27+
$this->database = $database;
28+
29+
$this->tablePrefix = $tablePrefix;
30+
31+
$this->config = $config;
32+
33+
// We need to initialize a query grammar and the query post processors
34+
// which are both very important parts of the database abstractions
35+
// so we initialize these to their default values while starting.
36+
$this->useDefaultQueryGrammar();
37+
38+
$this->useDefaultPostProcessor();
39+
}
40+
41+
/**
42+
* Run a select statement against the database.
43+
*
44+
* @param string $query
45+
* @param array $bindings
46+
* @return array
47+
*/
48+
public function select($query, $bindings = [], $useReadPdo = true)
49+
{
50+
// new version since Laravel 5.4
51+
// /vendor/laravel/framework/src/Illuminate/Database/Connection.php
52+
// --> function: select(...)
53+
return $this->run($query, $bindings, function ($query, $bindings) {
54+
if ($this->pretending()) return [];
55+
56+
// For select statements, we'll simply execute the query and return an array
57+
// of the database result set. Each element in the array will be a single
58+
// row from the database table, and will either be an array or objects.
59+
$statement = $this->getReadPdo()->prepare($query);
60+
61+
$statement->execute($this->prepareBindings($bindings));
62+
63+
return $statement->fetchAll();
64+
});
65+
}
66+
67+
/**
68+
* Run a select statement against the database and returns a generator.
69+
*
70+
* @param string $query
71+
* @param array $bindings
72+
* @param bool $useReadPdo
73+
* @return \Generator
74+
*/
75+
public function cursor($query, $bindings = [], $useReadPdo = true)
76+
{
77+
$statement = $this->run($query, $bindings, function ($query, $bindings) use ($useReadPdo) {
78+
if ($this->pretending()) {
79+
return [];
80+
}
81+
82+
// First we will create a statement for the query. Then, we will set the fetch
83+
// mode and prepare the bindings for the query. Once that's done we will be
84+
// ready to execute the query against the database and return the cursor.
85+
$statement = $this->getReadPdo()->prepare($query);
86+
87+
$statement->execute($this->prepareBindings($bindings));
88+
89+
return $statement;
90+
});
91+
92+
while ($record = $statement->fetch()) {
93+
yield $record;
94+
}
95+
}
96+
97+
/**
98+
* Run an SQL statement and get the number of rows affected.
99+
*
100+
* @param string $query
101+
* @param array $bindings
102+
* @return int
103+
*/
104+
public function affectingStatement($query, $bindings = [])
105+
{
106+
return $this->run($query, $bindings, function ($query, $bindings) {
107+
if ($this->pretending()) return 0;
108+
109+
// For update or delete statements, we want to get the number of rows affected
110+
// by the statement and return that back to the developer. We'll first need
111+
// to execute the statement and then we'll use PDO to fetch the affected.
112+
$statement = $this->getPdo()->prepare($query);
113+
114+
$statement->execute($this->prepareBindings($bindings));
115+
116+
return $statement->affectedRows();
117+
});
118+
}
119+
120+
/**
121+
* Get the default query grammar instance.
122+
*
123+
* @return Illuminate\Database\Query\Grammars\Grammars\Grammar
124+
*/
125+
protected function getDefaultQueryGrammar()
126+
{
126127
return $this->withTablePrefix(new SQLAnywhereQueryGrammar);
127-
}
128-
129-
/**
130-
* Get the default schema grammar instance.
131-
*
132-
* @return Illuminate\Database\Schema\Grammars\Grammar
133-
*/
134-
protected function getDefaultSchemaGrammar()
135-
{
128+
}
129+
130+
/**
131+
* Get the default schema grammar instance.
132+
*
133+
* @return Illuminate\Database\Schema\Grammars\Grammar
134+
*/
135+
protected function getDefaultSchemaGrammar()
136+
{
136137
return $this->withTablePrefix(new SQLAnywhereSchemaGrammar);
137-
}
138-
138+
}
139139
}
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,49 @@
1-
<?php namespace emericklaw\SQLAnywhere;
1+
<?php
2+
3+
namespace emericklaw\SQLAnywhere;
24

35
use Illuminate\Database\Connectors\Connector;
46
use Illuminate\Database\Connectors\ConnectorInterface;
57
use Illuminate\Support\Arr;
68
use \emericklaw\SQLAnywhereClient;
79

8-
class SQLAnywhereConnector extends Connector implements ConnectorInterface {
10+
class SQLAnywhereConnector extends Connector implements ConnectorInterface
11+
{
912

10-
/**
11-
* Establish a database connection.
12-
*
13-
* @param array $options
14-
* @return PDO
15-
*/
16-
public function connect(array $config)
17-
{
18-
return $this->createConnection(array(), $config, array());
19-
}
13+
/**
14+
* Establish a database connection.
15+
*
16+
* @param array $options
17+
* @return PDO
18+
*/
19+
public function connect(array $config)
20+
{
21+
return $this->createConnection([], $config, []);
22+
}
2023

2124

22-
/**
23-
* Create a new PDO connection.
24-
*
25-
* @param array $config
26-
* @param array $options
27-
* @return SQLAnywhere
28-
*/
29-
public function createConnection($dsn, array $config, array $options)
30-
{
31-
$autocommit = Arr::get($config, 'autocommit');
32-
$persintent = Arr::get($config, 'persintent');
25+
/**
26+
* Create a new PDO connection.
27+
*
28+
* @param array $config
29+
* @param array $options
30+
* @return SQLAnywhere
31+
*/
32+
public function createConnection($dsn, array $config, array $options)
33+
{
34+
$autocommit = Arr::get($config, 'autocommit');
35+
$persintent = Arr::get($config, 'persintent');
3336

34-
return new SQLAnywhereClient($this->getDsn($config), $autocommit, $persintent);
35-
}
37+
return new SQLAnywhereClient($this->getDsn($config), $autocommit, $persintent);
38+
}
3639

37-
/**
40+
/**
3841
* Create a DSN string from a configuration.
3942
*
4043
* @param array $config
4144
* @return string
4245
*/
43-
protected function getDsn(array $config)
46+
protected function getDsn(array $config)
4447
{
4548
// First we will create the basic DSN setup as well as the port if it is in
4649
// in the configuration options. This will give us the basic DSN we will
@@ -53,12 +56,12 @@ protected function getDsn(array $config)
5356
// Sample: UID=test;PWD=test;ENG=dbserv;DBN=dbname;COMMLINKS=TCPIP{HOST=192.168.100.100:2638}
5457
$dsn = "uid={$username};pwd={$password};dbn={$database};commlinks=tcpip{host={$host}:{$port}}";
5558
if (isset($charset)) {
56-
$dsn.= ";charset={$charset}";
59+
$dsn .= ";charset={$charset}";
5760
}
5861
if (isset($dbserver)) {
59-
$dsn.= ";ENG={$dbserver}";
62+
$dsn .= ";ENG={$dbserver}";
6063
}
6164

62-
return $dsn;
65+
return $dsn;
6366
}
6467
}

0 commit comments

Comments
 (0)