Moodle  2.2.1
http://www.collinsharper.com
mssql_sql_generator Class Reference
Inheritance diagram for mssql_sql_generator:
Collaboration diagram for mssql_sql_generator:

Public Member Functions

 getResetSequenceSQL ($table)
 getTableName (xmldb_table $xmldb_table, $quoted=true)
 getCreateTempTableSQL ($xmldb_table)
 getDropTempTableSQL ($xmldb_table)
 getTypeSQL ($xmldb_type, $xmldb_length=null, $xmldb_decimals=null)
 getDropFieldSQL ($xmldb_table, $xmldb_field)
 getRenameFieldSQL ($xmldb_table, $xmldb_field, $newname)
 getRenameTableExtraSQL ($xmldb_table, $newname)
 getAlterFieldSQL ($xmldb_table, $xmldb_field, $skip_type_clause=NULL, $skip_default_clause=NULL, $skip_notnull_clause=NULL)
 getModifyDefaultSQL ($xmldb_table, $xmldb_field)
 getDropEnumSQL ($xmldb_table, $xmldb_field)
 getCreateDefaultSQL ($xmldb_table, $xmldb_field)
 getDropDefaultSQL ($xmldb_table, $xmldb_field)
 getDefaultConstraintName ($xmldb_table, $xmldb_field)
 getCheckConstraintsFromDB ($xmldb_table, $xmldb_field=null)
 getNameForObject ($tablename, $fields, $suffix='')
 isNameInUse ($object_name, $type, $table_name)
 getCommentSQL ($xmldb_table)
 addslashes ($s)

Static Public Member Functions

static getReservedWords ()

Data Fields

 $statement_end = "\ngo"
 Only set values that are different from the defaults present in XMLDBgenerator.
 $number_type = 'DECIMAL'
 $unsigned_allowed = false
 $default_for_char = ''
 $specify_nulls = true
 $sequence_extra_code = false
 $sequence_name = 'IDENTITY(1,1)'
 $sequence_only = false
 $enum_inline_code = false
 $add_table_comments = false
 $concat_character = '+'
 $rename_table_sql = "sp_rename 'OLDNAME', 'NEWNAME'"
 $rename_column_sql = "sp_rename 'TABLENAME.OLDFIELDNAME', 'NEWFIELDNAME', 'COLUMN'"
 $drop_index_sql = 'DROP INDEX TABLENAME.INDEXNAME'
 TABLENAME, OLDFIELDNAME and NEWFIELDNAME are dyanmically replaced.
 $rename_index_sql = "sp_rename 'TABLENAME.OLDINDEXNAME', 'NEWINDEXNAME', 'INDEX'"
 $rename_key_sql = null

Detailed Description

This class generate SQL code to be used against MSSQL It extends XMLDBgenerator so everything can be overridden as needed to generate correct SQL.

Definition at line 37 of file mssql_sql_generator.php.


Member Function Documentation

addslashes ( s)

Reimplemented from sql_generator.

Definition at line 635 of file mssql_sql_generator.php.

getAlterFieldSQL ( xmldb_table,
xmldb_field,
skip_type_clause = NULL,
skip_default_clause = NULL,
skip_notnull_clause = NULL 
)

Given one xmldb_table and one xmldb_field, return the SQL statements needed to alter the field in the table

To store all the needed SQL commands

Get the quoted name of the table and field

Take a look to field metadata

Detect if we are changing the type of the column

If the new field (and old) specs are for integer, let's be a bit more specific differentiating types of integers. Else, some combinations can cause things like MDL-21868

Detect if we are changing the length of the column, not always necessary to drop defaults if only the length changes, but it's safe to do it always

If type or length have changed drop the default if exists

Some changes of type require multiple alter statements, because mssql lacks direct implicit cast between such types Here it is the matrix: http://msdn.microsoft.com/en-us/library/ms187928(SQL.90).aspx Going to store such intermediate alters in array of objects, storing all the info needed

Just prevent default clauses in this type of sentences for mssql and launch the parent one

Finally, process the default clause to add it back if necessary

Return results

Reimplemented from sql_generator.

Definition at line 285 of file mssql_sql_generator.php.

Here is the call graph for this function:

getCheckConstraintsFromDB ( xmldb_table,
xmldb_field = null 
)

Given one xmldb_table returns one array with all the check constraints in the table (fetched from DB) Optionally the function allows one xmldb_field to be specified in order to return only the check constraints belonging to one field. Each element contains the name of the constraint and its description If no check constraints are found, returns an empty array

TODO: Moodle 2.1 - drop in Moodle 2.1

Filter by the required field if specified

Lets clean a bit each constraint description, looking for the filtered field

description starts by [$filter] assume it's a constraint belonging to the field

Assign filtered results to the final results array

Reimplemented from sql_generator.

Definition at line 535 of file mssql_sql_generator.php.

Here is the call graph for this function:

Here is the caller graph for this function:

getCommentSQL ( xmldb_table)

Returns the code (in array) needed to add one comment to the table

