@param string|null $conn

@return mixed
760094
public function checkHAAvailable($conn = null)
    {
        $response = $this->invoke('neo.core_get_ha_available', $conn)
          ->execute();

        return $this->handleHttpResponse($response);
    }
697730
protected function getGroupByClause($conn = null) {
		$statement = new QueryStatement($conn);
		if ($this->groups) {
			$groups = $this->groups;
			foreach ($groups as &$group) {
				$statement->addIdentifier($group);
				$group = QueryStatement::IDENTIFIER;
			}
			$statement->string = "\nGROUP BY " . implode(', ', $groups);
		}
		return $statement;
	}
79415
public function getConnection($context = null)
    {
        $db = $this->getDb($context);
        return $this->_di->getShared($db);
    }
1302511
public function createTransaction($conn = null, $queryMode = Client::NEOCLIENT_QUERY_MODE_WRITE)
    {
        $transaction = new Transaction($conn, $this, $queryMode);

        return $transaction;
    }
300602
public function findConnection(string $connectionName)
  {
    if ( empty($connectionName) ) {
      # Take first available connection
      $connection = reset($this->connections);
      if ($connection === false)
        return null;
    } else {
      # Attempt to find the connection from the pool
      $connection = ( $this->connections[strtolower($connectionName)] ?? null);
    }

    return $connection;
  }
86197
protected function getOrderByClause($conn = null) {
		$statement = new QueryStatement($conn);
		$orders = $this->orders;
		foreach ($orders as &$order) {
			$order_parts = explode(' ', $order);
			if (count($order_parts) == 1 || count($order_parts) == 2) {
				$statement->addIdentifier($order_parts[0]);
				$order_parts[0] = QueryStatement::IDENTIFIER;
			}
			$order = implode(' ', $order_parts);
		}
		$statement->string = "\nORDER BY " . implode(', ', $orders);
		return $statement;
	}
1149795
private function getLocation(ConnectionInterface $conn) {

        if($conn->WebSocket instanceof \StdClass) {

            if(($cache = $this->cacheService) != null) {

                $ip = $this->getIpAddress($conn);

                // load geo location from cache
                if($cache->getStorage()->exists($ip) === true) {
                    $location = $cache->getStorage()->get($ip);
                }

                // add to cache geo location
                $cache->getStorage()->save($ip, $this->geoService->location($ip));
            }
            else {
                try {
                    $location = $this->geoService->location($this->getIpAddress($conn));
                }
                catch(GeoServiceException $e) {
                    throw new AppServiceException($e->getMessage());
                }
            }
            return $location;
        }
        throw new AppServiceException('Location not defined');
    }
842574
public static function Get($dsn = null, $use_as_default = false) {
		if ($dsn !== null AND $use_as_default) {
			self::$default_dsn = $dsn;
		} elseif ($dsn === null AND self::$default_dsn !== null) {
			$dsn = self::$default_dsn;
		}

		/**
		 * A mysqli connection can only be accessed by the PID that has created it
		 * Create a new Mysqli object after forking
		 */
		if (isset(self::$pids[$dsn]) and self::$pids[$dsn] != getmypid()) {
			unset(self::$proxy[$dsn]);
			unset(self::$pids[$dsn]);
		}

		if (!isset(self::$proxy[$dsn]) OR self::$proxy[$dsn] == false) {
			self::$proxy[$dsn] = new Proxy($dsn);
			self::$pids[$dsn] = getmypid();
		}
		return self::$proxy[$dsn];
	}
1238448
protected function getColumnsClause($conn) {
		$table = $this->getTable();

		if (!$table) {
			throw new RuntimeException('No table specified.');
		}

		$statement = new QueryStatement($conn);
		$alias = $this->getAlias();
		$action = $this->action;

		if ($action == self::ACTION_DELETE) {
			return $statement;
		}

		if ($action == self::ACTION_COUNT) {
			if (!$this->needsComplexCount()) {
				$statement->string = 'count(0)';
				return $statement;
			}

			if (null === $this->getHaving()) {
				if ($this->groups) {
					$groups = $this->groups;
					foreach ($groups as &$group) {
						$statement->addIdentifier($group);
						$group = QueryStatement::IDENTIFIER;
					}
					$statement->string = implode(', ', $groups);
					return $statement;
				}

				if (!$this->distinct && $this->columns) {
					$columns_to_use = array();
					foreach ($this->columns as $alias => $column) {
						if (strpos($column, '(') === false) {
							continue;
						}
						if ($alias === $column) {
							$alias = '';
						} else {
							$alias = ' AS "' . $alias . '"';
						}
						$statement->addIdentifier($column);
						$columns_to_use[] = QueryStatement::IDENTIFIER . $alias;
					}
					if ($columns_to_use) {
						$statement->string = implode(', ', $columns_to_use);
						return $statement;
					}
				}
			}
		}

		// setup $columns_string
		if ($this->columns) {
			$columns = $this->columns;
			foreach ($columns as $alias => &$column) {
				if ($alias === $column) {
					$alias = '';
				} else {
					$alias = ' AS "' . $alias . '"';
				}

				$statement->addIdentifier($column);
				$column = QueryStatement::IDENTIFIER . $alias;
			}
			$columns_string = implode(', ', $columns);
		} elseif ($alias) {
			// default to selecting only columns from the target table
			$columns_string = "$alias.*";
		} else {
			// default to selecting only columns from the target table
			$columns_string = QueryStatement::IDENTIFIER . '.*';
			$statement->addIdentifier($table);
		}

		if ($this->distinct) {
			$columns_string = "DISTINCT $columns_string";
		}

		$statement->string = $columns_string;
		return $statement;
	}
815890
public static function createConnectionFromDSN($dsn)
    {
        if (is_string($dsn)) {
            $parsed = self::parseDSN($dsn);
        } else {
            $parsed = $dsn;
        }

        /**
         * @todo retry connection here.
         */
        return DriverManager::getConnection($parsed);
    }
722283
public function isDbEmpty($conn)
    {
        $Folder = new Folder($this->config('schemaPath'));
        $existingSchemas = $conn->schemaCollection()->listTables();
        $newSchemas = array_map(function ($item) {
            return Inflector::underscore(str_replace('Schema.php', '', $item));
        }, $Folder->read()[1]);
        $result = !array_intersect($existingSchemas, $newSchemas);
        if (!$result) {
            $this->error(__d('installer', 'A previous installation of QuickAppsCMS already exists, please drop your database tables before continue.'));
        }

        return $result;
    }
1052519
public function handleConnect($conn) {
        $conn->decor = new IoConnection($conn);
        $conn->decor->resourceId = (int)$conn->stream;

        $uri = $conn->getRemoteAddress();
        $conn->decor->remoteAddress = trim(
            parse_url((strpos($uri, '://') === false ? 'tcp://' : '') . $uri, PHP_URL_HOST),
            '[]'
        );

        $this->app->onOpen($conn->decor);

        $conn->on('data', function ($data) use ($conn) {
            $this->handleData($data, $conn);
        });
        $conn->on('close', function () use ($conn) {
            $this->handleEnd($conn);
        });
        $conn->on('error', function (\Exception $e) use ($conn) {
            $this->handleError($e, $conn);
        });
    }
1005591
public function getItemByMPN($mpn)
    {
        $item = current(array_filter($this->items, function (Item $item) use ($mpn) {
            return ($item->mpn === $mpn);
        }));

        return ($item) ? $item : null;
    }
282352
public function getConnection($connectionName = null)
    {
        /** @var Configuration $configuration */
        $configuration = $this->get('configuration');
        $connectionName = null !== $connectionName ?: $configuration['connection_name'];
        
        return $this->getConnectionManager()->getConnection($connectionName);
    }
837203
protected function conn_create($dsn)
    {
        // Get database specific connection options
        $dsn_options = $this->dsn_options($dsn);

        $function = $this->db_pconn ? 'oci_pconnect' : 'oci_connect';

        if (!function_exists($function)) {
            $this->db_error     = true;
            $this->db_error_msg = 'OCI8 extension not loaded. See http://php.net/manual/en/book.oci8.php';

            rcube::raise_error(array('code' => 500, 'type' => 'db',
                'line' => __LINE__, 'file' => __FILE__,
                'message' => $this->db_error_msg), true, false);

            return;
        }

        // connect
        $dbh = @$function($dsn['username'], $dsn['password'], $dsn_options['database'], $dsn_options['charset']);

        if (!$dbh) {
            $error              = oci_error();
            $this->db_error     = true;
            $this->db_error_msg = $error['message'];

            rcube::raise_error(array('code' => 500, 'type' => 'db',
                'line' => __LINE__, 'file' => __FILE__,
                'message' => $this->db_error_msg), true, false);

            return;
        }

        // configure session
        $this->conn_configure($dsn, $dbh);

        return $dbh;
    }
819539
public function checkHASlave($conn = null)
    {
        $response = $this->invoke('neo.core_get_ha_slave', $conn)
          ->execute();

        return $this->handleHttpResponse($response);
    }
463106
public function getLastVersionNumber($con = null)
    {
        $v = ChildDealerAdminVersionQuery::create()
            ->filterByDealerAdmin($this)
            ->orderByVersion('desc')
            ->findOne($con);
        if (!$v) {
            return 0;
        }

        return $v->getVersion();
    }