If bol == True, Raba will keep a count of every query time performed, logQueries == True it will also keep a record of all the queries
545277
def enableStats(self, bol, logQueries = False) :
		" "
		self._enableStats = bol
		self._logQueries = logQueries
		if bol :
			self._enableStats = True
			self.eraseStats()
			self.startTime = time.time()
643491
def _compare_records(src, sink, strict=False):
    # type: (MutableMapping[Text, Any], MutableMapping[Text, Any], bool) -> bool
    

    def _rec_fields(rec):  # type: (MutableMapping[Text, Any]) -> MutableMapping[Text, Any]
        out = {}
        for field in rec["fields"]:
            name = shortname(field["name"])
            out[name] = field["type"]
        return out

    srcfields = _rec_fields(src)
    sinkfields = _rec_fields(sink)
    for key in six.iterkeys(sinkfields):
        if (not can_assign_src_to_sink(
                srcfields.get(key, "null"), sinkfields.get(key, "null"), strict)
                and sinkfields.get(key) is not None):
            _logger.info("Record comparison failure for %s and %s\n"
                         "Did not match fields for %s: %s and %s",
                         src["name"], sink["name"], key, srcfields.get(key),
                         sinkfields.get(key))
            return False
    return True
678177
private boolean checkConnection() {
		if (connection == null) {
			if (System.currentTimeMillis() >= reconnectTimestamp) {
				long start = System.currentTimeMillis();
				try {
					connection = connect(url, user, password);
					statement = connection.prepareStatement(sql);
					InternalLogger.log(Level.ERROR, "Lost log entries due to broken database connection: " + lostCount);
					lostCount = 0;
					return true;
				} catch (NamingException ex) {
					long now = System.currentTimeMillis();
					reconnectTimestamp = now + Math.max(MIN_RETRY_INTERVAL, (now - start) * 2);
					closeConnectionSilently();
					return false;
				} catch (SQLException ex) {
					long now = System.currentTimeMillis();
					reconnectTimestamp = now + Math.max(MIN_RETRY_INTERVAL, (now - start) * 2);
					closeConnectionSilently();
					return false;
				}
			} else {
				return false;
			}
		} else {
			return true;
		}
	}
891900
def count( dbid, fieldNames, query = nil, qid = nil, qname = nil, clist = nil, slist = nil, fmt = "structured", options = nil )
      count = {}
      fieldNames.each{|field| count[field]=0 }
      hasValues = false
      iterateRecords(dbid,fieldNames,query,qid,qname,clist,slist,fmt,options){|record|
         fieldNames.each{|field|
            if record[field] and record[field].length > 0
               count[field] += 1
               hasValues = true
            end
         }
      }
      count = nil if not hasValues
      count
   end
497800
def query_transactions(self, initial_date, final_date,
                           page=None,
                           max_results=None):
        
        last_page = False
        results = []
        while last_page is False:
            search_result = self._consume_query_transactions(
                initial_date, final_date, page, max_results)
            results.extend(search_result.transactions)
            if search_result.current_page is None or \
               search_result.total_pages is None or \
               search_result.current_page == search_result.total_pages:
                last_page = True
            else:
                page = search_result.current_page + 1

        return results
1135237
public static void logSQL(final String logicSQL, final Collection<String> dataSourceNames) {
        log("Rule Type: master-slave");
        log("SQL: {} ::: DataSources: {}", logicSQL, Joiner.on(",").join(dataSourceNames));
    }
486797
def base_query
      query = ActionLog
              .where(visibility: %w(public-only all))
              .where(organization: options.fetch(:organization))

      query = query.where(user: options[:user]) if options[:user]

      query = filter_follows(query)

      query
    end
678996
private boolean _canSkipWhileScanning(MetricSchemaRecordQuery query, RecordType type) {


		if( (RecordType.METRIC.equals(type) || RecordType.SCOPE.equals(type))
				&& !SchemaService.containsFilter(query.getTagKey())
				&& !SchemaService.containsFilter(query.getTagValue())
				&& !SchemaService.containsFilter(query.getNamespace())) {
			if(RecordType.METRIC.equals(type) && !SchemaService.containsFilter(query.getMetric())) {
				return false;
			}

			if(RecordType.SCOPE.equals(type) && !SchemaService.containsFilter(query.getScope())) {
				return false;
			}

			return true;
		}

		return false;
	}
931051
def _updateall(self, query, vars, returning=False):
        
        cursor = self.get_db().cursor()
        self._log(cursor, query, vars)
        cursor.execute(query, vars)
        self.get_db().commit()
        return cursor.fetchall() if returning else None
843564
protected function logQuery()
    {
        $info = $this->info();

        if (!$info['started_iterating']) {
            if (!is_array($info['query'])) {
                $info['query'] = array();
            } else if (!isset($info['query']['$query'])) {
                $info['query'] = array('$query' => $info['query']);
            }

            // explain cursor
            $this->explainCursor->fields($info['fields']);
            $this->explainCursor->limit($info['limit']);
            $this->explainCursor->skip($info['skip']);
            if (isset($info['batchSize'])) {
                $this->explainCursor->batchSize($info['batchSize']);
            }
            if (isset($info['query']['$orderby'])) {
                $this->explainCursor->sort($info['query']['$orderby']);
            }
            if (isset($info['query']['$hint'])) {
                $this->explainCursor->hint($info['query']['$hint']);
            }
            if (isset($info['query']['$snapshot'])) {
                $this->explainCursor->snapshot();
            }
            $explain = $this->explainCursor->explain();

            // log
            $log = array(
                'type'   => $this->type,
                'query'  => isset($info['query']['$query']) && is_array($info['query']['$query']) ? $info['query']['$query'] : array(),
                'fields' => $info['fields'],
            );
            if (isset($info['query']['$orderby'])) {
                $log['sort'] = $info['query']['$orderby'];
            }
            if ($info['limit']) {
                $log['limit'] = $info['limit'];
            }
            if ($info['skip']) {
                $log['skip'] = $info['skip'];
            }
            if ($info['batchSize']) {
                $log['batchSize'] = $info['batchSize'];
            }
            if (isset($info['query']['$hint'])) {
                $log['hint'] = $info['query']['$hint'];
            }
            if (isset($info['query']['$snapshot'])) {
                $log['snapshot'] = 1;
            }
            $log['explain'] = array(
                'nscanned'        => $explain['nscanned'],
                'nscannedObjects' => $explain['nscannedObjects'],
                'n'               => $explain['n'],
                'indexBounds'     => $explain['indexBounds'],
            );
            $log['time'] = $explain['millis'];

            $this->log($log);
        }
    }
832080
def get_count(self, query=None):
        
        query = query or Query()
        return self.get_db().alerts.find(query.where).count()
1158526
function shouldUseMaster($query) {
    if (defined('USE_MASTER_DB') && USE_MASTER_DB) {
      return true;
    }

    if ($this->isWriteQuery($query)) {
      return true;
    }

    foreach ($_SESSION['master_slave_data'] as $table => $last_updated) {
      if ($this->queryUsesTable($query, $table)) {
        return true;
      }
    }

    return false;
  }
1118988
public boolean isBaseDatabase(Record record)
    {
        BaseDatabase database = record.getTable().getDatabase();
        boolean isBaseDB = true;
        int counter = (int)record.getCounterField().getValue();
        String startingID = database.getProperty(BaseDatabase.STARTING_ID);
        String endingID = database.getProperty(BaseDatabase.ENDING_ID);
        if (startingID != null)
            if (counter < Integer.parseInt(Converter.stripNonNumber(startingID)))
                isBaseDB = false;
        if (endingID != null)
            if (counter > Integer.parseInt(Converter.stripNonNumber(endingID)))
                isBaseDB = false;
        return isBaseDB;
    }
578012
def count(self, *_clauses, **kwargs):
        """"""
        # NOTE: this does not have support for limit and offset since I can't
        # see how this is useful. Still, there might be compatibility issues
        # with people using these flags. Let's see how it goes.
        if not self.exists:
            return 0

        args = self._args_to_clause(kwargs, clauses=_clauses)
        query = select([func.count()], whereclause=args)
        query = query.select_from(self.table)
        rp = self.db.executable.execute(query)
        return rp.fetchone()[0]
264283
private function logQuery($strQuery, $dblQueryTime)
    {
        if ($this->blnEnableProfiling) {
            // Dereference-ize Backtrace Information
            $objDebugBacktrace = debug_backtrace();

            // get rid of unnecessary backtrace info in case of:
            // query
            if ((count($objDebugBacktrace) > 3) &&
                (array_key_exists('function', $objDebugBacktrace[2])) &&
                (($objDebugBacktrace[2]['function'] == 'QueryArray') ||
                    ($objDebugBacktrace[2]['function'] == 'QuerySingle') ||
                    ($objDebugBacktrace[2]['function'] == 'QueryCount'))
            ) {
                $objBacktrace = $objDebugBacktrace[3];
            } else {
                if (isset($objDebugBacktrace[2])) // non query
                {
                    $objBacktrace = $objDebugBacktrace[2];
                } else // ad hoc query
                {
                    $objBacktrace = $objDebugBacktrace[1];
                }
            }

            // get rid of reference to current object in backtrace array
            if (isset($objBacktrace['object'])) {
                $objBacktrace['object'] = null;
            }

            for ($intIndex = 0, $intMax = count($objBacktrace['args']); $intIndex < $intMax; $intIndex++) {
                $obj = $objBacktrace['args'][$intIndex];

                if (is_null($obj)) {
                    $obj = 'null';
                } else {
                    if (gettype($obj) == 'integer') {
                    } else {
                        if (gettype($obj) == 'object') {
                            $obj = 'Object: ' . get_class($obj);
                            if (method_exists($obj, '__toString')) {
                                $obj .= '- ' . $obj;
                            }
                        } else {
                            if (is_array($obj)) {
                                $obj = 'Array';
                            } else {
                                $obj = sprintf("'%s'", $obj);
                            }
                        }
                    }
                }
                $objBacktrace['args'][$intIndex] = $obj;
            }

            // Push it onto the profiling information array
            $arrProfile = array(
                'objBacktrace' => $objBacktrace,
                'strQuery' => $strQuery,
                'dblTimeInfo' => $dblQueryTime
            );

            array_push($this->strProfileArray, $arrProfile);
        }
    }
717643
def by_sql(cls, sql, engine_or_session):
        
        ses, auto_close = ensure_session(engine_or_session)
        result = ses.query(cls).from_statement(sql).all()
        if auto_close:
            ses.close()
        return result
277792
function do_query (self, query, values) {
	return nr_fcall("nopg:do_query", function() {

		if(!query) { throw new TypeError("invalid: query: " + util.inspect(query)); }

		if(NoPg.debug) {
			debug.log('query = ', query, '\nvalues = ', values);
		}

		debug.assert(self).is('object');
		debug.assert(self._db).is('object');
		debug.assert(self._db[pg.query]).is('function');

		var start_time = new Date();
		return self._db[pg.query](query, values).then(function(res) {
			var end_time = new Date();

			self._record_sample({
				'event': 'query',
				'start': start_time,
				'end': end_time,
				'query': query,
				'params': values
			});

			//debug.log('res = ', res);

			return res;
		});
	});
}