<?php

require_once(dirname(__FILE__).'/upgrade.php');

class MSSQLUPGRADE extends UPGRADE
{
	/**
	* Check if a column exists in a table
	*
	* @param $table The table with the column we are checking for
	* @param $column The column to check for
	*
	* @return boolean If the column exists in the table return true
	*/
	function ColumnExists($table, $column)
	{
		$query = 
		"SELECT TABLE_NAME,COLUMN_NAME
        FROM INFORMATION_SCHEMA.COLUMNS
        WHERE TABLE_NAME='$table' AND COLUMN_NAME = '$column'
		";

		$result = $GLOBALS['AKB_DB']->Query($query);
		$row = $GLOBALS['AKB_DB']->Fetch($result);

		if (isset($row['COLUMN_NAME']) && $row['COLUMN_NAME'] == $column) {
			return true;
		} else {
			return false;
		}
	}
	
	/**
	* Check if a database table exists
	*
	* @param string $table The table name to check
	*
	* @return boolean If the table exists return true
	*/
	function TableExists($table)
	{
		$query = "SELECT name FROM sysobjects WHERE name = '$table'";
		$result = $GLOBALS['AKB_DB']->FetchOne($query);
		// If there is a table with this name already we don't need to run this
		// part of the upgrade script

		// We have to convert the name to lower case before comparing since
		// if MySQL is on windows the tables are converted to lowercase
		// when they are returned from our sql statement
		if (strtolower($result) == strtolower($table)) {
			return true;
		} else {
			return false;
		}
	}
		
}