plugins/contacts/symbian/contactsmodel/cntplsql/src/cntsqlsearch.cpp
changeset 5 603d3f8b6302
parent 0 876b1a06bc25
equal deleted inserted replaced
3:e4ebb16b39ea 5:603d3f8b6302
     1 /****************************************************************************
     1 /*
     2 **
     2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     4 ** All rights reserved.
     4 * This component and the accompanying materials are made available
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
     5 * under the terms of "Eclipse Public License v1.0"
     6 **
     6 * which accompanies this distribution, and is available
     7 ** This file is part of the examples of the Qt Toolkit.
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     8 **
     8 *
     9 ** $QT_BEGIN_LICENSE:LGPL$
     9 * Initial Contributors:
    10 ** No Commercial Usage
    10 * Nokia Corporation - initial contribution.
    11 ** This file contains pre-release code and may not be distributed.
    11 *
    12 ** You may use this file in accordance with the terms and conditions
    12 * Contributors:
    13 ** contained in the Technology Preview License Agreement accompanying
    13 *
    14 ** this package.
    14 * Description: Retrieves the character map for each of the numeric keys.
    15 **
    15 */
    16 ** GNU Lesser General Public License Usage
       
    17 ** Alternatively, this file may be used under the terms of the GNU Lesser
       
    18 ** General Public License version 2.1 as published by the Free Software
       
    19 ** Foundation and appearing in the file LICENSE.LGPL included in the
       
    20 ** packaging of this file.  Please review the following information to
       
    21 ** ensure the GNU Lesser General Public License version 2.1 requirements
       
    22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    23 **
       
    24 ** In addition, as a special exception, Nokia gives you certain additional
       
    25 ** rights.  These rights are described in the Nokia Qt LGPL Exception
       
    26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
    27 **
       
    28 ** If you have questions regarding the use of this file, please contact
       
    29 ** Nokia at qt-info@nokia.com.
       
    30 **
       
    31 **
       
    32 **
       
    33 **
       
    34 **
       
    35 **
       
    36 **
       
    37 **
       
    38 ** $QT_END_LICENSE$
       
    39 **
       
    40 ****************************************************************************/
       
    41 #include <QStringList>
    16 #include <QStringList>
    42 
    17 
    43 #include "cntsqlsearch.h"
    18 #include "cntsqlsearch.h"
    44 #include "cqwertykeymap.h"
    19 #include "cqwertykeymap.h"
    45 #include "c12keykeymap.h"
    20 #include "c12keykeymap.h"
    84 const QChar KHashChar('#');
    59 const QChar KHashChar('#');
    85 
    60 
    86 //Predictive search table
    61 //Predictive search table
    87 const QString QwertyTableName = "qm";
    62 const QString QwertyTableName = "qm";
    88 
    63 
    89 CntSqlSearch::CntSqlSearch()
    64 CntSqlSearch::CntSqlSearch( const CPcsKeyMap& twelveKeyKeyMap,
    90 	{
    65                             const CPcsKeyMap& qertyKeyMap ) 
    91     QT_TRAP_THROWING(mQertyKeyMap = CQwertyKeyMap::NewL());
    66         
    92     QT_TRAP_THROWING(mkeyKeyMap = C12keyKeyMap::NewL());
    67     : mkeyKeyMap( static_cast<const C12keyKeyMap*>(&twelveKeyKeyMap) ),
    93 	}
    68       mQertyKeyMap( static_cast<const CQwertyKeyMap*>(&qertyKeyMap) )
       
    69     {
       
    70     }
    94 
    71 
    95 CntSqlSearch::~CntSqlSearch()
    72 CntSqlSearch::~CntSqlSearch()
    96     {
    73     {
    97     delete mQertyKeyMap;
    74     }
    98     delete mkeyKeyMap;
    75 
    99     }
       
   100 // Basic cases:
    76 // Basic cases:
   101 // 1: "0", "5"
    77 // 1: "0", "5"
   102 // Just one digit. Select all contact ids from the table. No need to compare
    78 // Just one digit. Select all contact ids from the table. No need to compare
   103 // values.
    79 // values.
   104 //
    80 //
   105 // 2: "123", "01", "10", "010", "00"
    81 // 2: "123", "01", "10", "00"
   106 // No zeros which have non-zeros in their both sides
    82 // No zeros which have non-zeros in their both sides
   107 // One or zero tokens, when pattern is split using '0'.
    83 // One or zero tokens, when pattern is split using '0'.
   108 //
    84 //
   109 // 3: "101", "1001"
    85 // 3: "101", "1001"
   110 // Same digit of both sides of the zero
    86 // Same digit of both sides of the zero
   115 // 4: "102", "1002"
    91 // 4: "102", "1002"
   116 // One or more zeros in the middle, just one digit on either side of the zero(s)
    92 // One or more zeros in the middle, just one digit on either side of the zero(s)
   117 // and those digits are not the same.
    93 // and those digits are not the same.
   118 // Two tokens, each with length of 1 and tokens are different.
    94 // Two tokens, each with length of 1 and tokens are different.
   119 //
    95 //
   120 // 5: "1023", "0102", "1010", "00100200", "10203", "01020304050"
    96 // 5: "1023", "1010", "00100200", "10203", "01020304050"
   121 // Two tokens, at least one of them has length > 1.
    97 // Two tokens, at least one of them has length > 1.
   122 // If tokens are identical, handle as case 3, otherwise handle as case 4.
    98 // If tokens are identical, handle as case 3, otherwise handle as case 4.
   123 // ("10203" -> tokens "1" and "203"
    99 // ("10203" -> tokens "1" and "203"
   124 //  "0010023004560" -> tokens "001" and "23004560")
   100 //  "0010023004560" -> tokens "001" and "23004560")
   125 //
   101 //
   126 // 6: "10", "1000"
   102 // 6: "10", "1000"
   127 // One token, ends with zero.
   103 // One token, ends with zero.
   128 // In this case, query should look-up first toke and number ("10", "1000").
   104 // In this case, query should look-up first toke and number ("10", "1000").
   129 
   105 //
       
   106 // 7: "0102"
       
   107 // Same case 5, but first zero is remover in order to get more matches. 
       
   108 // e.g. 0102 is 01 AND 2 or 1 AND 2.
       
   109 //
   130 QString CntSqlSearch::CreatePredictiveSearch(const QString &pattern)
   110 QString CntSqlSearch::CreatePredictiveSearch(const QString &pattern)
   131 	{
   111 	{
   132 	int len = pattern.length();
   112 	int len = pattern.length();
   133 	QString newPattern;
   113 	QString newPattern;
   134 	if (isQwerty(pattern))
   114 	if (isQwerty(pattern))
   308     }
   288     }
   309 // pattern length is between KMinimumSearchPatternLength...KLimitLength
   289 // pattern length is between KMinimumSearchPatternLength...KLimitLength
   310 QString CntSqlSearch::CreateQuery(const QString& pattern) const
   290 QString CntSqlSearch::CreateQuery(const QString& pattern) const
   311 	{
   291 	{
   312 	QStringList tokens = GetTokens(pattern);
   292 	QStringList tokens = GetTokens(pattern);
   313 	if (tokens.count() < KTwoTokens)
   293 	if (TestPattern(pattern, CntSqlSearch::ZeroIsFirstNumber))
       
   294         {
       
   295         return CompareTwoColumnsWithModifiedPattern(pattern, tokens);  // Case 7
       
   296         }
       
   297 	else if(tokens.count() < KTwoTokens)
   314         {
   298         {
   315 	    if (TestPattern(pattern, CntSqlSearch::ZerosEndOfFirstToken))
   299 	    if (TestPattern(pattern, CntSqlSearch::ZerosEndOfFirstToken))
   316             {
   300             {
   317             return TwoDifferentTokensSearch(pattern, tokens);  // Case 6
   301             return TwoDifferentTokensSearch(pattern, tokens);  // Case 6
   318             }
   302             }
   319 	    
       
   320 	    if (TestPattern(pattern, CntSqlSearch::ZeroIsFirstNumber))
       
   321             {
       
   322             return CompareTwoColumnsWithModifiedPattern(pattern, tokens);  // Case 7
       
   323             }
       
   324         else
   303         else
   325             {
   304             {
   326             return ExactMatchSearch(pattern) + Order(tokens); // Case 2
   305             return ExactMatchSearch(pattern) + Order(tokens); // Case 2
   327             }
   306             }
   328         }
   307         }
   332             {
   311             {
   333             return IdenticalTokensSearch(pattern, tokens); // Case 3
   312             return IdenticalTokensSearch(pattern, tokens); // Case 3
   334             }
   313             }
   335         else
   314         else
   336             {
   315             {
   337             return IntersectionSearch(pattern, tokens); // Case 4
   316             return IntersectionSearch(pattern, tokens); // Case 4 or 5 first token start with multible zeros.
   338             }
   317             }
   339         }
   318         }
   340 	}
   319 	}
   341 
   320 
   342 QString CntSqlSearch::ExactMatchSearch(const QString& pattern) const
   321 QString CntSqlSearch::ExactMatchSearch(const QString& pattern) const
   500 
   479 
   501 
   480 
   502 QString CntSqlSearch::TwoDifferentTokensSearch(const QString& pattern, const QStringList& tokens) const
   481 QString CntSqlSearch::TwoDifferentTokensSearch(const QString& pattern, const QStringList& tokens) const
   503         {
   482         {
   504         QString token = tokens.at(0);
   483         QString token = tokens.at(0);
   505         QString sortPatern = pattern;
   484         /*QString sortPatern = pattern;
   506         sortPatern.truncate(pattern.length()-1);
   485         sortPatern.truncate(pattern.length()-1);*/
   507 #if defined(USE_DEMORGAN)
   486 #if defined(USE_DEMORGAN)
   508         QString query(SELECT_CONTACT_ID + SelectTable(pattern) + " WHERE NOT(NOT" +
   487         QString query(SELECT_CONTACT_ID + SelectTable(pattern) + " WHERE NOT(NOT" +
   509             ExactMatch(sortPatern) +
   488             ExactMatch(token) +
   510         " AND NOT" + ExactMatch(pattern) + ")");
   489         " AND NOT" + ExactMatch(pattern) + ")");
   511 #else
   490 #else
   512         QString query(SELECT_CONTACT_ID + SelectTable(pattern) + " WHERE (" +
   491         QString query(SELECT_CONTACT_ID + SelectTable(pattern) + " WHERE (" +
   513             ExactMatch(sortPatern) +  // exact match (e.g. "2")
   492             ExactMatch(token) +  // exact match (e.g. "2")
   514         ") OR " + ExactMatch(pattern)); // exact match (e.g. "20")
   493         ") OR " + ExactMatch(pattern)); // exact match (e.g. "20")
   515 #endif
   494 #endif
   516         query += Order(tokens);
   495         query += Order(tokens);
   517         return query;
   496         return query;
   518         }
   497         }
   525         UNION 
   504         UNION 
   526         SELECT predictivesearch0.contact_id, predictivesearch0.first_name, predictivesearch0.last_name FROM predictivesearch0
   505         SELECT predictivesearch0.contact_id, predictivesearch0.first_name, predictivesearch0.last_name FROM predictivesearch0
   527         WHERE ((NOT(NOT(predictivesearch0.nbr>22517998136852479 AND predictivesearch0.nbr<27021597764222976) AND NOT(predictivesearch0.nbr2>22517998136852479 AND predictivesearch0.nbr2<27021597764222976) AND NOT(predictivesearch0.nbr3>22517998136852479 AND predictivesearch0.nbr3<27021597764222976) AND NOT(predictivesearch0.nbr4>22517998136852479 AND predictivesearch0.nbr4<27021597764222976)))) 
   506         WHERE ((NOT(NOT(predictivesearch0.nbr>22517998136852479 AND predictivesearch0.nbr<27021597764222976) AND NOT(predictivesearch0.nbr2>22517998136852479 AND predictivesearch0.nbr2<27021597764222976) AND NOT(predictivesearch0.nbr3>22517998136852479 AND predictivesearch0.nbr3<27021597764222976) AND NOT(predictivesearch0.nbr4>22517998136852479 AND predictivesearch0.nbr4<27021597764222976)))) 
   528     ) AS PR
   507     ) AS PR
   529     ORDER BY PR.first_name, PR.last_name ASC;
   508     ORDER BY PR.first_name, PR.last_name ASC;
       
   509     
       
   510     - AND case - 
       
   511     SELECT contact_id FROM (
       
   512     SELECT predictivesearch5.contact_id, predictivesearch5.first_name, predictivesearch5.last_name FROM predictivesearch5 WHERE NOT(NOT(NOT(NOT(nbr>382805968326492159 AND nbr<387309567953862656) AND NOT(nbr2>382805968326492159 AND nbr2<387309567953862656) AND NOT(nbr3>382805968326492159 AND nbr3<387309567953862656) AND NOT(nbr4>382805968326492159 AND nbr4<387309567953862656))) AND NOT(NOT(NOT(nbr2>360287970189639679 AND nbr2<432345564227567616 AND nbr>382805968326492159 AND nbr<387309567953862656) AND NOT(nbr3>360287970189639679 AND nbr3<432345564227567616 AND nbr>382805968326492159 AND nbr<387309567953862656) AND NOT(nbr3>360287970189639679 AND nbr3<432345564227567616 AND nbr2>382805968326492159 AND nbr2<387309567953862656) AND NOT(nbr4>360287970189639679 AND nbr4<432345564227567616 AND nbr>382805968326492159 AND nbr<387309567953862656) AND NOT(nbr4>360287970189639679 AND nbr4<432345564227567616 AND nbr2>382805968326492159 AND nbr2<387309567953862656) AND NOT(nbr4>360287970189639679 AND nbr4<432345564227567616 AND nbr3>382805968326492159 AND nbr3<387309567953862656))) AND NOT(NOT(NOT(nbr2>382805968326492159 AND nbr2<387309567953862656 AND nbr>360287970189639679 AND nbr<432345564227567616) AND NOT(nbr3>382805968326492159 AND nbr3<387309567953862656 AND nbr>360287970189639679 AND nbr<432345564227567616) AND NOT(nbr3>382805968326492159 AND nbr3<387309567953862656 AND nbr2>360287970189639679 AND nbr2<432345564227567616) AND NOT(nbr4>382805968326492159 AND nbr4<387309567953862656 AND nbr>360287970189639679 AND nbr<432345564227567616) AND NOT(nbr4>382805968326492159 AND nbr4<387309567953862656 AND nbr2>360287970189639679 AND nbr2<432345564227567616) AND NOT(nbr4>382805968326492159 AND nbr4<387309567953862656 AND nbr3>360287970189639679 AND nbr3<432345564227567616)))) 
       
   513     UNION
       
   514     SELECT predictivesearch0.contact_id, predictivesearch0.first_name, predictivesearch0.last_name FROM predictivesearch0 WHERE ((NOT(NOT(predictivesearch0.nbr>23930870578544639 AND predictivesearch0.nbr<23931970090172416) AND NOT(predictivesearch0.nbr2>23930870578544639 AND predictivesearch0.nbr2<23931970090172416) AND NOT(predictivesearch0.nbr3>23930870578544639 AND predictivesearch0.nbr3<23931970090172416) AND NOT(predictivesearch0.nbr4>23930870578544639 AND predictivesearch0.nbr4<23931970090172416)))) AND NOT(NOT(NOT(nbr2>360287970189639679 AND nbr2<432345564227567616 AND nbr>0387309567953862656382805968326492159 AND nbr<0387309567953862656382805968326492159) AND NOT(nbr3>360287970189639679 AND nbr3<432345564227567616 AND nbr>0387309567953862656382805968326492159 AND nbr<0387309567953862656382805968326492159) AND NOT(nbr3>360287970189639679 AND nbr3<432345564227567616 AND nbr2>0387309567953862656382805968326492159 AND nbr2<0387309567953862656382805968326492159) AND NOT(nbr4>360287970189639679 AND nbr4<432345564227567616 AND nbr>0387309567953862656382805968326492159 AND nbr<0387309567953862656382805968326492159) AND NOT(nbr4>360287970189639679 AND nbr4<432345564227567616 AND nbr2>0387309567953862656382805968326492159 AND nbr2<0387309567953862656382805968326492159) AND NOT(nbr4>360287970189639679 AND nbr4<432345564227567616 AND nbr3>0387309567953862656382805968326492159 AND nbr3<0387309567953862656382805968326492159))) AND NOT(NOT(NOT(nbr2>0387309567953862656382805968326492159387309567953862656382805968326492159 AND nbr2<0387309567953862656382805968326492159387309567953862656382805968326492159 AND nbr>360287970189639679 AND nbr<432345564227567616) AND NOT(nbr3>0387309567953862656382805968326492159387309567953862656382805968326492159 AND nbr3<0387309567953862656382805968326492159387309567953862656382805968326492159 AND nbr>360287970189639679 AND nbr<432345564227567616) AND NOT(nbr3>0387309567953862656382805968326492159387309567953862656382805968326492159 AND nbr3<0387309567953862656382805968326492159387309567953862656382805968326492159 AND nbr2>360287970189639679 AND nbr2<432345564227567616) AND NOT(nbr4>0387309567953862656382805968326492159387309567953862656382805968326492159 AND nbr4<0387309567953862656382805968326492159387309567953862656382805968326492159 AND nbr>360287970189639679 AND nbr<432345564227567616) AND NOT(nbr4>0387309567953862656382805968326492159387309567953862656382805968326492159 AND nbr4<0387309567953862656382805968326492159387309567953862656382805968326492159 AND nbr2>360287970189639679 AND nbr2<432345564227567616) AND NOT(nbr4>0387309567953862656382805968326492159387309567953862656382805968326492159 AND nbr4<0387309567953862656382805968326492159387309567953862656382805968326492159 AND nbr3>360287970189639679 AND nbr3<432345564227567616)))
       
   515     )AS PR ORDER BY PR.first_name, PR.last_name ASC;
   530     */
   516     */
   531 
   517 
   532 QString CntSqlSearch::CompareTwoColumnsWithModifiedPattern(const QString& pattern,
   518 QString CntSqlSearch::CompareTwoColumnsWithModifiedPattern(const QString& pattern,
   533                                                                   const QStringList& tokens) const
   519                                                                   const QStringList& tokens) const
   534     {
   520     {
   535     QString patternAfterZero = pattern.right(pattern.count() - 1);
   521     QString queryString;
   536     // It has been checked earlier that tables are not same
   522     QString lower;
       
   523     QString upper;
       
   524     QString lower2;
       
   525     QString upper2;
       
   526     QString lower_without_zero;
       
   527     QString upper_without_zero;
       
   528     QString lower2_without_zero;
       
   529     QString upper2_without_zero;
       
   530     int err;
       
   531     int i(0);
       
   532     
       
   533     QString firstTokenWithoutZeros = tokens.at(0);
       
   534     firstTokenWithoutZeros.remove(QChar('0'), Qt::CaseInsensitive);
       
   535 
   537     QString firstTable = SelectTable(pattern);
   536     QString firstTable = SelectTable(pattern);
   538     QString secondTable = SelectTable(patternAfterZero);
   537     QString secondTable = SelectTable(firstTokenWithoutZeros);
   539     QString queryString;
   538     
   540     if (patternAfterZero.count() == 1)
   539     QString secondTokenWithoutZeros;
   541         { 
   540     
       
   541     if(tokens.count() > 1)
       
   542         {
       
   543         secondTokenWithoutZeros = tokens.at(1);
       
   544         i = pattern.length()-1;
       
   545         while (pattern[i] == '0') 
       
   546                {
       
   547                --i;
       
   548                }
       
   549         if(pattern.length()-1 != i)
       
   550             {
       
   551             pattern.leftRef(i);
       
   552             }
       
   553         //secondTokenWithoutZeros.remove(QChar('0'), Qt::CaseInsensitive);
       
   554         }
       
   555     
       
   556     // Case like 05
       
   557     if (tokens.at(0).count() == 1 && pattern.length() == 2)
       
   558         {
   542         queryString = QString("SELECT contact_id FROM (SELECT " + secondTable + ".contact_id, " + secondTable + ".first_name, " + secondTable + ".last_name FROM " + secondTable 
   559         queryString = QString("SELECT contact_id FROM (SELECT " + secondTable + ".contact_id, " + secondTable + ".first_name, " + secondTable + ".last_name FROM " + secondTable 
   543                                 + " UNION SELECT " + firstTable + ".contact_id, " + firstTable + ".first_name, " + firstTable + ".last_name FROM " + firstTable 
   560                                 + " UNION SELECT " + firstTable + ".contact_id, " + firstTable + ".first_name, " + firstTable + ".last_name FROM " + firstTable 
   544                                 + " WHERE " + ModifiedMatchColumns( pattern) + ") AS PR ORDER BY PR.first_name, PR.last_name ASC;");
   561                                 + " WHERE " + ModifiedMatchColumns( pattern) + ") AS PR ORDER BY PR.first_name, PR.last_name ASC;");
   545         }
   562         }
       
   563     //case like 05055 or 0506 or 00506 
       
   564     else if (tokens.count() > 1)
       
   565         { 
       
   566         err = mkeyKeyMap->GetNumericLimits(tokens.at(0), lower, upper);
       
   567         if(err)
       
   568             {
       
   569             return QString("");
       
   570             }
       
   571         err = mkeyKeyMap->GetNumericLimits(tokens.at(1), lower2, upper2);
       
   572         if(err)
       
   573             {
       
   574             return QString("");
       
   575             }
       
   576         
       
   577         err = mkeyKeyMap->GetNumericLimits(firstTokenWithoutZeros, lower_without_zero, upper_without_zero);
       
   578         if(err)
       
   579             {
       
   580             return QString("");
       
   581             }
       
   582         
       
   583         err = mkeyKeyMap->GetNumericLimits(secondTokenWithoutZeros, lower2_without_zero, upper2_without_zero);
       
   584         if(err)
       
   585            {
       
   586            return QString("");
       
   587            }
       
   588 
       
   589         queryString = QString("SELECT contact_id FROM (SELECT " + secondTable + ".contact_id, " + secondTable + ".first_name, " + secondTable + ".last_name FROM " + secondTable + 
       
   590                                    + " WHERE (" + CompareTwoColumns(lower_without_zero, upper_without_zero, lower2_without_zero, upper2_without_zero) + " OR" +
       
   591                                    CompareTwoColumns(lower2_without_zero, upper2_without_zero, lower_without_zero, upper_without_zero) + ")" +
       
   592                               " UNION" +
       
   593                                    " SELECT " + firstTable + ".contact_id, " + firstTable + ".first_name, " + firstTable + ".last_name FROM " + firstTable 
       
   594                                    + " WHERE " + ModifiedMatchColumns( pattern) + " OR"
       
   595                                    + CompareTwoColumns(lower, upper, lower2, upper2) + " OR"
       
   596                                    + CompareTwoColumns(lower2, upper2, lower, upper) +
       
   597                               ") AS PR ORDER BY PR.first_name, PR.last_name ASC;");
       
   598             
       
   599         
       
   600             
       
   601             /* "SELECT contact_id FROM ( SELECT... UNION SELECT ...) AS PR ORDER BY PR.first_name, PR.last_name ASC;*/
       
   602             /* 5 table 
       
   603              queryString = QString("SELECT " + secondTable + ".contact_id, " + secondTable + ".first_name, " + secondTable + ".last_name FROM " + secondTable 
       
   604                                                 + " WHERE NOT(NOT" + ExactMatch(tokens.at(0)) + " AND NOT" +
       
   605                                                CompareTwoColumns(lower, upper, lower2, upper2) + " AND NOT" +
       
   606                                                CompareTwoColumns(lower2, upper2, lower, upper) + " );");*/
       
   607         
       
   608             /* table 0 queryString = QString("SELECT " + firstTable + ".contact_id, " + firstTable + ".first_name, " + firstTable + ".last_name FROM " + firstTable 
       
   609                                                + " WHERE " + ModifiedMatchColumns( pattern) + " AND NOT"
       
   610                                                + CompareTwoColumns(zeroPrefix.append(lower), zeroPrefix.append(upper), lower2, upper2) + " AND NOT"
       
   611                                                + CompareTwoColumns(lower2, upper2, zeroPrefix.append(lower), zeroPrefix.append(upper)));*/
       
   612                 
       
   613         }
   546     else
   614     else
   547         {
   615         {
       
   616         //case like 055
   548         queryString = QString("SELECT contact_id FROM (SELECT " + secondTable + ".contact_id, " + secondTable + ".first_name, " + secondTable + ".last_name FROM " + secondTable 
   617         queryString = QString("SELECT contact_id FROM (SELECT " + secondTable + ".contact_id, " + secondTable + ".first_name, " + secondTable + ".last_name FROM " + secondTable 
   549                                 + " WHERE " + ModifiedMatchColumns( patternAfterZero) + 
   618                                 + " WHERE " + ModifiedMatchColumns( firstTokenWithoutZeros) + 
   550                                 + " UNION SELECT " + firstTable + ".contact_id, " + firstTable + ".first_name, " + firstTable + ".last_name FROM " + firstTable 
   619                                 + " UNION SELECT " + firstTable + ".contact_id, " + firstTable + ".first_name, " + firstTable + ".last_name FROM " + firstTable 
   551                                 + " WHERE " + ModifiedMatchColumns( pattern) + ") AS PR ORDER BY PR.first_name, PR.last_name ASC;");
   620                                 + " WHERE " + ModifiedMatchColumns( pattern) + ") AS PR ORDER BY PR.first_name, PR.last_name ASC;");
   552         }
   621         }
   553     return queryString;
   622     return queryString;
   554     }
   623     }
   946     QStringList tokens = GetTokens(pattern);
  1015     QStringList tokens = GetTokens(pattern);
   947     if (!tokens.isEmpty() && !pattern.isEmpty())
  1016     if (!tokens.isEmpty() && !pattern.isEmpty())
   948         {
  1017         {
   949         if (CntSqlSearch::ZerosEndOfFirstToken == searchMethod)
  1018         if (CntSqlSearch::ZerosEndOfFirstToken == searchMethod)
   950             {
  1019             {
   951             if( tokens.count() == KOneToken && !tokens.at(0).contains("0")
  1020             if( tokens.count() == KOneToken /*&& !tokens.at(0).contains("0")*/
   952                 && !pattern.startsWith('0') && pattern.count('0') == 1
  1021                 && !pattern.startsWith('0') /*&& pattern.count('0') == 1*/
   953                 && pattern.endsWith('0'))
  1022                 && pattern.endsWith('0'))
   954                 {
  1023                 {
   955                 return true;
  1024                 return true;
   956                 }
  1025                 }
   957             }
  1026             }
   958         if (CntSqlSearch::ZeroIsFirstNumber == searchMethod )
  1027         if (CntSqlSearch::ZeroIsFirstNumber == searchMethod )
   959             {
  1028             {
   960             if(pattern.startsWith('0') && pattern.count() > 1 
  1029             if(pattern.startsWith('0') && pattern.count() > 1 )
   961                 && pattern.at(1) != '0')
  1030                 {
       
  1031                 return true;
       
  1032                 }
       
  1033             if (pattern.startsWith('0') && tokens.count() >= KTwoTokens )
   962                 {
  1034                 {
   963                 return true;
  1035                 return true;
   964                 }
  1036                 }
   965             }
  1037             }
   966         }
  1038         }