Reimplemented from sql_generator.

Definition at line 631 of file mssql_sql_generator.php.

getCreateDefaultSQL ( xmldb_table,
xmldb_field 
)

Given one xmldb_table and one xmldb_field, return the SQL statements needed to create its default (usually invoked from getModifyDefaultSQL()

MSSQL is a bit special and it requires the corresponding DEFAULT CONSTRAINT to be dropped

Get the quoted name of the table and field

Now, check if, with the current field attributes, we have to build one default

We need to build the default (Moodle) default, so do it

Reimplemented from sql_generator.

Definition at line 462 of file mssql_sql_generator.php.

Here is the call graph for this function:

Here is the caller graph for this function:

getCreateTempTableSQL ( xmldb_table)

Given one correct xmldb_table, returns the SQL statements to create temporary table (inside one array)

Reimplemented from sql_generator.

Definition at line 125 of file mssql_sql_generator.php.

Here is the call graph for this function:

getDefaultConstraintName ( xmldb_table,
xmldb_field 
)

Given one xmldb_table and one xmldb_field, returns the name of its default constraint in DB or false if not found This function should be considered internal and never used outside from generator

Get the quoted name of the table and field

Look for any default constraint in this field and drop it

Definition at line 508 of file mssql_sql_generator.php.

Here is the call graph for this function:

Here is the caller graph for this function:

getDropDefaultSQL ( xmldb_table,
xmldb_field 
)

Given one xmldb_table and one xmldb_field, return the SQL statements needed to drop its default (usually invoked from getModifyDefaultSQL()

MSSQL is a bit special and it requires the corresponding DEFAULT CONSTRAINT to be dropped

Get the quoted name of the table and field

Look for the default contraint and, if found, drop it

Reimplemented from sql_generator.

Definition at line 486 of file mssql_sql_generator.php.

Here is the call graph for this function:

Here is the caller graph for this function:

getDropEnumSQL ( xmldb_table,
xmldb_field 
)

Given one xmldb_table and one xmldb_field, return the SQL statements needed to drop its enum (usually invoked from getModifyEnumSQL()

TODO: Moodle 2.1 - drop in Moodle 2.1

Let's introspect to know the real name of the check constraint

Get the 1st (should be only one)

Extract the REAL name

All we have to do is to drop the check constraint

Constraint not found. Nothing to do

Reimplemented from sql_generator.

Definition at line 445 of file mssql_sql_generator.php.

Here is the call graph for this function:

Here is the caller graph for this function:

getDropFieldSQL ( xmldb_table,
xmldb_field 
)

Given one xmldb_table and one xmldb_field, return the SQL statements needed to drop the field from the table MSSQL overwrites the standard sentence because it needs to do some extra work dropping the default and check constraints

Get the quoted name of the table and field

Look for any default constraint in this field and drop it

Look for any check constraint in this field and drop it

Build the standard alter table drop column

Reimplemented from sql_generator.

Definition at line 206 of file mssql_sql_generator.php.

Here is the call graph for this function:

getDropTempTableSQL ( xmldb_table)

Given one correct xmldb_table and the new name, returns the SQL statements to drop it (inside one array)

Reimplemented from sql_generator.

Definition at line 135 of file mssql_sql_generator.php.

Here is the call graph for this function:

getModifyDefaultSQL ( xmldb_table,
xmldb_field 
)

Given one xmldb_table and one xmldb_field, return the SQL statements needed to modify the default of the field in the table

MSSQL is a bit special with default constraints because it implements them as external constraints so normal ALTER TABLE ALTER COLUMN don't work to change defaults. Because this, we have this method overloaded here

Decide if we are going to create/modify or to drop the default

Reimplemented from sql_generator.

Definition at line 418 of file mssql_sql_generator.php.

Here is the call graph for this function:

getNameForObject ( tablename,
fields,
suffix = '' 
)

Given three strings (table name, list of fields (comma separated) and suffix), create the proper object name quoting it if necessary.

IMPORTANT: This function must be used to CALCULATE NAMES of objects TO BE CREATED, NEVER TO GUESS NAMES of EXISTING objects!!!

IMPORTANT: We are overriding this function for the MSSQL generator because objects belonging to temporary tables aren't searchable in the catalog neither in information schema tables. So, for temporary tables, we are going to add 4 randomly named "virtual" fields, so the generated names won't cause concurrency problems. Really nasty hack, but the alternative involves modifying all the creation table code to avoid naming constraints for temp objects and that will dupe a lot of code.

Reimplemented from sql_generator.

Definition at line 589 of file mssql_sql_generator.php.

Here is the call graph for this function:

Here is the caller graph for this function:

getRenameFieldSQL ( xmldb_table,
xmldb_field,
newname 
)

Given one correct xmldb_field and the new name, returns the SQL statements to rename it (inside one array) MSSQL is special, so we overload the function here. It needs to drop the constraints BEFORE renaming the field

Although this is checked in database_manager::rename_field() - double check that we aren't trying to rename one "id" field. Although it could be implemented (if adding the necessary code to rename sequences, defaults, triggers... and so on under each getRenameFieldExtraSQL() function, it's better to forbid it, mainly because this field is the default PK and in the future, a lot of FKs can be pointing here. So, this field, more or less, must be considered immutable!

Call to standard (parent) getRenameFieldSQL() function

Reimplemented from sql_generator.

Definition at line 235 of file mssql_sql_generator.php.

getRenameTableExtraSQL ( xmldb_table,
newname 
)

Returns the code (array of statements) needed to execute extra statements on table rename

Rename all the check constraints in the table

Drop the old constraint

Reimplemented from sql_generator.

Definition at line 259 of file mssql_sql_generator.php.

Here is the call graph for this function:

static getReservedWords ( ) [static]

Returns an array of reserved words (lowercase) for this DB

This file contains the reserved words for MSSQL databases from http://msdn2.microsoft.com/en-us/library/ms189822.aspx

Reimplemented from sql_generator.

Definition at line 644 of file mssql_sql_generator.php.

getResetSequenceSQL ( table)

Reset a sequence to the id field of a table.

Parameters:
string$tablename of table or xmldb_table object
Returns:
array sql commands to execute

Reimplemented from sql_generator.

Definition at line 82 of file mssql_sql_generator.php.

Here is the call graph for this function:

getTableName ( xmldb_table xmldb_table,
quoted = true 
)

Given one xmldb_table, returns it's correct name, depending of all the parametrization Overridden to allow change of names in temp tables

Parameters:
xmldb_tabletable whose name we want
booleanto specify if the name must be quoted (if reserved word, only!)
Returns:
string the correct name of the table

Get the name, supporting special mssql names for temp tables

Apply quotes optionally

Reimplemented from sql_generator.

Definition at line 104 of file mssql_sql_generator.php.

Here is the call graph for this function:

Here is the caller graph for this function:

getTypeSQL ( xmldb_type,
xmldb_length = null,
xmldb_decimals = null 
)

Given one XMLDB Type, lenght and decimals, returns the DB proper SQL type

38 is the max allowed

Reimplemented from sql_generator.

Definition at line 144 of file mssql_sql_generator.php.

isNameInUse ( object_name,
type,
table_name 
)

Given one object name and it's type (pk, uk, fk, ck, ix, uix, seq, trg) return if such name is currently in use (true) or no (false) (invoked from getNameForObject()

Reimplemented from sql_generator.

Definition at line 602 of file mssql_sql_generator.php.


Field Documentation

$add_table_comments = false

Reimplemented from sql_generator.

Definition at line 57 of file mssql_sql_generator.php.

$concat_character = '+'

Reimplemented from sql_generator.

Definition at line 59 of file mssql_sql_generator.php.

$default_for_char = ''

Reimplemented from sql_generator.

Definition at line 46 of file mssql_sql_generator.php.

$drop_index_sql = 'DROP INDEX TABLENAME.INDEXNAME'

TABLENAME, OLDFIELDNAME and NEWFIELDNAME are dyanmically replaced.

Reimplemented from sql_generator.

Definition at line 68 of file mssql_sql_generator.php.

$enum_inline_code = false

Definition at line 55 of file mssql_sql_generator.php.

$number_type = 'DECIMAL'

Reimplemented from sql_generator.

Definition at line 43 of file mssql_sql_generator.php.

$rename_column_sql = "sp_rename 'TABLENAME.OLDFIELDNAME', 'NEWFIELDNAME', 'COLUMN'"

Reimplemented from sql_generator.

Definition at line 65 of file mssql_sql_generator.php.

$rename_index_sql = "sp_rename 'TABLENAME.OLDINDEXNAME', 'NEWINDEXNAME', 'INDEX'"

Reimplemented from sql_generator.

Definition at line 71 of file mssql_sql_generator.php.

$rename_key_sql = null

Reimplemented from sql_generator.

Definition at line 74 of file mssql_sql_generator.php.

$rename_table_sql = "sp_rename 'OLDNAME', 'NEWNAME'"

Reimplemented from sql_generator.

Definition at line 62 of file mssql_sql_generator.php.

$sequence_extra_code = false

Reimplemented from sql_generator.

Definition at line 51 of file mssql_sql_generator.php.

$sequence_name = 'IDENTITY(1,1)'

Reimplemented from sql_generator.

Definition at line 52 of file mssql_sql_generator.php.

$sequence_only = false

Reimplemented from sql_generator.

Definition at line 53 of file mssql_sql_generator.php.

$specify_nulls = true

Reimplemented from sql_generator.

Definition at line 48 of file mssql_sql_generator.php.

$statement_end = "\ngo"

Only set values that are different from the defaults present in XMLDBgenerator.

Reimplemented from sql_generator.

Definition at line 41 of file mssql_sql_generator.php.

$unsigned_allowed = false

Reimplemented from sql_generator.

Definition at line 45 of file mssql_sql_generator.php.


The documentation for this class was generated from the following file:
 All Data Structures Namespaces Files Functions Variables Enumerations