#6160: Columns with blank spaces can't be unique.
---------------------------------------------------------------+------------
    Reporter:  braulio                                         |          Type: 
 Bug  
      Status:  new                                             |      Priority: 
 High 
   Milestone:  1.2.x.x                                         |     Component: 
 Model
     Version:  1.2 Final                                       |      Severity: 
 Major
    Keywords:  dbo_source.php,model,columns,blank space,mssql  |   Php_version: 
 n/a  
Cake_version:  1.2.1.8004                                      |  
---------------------------------------------------------------+------------
 Hello.[[BR]][[BR]]
 When having a model of a table with a column named like "Cédula Jurídica"
 (with a blank space), if you set this model attribute unique, SQL will
 fail.[[BR]]
 Example:
 {{{
                 'Cédula jurídica' => array(
                         'isUnique' => array(
                                 'rule' => 'isUnique',
                                 'required' => true,
                                 'message' => 'Esa cédula jurídica ya
 existe en la base de datos, una empresa no puede registrarse dos veces.'
                         )
                 ),
 }}}
 will raise the following error:  "mssql_query() [function.mssql-query]:
 message: An expression of non-boolean type specified in a context where a
 condition is expected, near 'jurídica'. (severity 15)" (using Microsoft
 SQL Server).[[BR]][[BR]]
 This happens because the following SQL is generated for isUnique:
 {{{
 SELECT  COUNT(*) AS [count] FROM [companies] AS [Company]   WHERE
 [Company].[Cédula] jurídica = '444444444444444'
 }}}
 As you can see, brackets should enclose all the expression "Cédula
 jurídica", but they do not.  And, this is a mistake since "jurídica" is
 not a valid operator.[[BR]][[BR]]
 This is corrected changing the dbo_source.php file adding this code:
 {{{
                         if (!preg_match($operatorMatch, $operator)) {
                                 $key = $key . ' ' . $operator;
                                 $operator = '=';
                         }
 }}}
 just like this:
 {{{
                 if (!strpos($key, ' ')) {
                         $operator = '=';
                 } else {
                         list($key, $operator) = explode(' ', trim($key),
 2);

                         if (!preg_match($operatorMatch, trim($operator))
 && strpos($operator, ' ') !== false) {
                                 $key = $key . ' ' . $operator;
                                 $split = strrpos($key, ' ');
                                 $operator = substr($key, $split);
                                 $key = substr($key, 0, $split);
                         }
                         if (!preg_match($operatorMatch, $operator)) {
                                 $key = $key . ' ' . $operator;
                                 $operator = '=';
                         }
                 }
 }}}
 Sorry I am still not attaching patches.[[BR]][[BR]]
 Hope this helps,[[BR]][[BR]]
 B.

-- 
Ticket URL: <https://trac.cakephp.org/ticket/6160>
CakePHP : The Rapid Development Framework for PHP <https://trac.cakephp.org/>
Cake is a rapid development framework for PHP which uses commonly known design 
patterns like ActiveRecord, Association Data Mapping, Front Controller and MVC. 
Our primary goal is to provide a structured framework that enables PHP users at 
all levels to rapidly develop robust web applications, without any loss to 
flexibility.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"tickets cakephp" group.
To post to this group, send email to tickets-cakephp@googlegroups.com
To unsubscribe from this group, send email to 
tickets-cakephp+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/tickets-cakephp?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to