Wednesday, April 23, 2014

Re: Spaces in Field Names

if you have a fix, please make a PR against the master branch including tests.
Then we all can see right away if that fix really works and doesn't break anything else.
It can also then be merged right away - so it is essentially the fasted way for you to cleanly resolve the issue.
Posting it here doesn't help that much compared to that :)


Am Dienstag, 22. April 2014 16:52:41 UTC+2 schrieb Joe Trums:
Not sure if you found the workaround yet. I was having the same issue, trying
to retro-fit an SQL Server database (with bad naming conventions) to a
CakePHP application. The issue is occurring in the regex checks in
*DboSource::name()*. The fix I came up with was to create a custom
*Datasource* (as to not modify the core lib). I copied the Sqlserver.php
(probably Mysql in your case) from /lib/Cake/Model/Datasource/Database/ -to-
/app/Model/Datasource/Database/. I renamed the file and class to /SQLSRV/. I
copied the method *DboSource::name()* to the bottom of SQLSRV ( as this will
now overwrite the parent method ) and made the following change to the last
regex test in the method:

                if (preg_match('/^[\w-_\s]*[\w-_]+/', $data)) {
                        return $this->cacheMethod(__FUNCTION__, $cacheKey, $this->startQuote .
$data . $this->endQuote);
                }
                return $this->cacheMethod(__FUNCTION__, $cacheKey, $data);

Became ->

        if (preg_match('/^[\w-_\s]*[\w-_]+/', $data)) {
            if( strpos( $data , '.' ) !== FALSE ){
                $items = explode('.', $data);
                return $this->cacheMethod(__FUNCTION__, $cacheKey,
                    $this->startQuote . implode($this->endQuote . '.' .
$this->startQuote, $items) . $this->endQuote
                );
            }
            return $this->cacheMethod(__FUNCTION__, $cacheKey,
$this->startQuote . $data . $this->endQuote);
        }

Finally I updated the database.php in config to use the new
*Database/SQLSRV* datasource.



--
View this message in context: http://cakephp.1045679.n5.nabble.com/Spaces-in-Field-Names-tp5717644p5718006.html
Sent from the CakePHP mailing list archive at Nabble.com.

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.

No comments: