-
Notifications
You must be signed in to change notification settings - Fork 268
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
Allow to specify a column specific character set #206
base: master
Are you sure you want to change the base?
Conversation
…scii" via constrain parameter, required to be first part of suffix
Do you want me to modify this pull request to use Ralf |
I don't know whether you gave this some consideration, but I wonder if there might be a way we could add something that would allow us to add any user defined options that might be required, for example in your case:
or perhaps a slightly more sophisticated example option using SQL SERVER:
This would allow users to define any column definitions they want without us having to shoehorn even more sophisticated parsing into what is already a difficult to maintain piece of code. @dregad , I wonder if you have any opinion about this, and whether this would be an appropriate time to achieve such a feature. |
As a matter of fact, I was actually thinking along the same lines. In my opinion, having a generic option that is passed on to the driver as is, is probably the most flexible way to achieve this, while requiring the least maintenance on ADOdb end. |
So I'm stealing an idea here from AXMLS. What if the $flds argument to $flds = array('COL1'=>array('type'=>'C(32)',
'portableOptions'=>array("NOTNULL",
"DEFAULT 'abc'"
),
'driverOptions'=>array('mysqli'=>array("CHARACTER SET 'UTF8'"),
'mssqlnative'=>array("COLLATE 'UTF8'",
"SPARSE")
),
'providerOptions'=>array(),
),
'COL2'=>array('type'=>'I',
'portableOptions'=>array("DEFAULT 0")
)
); The minimum required entries would be the key (field name) the 'type'.
|
The approach is interesting, and has the advantage of providing good flexibility. How would you propose we handle backwards compatibility ? |
I don't see a column specific character set as something driver specific, even if some databases might not offer it. ADOdb drivers should be used to abstract the db specific syntax for column specific charsets. As driver specific I see eg. certain type of indexes. |
I was just using the character set as an example, but my point about stealing the idea from AXMLS still stands. For example, here is part of an AXMLS table from my system: <?xml version="1.0"?>
<schema version="0.3">
<table name="words" >
<opt platform="mysql">TYPE=MyISAM</opt>
<opt platform="db2">TABLESPACE="APP-LARGE-SPACE"</opt>
..... Based on the provider, the options are passed into I understand your point about ADOdb being an abstraction device, and I believe that my concept of 'portableOptions' addresses that. If an option such as CHARACTER SET is worthy of becoming a portable option, I think this redesign would allow us to achieve that without disturbing the core code too much. Perhaps each portable option could become a standardized API method that could be extended as necessary on a driver by driver basis. We should also recognize that a lot of people use ADOdb as an abstraction device, but are not interested in portability, just that the software provides easy access to database functionality, and our data dictionary should accommodate it with driver-specific functionality. /*
* We pass in our field definitions
*/
$flds = array('COL1'=>array('type'=>'C(32)',
'portableOptions'=>array("NOTNULL",
"DEFAULT'=>'abc',
'CHARACTERSET'=>'UTF-8'.
),
/*
* For each of our portable options we have a method
*/
protected function metaOption_NOTNULL()
{
return 'NOT NULL';
}
protected function metaOption_CHARACTERSET()
{
$a = func_get_args();
$cSet = "CHARACTER SET '" . $a[0] . "'";
return $cSet;
}
/*
* In our SQL Server driver, we would then overload
*/
final protected function metaOption_CHARACTERSET()
{
$a = func_get_args();
$cSet = "COLLATE ' " . $a[0] . "'";
return $cSet;
} In the above example, the passed arguments are flexible that we could pass a string, an empty string or even another array depending on the complexity of the option. If needed, extra portable options could then be implemented by simply adding the method to the file. We would then iterate through our portable options foreach ($flds as $fieldName=>$items)
{
foreach ($items['portableOptions'] as $k=>$v)
{
$f = 'metaOption_' . $k;
$text .= $this->$f($v);
}
} Indeed, we could take the functionality further by making each method a self-enclosed class, and each option becomes a plugin. The main methods such as createIndexSql(), addColumnSql() would no longer need to be modified if a new portable option needed to be created. From a backwards compatibility perspective, my suggestion about testing for an array instead of a string is still a valid test, I think. We would branch off there and return without entering the main body of the genfield() code. To summarize, my main points are this:
I do however, recognize that what you are trying to do is get your own enhancements into the core product as quickly as possible, and that this is quite a substantial project, so maybe it might be possible to do that on the basis that your request would be a one-off, and no further requests on the subject would be accepted. |
Limiting index size is important for MySQL performance. This pull request allows eg. to create columns with ascii charset (1 byte instead of 3 for utf8), if content only requires ascii characters.
The patch (mis-)uses constrain parsing to specify the character set, eg.
C(64) CONSTRAIN "CHARACTER SET ascii"
Original goal was to keep ADOdb modifications to a minimum, but I could also change parser to understand something like
C(64) CHARACTER SET ascii
and pass it via an extra parameter to _CreateSuffix for data dictionaries supporting it.Ralf