Skip to content
Snippets Groups Projects
Unverified Commit eaa5e119 authored by Tim van Dijen's avatar Tim van Dijen Committed by GitHub
Browse files

Merge pull request #1516 from simplesamlphp/entity_data_size

Fix entity data size for MySQL
parents 81d06bfc 70d61a1e
No related branches found
No related tags found
No related merge requests found
...@@ -4,6 +4,7 @@ declare(strict_types=1); ...@@ -4,6 +4,7 @@ declare(strict_types=1);
namespace SimpleSAML; namespace SimpleSAML;
use Exception;
use PDO; use PDO;
use PDOException; use PDOException;
use PDOStatement; use PDOStatement;
...@@ -164,7 +165,7 @@ class Database ...@@ -164,7 +165,7 @@ class Database
return $db; return $db;
} catch (PDOException $e) { } catch (PDOException $e) {
throw new \Exception("Database error: " . $e->getMessage()); throw new Exception("Database error: " . $e->getMessage());
} }
} }
...@@ -227,7 +228,7 @@ class Database ...@@ -227,7 +228,7 @@ class Database
return $query; return $query;
} catch (PDOException $e) { } catch (PDOException $e) {
$this->lastError = $db->errorInfo(); $this->lastError = $db->errorInfo();
throw new \Exception("Database error: " . $e->getMessage()); throw new Exception("Database error: " . $e->getMessage());
} }
} }
...@@ -247,7 +248,7 @@ class Database ...@@ -247,7 +248,7 @@ class Database
return $db->exec($stmt); return $db->exec($stmt);
} catch (PDOException $e) { } catch (PDOException $e) {
$this->lastError = $db->errorInfo(); $this->lastError = $db->errorInfo();
throw new \Exception("Database error: " . $e->getMessage()); throw new Exception("Database error: " . $e->getMessage());
} }
} }
...@@ -291,4 +292,15 @@ class Database ...@@ -291,4 +292,15 @@ class Database
{ {
return $this->lastError; return $this->lastError;
} }
/**
* Return the name of the PDO-driver
*
* @return string
*/
public function getDriver(): string
{
return $this->dbPrimary->getAttribute(PDO::ATTR_DRIVER_NAME);
}
} }
...@@ -279,18 +279,28 @@ class MetaDataStorageHandlerPdo extends MetaDataStorageSource ...@@ -279,18 +279,28 @@ class MetaDataStorageHandlerPdo extends MetaDataStorageSource
{ {
$stmt = 0; $stmt = 0;
$fine = true; $fine = true;
$driver = $this->db->getDriver();
$text = 'TEXT';
if ($driver === 'mysql') {
$text = 'MEDIUMTEXT';
}
foreach ($this->supportedSets as $set) { foreach ($this->supportedSets as $set) {
$tableName = $this->getTableName($set); $tableName = $this->getTableName($set);
$rows = $this->db->write( $rows = $this->db->write(sprintf(
"CREATE TABLE IF NOT EXISTS $tableName (entity_id VARCHAR(255) PRIMARY KEY NOT NULL, entity_data " . "CREATE TABLE IF NOT EXISTS $tableName (entity_id VARCHAR(255) PRIMARY KEY NOT NULL, "
"TEXT NOT NULL)" . "entity_data %s NOT NULL)",
); $text
));
if ($rows === false) { if ($rows === false) {
$fine = false; $fine = false;
} else { } else {
$stmt += $rows; $stmt += $rows;
} }
} }
if (!$fine) { if (!$fine) {
return false; return false;
} }
......
...@@ -222,6 +222,13 @@ class DatabaseTest extends TestCase ...@@ -222,6 +222,13 @@ class DatabaseTest extends TestCase
$this->assertEquals($prefix . $table, $pftable, "Did not properly apply the table prefix"); $this->assertEquals($prefix . $table, $pftable, "Did not properly apply the table prefix");
} }
/**
* @test
*/
public function testGetDriver(): void
{
$this->assertEquals('sqlite', $this->db->getDriver());
}
/** /**
* @test * @test
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment