From 849d686a16d86160075be714955fa879ace2db62 Mon Sep 17 00:00:00 2001 From: Matt Emerick-Law Date: Mon, 17 Jan 2022 17:49:47 +0000 Subject: [PATCH] Formatting update to spaces --- .../SQLAnywhere/SQLAnywhereConnection.php | 264 +++--- .../SQLAnywhere/SQLAnywhereConnector.php | 63 +- .../SQLAnywhere/SQLAnywhereQueryGrammar.php | 236 ++--- .../SQLAnywhere/SQLAnywhereSchemaGrammar.php | 817 +++++++++--------- .../SQLAnywhereServiceProvider.php | 90 +- 5 files changed, 737 insertions(+), 733 deletions(-) diff --git a/src/emericklaw/SQLAnywhere/SQLAnywhereConnection.php b/src/emericklaw/SQLAnywhere/SQLAnywhereConnection.php index 538391137..7677fe2a4 100644 --- a/src/emericklaw/SQLAnywhere/SQLAnywhereConnection.php +++ b/src/emericklaw/SQLAnywhere/SQLAnywhereConnection.php @@ -1,139 +1,139 @@ -pdo = $pdo; - - // First we will setup the default properties. We keep track of the DB - // name we are connected to since it is needed when some reflective - // type commands are run such as checking whether a table exists. - $this->database = $database; - - $this->tablePrefix = $tablePrefix; - - $this->config = $config; - - // We need to initialize a query grammar and the query post processors - // which are both very important parts of the database abstractions - // so we initialize these to their default values while starting. - $this->useDefaultQueryGrammar(); - - $this->useDefaultPostProcessor(); - } - - /** - * Run a select statement against the database. - * - * @param string $query - * @param array $bindings - * @return array - */ - public function select($query, $bindings = array(), $useReadPdo = true) - { - // new version since Laravel 5.4 - // /vendor/laravel/framework/src/Illuminate/Database/Connection.php - // --> function: select(...) - return $this->run($query, $bindings, function($query, $bindings) - { - if ($this->pretending()) return array(); - - // For select statements, we'll simply execute the query and return an array - // of the database result set. Each element in the array will be a single - // row from the database table, and will either be an array or objects. - $statement = $this->getReadPdo()->prepare($query); - - $statement->execute($this->prepareBindings($bindings)); - - return $statement->fetchAll(); - }); - } - - /** - * Run a select statement against the database and returns a generator. - * - * @param string $query - * @param array $bindings - * @param bool $useReadPdo - * @return \Generator - */ - public function cursor($query, $bindings = [], $useReadPdo = true) - { - $statement = $this->run($query, $bindings, function ($query, $bindings) use ($useReadPdo) { - if ($this->pretending()) { - return []; - } - - // First we will create a statement for the query. Then, we will set the fetch - // mode and prepare the bindings for the query. Once that's done we will be - // ready to execute the query against the database and return the cursor. - $statement = $this->getReadPdo()->prepare($query); - - $statement->execute($this->prepareBindings($bindings)); - - return $statement; - }); - - while ($record = $statement->fetch()) { - yield $record; - } - } - - /** - * Run an SQL statement and get the number of rows affected. - * - * @param string $query - * @param array $bindings - * @return int - */ - public function affectingStatement($query, $bindings = array()) - { - return $this->run($query, $bindings, function($query, $bindings) - { - if ($this->pretending()) return 0; - - // For update or delete statements, we want to get the number of rows affected - // by the statement and return that back to the developer. We'll first need - // to execute the statement and then we'll use PDO to fetch the affected. - $statement = $this->getPdo()->prepare($query); - - $statement->execute($this->prepareBindings($bindings)); - - return $statement->affectedRows(); - }); - } - - /** - * Get the default query grammar instance. - * - * @return Illuminate\Database\Query\Grammars\Grammars\Grammar - */ - protected function getDefaultQueryGrammar() - { +class SQLAnywhereConnection extends Connection +{ + + /** + * Create a new database connection instance. + * + * @param PDO $pdo + * @param string $database + * @param string $tablePrefix + * @param array $config + * @return void + */ + public function __construct(SQLAnywhereClient $pdo, $database = '', $tablePrefix = '', array $config = []) + { + $this->pdo = $pdo; + + // First we will setup the default properties. We keep track of the DB + // name we are connected to since it is needed when some reflective + // type commands are run such as checking whether a table exists. + $this->database = $database; + + $this->tablePrefix = $tablePrefix; + + $this->config = $config; + + // We need to initialize a query grammar and the query post processors + // which are both very important parts of the database abstractions + // so we initialize these to their default values while starting. + $this->useDefaultQueryGrammar(); + + $this->useDefaultPostProcessor(); + } + + /** + * Run a select statement against the database. + * + * @param string $query + * @param array $bindings + * @return array + */ + public function select($query, $bindings = [], $useReadPdo = true) + { + // new version since Laravel 5.4 + // /vendor/laravel/framework/src/Illuminate/Database/Connection.php + // --> function: select(...) + return $this->run($query, $bindings, function ($query, $bindings) { + if ($this->pretending()) return []; + + // For select statements, we'll simply execute the query and return an array + // of the database result set. Each element in the array will be a single + // row from the database table, and will either be an array or objects. + $statement = $this->getReadPdo()->prepare($query); + + $statement->execute($this->prepareBindings($bindings)); + + return $statement->fetchAll(); + }); + } + + /** + * Run a select statement against the database and returns a generator. + * + * @param string $query + * @param array $bindings + * @param bool $useReadPdo + * @return \Generator + */ + public function cursor($query, $bindings = [], $useReadPdo = true) + { + $statement = $this->run($query, $bindings, function ($query, $bindings) use ($useReadPdo) { + if ($this->pretending()) { + return []; + } + + // First we will create a statement for the query. Then, we will set the fetch + // mode and prepare the bindings for the query. Once that's done we will be + // ready to execute the query against the database and return the cursor. + $statement = $this->getReadPdo()->prepare($query); + + $statement->execute($this->prepareBindings($bindings)); + + return $statement; + }); + + while ($record = $statement->fetch()) { + yield $record; + } + } + + /** + * Run an SQL statement and get the number of rows affected. + * + * @param string $query + * @param array $bindings + * @return int + */ + public function affectingStatement($query, $bindings = []) + { + return $this->run($query, $bindings, function ($query, $bindings) { + if ($this->pretending()) return 0; + + // For update or delete statements, we want to get the number of rows affected + // by the statement and return that back to the developer. We'll first need + // to execute the statement and then we'll use PDO to fetch the affected. + $statement = $this->getPdo()->prepare($query); + + $statement->execute($this->prepareBindings($bindings)); + + return $statement->affectedRows(); + }); + } + + /** + * Get the default query grammar instance. + * + * @return Illuminate\Database\Query\Grammars\Grammars\Grammar + */ + protected function getDefaultQueryGrammar() + { return $this->withTablePrefix(new SQLAnywhereQueryGrammar); - } - - /** - * Get the default schema grammar instance. - * - * @return Illuminate\Database\Schema\Grammars\Grammar - */ - protected function getDefaultSchemaGrammar() - { + } + + /** + * Get the default schema grammar instance. + * + * @return Illuminate\Database\Schema\Grammars\Grammar + */ + protected function getDefaultSchemaGrammar() + { return $this->withTablePrefix(new SQLAnywhereSchemaGrammar); - } - + } } diff --git a/src/emericklaw/SQLAnywhere/SQLAnywhereConnector.php b/src/emericklaw/SQLAnywhere/SQLAnywhereConnector.php index 5a2fdedc5..c277253d3 100644 --- a/src/emericklaw/SQLAnywhere/SQLAnywhereConnector.php +++ b/src/emericklaw/SQLAnywhere/SQLAnywhereConnector.php @@ -1,46 +1,49 @@ -createConnection(array(), $config, array()); - } + /** + * Establish a database connection. + * + * @param array $options + * @return PDO + */ + public function connect(array $config) + { + return $this->createConnection([], $config, []); + } - /** - * Create a new PDO connection. - * - * @param array $config - * @param array $options - * @return SQLAnywhere - */ - public function createConnection($dsn, array $config, array $options) - { - $autocommit = Arr::get($config, 'autocommit'); - $persintent = Arr::get($config, 'persintent'); + /** + * Create a new PDO connection. + * + * @param array $config + * @param array $options + * @return SQLAnywhere + */ + public function createConnection($dsn, array $config, array $options) + { + $autocommit = Arr::get($config, 'autocommit'); + $persintent = Arr::get($config, 'persintent'); - return new SQLAnywhereClient($this->getDsn($config), $autocommit, $persintent); - } + return new SQLAnywhereClient($this->getDsn($config), $autocommit, $persintent); + } - /** + /** * Create a DSN string from a configuration. * * @param array $config * @return string */ - protected function getDsn(array $config) + protected function getDsn(array $config) { // First we will create the basic DSN setup as well as the port if it is in // in the configuration options. This will give us the basic DSN we will @@ -53,12 +56,12 @@ protected function getDsn(array $config) // Sample: UID=test;PWD=test;ENG=dbserv;DBN=dbname;COMMLINKS=TCPIP{HOST=192.168.100.100:2638} $dsn = "uid={$username};pwd={$password};dbn={$database};commlinks=tcpip{host={$host}:{$port}}"; if (isset($charset)) { - $dsn.= ";charset={$charset}"; + $dsn .= ";charset={$charset}"; } if (isset($dbserver)) { - $dsn.= ";ENG={$dbserver}"; + $dsn .= ";ENG={$dbserver}"; } - return $dsn; + return $dsn; } } diff --git a/src/emericklaw/SQLAnywhere/SQLAnywhereQueryGrammar.php b/src/emericklaw/SQLAnywhere/SQLAnywhereQueryGrammar.php index b1af03332..c6e8ea4a8 100644 --- a/src/emericklaw/SQLAnywhere/SQLAnywhereQueryGrammar.php +++ b/src/emericklaw/SQLAnywhere/SQLAnywhereQueryGrammar.php @@ -1,122 +1,124 @@ -columns)) $query->columns = array('*'); - - return 'select ' . trim($this->concatenate($this->compileComponents($query))); - } - - /** - * Compile an aggregated select clause. - * - * @param \Illuminate\Database\Query\Builder $query - * @param array $aggregate - * @return string - */ - protected function compileAggregate(Builder $query, $aggregate) - { - $column = $this->columnize($aggregate['columns']); - - // If the query has a "distinct" constraint and we're not asking for all columns - // we need to prepend "distinct" onto the column name so that the query takes - // it into account when it performs the aggregating operations on the data. - if ($query->distinct && $column !== '*') - { - $column = 'distinct '.$column; - } - - return $aggregate['function'].'('.$column.') as aggregate'; - } - - /** - * Compile the "select *" portion of the query. - * - * @param \Illuminate\Database\Query\Builder $query - * @param array $columns - * @return string - */ - protected function compileColumns(Builder $query, $columns) - { - // If the query is actually performing an aggregating select, we will let that - // compiler handle the building of the select clauses, as it will need some - // more syntax that is best handled by that function to keep things neat. - if ( ! is_null($query->aggregate)) return; - - $select = $query->distinct ? 'distinct' : ''; - - return $select.$this->columnize($columns); - } - - - /** - * Compile the "limit" portions of the query. - * - * @param \Illuminate\Database\Query\Builder $query - * @param int $limit - * @return string - */ - protected function compileLimit(Builder $query, $limit) - { - return 'top '.(int) $limit; - } - - /** - * Compile the "offset" portions of the query. - * - * @param \Illuminate\Database\Query\Builder $query - * @param int $offset - * @return string - */ - protected function compileOffset(Builder $query, $offset) - { - return 'start at '.((int) $offset+1); - } - - /** - * Compile the "random" portions of the query. - * - * @param \Illuminate\Database\Query\Builder $query - * @param int $seed - * @return string - */ - public function compileRandom($seed) - { - if (is_int($seed)) { - return 'rand('.((int) $seed).')'; - } else { - return 'rand()'; - } - } +class SQLAnywhereQueryGrammar extends Grammar +{ + + /** + * The components that make up a select clause. + * + * @var array + */ + protected $selectComponents = [ + 'limit', + 'offset', + 'aggregate', + 'columns', + 'from', + 'joins', + 'wheres', + 'groups', + 'havings', + 'orders', + 'unions', + 'lock', + ]; + + /** + * Compile a select query into SQL. + * + * @param \Illuminate\Database\Query\Builder + * @return string + */ + public function compileSelect(Builder $query) + { + if (is_null($query->columns)) $query->columns = ['*']; + + return 'select ' . trim($this->concatenate($this->compileComponents($query))); + } + + /** + * Compile an aggregated select clause. + * + * @param \Illuminate\Database\Query\Builder $query + * @param array $aggregate + * @return string + */ + protected function compileAggregate(Builder $query, $aggregate) + { + $column = $this->columnize($aggregate['columns']); + + // If the query has a "distinct" constraint and we're not asking for all columns + // we need to prepend "distinct" onto the column name so that the query takes + // it into account when it performs the aggregating operations on the data. + if ($query->distinct && $column !== '*') { + $column = 'distinct ' . $column; + } + + return $aggregate['function'] . '(' . $column . ') as aggregate'; + } + + /** + * Compile the "select *" portion of the query. + * + * @param \Illuminate\Database\Query\Builder $query + * @param array $columns + * @return string + */ + protected function compileColumns(Builder $query, $columns) + { + // If the query is actually performing an aggregating select, we will let that + // compiler handle the building of the select clauses, as it will need some + // more syntax that is best handled by that function to keep things neat. + if (!is_null($query->aggregate)) return; + + $select = $query->distinct ? 'distinct' : ''; + + return $select . $this->columnize($columns); + } + + + /** + * Compile the "limit" portions of the query. + * + * @param \Illuminate\Database\Query\Builder $query + * @param int $limit + * @return string + */ + protected function compileLimit(Builder $query, $limit) + { + return 'top ' . (int) $limit; + } + + /** + * Compile the "offset" portions of the query. + * + * @param \Illuminate\Database\Query\Builder $query + * @param int $offset + * @return string + */ + protected function compileOffset(Builder $query, $offset) + { + return 'start at ' . ((int) $offset + 1); + } + + /** + * Compile the "random" portions of the query. + * + * @param \Illuminate\Database\Query\Builder $query + * @param int $seed + * @return string + */ + public function compileRandom($seed) + { + if (is_int($seed)) { + return 'rand(' . ((int) $seed) . ')'; + } else { + return 'rand()'; + } + } } diff --git a/src/emericklaw/SQLAnywhere/SQLAnywhereSchemaGrammar.php b/src/emericklaw/SQLAnywhere/SQLAnywhereSchemaGrammar.php index 74497bd80..64b126056 100644 --- a/src/emericklaw/SQLAnywhere/SQLAnywhereSchemaGrammar.php +++ b/src/emericklaw/SQLAnywhere/SQLAnywhereSchemaGrammar.php @@ -1,415 +1,414 @@ -getColumns($blueprint)); - - return 'CREATE TABLE '.$this->wrapTable($blueprint)." ($columns)"; - } - - /** - * Compile a create table command. - * - * @param Illuminate\Database\Schema\Blueprint $blueprint - * @param Illuminate\Support\Fluent $command - * @return string - */ - public function compileAdd(Blueprint $blueprint, Fluent $command) - { - $table = $this->wrapTable($blueprint); - - $columns = $this->prefixArray('add', $this->getColumns($blueprint)); - - return 'ALTER TABLE '.$table.' '.implode(', ', $columns); - } - - /** - * Compile a primary key command. - * - * @param Illuminate\Database\Schema\Blueprint $blueprint - * @param Illuminate\Support\Fluent $command - * @return string - */ - public function compilePrimary(Blueprint $blueprint, Fluent $command) - { - $command->name(null); - - return $this->compileKey($blueprint, $command, 'primary key'); - } - - /** - * Compile a unique key command. - * - * @param Illuminate\Database\Schema\Blueprint $blueprint - * @param Illuminate\Support\Fluent $command - * @return string - */ - public function compileUnique(Blueprint $blueprint, Fluent $command) - { - return $this->compileKey($blueprint, $command, 'unique'); - } - - /** - * Compile a plain index key command. - * - * @param Illuminate\Database\Schema\Blueprint $blueprint - * @param Illuminate\Support\Fluent $command - * @return string - */ - public function compileIndex(Blueprint $blueprint, Fluent $command) - { - return $this->compileKey($blueprint, $command, 'index'); - } - - /** - * Compile an index creation command. - * - * @param Illuminate\Database\Schema\Blueprint $blueprint - * @param Illuminate\Support\Fluent $command - * @param string $type - * @return string - */ - protected function compileKey(Blueprint $blueprint, Fluent $command, $type) - { - $columns = $this->columnize($command->columns); - - $table = $this->wrapTable($blueprint); - - return "ALTER TABLE {$table} ADD {$type} {$command->index}($columns)"; - } - - /** - * Compile a drop table command. - * - * @param Illuminate\Database\Schema\Blueprint $blueprint - * @param Illuminate\Support\Fluent $command - * @return string - */ - public function compileDrop(Blueprint $blueprint, Fluent $command) - { - return 'DROP TABLE '.$this->wrapTable($blueprint); - } - - /** - * Compile a drop table (if exists) command. - * - * @param Illuminate\Database\Schema\Blueprint $blueprint - * @param Illuminate\Support\Fluent $command - * @return string - */ - public function compileDropIfExists(Blueprint $blueprint, Fluent $command) - { - return 'DROP TABLE IF EXISTS '.$this->wrapTable($blueprint); - } - - /** - * Compile a drop column command. - * - * @param Illuminate\Database\Schema\Blueprint $blueprint - * @param Illuminate\Support\Fluent $command - * @return string - */ - public function compileDropColumn(Blueprint $blueprint, Fluent $command) - { - $columns = $this->prefixArray('drop', $this->wrapArray($command->columns)); - - $table = $this->wrapTable($blueprint); - - return 'ALTER TABLE '.$table.' '.implode(', ', $columns); - } - - /** - * Compile a drop primary key command. - * - * @param Illuminate\Database\Schema\Blueprint $blueprint - * @param Illuminate\Support\Fluent $command - * @return string - */ - public function compileDropPrimary(Blueprint $blueprint, Fluent $command) - { - return 'ALTER TABLE '.$this->wrapTable($blueprint).' drop primary key'; - } - - /** - * Compile a drop unique key command. - * - * @param Illuminate\Database\Schema\Blueprint $blueprint - * @param Illuminate\Support\Fluent $command - * @return string - */ - public function compileDropUnique(Blueprint $blueprint, Fluent $command) - { - $table = $this->wrapTable($blueprint); - - return "alter table {$table} drop index {$command->index}"; - } - - /** - * Compile a drop index command. - * - * @param Illuminate\Database\Schema\Blueprint $blueprint - * @param Illuminate\Support\Fluent $command - * @return string - */ - public function compileDropIndex(Blueprint $blueprint, Fluent $command) - { - $table = $this->wrapTable($blueprint); - - return "alter table {$table} drop index {$command->index}"; - } - - /** - * Compile a drop foreign key command. - * - * @param Illuminate\Database\Schema\Blueprint $blueprint - * @param Illuminate\Support\Fluent $command - * @return string - */ - public function compileDropForeign(Blueprint $blueprint, Fluent $command) - { - $table = $this->wrapTable($blueprint); - - return "alter table {$table} drop foreign key {$command->index}"; - } - - /** - * Compile a rename table command. - * - * @param Illuminate\Database\Schema\Blueprint $blueprint - * @param Illuminate\Support\Fluent $command - * @return string - */ - public function compileRename(Blueprint $blueprint, Fluent $command) - { - $from = $this->wrapTable($blueprint); - - return "RENAME TABLE {$from} to ".$this->wrapTable($command->to); - } - - /** - * Create the column definition for a string type. - * - * @param Illuminate\Support\Fluent $column - * @return string - */ - protected function typeString(Fluent $column) - { - return "varchar({$column->length})"; - } - - /** - * Create the column definition for a text type. - * - * @param Illuminate\Support\Fluent $column - * @return string - */ - protected function typeText(Fluent $column) - { - return 'text'; - } - - /** - * Create the column definition for a integer type. - * - * @param Illuminate\Support\Fluent $column - * @return string - */ - protected function typeInteger(Fluent $column) - { - return 'int'; - } - - /** - * Create the column definition for a float type. - * - * @param Illuminate\Support\Fluent $column - * @return string - */ - protected function typeFloat(Fluent $column) - { - return "float({$column->total}, {$column->places})"; - } - - /** - * Create the column definition for a decimal type. - * - * @param Illuminate\Support\Fluent $column - * @return string - */ - protected function typeDecimal(Fluent $column) - { - return "decimal({$column->total}, {$column->places})"; - } - - /** - * Create the column definition for a boolean type. - * - * @param Illuminate\Support\Fluent $column - * @return string - */ - protected function typeBoolean(Fluent $column) - { - return 'tinyint'; - } - - /** - * Create the column definition for a enum type. - * - * @param Illuminate\Support\Fluent $column - * @return string - */ - protected function typeEnum(Fluent $column) - { - return "enum('".implode("', '", $column->allowed)."')"; - } - - /** - * Create the column definition for a date type. - * - * @param Illuminate\Support\Fluent $column - * @return string - */ - protected function typeDate(Fluent $column) - { - return 'date'; - } - - /** - * Create the column definition for a date-time type. - * - * @param Illuminate\Support\Fluent $column - * @return string - */ - protected function typeDateTime(Fluent $column) - { - return 'datetime'; - } - - /** - * Create the column definition for a time type. - * - * @param Illuminate\Support\Fluent $column - * @return string - */ - protected function typeTime(Fluent $column) - { - return 'time'; - } - - /** - * Create the column definition for a timestamp type. - * - * @param Illuminate\Support\Fluent $column - * @return string - */ - protected function typeTimestamp(Fluent $column) - { - return 'timestamp default 0'; - } - - /** - * Create the column definition for a binary type. - * - * @param Illuminate\Support\Fluent $column - * @return string - */ - protected function typeBinary(Fluent $column) - { - return 'blob'; - } - - /** - * Get the SQL for an unsigned column modifier. - * - * @param Illuminate\Database\Schema\Blueprint $blueprint - * @param Illuminate\Support\Fluent $column - * @return string|null - */ - protected function modifyUnsigned(Blueprint $blueprint, Fluent $column) - { - if ($column->type == 'integer' and $column->unsigned) - { - return ' unsigned'; - } - } - - /** - * Get the SQL for a nullable column modifier. - * - * @param Illuminate\Database\Schema\Blueprint $blueprint - * @param Illuminate\Support\Fluent $column - * @return string|null - */ - protected function modifyNullable(Blueprint $blueprint, Fluent $column) - { - return $column->nullable ? ' null' : ' not null'; - } - - /** - * Get the SQL for a default column modifier. - * - * @param Illuminate\Database\Schema\Blueprint $blueprint - * @param Illuminate\Support\Fluent $column - * @return string|null - */ - protected function modifyDefault(Blueprint $blueprint, Fluent $column) - { - if ( ! is_null($column->default)) - { - return " default '".$this->getDefaultValue($column->default)."'"; - } - } - - /** - * Get the SQL for an auto-increment column modifier. - * - * @param Illuminate\Database\Schema\Blueprint $blueprint - * @param Illuminate\Support\Fluent $column - * @return string|null - */ - protected function modifyIncrement(Blueprint $blueprint, Fluent $column) - { - if ($column->type == 'integer' and $column->autoIncrement) - { - return ' auto_increment primary key'; - } - } - +class SQLAnywhereSchemaGrammar extends Grammar +{ + + /** + * The keyword identifier wrapper format. + * + * @var string + */ + protected $wrapper = '%s'; + + /** + * The possible column modifiers. + * + * @var array + */ + protected $modifiers = ['Unsigned', 'Nullable', 'Default', 'Increment']; + + /** + * Compile the query to determine if a table exists. + * + * @return string + */ + public function compileTableExists() + { + return 'SELECT * FROM sys.systab WHERE table_type_str = ?'; + } + + /** + * Compile a create table command. + * + * @param Illuminate\Database\Schema\Blueprint $blueprint + * @param Illuminate\Support\Fluent $command + * @return string + */ + public function compileCreate(Blueprint $blueprint, Fluent $command) + { + $columns = implode(', ', $this->getColumns($blueprint)); + + return 'CREATE TABLE ' . $this->wrapTable($blueprint) . " ($columns)"; + } + + /** + * Compile a create table command. + * + * @param Illuminate\Database\Schema\Blueprint $blueprint + * @param Illuminate\Support\Fluent $command + * @return string + */ + public function compileAdd(Blueprint $blueprint, Fluent $command) + { + $table = $this->wrapTable($blueprint); + + $columns = $this->prefixArray('add', $this->getColumns($blueprint)); + + return 'ALTER TABLE ' . $table . ' ' . implode(', ', $columns); + } + + /** + * Compile a primary key command. + * + * @param Illuminate\Database\Schema\Blueprint $blueprint + * @param Illuminate\Support\Fluent $command + * @return string + */ + public function compilePrimary(Blueprint $blueprint, Fluent $command) + { + $command->name(null); + + return $this->compileKey($blueprint, $command, 'primary key'); + } + + /** + * Compile a unique key command. + * + * @param Illuminate\Database\Schema\Blueprint $blueprint + * @param Illuminate\Support\Fluent $command + * @return string + */ + public function compileUnique(Blueprint $blueprint, Fluent $command) + { + return $this->compileKey($blueprint, $command, 'unique'); + } + + /** + * Compile a plain index key command. + * + * @param Illuminate\Database\Schema\Blueprint $blueprint + * @param Illuminate\Support\Fluent $command + * @return string + */ + public function compileIndex(Blueprint $blueprint, Fluent $command) + { + return $this->compileKey($blueprint, $command, 'index'); + } + + /** + * Compile an index creation command. + * + * @param Illuminate\Database\Schema\Blueprint $blueprint + * @param Illuminate\Support\Fluent $command + * @param string $type + * @return string + */ + protected function compileKey(Blueprint $blueprint, Fluent $command, $type) + { + $columns = $this->columnize($command->columns); + + $table = $this->wrapTable($blueprint); + + return "ALTER TABLE {$table} ADD {$type} {$command->index}($columns)"; + } + + /** + * Compile a drop table command. + * + * @param Illuminate\Database\Schema\Blueprint $blueprint + * @param Illuminate\Support\Fluent $command + * @return string + */ + public function compileDrop(Blueprint $blueprint, Fluent $command) + { + return 'DROP TABLE ' . $this->wrapTable($blueprint); + } + + /** + * Compile a drop table (if exists) command. + * + * @param Illuminate\Database\Schema\Blueprint $blueprint + * @param Illuminate\Support\Fluent $command + * @return string + */ + public function compileDropIfExists(Blueprint $blueprint, Fluent $command) + { + return 'DROP TABLE IF EXISTS ' . $this->wrapTable($blueprint); + } + + /** + * Compile a drop column command. + * + * @param Illuminate\Database\Schema\Blueprint $blueprint + * @param Illuminate\Support\Fluent $command + * @return string + */ + public function compileDropColumn(Blueprint $blueprint, Fluent $command) + { + $columns = $this->prefixArray('drop', $this->wrapArray($command->columns)); + + $table = $this->wrapTable($blueprint); + + return 'ALTER TABLE ' . $table . ' ' . implode(', ', $columns); + } + + /** + * Compile a drop primary key command. + * + * @param Illuminate\Database\Schema\Blueprint $blueprint + * @param Illuminate\Support\Fluent $command + * @return string + */ + public function compileDropPrimary(Blueprint $blueprint, Fluent $command) + { + return 'ALTER TABLE ' . $this->wrapTable($blueprint) . ' drop primary key'; + } + + /** + * Compile a drop unique key command. + * + * @param Illuminate\Database\Schema\Blueprint $blueprint + * @param Illuminate\Support\Fluent $command + * @return string + */ + public function compileDropUnique(Blueprint $blueprint, Fluent $command) + { + $table = $this->wrapTable($blueprint); + + return "alter table {$table} drop index {$command->index}"; + } + + /** + * Compile a drop index command. + * + * @param Illuminate\Database\Schema\Blueprint $blueprint + * @param Illuminate\Support\Fluent $command + * @return string + */ + public function compileDropIndex(Blueprint $blueprint, Fluent $command) + { + $table = $this->wrapTable($blueprint); + + return "alter table {$table} drop index {$command->index}"; + } + + /** + * Compile a drop foreign key command. + * + * @param Illuminate\Database\Schema\Blueprint $blueprint + * @param Illuminate\Support\Fluent $command + * @return string + */ + public function compileDropForeign(Blueprint $blueprint, Fluent $command) + { + $table = $this->wrapTable($blueprint); + + return "alter table {$table} drop foreign key {$command->index}"; + } + + /** + * Compile a rename table command. + * + * @param Illuminate\Database\Schema\Blueprint $blueprint + * @param Illuminate\Support\Fluent $command + * @return string + */ + public function compileRename(Blueprint $blueprint, Fluent $command) + { + $from = $this->wrapTable($blueprint); + + return "RENAME TABLE {$from} to " . $this->wrapTable($command->to); + } + + /** + * Create the column definition for a string type. + * + * @param Illuminate\Support\Fluent $column + * @return string + */ + protected function typeString(Fluent $column) + { + return "varchar({$column->length})"; + } + + /** + * Create the column definition for a text type. + * + * @param Illuminate\Support\Fluent $column + * @return string + */ + protected function typeText(Fluent $column) + { + return 'text'; + } + + /** + * Create the column definition for a integer type. + * + * @param Illuminate\Support\Fluent $column + * @return string + */ + protected function typeInteger(Fluent $column) + { + return 'int'; + } + + /** + * Create the column definition for a float type. + * + * @param Illuminate\Support\Fluent $column + * @return string + */ + protected function typeFloat(Fluent $column) + { + return "float({$column->total}, {$column->places})"; + } + + /** + * Create the column definition for a decimal type. + * + * @param Illuminate\Support\Fluent $column + * @return string + */ + protected function typeDecimal(Fluent $column) + { + return "decimal({$column->total}, {$column->places})"; + } + + /** + * Create the column definition for a boolean type. + * + * @param Illuminate\Support\Fluent $column + * @return string + */ + protected function typeBoolean(Fluent $column) + { + return 'tinyint'; + } + + /** + * Create the column definition for a enum type. + * + * @param Illuminate\Support\Fluent $column + * @return string + */ + protected function typeEnum(Fluent $column) + { + return "enum('" . implode("', '", $column->allowed) . "')"; + } + + /** + * Create the column definition for a date type. + * + * @param Illuminate\Support\Fluent $column + * @return string + */ + protected function typeDate(Fluent $column) + { + return 'date'; + } + + /** + * Create the column definition for a date-time type. + * + * @param Illuminate\Support\Fluent $column + * @return string + */ + protected function typeDateTime(Fluent $column) + { + return 'datetime'; + } + + /** + * Create the column definition for a time type. + * + * @param Illuminate\Support\Fluent $column + * @return string + */ + protected function typeTime(Fluent $column) + { + return 'time'; + } + + /** + * Create the column definition for a timestamp type. + * + * @param Illuminate\Support\Fluent $column + * @return string + */ + protected function typeTimestamp(Fluent $column) + { + return 'timestamp default 0'; + } + + /** + * Create the column definition for a binary type. + * + * @param Illuminate\Support\Fluent $column + * @return string + */ + protected function typeBinary(Fluent $column) + { + return 'blob'; + } + + /** + * Get the SQL for an unsigned column modifier. + * + * @param Illuminate\Database\Schema\Blueprint $blueprint + * @param Illuminate\Support\Fluent $column + * @return string|null + */ + protected function modifyUnsigned(Blueprint $blueprint, Fluent $column) + { + if ($column->type == 'integer' and $column->unsigned) { + return ' unsigned'; + } + } + + /** + * Get the SQL for a nullable column modifier. + * + * @param Illuminate\Database\Schema\Blueprint $blueprint + * @param Illuminate\Support\Fluent $column + * @return string|null + */ + protected function modifyNullable(Blueprint $blueprint, Fluent $column) + { + return $column->nullable ? ' null' : ' not null'; + } + + /** + * Get the SQL for a default column modifier. + * + * @param Illuminate\Database\Schema\Blueprint $blueprint + * @param Illuminate\Support\Fluent $column + * @return string|null + */ + protected function modifyDefault(Blueprint $blueprint, Fluent $column) + { + if (!is_null($column->default)) { + return " default '" . $this->getDefaultValue($column->default) . "'"; + } + } + + /** + * Get the SQL for an auto-increment column modifier. + * + * @param Illuminate\Database\Schema\Blueprint $blueprint + * @param Illuminate\Support\Fluent $column + * @return string|null + */ + protected function modifyIncrement(Blueprint $blueprint, Fluent $column) + { + if ($column->type == 'integer' and $column->autoIncrement) { + return ' auto_increment primary key'; + } + } } diff --git a/src/emericklaw/SQLAnywhere/SQLAnywhereServiceProvider.php b/src/emericklaw/SQLAnywhere/SQLAnywhereServiceProvider.php index e2cc0037d..70a636298 100644 --- a/src/emericklaw/SQLAnywhere/SQLAnywhereServiceProvider.php +++ b/src/emericklaw/SQLAnywhere/SQLAnywhereServiceProvider.php @@ -1,56 +1,56 @@ -app['db']; - $factory->extend('sqlanywhere', function($config) { - if ( ! isset($config['prefix']) ) - { - $config['prefix'] = ''; - } + $factory->extend('sqlanywhere', function ($config) { + if (!isset($config['prefix'])) { + $config['prefix'] = ''; + } $connector = new SQLAnywhereConnector(); - $pdo = $connector->connect($config); + $pdo = $connector->connect($config); return new SQLAnywhereConnection($pdo, $config['database'], $config['prefix']); - - }); - } - - /** - * Register the service provider. - * - * @return void - */ - public function register() - { - // - } - - /** - * Get the services provided by the provider. - * - * @return array - */ - public function provides() - { - return array(); - } - + }); + } + + /** + * Register the service provider. + * + * @return void + */ + public function register() + { + // + } + + /** + * Get the services provided by the provider. + * + * @return array + */ + public function provides() + { + return []; + } }