Expiry not working - Binary type not compatible with aura/sql fetchOne method
Omniru opened this issue · 3 comments
Binary type not compatible with aura/sql fetchOne method
YOURLS-Expiry/expiry/plugin.php
Line 1328 in 5bf6c72
YOURLS-Expiry/expiry/plugin.php
Line 790 in 5bf6c72
In the latest version 2.4.0 I had issues with the create statement creating the field as a binary type instead of a varchar(200) like is shown in the expiry.sql code. After changing that type to varchar yourl's aura/sql implementation of fetchOne is able to find the record in the database and successfully delete them as expected.
`yourls_add_action( 'activated_expiry/plugin.php', function () {
global $ydb;
// Create the expiry table
$table = YOURLS_DB_PREFIX . 'expiry';
$table_expiry = "CREATE TABLE IF NOT EXISTS ".$table."
(";
$table_expiry .= "keyword varchar(200) NOT NULL, ";
$table_expiry .= "type varchar(5) NOT NULL, ";
$table_expiry .= "click varchar(5), ";
$table_expiry .= "timestamp varchar(20), ";
$table_expiry .= "shelflife varchar(20), ";
$table_expiry .= "postexpire varchar(200), ";
$table_expiry .= "PRIMARY KEY (keyword) ";
$table_expiry .= ") ENGINE=InnoDB DEFAULT CHARSET=latin1;";
$tables = $ydb->fetchAffected($table_expiry);
});`
i pushed this. Thanks for the fix, maybe consider looking into learning about pull requests?
I ended up formatting the table like this to make it respect casing, modeled after yourls_url table. I am still testing it though.
--I'm also unsure if bigint is an issue for other databases or not as I'm not sure what's normally supported.
// Create tables for this plugin when activated
yourls_add_action('activated_expiry/plugin.php', function () {
global $ydb;
// Create the expiry table
$table = YOURLS_DB_PREFIX . 'expiry';
$table_expiry = "CREATE TABLE IF NOT EXISTS `" . $table . "` (";
$table_expiry .= "keyword varchar(100) COLLATE utf8mb4_bin NOT NULL DEFAULT '', ";
$table_expiry .= "type varchar(5) NOT NULL, ";
$table_expiry .= "click varchar(5), ";
$table_expiry .= "timestamp bigint(20), ";
$table_expiry .= "shelflife int(11), ";
$table_expiry .= "postexpire varchar(200), ";
$table_expiry .= "PRIMARY KEY (keyword) ";
$table_expiry .= ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;";
$tables = $ydb->fetchAffected($table_expiry);
});