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

Action `stats` with filter `rand` gives and SQL Exception #2516

Closed
AmauryOrtega opened this Issue Mar 15, 2019 · 2 comments

Comments

Projects
None yet
2 participants
@AmauryOrtega
Copy link

AmauryOrtega commented Mar 15, 2019

Description

SQL Exception caused by using the action stats with filter rand.

Steps to reproduce

Using httpie

http get https://some-server-name.com/yourls-api.php signature==44aa822a05dfe6d33f36d3b07297b39c timestamp==1552654863 action==stats limit==3 filter==rand format==json

I always get this response

HTTP/1.1 500 Internal Server Error
Connection: keep-alive
Content-Type: text/html; charset=UTF-8
Date: Fri, 15 Mar 2019 13:06:19 GMT
Server: nginx/1.14.0 (Ubuntu)
Transfer-Encoding: chunked

Expected behavior: Get stats of 3 random urls.

Actual behavior:

PHP message: PHP Fatal error:  Uncaught PDOException: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'RAND()' in 'order clause' in /path/to/YOURLS-1.7.3/includes/vendor/aura/sql/src/ExtendedPdo.php:748
Stack trace:
#0 /path/to/YOURLS-1.7.3/includes/vendor/aura/sql/src/ExtendedPdo.php(748): PDOStatement->execute()
#1 /path/to/YOURLS-1.7.3/includes/vendor/aura/sql/src/ExtendedPdo.php(523): Aura\Sql\ExtendedPdo->perform('SELECT * FROM `...', Array)
#2 /path/to/YOURLS-1.7.3/includes/functions.php(599): Aura\Sql\ExtendedPdo->fetchObjects('SELECT * FROM `...')
#3 /path/to/YOURLS-1.7.3/includes/functions-api.php(168): yourls_get_stats('rand', 3, 0)
#4 /path/to/YOURLS-1.7.3/includes/functions-api.php(37): yourls_api_stats('rand', '3', '')
#5 /path/to/YOURLS-1.7.3/includes/functions-plugins.php(150): yourls_api_action_stats(false)
#6 /path/to/YOURLS-1.7.3/yourls-api.php(35): yourls_apply_filter('api_action_stat...', false)
#7 {main}

Reproduces how often: How often you make this API call

Versions

  • OS: Ubuntu 18.04.2 LTS
  • YOURLS 1.7.3
  • MySQL 8.0.13
  • PHP 7.2.15
  • PHP-FPM 7.2.15
  • NGINX 1.14.0

PHP Packages

  • php-common
  • php-pear 1.10.5
  • php7.2-bcmath
  • php7.2-cli
  • php7.2-common
  • php7.2-curl
  • php7.2-fpm
  • php7.2-gd
  • php7.2-json
  • php7.2-mbstring
  • php7.2-mysql
  • php7.2-opcache
  • php7.2-readline
  • php7.2-xml
  • php7.2-zip

Additional information

NGINX

server {
  listen 443;
  # SSL Certificates configurations
  # ...
  server_name some-server-name.com;
  charset utf-8;

  root /path/to/YOURLS-1.7.3;
  index index.php;
  location / {
    try_files $uri $uri/ /yourls-loader.php$is_args$args;
  }
  error_page 403 = @main_site;
  location @main_site {
    return 301 https://some-other-site;
  }
  location ~ \.php$ {
    proxy_set_header X-Real-IP $remote_addr;
    include fastcgi.conf;
    fastcgi_index index.php;
    fastcgi_pass 127.0.0.1:9002;
  }
}

PHP-FPM Pool

[yourls]
user = www-data
group = www-data
listen = 127.0.0.1:9002
listen.allowed_clients = 127.0.0.1
# PM Dynamic configuration, 2 start servers with a maximum of 5
# ...
chdir = /path/to/YOURLS-1.7.3
catch_workers_output = yes
@ozh

This comment has been minimized.

Copy link
Member

ozh commented Mar 24, 2019

Indeed. SQL generated is order by 'RAND()' while it should be order by RAND()

ozh added a commit that referenced this issue Mar 24, 2019

@ozh ozh closed this in #2519 Mar 25, 2019

@AmauryOrtega

This comment has been minimized.

Copy link
Author

AmauryOrtega commented Mar 25, 2019

Thanks @ozh, looking forward to the next release 🎇

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.