From 7ecb5c69d466e3a71e35ac76fc7bc0321fe2048d Mon Sep 17 00:00:00 2001 From: Mzhelskiy Maxim Date: Tue, 26 Apr 2011 16:43:26 +0000 Subject: [PATCH] =?UTF-8?q?!isFieldExists()=20=D0=B4=D0=BB=D1=8F=20=D0=BF?= =?UTF-8?q?=D1=80=D0=BE=D0=B2=D0=B5=D1=80=D0=BA=D0=B8=20=D1=81=D1=83=D1=89?= =?UTF-8?q?=D0=B5=D1=81=D1=82=D0=B2=D0=BE=D0=B0=D0=BD=D0=B8=D1=8F=20=D0=BF?= =?UTF-8?q?=D0=BE=D0=BB=D1=8F=20=D0=B2=20=D1=82=D0=B0=D0=B1=D0=BB=D0=B8?= =?UTF-8?q?=D1=86=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- engine/classes/Plugin.class.php | 11 +++++++++ engine/modules/database/Database.class.php | 28 ++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/engine/classes/Plugin.class.php b/engine/classes/Plugin.class.php index 8a07bd05..75019332 100644 --- a/engine/classes/Plugin.class.php +++ b/engine/classes/Plugin.class.php @@ -194,6 +194,17 @@ abstract class Plugin extends Object { return $this->Database_isTableExists($sTableName); } + /** + * Проверяет наличие поля в таблице + * + * @param unknown_type $sTableName + * @param unknown_type $sFieldName + * @return unknown + */ + protected function isFieldExists($sTableName,$sFieldName) { + return $this->Database_isFieldExists($sTableName,$sFieldName); + } + /** * Получает версию плагина * diff --git a/engine/modules/database/Database.class.php b/engine/modules/database/Database.class.php index 3570e275..219113fe 100644 --- a/engine/modules/database/Database.class.php +++ b/engine/modules/database/Database.class.php @@ -162,6 +162,13 @@ class ModuleDatabase extends Module { return array('result'=>false,'errors'=>$aErrors); } + /** + * Проверяет существование таблицы + * + * @param string $sTableName + * @param array $aConfig + * @return bool + */ public function isTableExists($sTableName,$aConfig=null) { $sTableName = str_replace('prefix_', Config::Get('db.table.prefix'), $sTableName); $sQuery="SHOW TABLES LIKE '{$sTableName}'"; @@ -170,6 +177,27 @@ class ModuleDatabase extends Module { } return false; } + + /** + * Проверяет существование поля в таблице + * + * @param string $sTableName + * @param string $sFieldName + * @param array $aConfig + * @return bool + */ + public function isFieldExists($sTableName,$sFieldName,$aConfig=null) { + $sTableName = str_replace('prefix_', Config::Get('db.table.prefix'), $sTableName); + $sQuery="SHOW FIELDS FROM '{$sTableName}'"; + if ($aRows=$this->GetConnect($aConfig)->select($sQuery)) { + foreach ($aRows as $aRow){ + if ($aRow['Field'] == $sFieldName){ + return true; + } + } + } + return false; + } }