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

Replace sql type TEXT by LONGTEXT for profile field when using mysql … #487

Merged
merged 1 commit into from
Jan 3, 2023

Conversation

Mmasson-01
Copy link

@Mmasson-01 Mmasson-01 commented Dec 21, 2022

Problem

mysql driver truncate data when using field type TEXT while exceeding 65535 characters

Solution

Use field type LONGTEXT when using mysql driver.

Related PR

Alternative

I believe it could add a nice touch to implement an abstract class as a Driver helper.
Something like this:

<?php

namespace XHGui\Db;

abstract class PdoDriverAbstract 
{
    /* @var PdoDriverAbstract */
    private $driver;

    public function __construct(string $driverName) 
    {
        switch($driverName)
        {
            case "mysql":
                $this->driver = new PdoMysqlDriver();
                break;
            default:
                $this->driver = new PdoSqliteDriver();
        }

    }
    
    abstract public function getTableQuery(): string;
}

Then we could do something like this:

 public function __construct(PDO $pdo, string $driverName, string $table, string $tableWatch)
    {
        $this->pdo = $pdo;
        $this->driver = new PdoDriverAbstract($driverName);
        $this->table = sprintf('"%s"', $table);
        $this->tableWatches = sprintf('"%s"', $tableWatch);
        $this->initSchema();
    }

 public function initSchema(): void
    {
            $this->pdo->exec($this->driver->getTableQuery()
                ', $this->table));
   ...
}

It would be ready to scale if other exception happens in the futur...but then its a bit overkill for now.

Let me know !

@glensc
Copy link
Contributor

glensc commented Dec 21, 2022

Maybe less copy paste, and create $profileColumnType = "LONGTEXT" and use that in expression?

@Mmasson-01
Copy link
Author

@glensc Agreed. Let me fix this real quick
Meanwhile, what about my alternative suggestion ?

@Mmasson-01 Mmasson-01 force-pushed the fix-pdo-mysql-schema-tablew branch 2 times, most recently from 44d61f3 to 24ec45d Compare December 21, 2022 20:41
src/Db/PdoRepository.php Outdated Show resolved Hide resolved
@glensc glensc merged commit ff15ced into perftools:0.21.x Jan 3, 2023
@glensc glensc added this to the 0.21.3 milestone Jan 3, 2023
@Mmasson-01 Mmasson-01 deleted the fix-pdo-mysql-schema-tablew branch January 9, 2024 03:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants