handle somethind before parse, common handle for every query
350490
protected function beforeParse()
    {
        // has alias
        if( isset($this->query['table'])) {
            $tables_str = implode(',', $this->query['table']);
            if (preg_match('/((?:as|\,|join)\w+)/i', $tables_str) > 0) {
                $this->query->hasAlias(true);
            }
        }
    }
1301434
function exec(query, config, done) {
  if(!query || (typeof query != 'string')){
    throw new Error('Node-SQL: query was not in the correct format.');
    return;
  }
  if(!config || (typeof config != 'object')){
    throw new Error('Node-SQL: config was not in the correct format.');
    return;
  }
  if(!done || (typeof done != 'function')){
    done = function(a, b){};
  }
  var connection = new Connection(config);
  connection.on('connect', function(err) {
    if(err){
      done(err, null);
      return;
    }
    var request = new Request(query, function(_err) {
      if (_err) {
        done(_err, null);
        return;
      }
      connection.close();
    });
    var result = [];
    request.on('row', function(columns) {
      var row = {};
      columns.forEach(function(column) {
        row[column.metadata.colName] = column.value;
      });
      result.push(row);
    });
    request.on('doneProc', function(rowCount, more, returnStatus) {
      if(returnStatus == 0) done(null, result);
    });
    connection.execSql(request);
  });
}
50223
def before_insert(mapper, conn, target):
        """"""
        from sqlalchemy import text

        if not target.id:
            sql = text('SELECT max(f_id)+1 FROM files WHERE f_d_vid = :did')

            target.id, = conn.execute(sql, did=target.d_vid).fetchone()

            if not target.id:
                target.id = 1

        if target.contents and isinstance(target.contents, six.text_type):
            target.contents = target.contents.encode('utf-8')

        File.before_update(mapper, conn, target)
800848
function handleText() {
    if ($this->hasParent('pre') && strpos($this->parser->node, "\n") !== false) {
      $this->parser->node = str_replace("\n", "\n".$this->indent, $this->parser->node);
    }
    if (!$this->hasParent('code') && !$this->hasParent('pre')) {
      # entity decode
      $this->parser->node = $this->decode($this->parser->node);
      if (!$this->skipConversion) {
        # escape some chars in normal Text
        $this->parser->node = preg_replace($this->escapeInText['search'], $this->escapeInText['replace'], $this->parser->node);
      }
    } else {
      $this->parser->node = str_replace(array('&quot;', '&apos'), array('"', '\''), $this->parser->node);
    }
    $this->out($this->parser->node);
    $this->lastClosedTag = '';
  }
221943
function querystring(query) {
  var parser = /([^=?&]+)=?([^&]*)/g
    , result = {}
    , part;

  while (part = parser.exec(query)) {
    var key = decode(part[1])
      , value = decode(part[2]);

    //
    // Prevent overriding of existing properties. This ensures that build-in
    // methods like `toString` or __proto__ are not overriden by malicious
    // querystrings.
    //
    if (key in result) continue;
    result[key] = value;
  }

  return result;
}
462406
async function CLI ({
  beforeParse,
  afterParse
}) {
  const cli = CAC()
  beforeParse && await beforeParse(cli)
  cli.parse(process.argv)
  afterParse && await afterParse(cli)
}
934523
async def handler(event):
    """"""
    q1 = event.pattern_match.group(1)
    q2 = urllib.parse.quote(q1)
    await asyncio.wait([
        event.delete(),
        event.respond(DOCS.format(q1, q2), reply_to=event.reply_to_msg_id)
    ])
527726
function runQuery(query, connection) {
  let incomplete = false;
  const rows = [];
  const port = connection.port || 8080;
  const prestoConfig = {
    url: `http://${connection.host}:${port}`,
    user: connection.username,
    catalog: connection.prestoCatalog,
    schema: connection.prestoSchema
  };
  return presto.send(prestoConfig, query).then(result => {
    if (!result) {
      throw new Error('No result returned');
    }
    let { data, columns } = result;
    if (data.length > connection.maxRows) {
      incomplete = true;
      data = data.slice(0, connection.maxRows);
    }
    for (let r = 0; r < data.length; r++) {
      const row = {};
      for (let c = 0; c < columns.length; c++) {
        row[columns[c].name] = data[r][c];
      }
      rows.push(row);
    }
    return { rows, incomplete };
  });
}
1007089
def before_processing(eng, objects):
        """"""
        super(InvenioProcessingFactory, InvenioProcessingFactory)\
            .before_processing(eng, objects)
        eng.save(WorkflowStatus.RUNNING)
        db.session.commit()
78999
def format_with_handler(self, query_result, return_type):
        
        handler = self.get_handler(type(query_result), return_type)
        return handler.format_result(query_result)
