Hello,
I use Extra Builder for custome table management.
In manager if I user a column with DB Type “date” automatically precision field set to “0”.
Whem built the schema and alter the table I have the following error:
Error altering field customer\Model\Customers->birthday: Array
(
[0] => 42000
[1] => 1064
[2] => You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '(0) NULL DEFAULT ''' at line 1
)
I could alter schema.xml manually.
How to fix this problem?
Thank you in advance.
Bye
Chris
What is the exact line in the schema that gets produced for this field? (There is a button “Preview Schema” in the “Manage Objects” tab to preview the schema)?
<field key="birthday" dbtype="date" precision="0" phptype="date" null="true" default=""/>
according to the error message in sql MariaDB don’t accept precition=0
It looks like ExtraBuilder doesn’t handle the type “date” correctly.
To fix it, the easiest way is probably to use the type “datetime” instead.
Otherwise you have to copy this line in the code
$objectTpl = '<object class="{class}" table="{table_name}" extends="{extends}">';
$indexTpl = '<index alias="{column_name}" name="{column_name}" {index_attributes} type="{index}">
<column key="{column_name}" length="" collation="A" null="false"/>
</index>';
$relTpl = '<{relation_type} alias="{alias}" class="{class}" local="{local}" foreign="{foreign}" cardinality="{cardinality}" owner="{owner}"/>';
// Define field types
$fieldTplArr = [
'default' => '<field key="{column_name}" dbtype="{dbtype}" precision="{precision}" phptype="{phptype}" null="{allownull}" default="{default}"/>',
'datetime' => '<field key="{column_name}" dbtype="{dbtype}" phptype="{phptype}" null="{allownull}"/>',
'text' => '<field key="{column_name}" dbtype="{dbtype}" phptype="{phptype}" null="{allownull}" default="{default}"/>'
];
$fieldTplArr = array_merge(
$fieldTplArr,
array_fill_keys([
'tinytext', 'mediumtext', 'longtext', 'blob', 'tinyblob', 'mediumblob', 'longblob'
], $fieldTplArr['text'])
);
$this->logMessages[] = "Field template array: ".print_r($fieldTplArr, true);
and create a new entry in the array $fieldTplArr with date as the key:
'date' => '<field key="{column_name}" dbtype="{dbtype}" phptype="{phptype}" null="{allownull}"/>',
great. thank you so much.
I think enum db field type isn’t intended, right?
how could I declare a enum field? May be extra builder have problems?
I don’t think I have ever seen a field of type “enum” in a MODX extra.
Do you really need an “enum”?
Maybe just use a “tinyint” instead.
There are “enum” fields in this sample-schema in xPDO:
<?xml version="1.0" encoding="UTF-8"?>
<model package="sample" baseClass="xPDO\\Om\\xPDOObject" platform="mysql" defaultEngine="MyISAM" version="1.1">
<object class="Person" table="person" extends="xPDO\\Om\\xPDOSimpleObject">
<field key="first_name" dbtype="varchar" precision="100" phptype="string" null="false" default="" />
<field key="last_name" dbtype="varchar" precision="100" phptype="string" null="false" default="" />
<field key="middle_name" dbtype="varchar" precision="100" phptype="string" null="false" default="" />
<field key="date_modified" dbtype="timestamp" phptype="timestamp" null="false" default="CURRENT_TIMESTAMP" attributes="ON UPDATE CURRENT_TIMESTAMP" />
<field key="dob" dbtype="date" phptype="date" null="true" />
<field key="gender" dbtype="enum" precision="'','M','F'" phptype="string" null="false" default="" />
<field key="blood_type" dbtype="varchar" precision="100" phptype="string" null="true" />
<field key="username" dbtype="varchar" precision="255" phptype="string" null="false" index="unique" />
<field key="password" dbtype="varchar" precision="255" phptype="password" null="false" default="" />
<field key="security_level" dbtype="tinyint" precision="4" phptype="integer" null="false" default="1" />
<alias key="date_of_birth" field="dob" />
<index alias="username" name="username" primary="false" unique="true" type="BTREE">
<column key="username" collation="A" null="false" />
</index>
So I guess the type “enum” is supported by xPDO and you could use it in your schema.
No, not really.
I use tinyint instead.
Thank you so much.