Skip to content

Commit fa2bbef

Browse files
committed
QA: Add all used classes to imports
1 parent 88439d4 commit fa2bbef

File tree

1 file changed

+48
-35
lines changed

1 file changed

+48
-35
lines changed

src/main/php/rdbms/sqlite3/SQLite3Connection.class.php

Lines changed: 48 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
11
<?php namespace rdbms\sqlite3;
22

3-
use rdbms\{DBConnection, QuerySucceeded, StatementFormatter, Transaction};
3+
use SQLite3, Exception;
4+
use lang\XPClass;
5+
use rdbms\{
6+
DBConnection,
7+
DBEvent,
8+
DriverManager,
9+
QuerySucceeded,
10+
SQLConnectException,
11+
StatementFormatter,
12+
SQLStateException,
13+
SQLStatementFailedException,
14+
Transaction
15+
};
416

517
/**
618
* Connection to SQLite 3.x Databases via ext/sqlite3
@@ -18,27 +30,28 @@
1830
*
1931
* Therefore, this class offers a cast function which may be used
2032
* whithin the SQL as following:
21-
* <pre>
22-
* select
23-
* cast(id, "int") id,
24-
* name,
25-
* cast(percentage, "float") percentage,
26-
* cast(lastchange, "date") lastchange,
27-
* changedby
28-
* from
29-
* test
30-
* </pre>
33+
*
34+
* ```sql
35+
* select
36+
* cast(id, "int") id,
37+
* name,
38+
* cast(percentage, "float") percentage,
39+
* cast(lastchange, "date") lastchange,
40+
* changedby
41+
* from
42+
* test
43+
* ```
3144
*
3245
* The resultset array will contain the following:
33-
* <pre>
34-
* key type
35-
* ------------ -------------
36-
* id int
37-
* name string
38-
* percentage float
39-
* lastchange util.Date
40-
* changedby string
41-
* </pre>
46+
* ```
47+
* key type
48+
* ------------ -------------
49+
* id int
50+
* name string
51+
* percentage float
52+
* lastchange util.Date
53+
* changedby string
54+
* ```
4255
*
4356
* @ext sqlite3
4457
* @see http://sqlite.org/
@@ -50,7 +63,7 @@ class SQLite3Connection extends DBConnection {
5063

5164
static function __static() {
5265
if (extension_loaded('sqlite3')) {
53-
\rdbms\DriverManager::register('sqlite+3', new \lang\XPClass(__CLASS__));
66+
DriverManager::register('sqlite+3', new XPClass(__CLASS__));
5467
}
5568
}
5669

@@ -72,30 +85,30 @@ public function __construct($dsn) {
7285
* @throws rdbms.SQLConnectException
7386
*/
7487
public function connect($reconnect= false) {
75-
if ($this->handle instanceof \SQLite3) return true; // Already connected
88+
if ($this->handle instanceof SQLite3) return true; // Already connected
7689
if (!$reconnect && (false === $this->handle)) return false; // Previously failed connecting
7790

7891
// Sanity check: SQLite(3) works local: either loads a database from a file
7992
// or from memory, so connecting to remote hosts is not supported, thus
8093
// checked here. You may pass "localhost", though
8194
if ('' != $this->dsn->getHost() && '.' != $this->dsn->getHost()) {
82-
throw new \rdbms\SQLConnectException('sqlite+3:// connecting to remote database not supported', $this->dsn);
95+
throw new SQLConnectException('sqlite+3:// connecting to remote database not supported', $this->dsn);
8396
}
8497

85-
$this->_obs && $this->notifyObservers(new \rdbms\DBEvent(\rdbms\DBEvent::CONNECT, $reconnect));
98+
$this->_obs && $this->notifyObservers(new DBEvent(DBEvent::CONNECT, $reconnect));
8699
$database= (string)urldecode((string)$this->dsn->getDatabase());
87100
if (0 === strlen($database) || false !== strpos($database, "\0")) {
88-
throw new \rdbms\SQLConnectException('Illegal filename', $this->dsn);
101+
throw new SQLConnectException('Illegal filename', $this->dsn);
89102
}
90103

91104
try {
92-
$this->handle= new \SQLite3($database, SQLITE3_OPEN_READWRITE | SQLITE3_OPEN_CREATE);
93-
} catch (\Exception $e) {
94-
throw new \rdbms\SQLConnectException($e->getMessage().': '.$database, $this->dsn);
105+
$this->handle= new SQLite3($database, SQLITE3_OPEN_READWRITE | SQLITE3_OPEN_CREATE);
106+
} catch (Exception $e) {
107+
throw new SQLConnectException($e->getMessage().': '.$database, $this->dsn);
95108
}
96109

97110
$this->getFormatter()->dialect->registerCallbackFunctions($this->handle);
98-
$this->_obs && $this->notifyObservers(new \rdbms\DBEvent(\rdbms\DBEvent::CONNECTED, $reconnect));
111+
$this->_obs && $this->notifyObservers(new DBEvent(DBEvent::CONNECTED, $reconnect));
99112

100113
return true;
101114
}
@@ -119,7 +132,7 @@ public function close() {
119132
* @throws rdbms.SQLStatementFailedException
120133
*/
121134
public function selectdb($db) {
122-
throw new \rdbms\SQLStatementFailedException(
135+
throw new SQLStatementFailedException(
123136
'Cannot select database, not implemented in SQLite'
124137
);
125138
}
@@ -130,9 +143,9 @@ public function selectdb($db) {
130143
* @return var identity value
131144
*/
132145
public function identity($field= null) {
133-
if (!$this->handle instanceof \SQLite3) throw new \rdbms\SQLStateException('Not connected');
146+
if (!$this->handle instanceof SQLite3) throw new SQLStateException('Not connected');
134147
$i= $this->handle->lastInsertRowID();
135-
$this->_obs && $this->notifyObservers(new \rdbms\DBEvent(\rdbms\DBEvent::IDENTITY, $i));
148+
$this->_obs && $this->notifyObservers(new DBEvent(DBEvent::IDENTITY, $i));
136149
return $i;
137150
}
138151

@@ -145,11 +158,11 @@ public function identity($field= null) {
145158
* @throws rdbms.SQLException
146159
*/
147160
protected function query0($sql, $buffered= true) {
148-
$this->handle instanceof \SQLite3 || $this->connections->establish($this);
149-
161+
$this->handle instanceof SQLite3 || $this->connections->establish($this);
162+
150163
$result= $this->handle->query($sql);
151164
if (false === $result) {
152-
$e= new \rdbms\SQLStatementFailedException(
165+
$e= new SQLStatementFailedException(
153166
'Statement failed: '.$this->handle->lastErrorMsg().' @ '.$this->dsn->getDatabase(),
154167
$sql,
155168
$this->handle->lastErrorCode()

0 commit comments

Comments
 (0)