<commit_before><?php

/**
 * @name      <NAME>
 * @copyright ElkArte Forum contributors
 * @license   BSD http://opensource.org/licenses/BSD-3-Clause
 *
 * This file contains code covered by:
 * copyright:	2011 Simple Machines (http://www.simplemachines.org)
 * license:  	BSD, See included LICENSE.TXT for terms and conditions.
 *
 * @version 1.1 beta 3
 *
 */

/**
 * Install script for PostgreSQL 8.3+
 *
 *
 * Create PostgreSQL functions.
 * Some taken from http://www.xach.com/aolserver/mysql-functions.sql and http://pgfoundry.org/projects/mysqlcompat/.
 * IP Regex in inet_aton from http://www.mkyong.com/database/regular-expression-in-postgresql/.
 */

class InstallInstructions_install_1_1_postgresql
{
	protected $db = null;
	protected $table = null;

	public function __construct($db, $table)
	{
		$this->db = $db;
		return $this->table = $table;
	}

	public function create_functions()
	{
		$this->db->query('', '
		CREATE OR REPLACE FUNCTION INET_ATON(text) RETURNS bigint AS \'
			SELECT
			CASE WHEN
				$1 !~ \'\'^[0-9]?[0-9]?[0-9]?\.[0-9]?[0-9]?[0-9]?\.[0-9]?[0-9]?[0-9]?\.[0-9]?[0-9]?[0-9]?$\'\' THEN 0
			ELSE
				split_part($1, \'\'.\'\', 1)::int8 * (256 * 256 * 256) +
				split_part($1, \'\'.\'\', 2)::int8 * (256 * 256) +
				split_part($1, \'\'.\'\', 3)::int8 * 256 +
				split_part($1, \'\'.\'\', 4)::int8
			END AS result\'
		LANGUAGE \'sql\';');

		$this->db->query('', '
		CREATE OR REPLACE FUNCTION INET_NTOA(bigint) RETURNS text AS \'
			SELECT
				(($1 >> 24) & 255::int8) || \'\'.\'\' ||
				(($1 >> 16) & 255::int8) || \'\'.\'\' ||
				(($1 >> 8) & 255::int8) || \'\'.\'\' ||
				($1 & 255::int8) AS result\'
		LANGUAGE \'sql\';');

		$this->db->query('', '
		CREATE OR REPLACE FUNCTION FIND_IN_SET(needle text, haystack text) RETURNS integer AS \'<commit_msg>restore compat functions for pgsql<commit_after><?php

/**
 * @name      ElkArte Forum
 * @copyright ElkArte Forum contributors
 * @license   BSD http://opensource.org/licenses/BSD-3-Clause
 *
 * This file contains code covered by:
 * copyright:	2011 Simple Machines (http://www.simplemachines.org)
 * license:  	BSD, See included LICENSE.TXT for terms and conditions.
 *
 * @version 1.1 beta 3
 *
 */

/**
 * Install script for PostgreSQL 8.3+
 *
 *
 * Create PostgreSQL functions.
 * Some taken from http://www.xach.com/aolserver/mysql-functions.sql and http://pgfoundry.org/projects/mysqlcompat/.
 * IP Regex in inet_aton from http://www.mkyong.com/database/regular-expression-in-postgresql/.
 */

class InstallInstructions_install_1_1_postgresql
{
	protected $db = null;
	protected $table = null;

	public function __construct($db, $table)
	{
		$this->db = $db;
		return $this->table = $table;
	}

	public function create_functions()
	{
		$this->db->query('', '
		CREATE OR REPLACE FUNCTION FROM_UNIXTIME(integer) RETURNS timestamp AS
			\'SELECT timestamp \'\'epoch\'\' + $1 * interval \'\'1 second\'\' AS result\'
		LANGUAGE \'sql\';');

		$this->db->query('', '
		CREATE OR REPLACE FUNCTION COALESCE (text, text) RETURNS text AS
			\'SELECT COALESCE($1, $2) AS result\'
		LANGUAGE \'sql\';');

		$this->db->query('', '
		CREATE OR REPLACE FUNCTION COALESCE (int4, int4) RETURNS int4 AS
			\'SELECT COALESCE($1, $2) AS result\'
		LANGUAGE \'sql\';');

		$this->db->query('', '
		CREATE OR REPLACE FUNCTION COALESCE (int8, int8) RETURNS int8 AS
			\'SELECT COALESCE($1, $2) AS result\'
		LANGUAGE \'sql\';');

		$this->db->query('', '
		CREATE OR REPLACE FUNCTION COALESCE (character varying, character varying) RETURNS character varying AS
			\'SELECT COALESCE($1, $2) AS result\'
		LANGUAGE \'sql\';');

		$this->db->query('', '
		CREATE OR REPLACE FUNCTION COALESCE (character varying, boolean) RETURNS character varying AS
			\'SELECT COALESCE($1, CAST(CAST($2 AS int) AS varchar)) AS result\'
		LANGUAGE \'sql\';');

		$this->db->query('', '
		CREATE OR REPLACE FUNCTION COALESCE (int, boolean) RETURNS int AS
			\'SELECT COALESCE($1, CAST($2 AS int)) AS result\'
		LANGUAGE \'sql\';');

		$this->db->query('', '
		CREATE OR REPLACE FUNCTION INET_ATON(text) RETURNS bigint AS \'
			SELECT
			CASE WHEN
				$1 !~ \'\'^[0-9]?[0-9]?[0-9]?\.[0-9]?[0-9]?[0-9]?\.[0-9]?[0-9]?[0-9]?\.[0-9]?[0-9]?[0-9]?$\'\' THEN 0
			ELSE
				split_part($1, \'\'.\'\', 1)::int8 * (256 * 256 * 256) +
				split_part($1, \'\'.\'\', 2)::int8 * (256 * 256) +
				split_part($1, \'\'.\'\', 3)::int8 * 256 +
				split_part($1, \'\'.\'\', 4)::int8
			END AS result\'
		LANGUAGE \'sql\';');

		$this->db->query('', '
		CREATE OR REPLACE FUNCTION INET_NTOA(bigint) RETURNS text AS \'
			SELECT
				(($1 >> 24) & 255::int8) || \'\'.\'\' ||
				(($1 >> 16) & 255::int8) || \'\'.\'\' ||
				(($1 >> 8) & 255::int8) || \'\'.\'\' ||
				($1 & 255::int8) AS result\'
		LANGUAGE \'sql\';');

		$this->db->query('', '
		CREATE OR REPLACE FUNCTION FIND_IN_SET(needle text, haystack text) RETURNS integer AS \'
{'fraction_non_alphanumeric': 0.21166084992814618, 'fraction_numerical': 0.042291110654896324, 'mean_word_length': 3.2072538860103625, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 46, 'https://': 0, 'lorem ipsum': 0, 'www.': 6, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3498913', 'n_tokens_mistral': 2158, 'n_tokens_neox': 1873, 'n_words': 438}