Skip to content

Instantly share code, notes, and snippets.

@ryonsherman
Last active August 29, 2015 14:05
Show Gist options
  • Save ryonsherman/fc21fc8116c78717c4bc to your computer and use it in GitHub Desktop.
Save ryonsherman/fc21fc8116c78717c4bc to your computer and use it in GitHub Desktop.
CodeIgniter Library for Accessing MSSQL Extended Property
<?php
class Extended_property {
var $CI;
function Extended_property()
{
this->CI =& get_instance();
}
function get($table, $column, $property)
{
$result = $this->CI->db
->query('
SELECT value
FROM ::fn_listextendedproperty(
N\''.$property.'\',
N\'user\', N\'dbo\',
N\'table\', N\''.$table.'\',
N\'column\', N\''.$column.'\')')
->limit(1)
->row();
return (!empty(@$result->value)) ? $result->value : false;
}
function set($table, $column, $property, $value)
{
$this->CI->db
->query('
IF EXISTS(
SELECT value
FROM ::fn_listextendedproperty(
N\''.$property.'\',
N\'user\', N\'dbo\',
N\'table\', N\''.$table.'\',
N\'column\', N\''.$column.'\'))
EXEC sp_dropextendedproperty
N\''.$property.'\',
N\'user\', N\'dbo\',
N\'table\', N\''.$table.'\',
N\'column\', N\''.$column.'\';
EXEC sp_addextendedproperty
N\''.$property.'\', N\''.$value.'\',
N\'user\', N\'dbo\',
N\'table\', N\''.$table.'\',
N\'column\', N\''.$column.'\'');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment