<commit_before><?php
require_once("PostgresqlDatabase.php");

class PostgresqlDatabaseAdmin extends PostgresqlDatabase implements GenericDatabaseAdmin
{

	/**
	 * __construct function.
	 * 
	 * @brief Creates the database connection
	 * @access public
	 * @param mixed $username
	 * @param mixed $password
	 * @param mixed $serverAddress
	 * @param mixed $databaseName
	 * @param mixed $tablePrefix
	 * @return void
	 */
	public function __construct($username, $password, $serverAddress, $serverPort, $databaseName, $tablePrefix, $cacher = null, $lazy = true)
	{
		parent::__construct($username, $password, $serverAddress, $serverPort, $databaseName, $tablePrefix, null, false);
	}
	
	public function isTransactional()
	{
		return true;
	}
	
	public function startTransaction()
	{
		return pg_query(parent::$this->databaseConnection, "BEGIN WORK");
	}
	
	public function commitTransaction()
	{
		return pg_query(parent::$this->databaseConnection, "COMMIT");
	}
	
	public function rollbackTransaction()
	{
		return pg_query(parent::$this->databaseConnection, "ROLLBACK");
	}
	
	private function runQuery($query, $params)
	{
		$result = pg_query_params(parent::$this->databaseConnection, $query, $params);
		
		if(!$result)
		{
			throw new exception("query failed");
		}
		
		return $result;
	}

	public function addPost($title, $data, $niceTitle, $uri, $author, $date, $draft, $postId = null)
	{	
		// if the postId is null then we have a new post to be posted, else we have a post we are looking to update
		if($postId === null)
		{
			$formattedQuery = sprintf('INSERT INTO %sposts ("Title", "NiceTitle", "URI", "PostData", "Author", "Date", "Draft") VALUES($1, $2, $3, $4, $5, $6, $7)', parent::$this->tablePrefix);
			
			$this->runQuery($formattedQuery, array($title, $niceTitle, $uri, $data, $author, $date, $draft));	
		}
		else
		{
			if($date !== null)
			{
				$formattedQuery = sprintf('UPDATE %sposts SET "Title"=$1, "NiceTitle"=$2, "URI"=$3, "PostData"=$4, "Author"=$5, "Date"=$6, "Draft"=$7 WHERE "PrimaryKey"=$8', parent::$this->tablePrefix);
				
				$this->runQuery($formattedQuery, array($title, $niceTitle, $uri, $data, $author, $date, $draft, $postId));
			}
			else
			{
				$formattedQuery = sprintf('UPDATE %sposts SET "Title"=$1, "NiceTitle"=$2, "URI"=$3, "PostData"=$4, "Author"=$5, "Draft"=$6 WHERE "PrimaryKey"=$7', parent::$this->tablePrefix);
				
				$this->runQuery($formattedQuery, array($title, $niceTitle, $uri, $data, $author, $draft, $postId));
			}
		}
	}
	
	public function deletePost($postId)
	{
	
	}
	
	public function addPage($title, $data, $niceTitle, $uri, $author, $date, $draft, $corral = null, $pageId = null)
	{
	
	}
	
	public function removePage($pageId)
	{
	
	}
	
	public function addUser($username, $displayName, $passwordHash, $salt, $permissions = 99, $canAdministrateUsers = 0)
	{
		$return = false;
		
		$formattedQuery = sprintf('INSERT INTO %susers ("loginName", "displayName", "PasswordHash", "Salt", "Permissions", "CanAdminUsers") VALUES($1, $2, $3, $4, $5, $6)', parent::$this->tablePrefix);
		
		$this->startTransaction();<commit_msg>just some notes<commit_after><?php
require_once("PostgresqlDatabase.php");

class PostgresqlDatabaseAdmin extends PostgresqlDatabase implements GenericDatabaseAdmin
{

	/**
	 * __construct function.
	 * 
	 * @brief Creates the database connection
	 * @access public
	 * @param mixed $username
	 * @param mixed $password
	 * @param mixed $serverAddress
	 * @param mixed $databaseName
	 * @param mixed $tablePrefix
	 * @return void
	 */
	public function __construct($username, $password, $serverAddress, $serverPort, $databaseName, $tablePrefix, $cacher = null, $lazy = true)
	{
		parent::__construct($username, $password, $serverAddress, $serverPort, $databaseName, $tablePrefix, null, false);
	}
	
	public function isTransactional()
	{
		return true;
	}
	
	public function startTransaction()
	{
		return pg_query(parent::$this->databaseConnection, "BEGIN WORK");
	}
	
	public function commitTransaction()
	{
		return pg_query(parent::$this->databaseConnection, "COMMIT");
	}
	
	public function rollbackTransaction()
	{
		return pg_query(parent::$this->databaseConnection, "ROLLBACK");
	}
	
	private function runQuery($query, $params)
	{
		$result = pg_query_params(parent::$this->databaseConnection, $query, $params);
		
		if(!$result)
		{
			throw new exception("query failed");
		}
		
		return $result;
	}

	public function addPost($title, $data, $niceTitle, $uri, $author, $date, $draft, $postId = null)
	{	
		// if the postId is null then we have a new post to be posted, else we have a post we are looking to update
		if($postId === null)
		{
			$formattedQuery = sprintf('INSERT INTO %sposts ("Title", "NiceTitle", "URI", "PostData", "Author", "Date", "Draft") VALUES($1, $2, $3, $4, $5, $6, $7)', parent::$this->tablePrefix);
			
			$this->runQuery($formattedQuery, array($title, $niceTitle, $uri, $data, $author, $date, $draft));	
		}
		else
		{
			if($date !== null)
			{
				$formattedQuery = sprintf('UPDATE %sposts SET "Title"=$1, "NiceTitle"=$2, "URI"=$3, "PostData"=$4, "Author"=$5, "Date"=$6, "Draft"=$7 WHERE "PrimaryKey"=$8', parent::$this->tablePrefix);
				
				$this->runQuery($formattedQuery, array($title, $niceTitle, $uri, $data, $author, $date, $draft, $postId));
			}
			else
			{
				$formattedQuery = sprintf('UPDATE %sposts SET "Title"=$1, "NiceTitle"=$2, "URI"=$3, "PostData"=$4, "Author"=$5, "Draft"=$6 WHERE "PrimaryKey"=$7', parent::$this->tablePrefix);
				
				$this->runQuery($formattedQuery, array($title, $niceTitle, $uri, $data, $author, $draft, $postId));
			}
		}
	}
	
	public function deletePost($postId)
	{
	
	}
	
	public function addPage($title, $data, $niceTitle, $uri, $author, $date, $draft, $corral = null, $pageId = null)
	{
	
	}
	
	public function removePage($pageId)
	{
	
	}
	
	public function addUser($username, $displayName, $passwordHash, $salt, $permissions = 99, $canAdministrateUsers = 0)
	{
		$return = false;
		
		$formattedQuery = sprintf('INSERT INTO %susers ("loginName", "displayName", "PasswordHash", "Salt", "Permissions", "CanAdminUsers") VALUES($1, $2, $3, $4, $5, $6)', parent::$this->tablePrefix);
		
		// we need to remove the start and rollback transactions as these should be done by the class calling the database.
		$this->startTransaction();
{'fraction_non_alphanumeric': 0.16909667194928685, 'fraction_numerical': 0.0098256735340729, 'mean_word_length': 4.848934198331789, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4935709', 'n_tokens_mistral': 2291, 'n_tokens_neox': 2065, 'n_words': 529}