Sets the FOR SHARE lock on select's output row

@param   string $table_name The table to lock
@param   string $glue       The glue by which to join the conditions. Defaults to ',' .

@return  PostgresqlQuery  FOR SHARE query element

@since   2.0
554645
public function forShare($table_name = null, $glue = ',')
    {
        if (is_null($this->forShare)) {
            $glue = strtoupper($glue);
            $this->forShare = new QueryElement('FOR SHARE', $table_name ? 'OF ' . $table_name : null, "$glue ");
        } else {
            $this->forShare->append($table_name);
        }

        return $this;
    }
1087729
private function _getPrimaryKeyFromInput($table_name, $keyed_array)
	{
		// Get the primary key
		$table_primary_key = self::_getTablePrimaryKey($table_name);

		// Find the primary key
		if (empty($keyed_array) || !array_key_exists($table_primary_key, $keyed_array))
		{
			Utility::throwException('Primary key value not found in input.');
		}

		return $keyed_array[$table_primary_key];
	}
571865
public static function MakeInsertRow (array $options, $table_name, array $merge_row = [], $forced_obtain = false) {
		return static::GetConnection($options)->makeInsertRow($table_name, $merge_row, $forced_obtain);
	}
1342455
public static function set($name, $definition, $shared = false, $locked = false)
    {
        if (isset(self::$services[$name]) && self::$services[$name]->isLocked()) {
            throw new ServiceLockedException(sprintf('Service "%s" is locked.', $name));
        }

        self::$services[$name] = new Service($name, $definition, $shared, $locked);
    }
56645
protected function _updateColumns ($table_name) {
		$stmt = $this->prepare('SELECT ccu.column_name FROM information_schema.table_constraints tc, information_schema.constraint_column_usage ccu WHERE tc.table_catalog = current_database() AND tc.table_name = ? AND tc.constraint_type = ? AND tc.table_catalog=ccu.table_catalog AND tc.table_schema = ccu.table_schema AND tc.table_name = ccu.table_name AND tc.constraint_name = ccu.constraint_name');
		$stmt->execute([$table_name, 'PRIMARY KEY']);
		$stmt->setFetchMode(\PDO::FETCH_NUM);
		$pkey_column_name = $stmt->fetch();
		$pkey_column_name = isset($pkey_column_name[0]) ? $pkey_column_name : null;

		$comments = [];
		$stmt = $this->prepare('SELECT pa.attname as column_name, pd.description as column_comment FROM pg_stat_all_tables psat, pg_description pd, pg_attribute pa WHERE psat.schemaname = current_schema() AND psat.relname = ? AND psat.relid = pd.objoid AND pd.objsubid <> 0 AND pd.objoid = pa.attrelid AND pd.objsubid = pa.attnum');
		$stmt->execute([$table_name]);
		foreach ($stmt as $comment) {
			$comments[$comment['column_name']] = $comment['column_comment'];
		}

		$pdo_param_list = $this->GetPdoParamList();

		$this->_columns[$table_name] = [];
		$stmt = $this->prepare('SELECT *  FROM information_schema.columns WHERE table_catalog = current_database() AND table_name = ? ORDER BY ordinal_position');
		$stmt->setFetchMode(\PDO::FETCH_ASSOC);
		$stmt->execute([$table_name]);
		foreach ($stmt as $columns) {
			$auto_increment = preg_match("/^nextval\('.+'::regclass\)$/", $columns['column_default']) !== 0;
			$this->_columns[$table_name][$columns['column_name']] = [
				'column_name'		=> $columns['column_name'],
				'type'				=> $columns['data_type'],
				'not_null'			=> filter_var($columns['is_nullable'], FILTER_VALIDATE_BOOLEAN),
				'default'			=> $columns['column_default'],
				'auto_increment'	=> $auto_increment,
				'primary_key'		=> $auto_increment ?: ($pkey_column_name === $columns['column_name']),
				'comment'			=> isset($comments[$columns['column_name']]) ? $comments[$columns['column_name']] : '',
				'raw_data'			=> $columns,
				'pdo_param'			=> $pdo_param_list[explode('(', $columns['data_type'])[0]],
			];
		}
	}
566249
private function _update($table_name, $keyed_array)
	{
		// Get the schema and primary key
		$table_schema      = self::_getTableSchema($table_name);
		$table_primary_key = self::_getTablePrimaryKey($table_name);

		// Get the columns and values
		list($parameter_columns, $parameter_values) = Validation::validateTableInput($table_name, $table_schema, $table_primary_key, $keyed_array);

		// Escape the column names
		$parameter_columns = self::_escapeColumnNames($parameter_columns);

		// List the number of parameters - Function creates an array of range 1..n and prepends '$' to each number
		$parameter_placeholders = self::_calculateInputPlaceholders($parameter_columns);

		// Construct the proper UPDATE parameters statement
		array_walk($parameter_placeholders,
			function(&$value, $key)
			{ 
				$value = $key . ' = ' . $value;
			}
		);

		// Construct the primary key requirement
		$primary_key_placeholder = '$' . (count($parameter_placeholders) + 1);
		$primary_key_value       = self::_getPrimaryKeyFromInput($table_name, $keyed_array);

		// Clean the table name
		$table_name = self::_getCleanTableName($table_name);

		// Construct the UPDATE statement
		$sql = '
			UPDATE ' . $table_name . ' SET
			' . implode(', ', $parameter_placeholders) . '
			WHERE ' . $table_primary_key . ' = ' . $primary_key_placeholder . '
			RETURNING *;
		';

		// Append the primary key value to the parameter values
		$parameter_values[] = $primary_key_value;

		// Sanitize and run the query
		$rows = Utility::pgQueryParams($sql, $parameter_values);

		// Validate result, check that primary key is set
		if (empty($rows) || !array_key_exists('0', $rows) || !array_key_exists($table_primary_key, $rows[0]))
		{
			Utility::throwException('Record not found for ' . $table_name . ' with a primary key value of ' . $primary_key_value);
		}

		// Return the only record
		return $rows[0];
	}
949048
protected static function _checkQueryCache($cache_key, $table_name = null, $connection_name = self::DEFAULT_CONNECTION)
        {
            if(isset(self::$_config[$connection_name]['check_query_cache']) && is_callable(self::$_config[$connection_name]['check_query_cache'])){
                return call_user_func_array(self::$_config[$connection_name]['check_query_cache'], array($cache_key, $table_name, $connection_name));
            } elseif (isset(self::$_query_cache[$connection_name][$cache_key])) {
                return self::$_query_cache[$connection_name][$cache_key];
            }

            return false;
        }
902722
public function makeInsertRow ($table_name, array $merge_row = [], $forced_obtain = false) {
		$merge_row += $merge_row + $this->getColumnDefaultValues($table_name, $forced_obtain);

		$not_null_columns = $this->getNotNullColumns($table_name, $forced_obtain);
		$columns = $this->getColumns($table_name, $forced_obtain);

		$auto_increment_column_list = [];
		foreach (array_keys($merge_row) as $column_name) {
			if (isset($auto_increment_column_list[$column_name])) {
				unset($merge_row[$column_name]);
			}
			if (isset($not_null_columns[$column_name]) && $merge_row[$column_name] === null) {
				$type = static::GetType($columns[$column_name]['Type']);
				switch (static::GetPdoParamList()[$type]) {
					case \PDO::PARAM_INT:
						$value = 0;
						break;
					case \PDO::PARAM_BOOL:
						$value = false;
						break;
					case \PDO::PARAM_STR:
						$value = '';
						break;
					case \PDO::PARAM_LOB:
						$value = 0;
						break;
					default:
						$value = '';
						break;
				}
				$merge_row[$column_name] = $value;
			}
		}
		ksort($merge_row);
		return $merge_row;
	}
940114
public static Store get(final String _name)
        throws CacheReloadException
    {
        final Cache<String, Store> cache = InfinispanCache.get().<String, Store>getCache(Store.NAMECACHE);
        if (!cache.containsKey(_name)) {
            Store.getStoreFromDB(CIDB.Store.Name, _name);
        }
        return cache.get(_name);
    }