44221
private void parseQueryResponse(boolean lastChunk) {
        if (sectionDone || queryParsingState == QUERY_STATE_INITIAL) {
            queryParsingState = transitionToNextToken(lastChunk);
        }

        if (queryParsingState == QUERY_STATE_SIGNATURE) {
            parseQuerySignature(lastChunk);
        }

        if (queryParsingState == QUERY_STATE_ROWS_DECIDE) {
            decideBetweenRawAndObjects(lastChunk);
        }
        if (queryParsingState == QUERY_STATE_ROWS) {
            parseQueryRows(lastChunk);
        } else if (queryParsingState == QUERY_STATE_ROWS_RAW) {
            parseQueryRowsRaw(lastChunk);
        }

        if (queryParsingState == QUERY_STATE_ERROR) {
            parseQueryError(lastChunk);
        }

        if (queryParsingState == QUERY_STATE_WARNING) {
            parseQueryError(lastChunk); //warning are treated the same as errors -> sent to errorObservable
        }

        if (queryParsingState == QUERY_STATE_STATUS) {
            parseQueryStatus(lastChunk);
        }

        if (queryParsingState == QUERY_STATE_INFO) {
            parseQueryInfo(lastChunk);
        } else if (queryParsingState == QUERY_STATE_NO_INFO) {
            finishInfo();
        }

        if (queryParsingState == QUERY_STATE_DONE) {
            //final state, but there could still be a small chunk with closing brackets
            //only finalize and reset if this is the last chunk
            sectionDone = lastChunk;
            //if false this will allow next iteration to skip non-relevant automatic
            //transition to next token (which is desirable since there is no more token).

            //complete queryProfile as we are parsing it only in handler v2
            queryProfileInfoObservable.onCompleted();
            if (sectionDone) {
                cleanupQueryStates();
            }
        }
    }
1233114
protected function _beforeQuerySelect()
    {
        $keywords = $this->search_term;

        if ($keywords) {
            $operation = null;

            if (strpos($keywords, ' OR ')) {
                $operation = 'OR';
                $keywords = explode(' OR ', $keywords);
            } else {
                $operation = 'AND';

                if (strpos($keywords, ' AND ')) {
                    $keywords = explode(' AND ', $keywords);
                } else {
                    $keywords = explode(' ', $keywords);
                }
            }

            foreach ($keywords as $index => $value) {
                if (strlen($value) < 3) {
                    unset($keywords[$index]);
                }
            }

            $clause = $this->clause('AND');

            foreach ($keywords as $keyword) {
                $clause->where('CONCAT(IF(node.name IS NULL,"",node.name), IF(node.body IS NULL,"",node.body)) LIKE @quote(%'.$keyword.'%)', $operation);
            }
        }

        $scopes = $this->getService('com:components.domain.entityset.scope');

        if ($this->scope instanceof ComComponentsDomainEntityScope) {
            $scopes = array($this->scope);
        }

        $comments = array();
        $types = array();

        foreach ($scopes as $scope) {
            $types[] = $scope->node_type;

            if ($scope->commentable) {
                $comments[] = (string) $scope->identifier;
            }
        }

        $comment_query = '';

        if (!empty($comments) && $this->_state->search_comments) {
            $comment_query = 'OR (@col(node.type) LIKE :comment_type AND node.parent_type IN (:parent_types) )';
        }

        $owner_query = '';

        if ($this->owner_context) {
            $owner_query = 'node.owner_id = '.$this->owner_context->id.' AND ';

            if (!empty($comment_query)) {
                $this->distinct = true;
                $this->join('LEFT', 'nodes AS comment_parent', 'node.type LIKE :comment_type AND comment_parent.id = node.parent_id');
                $comment_query = preg_replace_callback('/\)$/', function($matches) { return ' AND comment_parent.owner_id = '.$this->owner_context->id.')'; }, $comment_query);
            }
        }

        $this->where('( '.$owner_query.' @col(node.type) IN (:types) '.$comment_query.')')
             ->bind('types', $types)
             ->bind('comment_type', 'ComBaseDomainEntityComment%')
             ->bind('parent_types', $comments);
    }
546065
def handle_routine(self, que, opts, host, target, mine=False):
        '''
        
        '''
        opts = copy.deepcopy(opts)
        single = Single(
                opts,
                opts['argv'],
                host,
                mods=self.mods,
                fsclient=self.fsclient,
                thin=self.thin,
                mine=mine,
                **target)
        ret = {'id': single.id}
        stdout, stderr, retcode = single.run()
        # This job is done, yield
        try:
            data = salt.utils.json.find_json(stdout)
            if len(data) < 2 and 'local' in data:
                ret['ret'] = data['local']
            else:
                ret['ret'] = {
                    'stdout': stdout,
                    'stderr': stderr,
                    'retcode': retcode,
                }
        except Exception:
            ret['ret'] = {
                'stdout': stdout,
                'stderr': stderr,
                'retcode': retcode,
            }
        que.put(ret)
1308301
function run(query, params) {
        let stmt = sql.prepare(query);
        params = normalizeParams(params);
        stmt.run(params);
        stmt.free();
    }
679742
def _parse_prefix_query(self, query_str):
        
        sp = smart_parsing.PrefixSmartParser()
        query = sp.parse(query_str)
        return query
161271
function handler(instance, context, func, index, callback) {
	return function() {
		var old = instance.results[index];
		instance.results[index] = tryExpr(func, context);
		if (old === instance.results[index])
			return;
		if (instance.dependenciesCount === 1 || !Interpolable.allowDelayedUpdate)
			callback(instance.output(context), 'set');
		else if (!instance.willFire)
			instance.willFire = context.delay(function() { // call on nextTick to manage other dependencies update without multiple rerender
				if (instance.willFire) {
					instance.willFire = null;
					callback(instance.output(context), 'set');
				}
			}, 0);
	};
}
709301
function (event, query, handler, context) {
        return on(this, event, query, handler, context, false);
    }