Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix invalid phpdoc #17

Merged
merged 7 commits into from
Jul 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@
namespace DataTables;
if (!defined('DATATABLES')) exit();

use
DataTables\Database\Query,
DataTables\Database\Result;
use DataTables\Database\Query;
use DataTables\Database\Result;


/**
Expand All @@ -36,7 +35,7 @@ class Database {

/**
* Database instance constructor.
* @param string[] $opts Array of connection parameters for the database:
* @param array<string, string|\PDO> $opts Array of connection parameters for the database:
* ```php
* array(
* "user" => "", // User name
Expand Down Expand Up @@ -72,7 +71,7 @@ function __construct( $opts )
* Private properties
*/

/** @var resource */
/** @var \PDO */
private $_dbResource = null;

/** @var callable */
Expand Down Expand Up @@ -225,7 +224,7 @@ public function insert ( $table, $set, $pkey='' )
public function push ( $table, $set, $where=null, $pkey='' )
{
$selectColumn = '*';

if ( $pkey ) {
$selectColumn = is_array($pkey) ?
$pkey[0] :
Expand Down Expand Up @@ -298,7 +297,7 @@ public function raw ()

/**
* Get the database resource connector. This is typically a PDO object.
* @return resource PDO connection resource (driver dependent)
* @return \PDO PDO connection resource (driver dependent)
*/
public function resource ()
{
Expand Down
6 changes: 2 additions & 4 deletions Database/Driver/Db2Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ protected function _exec()
$stmt = $this->_stmt;

//echo $this->_sql."\n";

preg_match_all('/(:[a-zA-Z\-_0-9]*)/', $this->_sql, $matches);

//print_r( $matches );
//print_r( $bindings);

Expand All @@ -133,8 +133,6 @@ protected function _exec()

if (! $res) {
throw new \Exception('DB2 SQL error = '.db2_stmt_error($this->_stmt));

return false;
}

$resource = $this->database()->resource();
Expand Down
6 changes: 2 additions & 4 deletions Database/Driver/FirebirdQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ static function connect( $user, $pass='', $host='', $port='', $db='', $dsn='' )
protected function _prepare( $sql )
{
$this->database()->debugInfo( $sql, $this->_bindings );

$resource = $this->database()->resource();
$pkey = $this->pkey();

Expand Down Expand Up @@ -125,9 +125,7 @@ protected function _exec()
$this->_stmt->execute();
}
catch (\PDOException $e) {
throw new \Exception( "An SQL error occurred: ".$e->getMessage() );
error_log( "An SQL error occurred: ".$e->getMessage() );
return false;
throw new \Exception('An SQL error occurred: ' . $e->getMessage(), 0, $e);
}

$resource = $this->database()->resource();
Expand Down
4 changes: 1 addition & 3 deletions Database/Driver/MysqlQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,7 @@ protected function _exec()
$this->_stmt->execute();
}
catch (\PDOException $e) {
throw new \Exception( "An SQL error occurred: ".$e->getMessage() );
error_log( "An SQL error occurred: ".$e->getMessage() );
return false;
throw new \Exception('An SQL error occurred: ' . $e->getMessage(), 0, $e);
}

// $this->database()->debugInfo( 'Execution complete - duration: '. (hrtime(true) - $start) . ' Time: '. microtime(true), [] );
Expand Down
2 changes: 0 additions & 2 deletions Database/Driver/OracleQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,6 @@ protected function _exec()
if ( ! $res ) {
$e = oci_error( $this->_stmt );
throw new \Exception( "Oracle SQL error: ".$e['message'] );

return false;
}

$resource = $this->database()->resource();
Expand Down
2 changes: 1 addition & 1 deletion Database/Driver/OracleResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function fetchAll ( $fetchType=\PDO::FETCH_ASSOC /* irrelevant for oci8 *
{
if ( ! $this->_rows ) {
$out = array();

oci_fetch_all( $this->_stmt, $out, 0, -1, OCI_FETCHSTATEMENT_BY_ROW + OCI_ASSOC );

$this->_rows = $out;
Expand Down
8 changes: 3 additions & 5 deletions Database/Driver/PostgresQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ static function connect( $user, $pass='', $host='', $port='', $db='', $dsn='' )
protected function _prepare( $sql )
{
$this->database()->debugInfo( $sql, $this->_bindings );

$resource = $this->database()->resource();

// Add a RETURNING command to postgres insert queries so we can get the
// pkey value from the query reliably
if ( $this->_type === 'insert' ) {
Expand Down Expand Up @@ -134,9 +134,7 @@ protected function _exec()
$this->_stmt->execute();
}
catch (\PDOException $e) {
throw new \Exception( "An SQL error occurred: ".$e->getMessage() );
error_log( "An SQL error occurred: ".$e->getMessage() );
return false;
throw new \Exception('An SQL error occurred: ' . $e->getMessage(), 0, $e);
}

$resource = $this->database()->resource();
Expand Down
6 changes: 2 additions & 4 deletions Database/Driver/SqliteQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,8 @@ protected function _exec()
try {
$this->_stmt->execute();
}
catch (PDOException $e) {
throw new \Exception( "An SQL error occurred: ".$e->getMessage() );
error_log( "An SQL error occurred: ".$e->getMessage() );
return false;
catch (\PDOException $e) {
throw new \Exception('An SQL error occurred: ' . $e->getMessage(), 0, $e);
}

$resource = $this->database()->resource();
Expand Down
8 changes: 3 additions & 5 deletions Database/Driver/SqlserverQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,8 @@ protected function _exec()
try {
$this->_stmt->execute();
}
catch (PDOException $e) {
throw new \Exception( "An SQL error occurred: ".$e->getMessage() );
error_log( "An SQL error occurred: ".$e->getMessage() );
return false;
catch (\PDOException $e) {
throw new \Exception('An SQL error occurred: ' . $e->getMessage(), 0, $e);
}

$resource = $this->database()->resource();
Expand All @@ -139,7 +137,7 @@ protected function _build_limit()
if ( $this->_offset ) {
$out .= ' OFFSET '.$this->_offset.' ROWS';
}

if ( $this->_limit ) {
if ( ! $this->_offset ) {
$out .= ' OFFSET 0 ROWS';
Expand Down
33 changes: 16 additions & 17 deletions Database/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@
namespace DataTables\Database;
if (!defined('DATATABLES')) exit();

use
DataTables,
DataTables\Database,
DataTables\Database\Query,
DataTables\Database\Result;
use DataTables;
use DataTables\Database;
use DataTables\Database\Query;
use DataTables\Database\Result;


//
Expand Down Expand Up @@ -123,7 +122,7 @@ public function __construct( $dbHost, $type, $table=null )
protected $_limit = null;

/**
* @var int
* @var string
* @internal
*/
protected $_group_by = null;
Expand Down Expand Up @@ -263,7 +262,7 @@ public function bind ( $name, $value, $type=null )

/**
* Get the Database host for this query instance
* @return DataTable Database class instance
* @return Database Database class instance
*/
public function database ()
{
Expand Down Expand Up @@ -311,7 +310,7 @@ public function exec ( $sql=null )
else if ( $type === 'raw' ) {
return $this->_raw( $sql );
}

throw new \Exception("Unknown database command or not supported: ".$type, 1);
}

Expand Down Expand Up @@ -438,7 +437,7 @@ public function limit ( $lim )

/**
* Group the results by the values in a field
* @param string The field of which the values are to be grouped
* @param string $group_by The field of which the values are to be grouped
* @return self
*/
public function group_by ( $group_by )
Expand Down Expand Up @@ -748,9 +747,9 @@ public function where_group ( $inOut, $op='AND' )
* Note this is only suitable for local values, not a sub-query. For that use
* `->where()` with an unbound value.
*
* @param string Field name
* @param array Values
* @param string Conditional operator to use to join to the
* @param string $field Field name
* @param array $arr Values
* @param string $operator Conditional operator to use to join to the
* preceding condition. Default `AND`.
* @return self
*/
Expand Down Expand Up @@ -853,7 +852,7 @@ protected function _build_limit()
$out = '';
$limit = intval($this->_limit);
$offset = intval($this->_offset);

if ( $limit ) {
$out .= ' LIMIT '.$limit;
}
Expand Down Expand Up @@ -928,14 +927,14 @@ protected function _build_table()
if ( $this->_type === 'insert' ) {
// insert, update and delete statements don't need or want aliases in the table name
$a = array();

for ( $i=0, $ien=count($this->_table) ; $i<$ien ; $i++ ) {
$table = str_ireplace( ' as ', ' ', $this->_table[$i] );
$tableParts = explode( ' ', $table );

$a[] = $tableParts[0];
}

return ' '.implode(', ', $a).' ';
}

Expand Down Expand Up @@ -1204,7 +1203,7 @@ protected function _update()
/**
* Add an individual where condition to the query.
* @internal
* @param $where
* @param string|array $where
* @param null $value
* @param string $type
* @param string $op
Expand Down
4 changes: 2 additions & 2 deletions Database/Result.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ abstract public function count ();

/**
* Get the next row in a result set
* @param int PDO row fetch style - PDO::FETCH_ASSOC is the default
* @param int $fetchType PDO row fetch style - PDO::FETCH_ASSOC is the default
* @return array
*/
abstract public function fetch ( $fetchType=\PDO::FETCH_ASSOC );


/**
* Get all rows in the result set
* @param int PDO row fetch style - PDO::FETCH_ASSOC is the default
* @param int $fetchType PDO row fetch style - PDO::FETCH_ASSOC is the default
* @return array
*/
abstract public function fetchAll ( $fetchType=\PDO::FETCH_ASSOC );
Expand Down
Loading