예제 #1
0
 /**
  * @param array $info
  *
  * @return string
  * @throws \Exception
  */
 protected function buildColumnDefinition(array $info)
 {
     // This works for most except Oracle
     $type = isset($info['type']) ? $info['type'] : null;
     $typeExtras = isset($info['type_extras']) ? $info['type_extras'] : null;
     $definition = $type . $typeExtras;
     $allowNull = isset($info['allow_null']) ? $info['allow_null'] : null;
     $definition .= $allowNull ? ' NULL' : ' NOT NULL';
     $default = isset($info['db_type']) ? $info['db_type'] : null;
     if (isset($default)) {
         if (is_array($default)) {
             $expression = isset($default['expression']) ? $default['expression'] : null;
             if (null !== $expression) {
                 $definition .= ' DEFAULT ' . $expression;
             }
         } else {
             $default = $this->connection->quoteValue($default);
             $definition .= ' DEFAULT ' . $default;
         }
     }
     $isUniqueKey = isset($info['is_unique']) ? filter_var($info['is_unique'], FILTER_VALIDATE_BOOLEAN) : false;
     $isPrimaryKey = isset($info['is_primary_key']) ? filter_var($info['is_primary_key'], FILTER_VALIDATE_BOOLEAN) : false;
     if ($isPrimaryKey && $isUniqueKey) {
         throw new \Exception('Unique and Primary designations not allowed simultaneously.');
     }
     if ($isUniqueKey) {
         $definition .= ' UNIQUE KEY';
     } elseif ($isPrimaryKey) {
         $definition .= ' PRIMARY KEY';
     }
     return $definition;
 }
예제 #2
0
 /**
  * Gets the TableSchema for this model.
  *
  * @return TableSchema
  */
 public function getTableSchema()
 {
     if (empty($this->adaptedConnection)) {
         $connection = $this->getConnection();
         $this->adaptedConnection = ConnectionAdapter::getLegacyConnection($connection);
         $this->cachePrefix = 'model_' . $this->getTable() . ':';
         $this->adaptedConnection->setCache($this);
     }
     return $this->adaptedConnection->getSchema()->getTable($this->table);
 }
예제 #3
0
 public static function checkRequirements($driver, $throw_exception = true)
 {
     if (!extension_loaded('mysql') && !extension_loaded('mysqlnd')) {
         if ($throw_exception) {
             throw new \Exception("Required extension or module 'mysql' is not installed or loaded.");
         } else {
             return false;
         }
     }
     return parent::checkRequirements('mysql', $throw_exception);
 }
예제 #4
0
 public function __construct($dsn = '', $username = '', $password = '')
 {
     $file = substr($dsn, 7);
     if (false === strpos($file, DIRECTORY_SEPARATOR)) {
         // no directories involved, store it where we want to store it
         $storage = config('df.db.sqlite_storage');
         if (!is_dir($storage)) {
             // Attempt
             @mkdir($storage);
         }
         if (!is_dir($storage)) {
             logger('Failed to access storage path ' . $storage);
             throw new InternalServerErrorException('Failed to access storage path.');
         }
         $dsn = 'sqlite:' . rtrim($storage, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . $file;
     }
     parent::__construct($dsn, $username, $password);
 }
예제 #5
0
 public function __construct($dsn = '', $username = '', $password = '')
 {
     if (null !== ($dumpLocation = config('df.db.freetds.dump'))) {
         if (!putenv("TDSDUMP={$dumpLocation}")) {
             \Log::alert('Could not write environment variable for TDSDUMP location.');
         }
     }
     if (null !== ($dumpConfLocation = config('df.db.freetds.dumpconfig'))) {
         if (!putenv("TDSDUMPCONFIG={$dumpConfLocation}")) {
             \Log::alert('Could not write environment variable for TDSDUMPCONFIG location.');
         }
     }
     if (null !== ($confLocation = config('df.db.freetds.sqlanywhere'))) {
         if (!putenv("FREETDSCONF={$confLocation}")) {
             \Log::alert('Could not write environment variable for FREETDSCONF location.');
         }
     }
     parent::__construct($dsn, $username, $password);
 }
예제 #6
0
 public function __construct($dsn = '', $username = '', $password = '')
 {
     if (substr(PHP_OS, 0, 3) == 'WIN') {
         // MS SQL Server on Windows
         $this->pdoClass = 'DreamFactory\\Core\\Database\\Mssql\\SqlsrvPdoAdapter';
     } else {
         if (null !== ($dumpLocation = config('df.db.freetds.dump'))) {
             if (!putenv("TDSDUMP={$dumpLocation}")) {
                 \Log::alert('Could not write environment variable for TDSDUMP location.');
             }
         }
         if (null !== ($dumpConfLocation = config('df.db.freetds.dumpconfig'))) {
             if (!putenv("TDSDUMPCONFIG={$dumpConfLocation}")) {
                 \Log::alert('Could not write environment variable for TDSDUMPCONFIG location.');
             }
         }
         if (null !== ($confLocation = config('df.db.freetds.sqlsrv'))) {
             if (!putenv("FREETDSCONF={$confLocation}")) {
                 \Log::alert('Could not write environment variable for FREETDSCONF location.');
             }
         }
     }
     parent::__construct($dsn, $username, $password);
 }
예제 #7
0
 public function refreshTableCache()
 {
     $this->dbConn->getSchema()->refresh();
 }