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

Expiry not working - Binary type not compatible with aura/sql fetchOne method #36

Closed
Omniru opened this issue Jun 15, 2021 · 3 comments
Closed
Labels

Comments

@Omniru
Copy link

Omniru commented Jun 15, 2021

Binary type not compatible with aura/sql fetchOne method

$table_expiry .= "keyword binary(100) NOT NULL, ";

$expiry = $ydb->fetchOne($sql, $binds);

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);
});`

@Omniru Omniru changed the title Binary type not compatible with aura/sql fetchOne method Expiry not working - Binary type not compatible with aura/sql fetchOne method Jun 17, 2021
@joshp23 joshp23 added the bug label Jun 17, 2021
@joshp23
Copy link
Owner

joshp23 commented Jun 17, 2021

i pushed this. Thanks for the fix, maybe consider looking into learning about pull requests?

@Omniru
Copy link
Author

Omniru commented Jun 17, 2021 via email

@Omniru
Copy link
Author

Omniru commented Jun 18, 2021

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);
});

brknkfr pushed a commit to brknkfr/YOURLS-Expiry that referenced this issue Mar 26, 2024
Ability to keep expired links in database
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants