mirror of
https://github.com/silverstripe/silverstripe-mssql
synced 2024-10-22 08:05:53 +02:00
API CHANGE: Allow use of temporary option in MSSQLDatabase::createTable()
This commit is contained in:
parent
b39b915a2f
commit
a7328a7316
@ -239,10 +239,23 @@ class MSSQLDatabase extends Database {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new table.
|
||||
* @param $tableName The name of the table
|
||||
* @param $fields A map of field names to field types
|
||||
* @param $indexes A map of indexes
|
||||
* @param $options An map of additional options. The available keys are as follows:
|
||||
* - 'MSSQLDatabase'/'MySQLDatabase'/'PostgreSQLDatabase' - database-specific options such as "engine" for MySQL.
|
||||
* - 'temporary' - If true, then a temporary table will be created
|
||||
* @return The table name generated. This may be different from the table name, for example with temporary tables.
|
||||
*/
|
||||
public function createTable($tableName, $fields = null, $indexes = null, $options = null) {
|
||||
$fieldSchemas = $indexSchemas = "";
|
||||
if($fields) foreach($fields as $k => $v) $fieldSchemas .= "\"$k\" $v,\n";
|
||||
|
||||
// Temporary tables start with "#" in MSSQL-land
|
||||
if(!empty($options['temporary'])) $tableName = "#$tableName";
|
||||
|
||||
$this->query("CREATE TABLE \"$tableName\" (
|
||||
$fieldSchemas
|
||||
primary key (\"ID\")
|
||||
@ -255,6 +268,8 @@ class MSSQLDatabase extends Database {
|
||||
}
|
||||
|
||||
if($indexSchemas) $this->query($indexSchemas);
|
||||
|
||||
return $tableName;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user