ezSQL compat functions, and $infos stuff

[skip ci]
This commit is contained in:
ozh 2017-08-21 21:32:25 +02:00
parent 4ad5532d79
commit 039ac6aa80
3 changed files with 53 additions and 17 deletions

View File

@ -74,6 +74,10 @@ class Logger extends \Aura\Sql\Profiler {
* @return strings Readable SQL query with placeholders replaced
*/
public function pretty_format($statement, array $values = array() ) {
if (!$values) {
return $statement;
}
return preg_replace_callback(
'/:([^\s;)]*)/',
function ($matches) use ($values) {

View File

@ -15,7 +15,7 @@ namespace YOURLS\Database;
use YOURLS\Admin\Logger;
use Aura\Sql\ExtendedPdo;
use PDO;
class YDB extends ExtendedPdo {
@ -135,6 +135,29 @@ class YDB extends ExtendedPdo {
}
// Infos (related to keyword) low level functions
public function set_infos($keyword, $infos) {
$this->info[$keyword] = $infos;
}
public function has_infos($keyword) {
return array_key_exists($keyword, $this->infos);
}
public function get_infos($keyword) {
return $this->infos[$keyword];
}
public function delete_infos($keyword) {
unset($this->infos[$keyword]);
}
/**
* @todo: infos & options are working the same way here. Abstract this.
*/
// Plugin low level functions, see functions-plugins.php
public function get_plugins() {
@ -222,7 +245,7 @@ class YDB extends ExtendedPdo {
public function get_queries() {
$queries = $this->getProfiler()->getProfiles();
if ($this->getAttribute(\PDO::ATTR_EMULATE_PREPARES)) {
if ($this->getAttribute(PDO::ATTR_EMULATE_PREPARES)) {
// keep queries if $query['function'] != 'prepare'
$queries = array_filter($queries, function($query) {return $query['function'] !== 'prepare';});
}
@ -266,7 +289,7 @@ class YDB extends ExtendedPdo {
* @return string
*/
public function mysql_version() {
$version = $this->pdo->getAttribute(\PDO::ATTR_SERVER_VERSION);
$version = $this->pdo->getAttribute(PDO::ATTR_SERVER_VERSION);
return preg_replace('/(^[^0-9]*)|[^0-9.].*/', '', $version);
}
@ -284,28 +307,36 @@ class YDB extends ExtendedPdo {
throw new \Exception\escape();
}
public function get_col() {
//->fetchAll(PDO::FETCH_COLUMN) -> array
throw new \Exception\get_col();
public function get_col($query) {
yourls_deprecated_function( '$ydb->'.__FUNCTION__, '1.7.3', 'PDO' );
yourls_debug_log('LEGACY SQL: '.$query);
return $this->fetchCol($query);
}
public function get_results($query) {
yourls_deprecated_function( '$ydb->'.__FUNCTION__, '1.7.3', 'PDO' );
yourls_debug_log('LEGACY SQL: '.$query);
$stm = parent::query($query);
return($stm->fetchAll(\PDO::FETCH_OBJ));
return($stm->fetchAll(PDO::FETCH_OBJ));
}
public function get_row($sql) {
public function get_row($query) {
yourls_deprecated_function( '$ydb->'.__FUNCTION__, '1.7.3', 'PDO' );
$row = $this->fetchObjects($sql);
yourls_debug_log('LEGACY SQL: '.$query);
$row = $this->fetchObjects($query);
return $row[0];
}
public function get_var() {
throw new \Exception\get_var();
public function get_var($query) {
yourls_deprecated_function( '$ydb->'.__FUNCTION__, '1.7.3', 'PDO' );
yourls_debug_log('LEGACY SQL: '.$query);
return $this->fetchValue($query);
}
public function query($query) {
throw new \Exception\query();
yourls_deprecated_function( '$ydb->'.__FUNCTION__, '1.7.3', 'PDO' );
yourls_debug_log('LEGACY SQL: '.$query);
return $this->fetchAffected($query);
}
}

View File

@ -409,6 +409,7 @@ function yourls_keyword_is_taken( $keyword ) {
$keyword = yourls_escape( yourls_sanitize_keyword( $keyword ) );
$taken = false;
$table = YOURLS_DB_TABLE_URL;
$already_exists = $ydb->get_var( "SELECT COUNT(`keyword`) FROM `$table` WHERE `keyword` = '$keyword';" );
if ( $already_exists )
$taken = true;
@ -436,8 +437,8 @@ function yourls_get_keyword_infos( $keyword, $use_cache = true ) {
yourls_do_action( 'pre_get_keyword', $keyword, $use_cache );
if( isset( $ydb->infos[$keyword] ) && $use_cache == true ) {
return yourls_apply_filter( 'get_keyword_infos', $ydb->infos[$keyword], $keyword );
if( $ydb->has_infos($keyword) && $use_cache == true ) {
return yourls_apply_filter( 'get_keyword_infos', $ydb->get_infos($keyword), $keyword );
}
yourls_do_action( 'get_keyword_not_cached', $keyword );
@ -447,12 +448,12 @@ function yourls_get_keyword_infos( $keyword, $use_cache = true ) {
if( $infos ) {
$infos = (array)$infos;
$ydb->infos[ $keyword ] = $infos;
$ydb->set_infos($keyword, $infos);
} else {
$ydb->infos[ $keyword ] = false;
$ydb->set_infos($keyword, false);
}
return yourls_apply_filter( 'get_keyword_infos', $ydb->infos[$keyword], $keyword );
return yourls_apply_filter( 'get_keyword_infos', $infos, $keyword );
}
/**