MODX Revolution PHP Cross Reference Content Management Systems

Source: /core/xpdo/om/sqlsrv/xpdomanager.class.php - 455 lines - 24792 bytes - Summary - Text - Print

Description: The sqlsrv implementation of the xPDOManager class.

   1  <?php
   2  /*

   3   * Copyright 2010-2013 by MODX, LLC.

   4   *

   5   * This file is part of xPDO.

   6   *

   7   * xPDO is free software; you can redistribute it and/or modify it under the

   8   * terms of the GNU General Public License as published by the Free Software

   9   * Foundation; either version 2 of the License, or (at your option) any later

  10   * version.

  11   *

  12   * xPDO is distributed in the hope that it will be useful, but WITHOUT ANY

  13   * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR

  14   * A PARTICULAR PURPOSE. See the GNU General Public License for more details.

  15   *

  16   * You should have received a copy of the GNU General Public License along with

  17   * xPDO; if not, write to the Free Software Foundation, Inc., 59 Temple Place,

  18   * Suite 330, Boston, MA 02111-1307 USA

  19   */
  20  
  21  /**

  22   * The sqlsrv implementation of the xPDOManager class.

  23   *

  24   * @package xpdo

  25   * @subpackage om.sqlsrv

  26   */
  27  
  28  /**

  29   * Include the parent {@link xPDOManager} class.

  30   */
  31  require_once (dirname(dirname(__FILE__)) . '/xpdomanager.class.php');
  32  
  33  /**

  34   * Provides sqlsrv data source management for an xPDO instance.

  35   *

  36   * These are utility functions that only need to be loaded under special

  37   * circumstances, such as creating tables, adding indexes, altering table

  38   * structures, etc.  xPDOManager class implementations are specific to a

  39   * database driver and this instance is implemented for sqlsrv.

  40   *

  41   * @package xpdo

  42   * @subpackage om.sqlsrv

  43   */
  44  class xPDOManager_sqlsrv extends xPDOManager {
  45      public function createSourceContainer($dsnArray = null, $username= null, $password= null, $containerOptions= array ()) {
  46          $created = false;
  47          if ($this->xpdo->getConnection(array(xPDO::OPT_CONN_MUTABLE => true))) {
  48              if ($dsnArray === null) $dsnArray = xPDO::parseDSN($this->xpdo->getOption('dsn'));
  49              if ($username === null) $username = $this->xpdo->getOption('username', null, '');
  50              if ($password === null) $password = $this->xpdo->getOption('password', null, '');
  51              if (is_array($dsnArray) && is_string($username) && is_string($password)) {
  52                  $sql= 'CREATE DATABASE ' . $this->xpdo->escape($dsnArray['dbname']);
  53                  if (isset ($containerOptions['collation'])) {
  54                      $sql.= ' COLLATE ' . $containerOptions['collation'];
  55                  }
  56                  try {
  57                      $pdo = new PDO("sqlsrv:server={$dsnArray['server']}", $username, $password, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
  58                      $result = $pdo->exec($sql);
  59                      if ($result !== false) {
  60                          $created = true;
  61                      } else {
  62                          $this->xpdo->log(xPDO::LOG_LEVEL_ERROR, "Could not create source container:\n{$sql}\nresult = " . var_export($result, true));
  63                      }
  64                  } catch (PDOException $pe) {
  65                      $this->xpdo->log(xPDO::LOG_LEVEL_ERROR, "Could not connect to database server: " . $pe->getMessage());
  66                  } catch (Exception $e) {
  67                      $this->xpdo->log(xPDO::LOG_LEVEL_ERROR, "Could not create source container: " . $e->getMessage());
  68                  }
  69              }
  70          } else {
  71              $this->xpdo->log(xPDO::LOG_LEVEL_ERROR, "Could not get writable connection", '', __METHOD__, __FILE__, __LINE__);
  72          }
  73          return $created;
  74      }
  75  
  76      public function removeSourceContainer($dsnArray = null, $username= null, $password= null) {
  77          $removed= false;
  78          if ($this->xpdo->getConnection(array(xPDO::OPT_CONN_MUTABLE => true))) {
  79              if ($dsnArray === null) $dsnArray = xPDO::parseDSN($this->xpdo->getOption('dsn'));
  80              if ($username === null) $username = $this->xpdo->getOption('username', null, '');
  81              if ($password === null) $password = $this->xpdo->getOption('password', null, '');
  82              if (is_array($dsnArray) && is_string($username) && is_string($password)) {
  83                  $sql= 'DROP DATABASE ' . $this->xpdo->escape($dsnArray['dbname']);
  84                  try {
  85                      $pdo = new PDO("sqlsrv:server={$dsnArray['server']}", $username, $password, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
  86                      $pdo->exec("ALTER DATABASE {$this->xpdo->escape($dsnArray['dbname'])} SET single_user WITH ROLLBACK IMMEDIATE");
  87                      $result = $pdo->exec($sql);
  88                      if ($result !== false) {
  89                          $removed = true;
  90                      } else {
  91                          $this->xpdo->log(xPDO::LOG_LEVEL_ERROR, "Could not remove source container:\n{$sql}\nresult = " . var_export($result, true));
  92                      }
  93                  } catch (PDOException $pe) {
  94                      $this->xpdo->log(xPDO::LOG_LEVEL_ERROR, "Could not connect to database server: " . $pe->getMessage());
  95                  } catch (Exception $e) {
  96                      $this->xpdo->log(xPDO::LOG_LEVEL_ERROR, "Could not remove source container: " . $e->getMessage());
  97                  }
  98              }
  99          } else {
 100              $this->xpdo->log(xPDO::LOG_LEVEL_ERROR, "Could not get writable connection", '', __METHOD__, __FILE__, __LINE__);
 101          }
 102          return $removed;
 103      }
 104  
 105      public function removeObjectContainer($className) {
 106          $removed= false;
 107          if ($this->xpdo->getConnection(array(xPDO::OPT_CONN_MUTABLE => true))) {
 108              $instance= $this->xpdo->newObject($className);
 109              if ($instance) {
 110                  $sql= 'DROP TABLE ' . $this->xpdo->getTableName($className);
 111                  $removed= $this->xpdo->exec($sql);
 112                  if ($removed === false && $this->xpdo->errorCode() !== '' && $this->xpdo->errorCode() !== PDO::ERR_NONE) {
 113                      $this->xpdo->log(xPDO::LOG_LEVEL_ERROR, 'Could not drop table ' . $className . "\nSQL: {$sql}\nERROR: " . print_r($this->xpdo->pdo->errorInfo(), true));
 114                  } else {
 115                      $removed= true;
 116                      $this->xpdo->log(xPDO::LOG_LEVEL_INFO, 'Dropped table' . $className . "\nSQL: {$sql}\n");
 117                  }
 118              }
 119          } else {
 120              $this->xpdo->log(xPDO::LOG_LEVEL_ERROR, "Could not get writable connection", '', __METHOD__, __FILE__, __LINE__);
 121          }
 122          return $removed;
 123      }
 124  
 125      public function createObjectContainer($className) {
 126          $created= false;
 127          if ($this->xpdo->getConnection(array(xPDO::OPT_CONN_MUTABLE => true))) {
 128              $instance= $this->xpdo->newObject($className);
 129              if ($instance) {
 130                  $tableName= $this->xpdo->getTableName($className);
 131                  $existsStmt = $this->xpdo->query("SELECT COUNT(*) FROM {$tableName}");
 132                  if ($existsStmt && $existsStmt->fetchAll()) {
 133                      return true;
 134                  }
 135                  $tableMeta= $this->xpdo->getTableMeta($className);
 136                  $sql= 'CREATE TABLE ' . $tableName . ' (';
 137                  $fieldMeta = $this->xpdo->getFieldMeta($className, true);
 138                  $nativeGen = false;
 139                  $columns = array();
 140                  while (list($key, $meta)= each($fieldMeta)) {
 141                      $columns[] = $this->getColumnDef($className, $key, $meta);
 142                      if (array_key_exists('generated', $meta) && $meta['generated'] == 'native') $nativeGen = true;
 143                  }
 144                  $sql .= implode(', ', $columns);
 145                  $indexes = $this->xpdo->getIndexMeta($className);
 146                  $createIndices = array();
 147                  $tableConstraints = array();
 148                  if (!empty ($indexes)) {
 149                      foreach ($indexes as $indexkey => $indexdef) {
 150                          $indexType = ($indexdef['primary'] ? 'PRIMARY KEY' : ($indexdef['unique'] ? 'UNIQUE' : 'INDEX'));
 151                          $indexset = $this->getIndexDef($className, $indexkey, $indexdef);
 152                          switch ($indexType) {
 153                              case 'INDEX':
 154                                  $createIndices[$indexkey] = "CREATE INDEX {$this->xpdo->escape($indexkey)} ON {$tableName} ({$indexset})";
 155                                  break;
 156                              case 'PRIMARY KEY':
 157                                  if ($nativeGen) break;
 158                                  $tableConstraints[]= "{$indexType} ({$indexset})";
 159                                  break;
 160                              case 'UNIQUE':
 161                              default:
 162                                  $tableConstraints[]= "CONSTRAINT {$this->xpdo->escape($className . '_' . $indexkey)} {$indexType} ({$indexset})";
 163                                  break;
 164                          }
 165                      }
 166                  }
 167                  if (!empty($tableConstraints)) {
 168                      $sql .= ', ' . implode(', ', $tableConstraints);
 169                  }
 170                  $sql .= ")";
 171                  $created= $this->xpdo->exec($sql);
 172                  if ($created === false && $this->xpdo->errorCode() !== '' && $this->xpdo->errorCode() !== PDO::ERR_NONE) {
 173                      $this->xpdo->log(xPDO::LOG_LEVEL_ERROR, 'Could not create table ' . $tableName . "\nSQL: {$sql}\nERROR: " . print_r($this->xpdo->errorInfo(), true));
 174                  } else {
 175                      $created= true;
 176                      $this->xpdo->log(xPDO::LOG_LEVEL_INFO, 'Created table ' . $tableName . "\nSQL: {$sql}\n");
 177                  }
 178                  if ($created === true && !empty($createIndices)) {
 179                      foreach ($createIndices as $createIndexKey => $createIndex) {
 180                          $indexCreated = $this->xpdo->exec($createIndex);
 181                          if ($indexCreated === false && $this->xpdo->errorCode() !== '' && $this->xpdo->errorCode() !== PDO::ERR_NONE) {
 182                              $this->xpdo->log(xPDO::LOG_LEVEL_ERROR, "Could not create index {$createIndexKey}: {$createIndex} " . print_r($this->xpdo->errorInfo(), true));
 183                          } else {
 184                              $this->xpdo->log(xPDO::LOG_LEVEL_INFO, "Created index {$createIndexKey} on {$tableName}: {$createIndex}");
 185                          }
 186                      }
 187                  }
 188              }
 189          } else {
 190              $this->xpdo->log(xPDO::LOG_LEVEL_ERROR, "Could not get writable connection", '', __METHOD__, __FILE__, __LINE__);
 191          }
 192          return $created;
 193      }
 194  
 195      public function alterObjectContainer($className, array $options = array()) {
 196          if ($this->xpdo->getConnection(array(xPDO::OPT_CONN_MUTABLE => true))) {
 197              // TODO: Implement alterObjectContainer() method.

 198          } else {
 199              $this->xpdo->log(xPDO::LOG_LEVEL_ERROR, "Could not get writable connection", '', __METHOD__, __FILE__, __LINE__);
 200          }
 201      }
 202  
 203      public function addConstraint($class, $name, array $options = array()) {
 204          if ($this->xpdo->getConnection(array(xPDO::OPT_CONN_MUTABLE => true))) {
 205              // TODO: Implement addConstraint() method.

 206          } else {
 207              $this->xpdo->log(xPDO::LOG_LEVEL_ERROR, "Could not get writable connection", '', __METHOD__, __FILE__, __LINE__);
 208          }
 209      }
 210  
 211      public function addField($class, $name, array $options = array()) {
 212          $result = false;
 213          if ($this->xpdo->getConnection(array(xPDO::OPT_CONN_MUTABLE => true))) {
 214              $className = $this->xpdo->loadClass($class);
 215              if ($className) {
 216                  $meta = $this->xpdo->getFieldMeta($className, true);
 217                  if (is_array($meta) && array_key_exists($name, $meta)) {
 218                      $colDef = $this->getColumnDef($className, $name, $meta[$name]);
 219                      if (!empty($colDef)) {
 220                          $sql = "ALTER TABLE {$this->xpdo->getTableName($className)} ADD {$colDef}";
 221                          if ($this->xpdo->exec($sql) !== false) {
 222                              $result = true;
 223                          } else {
 224                              $this->xpdo->log(xPDO::LOG_LEVEL_ERROR, "Error adding field {$class}->{$name}: " . print_r($this->xpdo->errorInfo(), true), '', __METHOD__, __FILE__, __LINE__);
 225                          }
 226                      } else {
 227                          $this->xpdo->log(xPDO::LOG_LEVEL_ERROR, "Error adding field {$class}->{$name}: Could not get column definition");
 228                      }
 229                  } else {
 230                      $this->xpdo->log(xPDO::LOG_LEVEL_ERROR, "Error adding field {$class}->{$name}: No metadata defined");
 231                  }
 232              }
 233          } else {
 234              $this->xpdo->log(xPDO::LOG_LEVEL_ERROR, "Could not get writable connection", '', __METHOD__, __FILE__, __LINE__);
 235          }
 236          return $result;
 237      }
 238  
 239      public function addIndex($class, $name, array $options = array()) {
 240          $result = false;
 241          if ($this->xpdo->getConnection(array(xPDO::OPT_CONN_MUTABLE => true))) {
 242              $className = $this->xpdo->loadClass($class);
 243              if ($className) {
 244                  $meta = $this->xpdo->getIndexMeta($className);
 245                  if (is_array($meta) && array_key_exists($name, $meta)) {
 246                      $idxDef = $this->getIndexDef($className, $name, $meta[$name]);
 247                      if (!empty($idxDef)) {
 248                          $indexType = ($meta[$name]['primary'] ? 'PRIMARY KEY' : ($meta[$name]['unique'] ? 'UNIQUE' : 'INDEX'));
 249                          switch ($indexType) {
 250                              case 'PRIMARY KEY':
 251                              case 'UNIQUE':
 252                                  $sql = "ALTER TABLE {$this->xpdo->getTableName($className)} ADD CONSTRAINT {$this->xpdo->escape($name)} {$indexType} ({$idxDef})";
 253                                  break;
 254                              default:
 255                                  $sql = "CREATE {$indexType} {$this->xpdo->escape($name)} ON {$this->xpdo->getTableName($className)} ({$idxDef})";
 256                                  break;
 257                          }
 258                          if ($this->xpdo->exec($sql) !== false) {
 259                              $result = true;
 260                          } else {
 261                              $this->xpdo->log(xPDO::LOG_LEVEL_ERROR, "Error adding index {$name} to {$class}: " . print_r($this->xpdo->errorInfo(), true), '', __METHOD__, __FILE__, __LINE__);
 262                          }
 263                      } else {
 264                          $this->xpdo->log(xPDO::LOG_LEVEL_ERROR, "Error adding index {$name} to {$class}: Could not get index definition");
 265                      }
 266                  } else {
 267                      $this->xpdo->log(xPDO::LOG_LEVEL_ERROR, "Error adding index {$name} to {$class}: No metadata defined");
 268                  }
 269              }
 270          } else {
 271              $this->xpdo->log(xPDO::LOG_LEVEL_ERROR, "Could not get writable connection", '', __METHOD__, __FILE__, __LINE__);
 272          }
 273          return $result;
 274      }
 275  
 276      public function alterField($class, $name, array $options = array()) {
 277          $result = false;
 278          if ($this->xpdo->getConnection(array(xPDO::OPT_CONN_MUTABLE => true))) {
 279              $className = $this->xpdo->loadClass($class);
 280              if ($className) {
 281                  $meta = $this->xpdo->getFieldMeta($className, true);
 282                  if (is_array($meta) && array_key_exists($name, $meta)) {
 283                      $colDef = $this->getColumnDef($className, $name, $meta[$name]);
 284                      if (!empty($colDef)) {
 285                          $sql = "ALTER TABLE {$this->xpdo->getTableName($className)} ALTER COLUMN {$colDef}";
 286                          if ($this->xpdo->exec($sql) !== false) {
 287                              $result = true;
 288                          } else {
 289                              $this->xpdo->log(xPDO::LOG_LEVEL_ERROR, "Error altering field {$class}->{$name}: " . print_r($this->xpdo->errorInfo(), true), '', __METHOD__, __FILE__, __LINE__);
 290                          }
 291                      } else {
 292                          $this->xpdo->log(xPDO::LOG_LEVEL_ERROR, "Error altering field {$class}->{$name}: Could not get column definition");
 293                      }
 294                  } else {
 295                      $this->xpdo->log(xPDO::LOG_LEVEL_ERROR, "Error altering field {$class}->{$name}: No metadata defined");
 296                  }
 297              }
 298          } else {
 299              $this->xpdo->log(xPDO::LOG_LEVEL_ERROR, "Could not get writable connection", '', __METHOD__, __FILE__, __LINE__);
 300          }
 301          return $result;
 302      }
 303  
 304      public function removeConstraint($class, $name, array $options = array()) {
 305          $result = false;
 306          if ($this->xpdo->getConnection(array(xPDO::OPT_CONN_MUTABLE => true))) {
 307              $className = $this->xpdo->loadClass($class);
 308              if ($className) {
 309                  $sql = "ALTER TABLE {$this->xpdo->getTableName($className)} DROP CONSTRAINT {$this->xpdo->escape($name)}";
 310                  $result = $this->xpdo->exec($sql);
 311                  if ($result !== false || (!$result && $this->xpdo->errorCode() === '00000')) {
 312                      $result = true;
 313                  } else {
 314                      $this->xpdo->log(xPDO::LOG_LEVEL_ERROR, "Error removing field {$class}->{$name}: " . print_r($this->xpdo->errorInfo(), true), '', __METHOD__, __FILE__, __LINE__);
 315                  }
 316              }
 317          } else {
 318              $this->xpdo->log(xPDO::LOG_LEVEL_ERROR, "Could not get writable connection", '', __METHOD__, __FILE__, __LINE__);
 319          }
 320          return $result;
 321      }
 322  
 323      public function removeField($class, $name, array $options = array()) {
 324          $result = false;
 325          if ($this->xpdo->getConnection(array(xPDO::OPT_CONN_MUTABLE => true))) {
 326              $className = $this->xpdo->loadClass($class);
 327              if ($className) {
 328                  if ($defaultConstraints = $this->getDefaultConstraints($class, $name)) {
 329                      foreach ($defaultConstraints as $defaultConstraint) {
 330                          $this->removeConstraint($class, $defaultConstraint);
 331                      }
 332                  }
 333                  $sql = "ALTER TABLE {$this->xpdo->getTableName($className)} DROP COLUMN {$this->xpdo->escape($name)}";
 334                  $result = $this->xpdo->exec($sql);
 335                  if ($result !== false || (!$result && $this->xpdo->errorCode() === '00000')) {
 336                      $result = true;
 337                  } else {
 338                      $this->xpdo->log(xPDO::LOG_LEVEL_ERROR, "Error removing field {$class}->{$name}: " . print_r($this->xpdo->errorInfo(), true), '', __METHOD__, __FILE__, __LINE__);
 339                  }
 340              }
 341          } else {
 342              $this->xpdo->log(xPDO::LOG_LEVEL_ERROR, "Could not get writable connection", '', __METHOD__, __FILE__, __LINE__);
 343          }
 344          return $result;
 345      }
 346  
 347      public function removeIndex($class, $name, array $options = array()) {
 348          $result = false;
 349          if ($this->xpdo->getConnection(array(xPDO::OPT_CONN_MUTABLE => true))) {
 350              $className = $this->xpdo->loadClass($class);
 351              if ($className) {
 352                  $indexType = (isset($options['type']) && in_array($options['type'], array('PRIMARY KEY', 'UNIQUE', 'INDEX', 'FULLTEXT')) ? $options['type'] : 'INDEX');
 353                  switch ($indexType) {
 354                      case 'PRIMARY KEY':
 355                      case 'UNIQUE':
 356                          $sql = "ALTER TABLE {$this->xpdo->getTableName($className)} DROP CONSTRAINT {$this->xpdo->escape($name)}";
 357                          break;
 358                      default:
 359                          $sql = "DROP INDEX {$this->xpdo->escape($name)} ON {$this->xpdo->getTableName($className)}";
 360                          break;
 361                  }
 362                  $result = $this->xpdo->exec($sql);
 363                  if ($result !== false || (!$result && $this->xpdo->errorCode() === '00000')) {
 364                      $result = true;
 365                  } else {
 366                      $this->xpdo->log(xPDO::LOG_LEVEL_ERROR, "Error removing index {$name} from {$class}: " . print_r($this->xpdo->errorInfo(), true), '', __METHOD__, __FILE__, __LINE__);
 367                  }
 368              }
 369          } else {
 370              $this->xpdo->log(xPDO::LOG_LEVEL_ERROR, "Could not get writable connection", '', __METHOD__, __FILE__, __LINE__);
 371          }
 372          return $result;
 373      }
 374  
 375      protected function getColumnDef($class, $name, $meta, array $options = array()) {
 376          $pk= $this->xpdo->getPK($class);
 377          $pktype= $this->xpdo->getPKType($class);
 378          $dbtype= strtoupper($meta['dbtype']);
 379          $precision= (isset ($meta['precision']) && !preg_match('/ENUM/i', $dbtype) && !in_array($this->xpdo->driver->getPHPType($dbtype), array('integer', 'bit', 'date', 'datetime', 'time'))) ? '(' . $meta['precision'] . ')' : '';
 380          if (preg_match('/ENUM/i', $dbtype)) {
 381              $maxlength = 255;
 382              if (isset($meta['precision'])) {
 383                  $pieces= explode(',', $meta['precision']);
 384                  if (!empty($pieces)) {
 385                      $length = 0;
 386                      $maxlength = 0;
 387                      foreach ($pieces as $piece) {
 388                          $length = strlen($piece);
 389                          if ($length > $maxlength) $maxlength = $length;
 390                      }
 391                      if ($maxlength < 1) $maxlength = 255;
 392                  }
 393              }
 394              $dbtype= 'VARCHAR';
 395              $precision= "({$maxlength})";
 396          }
 397          $notNull= !isset ($meta['null']) ? false : ($meta['null'] === 'false' || empty($meta['null']));
 398          $null= $notNull ? ' NOT NULL' : ' NULL';
 399          $extra = '';
 400          if (isset ($meta['index']) && $meta['index'] == 'pk' && !is_array($pk) && $pktype == 'integer' && isset ($meta['generated']) && $meta['generated'] == 'native') {
 401              $extra= ' IDENTITY PRIMARY KEY';
 402              $null= '';
 403          }
 404          if (empty ($extra) && isset ($meta['extra'])) {
 405              $extra= ' ' . $meta['extra'];
 406          }
 407          $default= '';
 408          if (array_key_exists('default', $meta)) {
 409              $defaultVal= $meta['default'];
 410              if ($defaultVal === null || strtoupper($defaultVal) === 'NULL' || in_array($this->xpdo->driver->getPHPType($dbtype), array('integer', 'float', 'bit')) || (in_array($this->xpdo->driver->getPHPType($dbtype), array('datetime', 'date', 'timestamp', 'time')) && in_array($defaultVal, array_merge($this->xpdo->driver->_currentTimestamps, $this->xpdo->driver->_currentDates, $this->xpdo->driver->_currentTimes)))) {
 411                  $default= ' DEFAULT ' . $defaultVal;
 412              } else {
 413                  $default= ' DEFAULT \'' . $defaultVal . '\'';
 414              }
 415          }
 416          $attributes= (isset ($meta['attributes'])) ? ' ' . $meta['attributes'] : '';
 417          if (strpos(strtolower($attributes), 'unsigned') !== false) {
 418              $result = $this->xpdo->escape($name) . ' ' . $dbtype . $precision . $attributes . $null . $default . $extra;
 419          } else {
 420              $result = $this->xpdo->escape($name) . ' ' . $dbtype . $precision . $null . $default . $attributes . $extra;
 421          }
 422          return $result;
 423      }
 424  
 425      protected function getIndexDef($class, $name, $meta, array $options = array()) {
 426          $result = '';
 427          $index = isset($meta['columns']) ? $meta['columns'] : null;
 428          if (is_array($index)) {
 429              $indexset= array ();
 430              foreach ($index as $indexmember => $indexmemberdetails) {
 431                  $indexMemberDetails = $this->xpdo->escape($indexmember);
 432                  $indexset[]= $indexMemberDetails;
 433              }
 434              $result= implode(',', $indexset);
 435          }
 436          return $result;
 437      }
 438  
 439      private function getDefaultConstraints($class, $name, array $options = array()) {
 440          $constraints = array();
 441          $table = $this->xpdo->getTableName($class);
 442          $sql = "SELECT name FROM sys.default_constraints WHERE parent_object_id = object_id(?) AND type = 'D' AND parent_column_id = (SELECT column_id FROM sys.columns WHERE object_id = object_id(?) AND name = ?)";
 443          $stmt = $this->xpdo->prepare($sql);
 444          $tstart = microtime(true);
 445          if ($stmt && $stmt->execute(array($table, $table, $name))) {
 446              $this->xpdo->queryTime += microtime(true) - $tstart;
 447              $this->xpdo->executedQueries++;
 448              $constraints = $stmt->fetchAll(PDO::FETCH_COLUMN);
 449          } elseif ($stmt) {
 450              $this->xpdo->queryTime += microtime(true) - $tstart;
 451              $this->xpdo->executedQueries++;
 452          }
 453          return $constraints;
 454      }
 455  }

title

Description

title

Description

title

Description

title

title

Body