Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.

Experimental SQLite specific SQL code generator.

Copyright: 2008 Andrei Bautu
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 463 lines (20 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class


Class: sqlite_sql_generator  - X-Ref

__construct($mdb)   X-Ref
Creates one new XMLDBmysql


getResetSequenceSQL($table)   X-Ref
Reset a sequence to the id field of a table.

param: xmldb_table|string $table name of table or the table object.
return: array of sql statements

getKeySQL($xmldb_table, $xmldb_key)   X-Ref
Given one correct xmldb_key, returns its specs


getTypeSQL($xmldb_type, $xmldb_length=null, $xmldb_decimals=null)   X-Ref
Given one XMLDB Type, length and decimals, returns the DB proper SQL type.

param: int $xmldb_type The xmldb_type defined constant. XMLDB_TYPE_INTEGER and other XMLDB_TYPE_* constants.
param: int $xmldb_length The length of that data type.
param: int $xmldb_decimals The decimal places of precision of the data type.
return: string The DB defined data type.

getAlterTableSchema($xmldb_table, $xmldb_add_field=NULL, $xmldb_delete_field=NULL)   X-Ref
Function to emulate full ALTER TABLE which SQLite does not support.
The function can be used to drop a column ($xmldb_delete_field != null and
$xmldb_add_field == null), add a column ($xmldb_delete_field == null and
$xmldb_add_field != null), change/rename a column ($xmldb_delete_field == null
and $xmldb_add_field == null).

param: xmldb_table $xmldb_table table to change
param: xmldb_field $xmldb_add_field column to create/modify (full specification is required)
param: xmldb_field $xmldb_delete_field column to delete/modify (only name field is required)
return: array of strings (SQL statements to alter the table structure)

getAlterFieldSQL($xmldb_table, $xmldb_field, $skip_type_clause = NULL, $skip_default_clause = NULL, $skip_notnull_clause = NULL)   X-Ref
Given one xmldb_table and one xmldb_field, return the SQL statements needed to alter the field in the table.

param: xmldb_table $xmldb_table The table related to $xmldb_field.
param: xmldb_field $xmldb_field The instance of xmldb_field to create the SQL from.
param: string $skip_type_clause The type clause on alter columns, NULL by default.
param: string $skip_default_clause The default clause on alter columns, NULL by default.
param: string $skip_notnull_clause The null/notnull clause on alter columns, NULL by default.
return: string The field altering SQL statement.

getAddKeySQL($xmldb_table, $xmldb_key)   X-Ref
Given one xmldb_table and one xmldb_key, return the SQL statements needed to add the key to the table
note that underlying indexes will be added as parametrised by $xxxx_keys and $xxxx_index parameters


getCreateDefaultSQL($xmldb_table, $xmldb_field)   X-Ref
Given one xmldb_table and one xmldb_field, return the SQL statements needed to add its default
(usually invoked from getModifyDefaultSQL()

param: xmldb_table $xmldb_table The xmldb_table object instance.
param: xmldb_field $xmldb_field The xmldb_field object instance.
return: array Array of SQL statements to create a field's default.

getRenameFieldSQL($xmldb_table, $xmldb_field, $newname)   X-Ref
Given one correct xmldb_field and the new name, returns the SQL statements
to rename it (inside one array).

param: xmldb_table $xmldb_table The table related to $xmldb_field.
param: xmldb_field $xmldb_field The instance of xmldb_field to get the renamed field from.
param: string $newname The new name to rename the field to.
return: array The SQL statements for renaming the field.

getRenameIndexSQL($xmldb_table, $xmldb_index, $newname)   X-Ref
Given one xmldb_table and one xmldb_index, return the SQL statements needed to rename the index in the table


getRenameKeySQL($xmldb_table, $xmldb_key, $newname)   X-Ref
Given one xmldb_table and one xmldb_key, return the SQL statements needed to rename the key in the table
Experimental! Shouldn't be used at all!


getDropFieldSQL($xmldb_table, $xmldb_field)   X-Ref
Given one xmldb_table and one xmldb_field, return the SQL statements needed to drop the field from the table.

param: xmldb_table $xmldb_table The table related to $xmldb_field.
param: xmldb_field $xmldb_field The instance of xmldb_field to create the SQL from.
return: array The SQL statement for dropping a field from the table.

getDropIndexSQL($xmldb_table, $xmldb_index)   X-Ref
Given one xmldb_table and one xmldb_index, return the SQL statements needed to drop the index from the table


getDropKeySQL($xmldb_table, $xmldb_key)   X-Ref
Given one xmldb_table and one xmldb_index, return the SQL statements needed to drop the index from the table


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

Note that this method may be dropped in future.

param: xmldb_table $xmldb_table The xmldb_table object instance.
param: xmldb_field $xmldb_field The xmldb_field object instance.
return: array Array of SQL statements to create a field's default.

getCommentSQL($xmldb_table)   X-Ref
Returns the code (array of statements) needed to add one comment to the table.

param: xmldb_table $xmldb_table The xmldb_table object instance.
return: array Array of SQL statements to add one comment to the table.

isNameInUse($object_name, $type, $table_name)   X-Ref
Given one object name and it's type (pk, uk, fk, ck, ix, uix, seq, trg).

(MySQL requires the whole xmldb_table object to be specified, so we add it always)

This is invoked from getNameForObject().
Only some DB have this implemented.

param: string $object_name The object's name to check for.
param: string $type The object's type (pk, uk, fk, ck, ix, uix, seq, trg).
param: string $table_name The table's name to check in
return: bool If such name is currently in use (true) or no (false)

getReservedWords()   X-Ref
Returns an array of reserved words (lowercase) for this DB

return: array An array of database specific reserved words

addslashes($s)   X-Ref
Adds slashes to string.

param: string $s
return: string The escaped string.