Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is DC2Type array datatype in mysql

I have been working with Symfony2 and doctrine2 recently and have realized a peculiar datatype called DC2Type:array that certain Symfony2 Roles get saved as. To me it just looks like a serialized PHP array where a signifies the total number of elements, i is the array index.

The value looks like this:

a:15:{i:0;s:32:"ROLE_SONATA_USER_ADMIN_USER_EDIT";i:1;s:32:"ROLE_SONATA_USER_ADMIN_USER_LIST";i:2;s:34:"ROLE_SONATA_USER_ADMIN_USER_CREATE";i:3;s:32:"ROLE_SONATA_USER_ADMIN_USER_VIEW";i:4;s:34:"ROLE_SONATA_USER_ADMIN_USER_DELETE";i:5;s:36:"ROLE_SONATA_USER_ADMIN_USER_OPERATOR";i:6;s:34:"ROLE_SONATA_USER_ADMIN_USER_MASTER";i:7;s:33:"ROLE_SONATA_USER_ADMIN_GROUP_EDIT";i:8;s:33:"ROLE_SONATA_USER_ADMIN_GROUP_LIST";i:9;s:35:"ROLE_SONATA_USER_ADMIN_GROUP_CREATE";i:10;s:33:"ROLE_SONATA_USER_ADMIN_GROUP_VIEW";i:11;s:35:"ROLE_SONATA_USER_ADMIN_GROUP_DELETE";i:12;s:37:"ROLE_SONATA_USER_ADMIN_GROUP_OPERATOR";i:13;s:35:"ROLE_SONATA_USER_ADMIN_GROUP_MASTER";i:14;s:10:"ROLE_ADMIN";}

I want to know what this datatype is?

And what do the following identifier signifies:

s:

I have searched the internet but haven't got any useful data.

I also bumped upon this cookbook entry - http://readthedocs.org/docs/doctrine-orm/en/2.0.x/cookbook/mysql-enums.html but didn't figure out the origin.

like image 840
Amit Avatar asked Apr 27 '12 06:04

Amit


People also ask

What is the data type in MySQL?

The data type is a guideline for SQL to understand what type of data is expected inside of each column, and it also identifies how SQL will interact with the stored data. In MySQL there are three main data types: string, numeric, and date and time. A FIXED length string (can contain letters, numbers, and special characters).

Is it possible to serialize a dc2type field with PHP?

Not any Database engine, like MySQL knows what PHP serialization is, so you can't do this at this level which means, that you will need to do it yes or yes with PHP. The DC2Type fields in doctrine is stored as a field with LONGTEXT type, as MySQL doesn't allow to store arrays in the database but strings.

Is there an array datatype in the DBMS?

As stated elsewhere, there is no "array" datatype in the dbms, you have to use some workaround. Thanks for contributing an answer to Stack Overflow!

Where are the dc2type fields stored in doctrine?

The DC2Type fields in doctrine is stored as a field with LONGTEXT type, as MySQL doesn't allow to store arrays in the database but strings. An example of the data (string) that Doctrine stores in a register in your database looks as follows:


2 Answers

This is not a data type. You might have noticed that the column type is LONGTEXT. DC2Type:array is a comment of the field.

Doctrine uses the field's comment as column's metadata storage place. Since Mysql does not allow you to store an array, Doctrine use DC2Type:array as comment in order to know how to unserialize the content.

Take a look at the link below.

https://github.com/doctrine/dbal/issues/1614

From the link you mentioned, you can see that the comment DC2Type:enumvisibility indicates that the content of the field is a flag, indicating that the record is visible or not. It is not a new data type at all. It should be considered an helper strategy in the database level. For Doctrine, it's a custom data type.

like image 195
P. R. Ribeiro Avatar answered Oct 13 '22 16:10

P. R. Ribeiro


This is simply a string. Its format is a serialized PHP array. The s: refers to the size or length of each item value in the array.

e.g. s:32:"ROLE_SONATA_USER_ADMIN_USER_EDIT"

If you count the characters in the ROLE string, there are 32.

Hope this helps.

like image 8
Strategist Avatar answered Oct 13 '22 16:10

Strategist