Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
doctrine-dbal
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Tomáš Trávníček
doctrine-dbal
Commits
a7cffda8
Commit
a7cffda8
authored
Nov 16, 2018
by
Benoît Burnichon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add some MySQL platform data in Tables
parent
ff6cbdbc
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
95 additions
and
0 deletions
+95
-0
MySqlPlatform.php
lib/Doctrine/DBAL/Platforms/MySqlPlatform.php
+14
-0
MySqlSchemaManager.php
lib/Doctrine/DBAL/Schema/MySqlSchemaManager.php
+42
-0
MySqlSchemaManagerTest.php
...e/Tests/DBAL/Functional/Schema/MySqlSchemaManagerTest.php
+39
-0
No files found.
lib/Doctrine/DBAL/Platforms/MySqlPlatform.php
View file @
a7cffda8
...
...
@@ -380,6 +380,20 @@ class MySqlPlatform extends AbstractPlatform
'FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = '
.
$database
.
' AND TABLE_NAME = '
.
$table
;
}
public
function
getListTableMetadataSQL
(
string
$table
,
?
string
$database
=
null
)
:
string
{
return
sprintf
(
<<<'SQL'
SELECT ENGINE, AUTO_INCREMENT, TABLE_COLLATION, TABLE_COMMENT, CREATE_OPTIONS
FROM information_schema.TABLES
WHERE TABLE_TYPE = 'BASE TABLE' AND TABLE_SCHEMA = %s AND TABLE_NAME = %s
SQL
,
$database
?
$this
->
quoteStringLiteral
(
$database
)
:
'DATABASE()'
,
$this
->
quoteStringLiteral
(
$table
)
);
}
/**
* {@inheritDoc}
*/
...
...
lib/Doctrine/DBAL/Schema/MySqlSchemaManager.php
View file @
a7cffda8
...
...
@@ -10,6 +10,7 @@ use function array_change_key_case;
use
function
array_shift
;
use
function
array_values
;
use
function
end
;
use
function
explode
;
use
function
preg_match
;
use
function
preg_replace
;
use
function
str_replace
;
...
...
@@ -17,6 +18,7 @@ use function stripslashes;
use
function
strpos
;
use
function
strtok
;
use
function
strtolower
;
use
function
trim
;
/**
* Schema manager for the MySql RDBMS.
...
...
@@ -284,4 +286,44 @@ class MySqlSchemaManager extends AbstractSchemaManager
return
$result
;
}
public
function
listTableDetails
(
$tableName
)
{
$table
=
parent
::
listTableDetails
(
$tableName
);
/** @var MySqlPlatform $platform */
$platform
=
$this
->
_platform
;
$sql
=
$platform
->
getListTableMetadataSQL
(
$tableName
);
$tableOptions
=
$this
->
_conn
->
fetchAssoc
(
$sql
);
$table
->
addOption
(
'engine'
,
$tableOptions
[
'ENGINE'
]);
if
(
$tableOptions
[
'TABLE_COLLATION'
]
!==
null
)
{
$table
->
addOption
(
'collation'
,
$tableOptions
[
'TABLE_COLLATION'
]);
}
if
(
$tableOptions
[
'AUTO_INCREMENT'
]
!==
null
)
{
$table
->
addOption
(
'autoincrement'
,
$tableOptions
[
'AUTO_INCREMENT'
]);
}
$table
->
addOption
(
'comment'
,
$tableOptions
[
'TABLE_COMMENT'
]);
if
(
$tableOptions
[
'CREATE_OPTIONS'
]
===
null
)
{
return
$table
;
}
$createOptionsString
=
trim
(
$tableOptions
[
'CREATE_OPTIONS'
]);
$createOptions
=
[];
if
(
$createOptionsString
!==
''
)
{
foreach
(
explode
(
' '
,
$createOptionsString
)
as
$option
)
{
[
$createOption
,
$value
]
=
explode
(
'='
,
$option
);
$createOptions
[
$createOption
]
=
$value
;
}
}
$table
->
addOption
(
'create_options'
,
$createOptions
);
return
$table
;
}
}
tests/Doctrine/Tests/DBAL/Functional/Schema/MySqlSchemaManagerTest.php
View file @
a7cffda8
...
...
@@ -486,4 +486,43 @@ class MySqlSchemaManagerTest extends SchemaManagerFunctionalTestCase
$onlineTable
=
$this
->
schemaManager
->
listTableDetails
(
'test_column_defaults_with_create'
);
self
::
assertSame
(
$default
,
$onlineTable
->
getColumn
(
'col1'
)
->
getDefault
());
}
public
function
testEnsureTableOptionsAreReflectedInMetadata
()
:
void
{
$this
->
connection
->
query
(
'DROP TABLE IF EXISTS test_table_metadata'
);
$sql
=
<<<'SQL'
CREATE TABLE test_table_metadata(
col1 INT NOT NULL AUTO_INCREMENT PRIMARY KEY
)
COLLATE utf8_general_ci
ENGINE InnoDB
ROW_FORMAT COMPRESSED
COMMENT 'This is a test'
AUTO_INCREMENT=42
SQL;
$this
->
connection
->
query
(
$sql
);
$onlineTable
=
$this
->
schemaManager
->
listTableDetails
(
'test_table_metadata'
);
self
::
assertEquals
(
'InnoDB'
,
$onlineTable
->
getOption
(
'engine'
));
self
::
assertEquals
(
'utf8_general_ci'
,
$onlineTable
->
getOption
(
'collation'
));
self
::
assertEquals
(
42
,
$onlineTable
->
getOption
(
'autoincrement'
));
self
::
assertEquals
(
'This is a test'
,
$onlineTable
->
getOption
(
'comment'
));
self
::
assertEquals
([
'row_format'
=>
'COMPRESSED'
],
$onlineTable
->
getOption
(
'create_options'
));
}
public
function
testEnsureTableWithoutOptionsAreReflectedInMetadata
()
:
void
{
$this
->
connection
->
query
(
'DROP TABLE IF EXISTS test_table_empty_metadata'
);
$this
->
connection
->
query
(
'CREATE TABLE test_table_empty_metadata(col1 INT NOT NULL)'
);
$onlineTable
=
$this
->
schemaManager
->
listTableDetails
(
'test_table_empty_metadata'
);
self
::
assertNotEmpty
(
$onlineTable
->
getOption
(
'engine'
));
// collation could be set to default or not set, information_schema indicate a possibly null value
self
::
assertFalse
(
$onlineTable
->
hasOption
(
'autoincrement'
));
self
::
assertEquals
(
''
,
$onlineTable
->
getOption
(
'comment'
));
self
::
assertEquals
([],
$onlineTable
->
getOption
(
'create_options'
));
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment