当前位置: 首页>>代码示例>>PHP>>正文


PHP Parser::getSql方法代码示例

本文整理汇总了PHP中Parser::getSql方法的典型用法代码示例。如果您正苦于以下问题:PHP Parser::getSql方法的具体用法?PHP Parser::getSql怎么用?PHP Parser::getSql使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Parser的用法示例。


在下文中一共展示了Parser::getSql方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: query

 public function query($q)
 {
     $parser = new Parser($this->user, $q);
     $error = $parser->parse();
     if ($error) {
         return $parser->getError();
     }
     $mysql_query = $parser->getSql();
     $meta = $parser->getObjectMetaData();
     $this->pearDB->startTransaction();
     $result = $this->pearDB->pquery($mysql_query, array());
     $error = $this->pearDB->hasFailedTransaction();
     $this->pearDB->completeTransaction();
     if ($error) {
         throw new WebServiceException(WebServiceErrorCode::$DATABASEQUERYERROR, "Database error while performing required operation");
     }
     $noofrows = $this->pearDB->num_rows($result);
     $output = array();
     for ($i = 0; $i < $noofrows; $i++) {
         $row = $this->pearDB->fetchByAssoc($result, $i);
         if (!$meta->hasPermission(EntityMeta::$RETRIEVE, $row["crmid"])) {
             continue;
         }
         $output[] = DataTransform::sanitizeDataWithColumn($row, $meta);
     }
     return $output;
 }
开发者ID:vtiger-jp,项目名称:vtigercrm-5.1.x-ja,代码行数:27,代码来源:VtigerModuleOperation.php

示例2: query

 public function query($q)
 {
     $parser = new Parser($this->user, $q);
     if (stripos($q, 'related.') > 0) {
         // related query
         require_once 'include/Webservices/Utils.php';
         require_once 'include/Webservices/GetRelatedRecords.php';
         $queryParameters['columns'] = trim(substr($q, 6, stripos($q, ' from ') - 5));
         $moduleRegex = "/[fF][rR][Oo][Mm]\\s+([^\\s;]+)/";
         preg_match($moduleRegex, $q, $m);
         $relatedModule = trim($m[1]);
         $moduleRegex = "/[rR][eE][lL][aA][tT][eE][dD]\\.([^\\s;]+)\\s*=\\s*([^\\s;]+)/";
         preg_match($moduleRegex, $q, $m);
         $moduleName = trim($m[1]);
         $id = trim($m[2], "(')");
         $mysql_query = __getRLQuery($id, $moduleName, $relatedModule, $queryParameters, $this->user);
         // where, limit and order
         $afterwhere = substr($q, stripos($q, ' where ') + 6);
         // eliminate related conditions
         $relatedCond = "/\\(*[rR][eE][lL][aA][tT][eE][dD]\\.([^\\s;]+)\\s*=\\s*([^\\s;]+)\\)*\\s*([aA][nN][dD]|[oO][rR]\\s)*/";
         preg_match($relatedCond, $afterwhere, $pieces);
         $glue = isset($pieces[3]) ? trim($pieces[3]) : 'and';
         $afterwhere = trim(preg_replace($relatedCond, '', $afterwhere), ' ;');
         $relatedCond = "/\\s+([aA][nN][dD]|[oO][rR])+\\s+([oO][rR][dD][eE][rR])+/";
         $afterwhere = trim(preg_replace($relatedCond, ' order ', $afterwhere), ' ;');
         $relatedCond = "/\\s+([aA][nN][dD]|[oO][rR])+\\s+([lL][iI][mM][iI][tT])+/";
         $afterwhere = trim(preg_replace($relatedCond, ' limit ', $afterwhere), ' ;');
         // if related is at the end of condition we need to strip last and|or
         if (strtolower(substr($afterwhere, -3)) == 'and') {
             $afterwhere = substr($afterwhere, 0, strlen($afterwhere) - 3);
         }
         if (strtolower(substr($afterwhere, -2)) == 'or') {
             $afterwhere = substr($afterwhere, 0, strlen($afterwhere) - 2);
         }
         // transform REST ids
         $relatedCond = "/=\\s*'*\\d+x(\\d+)'*/";
         $afterwhere = preg_replace($relatedCond, ' = $1 ', $afterwhere);
         // kill unbalanced parenthesis
         $balanced = 0;
         $pila = array();
         for ($ch = 0; $ch < strlen($afterwhere); $ch++) {
             if ($afterwhere[$ch] == '(') {
                 $pila[$balanced] = array('pos' => $ch, 'dir' => '(');
                 $balanced++;
             } elseif ($afterwhere[$ch] == ')') {
                 if ($balanced > 0 and $pila[$balanced - 1]['dir'] == '(') {
                     array_pop($pila);
                     $balanced--;
                 } else {
                     $pila[$balanced] = array('pos' => $ch, 'dir' => ')');
                     $balanced++;
                 }
             }
         }
         foreach ($pila as $paren) {
             $afterwhere[$paren['pos']] = ' ';
         }
         // transform artificial commentcontent for FAQ and Ticket comments
         if (strtolower($relatedModule) == 'modcomments' and (strtolower($moduleName) == 'helpdesk' or strtolower($moduleName) == 'faq')) {
             $afterwhere = str_ireplace('commentcontent', 'comments', $afterwhere);
         }
         // transform fieldnames to columnnames
         $handler = vtws_getModuleHandlerFromName($relatedModule, $this->user);
         $meta = $handler->getMeta();
         $fldmap = $meta->getFieldColumnMapping();
         $tblmap = $meta->getColumnTableMapping();
         $tok = strtok($afterwhere, ' ');
         $chgawhere = '';
         while ($tok !== false) {
             if (!empty($fldmap[$tok])) {
                 $chgawhere .= (strpos($tok, '.') ? '' : $tblmap[$fldmap[$tok]] . '.') . $fldmap[$tok] . ' ';
             } else {
                 $chgawhere .= $tok . ' ';
             }
             $tok = strtok(' ');
         }
         $afterwhere = $chgawhere;
         if (!empty($afterwhere)) {
             $start = strtolower(substr(trim($afterwhere), 0, 5));
             if ($start != 'limit' and $start != 'order') {
                 // there is a condition we add the glue
                 $mysql_query .= " {$glue} ";
             }
             $mysql_query .= " {$afterwhere}";
         }
         if (stripos($q, 'count(*)') > 0) {
             $mysql_query = str_ireplace(' as count ', '', mkCountQuery($mysql_query));
         }
     } else {
         $error = $parser->parse();
         if ($error) {
             return $parser->getError();
         }
         $mysql_query = $parser->getSql();
         $meta = $parser->getObjectMetaData();
     }
     $this->pearDB->startTransaction();
     $result = $this->pearDB->pquery($mysql_query, array());
     $error = $this->pearDB->hasFailedTransaction();
     $this->pearDB->completeTransaction();
//.........这里部分代码省略.........
开发者ID:mslokhat,项目名称:corebos,代码行数:101,代码来源:VtigerModuleOperation.php

示例3: wsVTQL2SQL


//.........这里部分代码省略.........
         $relatedModule = trim($m[1]);
         $moduleRegex = "/[rR][eE][lL][aA][tT][eE][dD]\\.([^\\s;]+)\\s*=\\s*([^\\s;]+)/";
         preg_match($moduleRegex, $q, $m);
         $moduleName = trim($m[1]);
         $id = trim($m[2], "(')");
         $mysql_query = __getRLQuery($id, $moduleName, $relatedModule, $queryParameters, $this->user);
         // where, limit and order
         $afterwhere = substr($q, stripos($q, ' where ') + 6);
         // eliminate related conditions
         $relatedCond = "/\\(*[rR][eE][lL][aA][tT][eE][dD]\\.([^\\s;]+)\\s*=\\s*([^\\s;]+)\\)*\\s*([aA][nN][dD]|[oO][rR]\\s)*/";
         preg_match($relatedCond, $afterwhere, $pieces);
         $glue = isset($pieces[3]) ? trim($pieces[3]) : 'and';
         $afterwhere = trim(preg_replace($relatedCond, '', $afterwhere), ' ;');
         $relatedCond = "/\\s+([aA][nN][dD]|[oO][rR])+\\s+([oO][rR][dD][eE][rR])+/";
         $afterwhere = trim(preg_replace($relatedCond, ' order ', $afterwhere), ' ;');
         $relatedCond = "/\\s+([aA][nN][dD]|[oO][rR])+\\s+([lL][iI][mM][iI][tT])+/";
         $afterwhere = trim(preg_replace($relatedCond, ' limit ', $afterwhere), ' ;');
         // if related is at the end of condition we need to strip last and|or
         if (strtolower(substr($afterwhere, -3)) == 'and') {
             $afterwhere = substr($afterwhere, 0, strlen($afterwhere) - 3);
         }
         if (strtolower(substr($afterwhere, -2)) == 'or') {
             $afterwhere = substr($afterwhere, 0, strlen($afterwhere) - 2);
         }
         // transform REST ids
         $relatedCond = "/=\\s*'*\\d+x(\\d+)'*/";
         $afterwhere = preg_replace($relatedCond, ' = $1 ', $afterwhere);
         // kill unbalanced parenthesis
         $balanced = 0;
         $pila = array();
         for ($ch = 0; $ch < strlen($afterwhere); $ch++) {
             if ($afterwhere[$ch] == '(') {
                 $pila[$balanced] = array('pos' => $ch, 'dir' => '(');
                 $balanced++;
             } elseif ($afterwhere[$ch] == ')') {
                 if ($balanced > 0 and $pila[$balanced - 1]['dir'] == '(') {
                     array_pop($pila);
                     $balanced--;
                 } else {
                     $pila[$balanced] = array('pos' => $ch, 'dir' => ')');
                     $balanced++;
                 }
             }
         }
         foreach ($pila as $paren) {
             $afterwhere[$paren['pos']] = ' ';
         }
         // transform artificial commentcontent for FAQ and Ticket comments
         if (strtolower($relatedModule) == 'modcomments' and (strtolower($moduleName) == 'helpdesk' or strtolower($moduleName) == 'faq')) {
             $afterwhere = str_ireplace('commentcontent', 'comments', $afterwhere);
         }
         $relhandler = vtws_getModuleHandlerFromName($moduleName, $this->user);
         $relmeta = $relhandler->getMeta();
         $queryRelatedModules[$moduleName] = $relmeta;
         // transform fieldnames to columnnames
         $handler = vtws_getModuleHandlerFromName($relatedModule, $this->user);
         $meta = $handler->getMeta();
         $fldmap = $meta->getFieldColumnMapping();
         $tblmap = $meta->getColumnTableMapping();
         $tok = strtok($afterwhere, ' ');
         $chgawhere = '';
         while ($tok !== false) {
             if (!empty($fldmap[$tok])) {
                 $chgawhere .= (strpos($tok, '.') ? '' : $tblmap[$fldmap[$tok]] . '.') . $fldmap[$tok] . ' ';
             } else {
                 $chgawhere .= $tok . ' ';
             }
             $tok = strtok(' ');
         }
         $afterwhere = $chgawhere;
         if (!empty($afterwhere)) {
             $start = strtolower(substr(trim($afterwhere), 0, 5));
             if ($start != 'limit' and $start != 'order') {
                 // there is a condition we add the glue
                 $mysql_query .= " {$glue} ";
             }
             $mysql_query .= " {$afterwhere}";
         }
         if (stripos($q, 'count(*)') > 0) {
             $mysql_query = str_ireplace(' as count ', '', mkCountQuery($mysql_query));
         }
     } elseif (__FQNExtendedQueryIsFQNQuery($q)) {
         // FQN extended syntax
         list($mysql_query, $queryRelatedModules) = __FQNExtendedQueryGetQuery($q, $this->user);
         $moduleRegex = "/[fF][rR][Oo][Mm]\\s+([^\\s;]+)/";
         preg_match($moduleRegex, $q, $m);
         $fromModule = trim($m[1]);
         $handler = vtws_getModuleHandlerFromName($fromModule, $this->user);
         $meta = $handler->getMeta();
     } else {
         $parser = new Parser($this->user, $q);
         $error = $parser->parse();
         if ($error) {
             return $parser->getError();
         }
         $mysql_query = $parser->getSql();
         $meta = $parser->getObjectMetaData();
     }
     return $mysql_query;
 }
开发者ID:kduqi,项目名称:corebos,代码行数:101,代码来源:VtigerModuleOperation.php


注:本文中的Parser::getSql方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。