404231
public function getTableAlias($table_name = null)
    {
        if (!$table_name) {
            $table_name = $this->getTableName();
        }
        $bits = explode("_", $table_name);
        $alias = '';
        foreach ($bits as $bit) {
            $alias .= strtolower(substr($bit, 0, 1));
        }
        return $alias;
    }
364176
public ForeignkeyDef getForeignkey(String name, String tableName)
    {
        String        realName = (name == null ? "" : name);
        ForeignkeyDef def      = null;

        for (Iterator it = getForeignkeys(); it.hasNext();)
        {
            def = (ForeignkeyDef)it.next();
            if (realName.equals(def.getName()) &&
                def.getTableName().equals(tableName))
            {
                return def;
            }
        }
        return null;
    }
1172129
public SQLSelect column(final String _name)
    {
        columns.add(new Column(tablePrefix, null, _name));
        return this;
    }
1032012
private function _select($table_name, $columns, $primary_key_value)
	{
		// Get the schema and primary key
		$table_schema      = self::_getTableSchema($table_name);
		$table_primary_key = self::_getTablePrimaryKey($table_name);

		// Get the columns
		$parameter_columns = Validation::validateTableColumns($table_name, $table_schema, $columns);

		// Escape the column names
		$parameter_columns = self::_escapeColumnNames($parameter_columns);

		// Construct the primary key requirement
		$primary_key_value = intval($primary_key_value);

		// Clean the table name
		$table_name = self::_getCleanTableName($table_name);

		// Construct the SELECT sql
		$sql = '
			SELECT ' . implode(', ', $parameter_columns) . '
			FROM ' . $table_name . '
			WHERE ' . $table_primary_key . ' = $1;
		';

		// Sanitize and run the query
		$rows = Utility::pgQueryParams($sql, array($primary_key_value));

		// Validate result, check that primary key is set
		if (empty($rows) || !array_key_exists('0', $rows) || !array_key_exists($table_primary_key, $rows[0]))
		{
			Utility::throwException('Record not found for ' . $table_name . ' with a primary key value of ' . $primary_key_value);
		}

		// Return the only record
		return $rows[0];
	}
1009312
public function lockTable($tableName)
	{
		$this->transactionStart();
		$this->setQuery('LOCK TABLE ' . $this->quoteName($tableName) . ' IN ACCESS EXCLUSIVE MODE')->execute();

		return $this;
	}
62242
private function queryAddPropertySelect(\Smalldb\Flupdo\FlupdoBuilder $query, string $table_alias, string $property_name, array $property, string $property_prefix = '')
	{
		$table_q = $query->quoteIdent($table_alias);
		$p_q = $query->quoteIdent($property_name);
		$pa_q = $query->quoteIdent($property_prefix.$property_name);
		if (!empty($property['components'])) {
			foreach ($property['components'] as $component => $column) {
				if (!isset($this->properties[$column])) {
					// make sure the components are selected, but only if they are not standalone properties
					$column_q = $query->quoteIdent($column);
					$alias_q = $property_prefix !== '' ? $query->quoteIdent($property_prefix.$column) : $column_q;
					$query->select("$table_q.$column_q AS $alias_q");
				}
			}
		} else if ((!empty($property['is_calculated']) || !empty($property['calculated'])) && isset($property['sql_select'])) {
			// FIXME: Provide a symbol for the current table alias - this will not work when importing properties.
			$query->select("({$property['sql_select']}) AS $pa_q");
		} else {
			$query->select("$table_q.$p_q AS $pa_q");
		}
	}
438055
public function scopeByName($query, $name, $strict = false)
    {
        $names = (array) $name;

        if (! $strict && $name !== '*') {
            $names[] = '*';
        }

        $query->whereIn("{$this->table}.name", $names);
    }
88888
public static AccessSet get(final String _name)
        throws CacheReloadException
    {
        final Cache<String, AccessSet> cache = InfinispanCache.get().<String, AccessSet>getCache(AccessSet.NAMECACHE);
        if (!cache.containsKey(_name)) {
            AccessSet.getAccessSetFromDB(AccessSet.SQL_NAME, _name);
        }
        return cache.get(_name);
    }