Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.0.x will end 8 May 2023 (12 months).
  • Bug fixes for security issues in 4.0.x will end 13 November 2023 (18 months).
  • PHP version: minimum PHP 7.3.0 Note: the minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is also supported.

Differences Between: [Versions 310 and 400] [Versions 311 and 400] [Versions 39 and 400] [Versions 400 and 401] [Versions 400 and 402] [Versions 400 and 403]

(no description)

File Size: 2218 lines (55 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 2 files
 lib/adodb/adodb-datadict.inc.php
 lib/adodb/adodb.inc.php

Defines 6 classes

dbObject:: (9 methods):
  __construct()
  _tag_open()
  _tag_cdata()
  _tag_close()
  create()
  destroy()
  supportedPlatform()
  prefix()
  FieldID()

dbTable:: (11 methods):
  __construct()
  _tag_open()
  _tag_cdata()
  _tag_close()
  addIndex()
  addData()
  addField()
  addFieldOpt()
  addTableOpt()
  create()
  drop()

dbIndex:: (8 methods):
  __construct()
  _tag_open()
  _tag_cdata()
  _tag_close()
  addField()
  addIndexOpt()
  create()
  drop()

dbData:: (7 methods):
  __construct()
  _tag_open()
  _tag_cdata()
  _tag_close()
  addField()
  addData()
  create()

dbQuerySet:: (10 methods):
  __construct()
  _tag_open()
  _tag_cdata()
  _tag_close()
  newQuery()
  discardQuery()
  buildQuery()
  addQuery()
  create()
  prefixQuery()

adoSchema:: (32 methods):
  __construct()
  SetUpgradeMethod()
  ExecuteInline()
  ContinueOnError()
  ParseSchema()
  ParseSchemaFile()
  ParseSchemaString()
  RemoveSchema()
  RemoveSchemaString()
  ExecuteSchema()
  PrintSQL()
  SaveSQL()
  create_parser()
  _tag_open()
  _tag_cdata()
  _tag_close()
  ConvertSchemaString()
  _file_get_contents()
  ConvertSchemaFile()
  TransformSchema()
  xslt_error_handler()
  SchemaFileVersion()
  SchemaStringVersion()
  ExtractSchema()
  SetPrefix()
  prefix()
  supportedPlatform()
  clearSQL()
  addSQL()
  getSQL()
  Destroy()
  logMsg()

Defines 32 functions


Class: dbObject  - X-Ref

Abstract DB Object. This class provides basic methods for database objects, such
as tables and indexes.

__construct( &$parent, $attributes = NULL )   X-Ref
NOP


_tag_open( &$parser, $tag, $attributes )   X-Ref
XML Callback to process start elements


_tag_cdata( &$parser, $cdata )   X-Ref
XML Callback to process CDATA elements


_tag_close( &$parser, $tag )   X-Ref
XML Callback to process end elements


create(&$xmls)   X-Ref
No description

destroy()   X-Ref
Destroys the object


supportedPlatform( $platform = NULL )   X-Ref
Checks whether the specified RDBMS is supported by the current
database object or its ranking ancestor.

return: boolean TRUE if RDBMS is supported; otherwise returns FALSE.
param: string $platform RDBMS platform name (from ADODB platform list).

prefix( $name = '' )   X-Ref
Returns the prefix set by the ranking ancestor of the database object.

return: string Prefix.
param: string $name Prefix string.

FieldID( $field )   X-Ref
Extracts a field ID from the specified field.

return: string Field ID.
param: string $field Field.

Class: dbTable  - X-Ref

Creates a table object in ADOdb's datadict format

This class stores information about a database table. As charactaristics
of the table are loaded from the external source, methods and properties
of this class are used to build up the table description in ADOdb's
datadict format.

__construct( &$parent, $attributes = NULL )   X-Ref
Iniitializes a new table object.

param: string $prefix DB Object prefix
param: array $attributes Array of table attributes.

_tag_open( &$parser, $tag, $attributes )   X-Ref
XML Callback to process start elements. Elements currently
processed are: INDEX, DROP, FIELD, KEY, NOTNULL, AUTOINCREMENT & DEFAULT.


_tag_cdata( &$parser, $cdata )   X-Ref
XML Callback to process CDATA elements


_tag_close( &$parser, $tag )   X-Ref
XML Callback to process end elements


addIndex( $attributes )   X-Ref
Adds an index to a table object

return: object dbIndex object
param: array $attributes Index attributes

addData( $attributes )   X-Ref
Adds data to a table object

return: object dbData object
param: array $attributes Data attributes

addField( $name, $type, $size = NULL, $opts = NULL )   X-Ref
Adds a field to a table object

$name is the name of the table to which the field should be added.
$type is an ADODB datadict field type. The following field types
are supported as of ADODB 3.40:
- C:  varchar
- X:  CLOB (character large object) or largest varchar size
if CLOB is not supported
- C2: Multibyte varchar
- X2: Multibyte CLOB
- B:  BLOB (binary large object)
- D:  Date (some databases do not support this, and we return a datetime type)
- T:  Datetime or Timestamp
- L:  Integer field suitable for storing booleans (0 or 1)
- I:  Integer (mapped to I4)
- I1: 1-byte integer
- I2: 2-byte integer
- I4: 4-byte integer
- I8: 8-byte integer
- F:  Floating point number
- N:  Numeric or decimal number

return: array Field specifier array
param: string $name Name of the table to which the field will be added.
param: string $type    ADODB datadict field type.
param: string $size    Field size
param: array $opts    Field options array

addFieldOpt( $field, $opt, $value = NULL )   X-Ref
Adds a field option to the current field specifier

This method adds a field option allowed by the ADOdb datadict
and appends it to the given field.

return: array Field specifier array
param: string $field    Field name
param: string $opt ADOdb field option
param: mixed $value Field option value

addTableOpt( $opt )   X-Ref
Adds an option to the table

This method takes a comma-separated list of table-level options
and appends them to the table object.

return: array Options
param: string $opt Table option

create( &$xmls )   X-Ref
Generates the SQL that will create the table in the database

return: array Array containing table creation SQL
param: object $xmls adoSchema object

drop()   X-Ref
Marks a field or table for destruction


Class: dbIndex  - X-Ref

Creates an index object in ADOdb's datadict format

This class stores information about a database index. As charactaristics
of the index are loaded from the external source, methods and properties
of this class are used to build up the index description in ADOdb's
datadict format.

__construct( &$parent, $attributes = NULL )   X-Ref
Initializes the new dbIndex object.

param: object $parent Parent object
param: array $attributes Attributes

_tag_open( &$parser, $tag, $attributes )   X-Ref
XML Callback to process start elements

Processes XML opening tags.
Elements currently processed are: DROP, CLUSTERED, BITMAP, UNIQUE, FULLTEXT & HASH.


_tag_cdata( &$parser, $cdata )   X-Ref
XML Callback to process CDATA elements

Processes XML cdata.


_tag_close( &$parser, $tag )   X-Ref
XML Callback to process end elements


addField( $name )   X-Ref
Adds a field to the index

return: string Field list
param: string $name Field name

addIndexOpt( $opt )   X-Ref
Adds options to the index

return: string Option list
param: string $opt Comma-separated list of index options.

create( &$xmls )   X-Ref
Generates the SQL that will create the index in the database

return: array Array containing index creation SQL
param: object $xmls adoSchema object

drop()   X-Ref
Marks an index for destruction


Class: dbData  - X-Ref

Creates a data object in ADOdb's datadict format

This class stores information about table data.

__construct( &$parent, $attributes = NULL )   X-Ref
Initializes the new dbIndex object.

param: object $parent Parent object
param: array $attributes Attributes

_tag_open( &$parser, $tag, $attributes )   X-Ref
XML Callback to process start elements

Processes XML opening tags.
Elements currently processed are: DROP, CLUSTERED, BITMAP, UNIQUE, FULLTEXT & HASH.


_tag_cdata( &$parser, $cdata )   X-Ref
XML Callback to process CDATA elements

Processes XML cdata.


_tag_close( &$parser, $tag )   X-Ref
XML Callback to process end elements


addField( $attributes )   X-Ref
Adds a field to the index

return: string Field list
param: string $name Field name

addData( $cdata )   X-Ref
Adds options to the index

return: string Option list
param: string $opt Comma-separated list of index options.

create( &$xmls )   X-Ref
Generates the SQL that will create the index in the database

return: array Array containing index creation SQL
param: object $xmls adoSchema object

Class: dbQuerySet  - X-Ref

Creates the SQL to execute a list of provided SQL queries

__construct( &$parent, $attributes = NULL )   X-Ref
Initializes the query set.

param: object $parent Parent object
param: array $attributes Attributes

_tag_open( &$parser, $tag, $attributes )   X-Ref
XML Callback to process start elements. Elements currently
processed are: QUERY.


_tag_cdata( &$parser, $cdata )   X-Ref
XML Callback to process CDATA elements


_tag_close( &$parser, $tag )   X-Ref
XML Callback to process end elements


newQuery()   X-Ref
Re-initializes the query.

return: boolean TRUE

discardQuery()   X-Ref
Discards the existing query.

return: boolean TRUE

buildQuery( $sql = NULL )   X-Ref
Appends a line to a query that is being built line by line

return: string SQL query string.
param: string $data Line of SQL data or NULL to initialize a new query

addQuery()   X-Ref
Adds a completed query to the query list

return: string    SQL of added query

create( &$xmls )   X-Ref
Creates and returns the current query set

return: array Query set
param: object $xmls adoSchema object

prefixQuery( $regex, $query, $prefix = NULL )   X-Ref
Rebuilds the query with the prefix attached to any objects

return: string Prefixed SQL query string.
param: string $regex Regex used to add prefix
param: string $query SQL query string
param: string $prefix Prefix to be appended to tables, indices, etc.

Class: adoSchema  - X-Ref

Loads and parses an XML file, creating an array of "ready-to-run" SQL statements

This class is used to load and parse the XML file, to create an array of SQL statements
that can be used to build a database, and to build the database using the SQL array.

__construct( $db )   X-Ref
Creates an adoSchema object

Creating an adoSchema object is the first step in processing an XML schema.
The only parameter is an ADOdb database connection object, which must already
have been created.

param: object $db ADOdb database connection object.

SetUpgradeMethod( $method = '' )   X-Ref
Sets the method to be used for upgrading an existing database

Use this method to specify how existing database objects should be upgraded.
The method option can be set to ALTER, REPLACE, BEST, or NONE. ALTER attempts to
alter each database object directly, REPLACE attempts to rebuild each object
from scratch, BEST attempts to determine the best upgrade method for each
object, and NONE disables upgrading.

This method is not yet used by AXMLS, but exists for backward compatibility.
The ALTER method is automatically assumed when the adoSchema object is
instantiated; other upgrade methods are not currently supported.

returns: string Upgrade method used
param: string $method Upgrade method (ALTER|REPLACE|BEST|NONE)

ExecuteInline( $mode = NULL )   X-Ref
Enables/disables inline SQL execution.

Call this method to enable or disable inline execution of the schema. If the mode is set to TRUE (inline execution),
AXMLS applies the SQL to the database immediately as each schema entity is parsed. If the mode
is set to FALSE (post execution), AXMLS parses the entire schema and you will need to call adoSchema::ExecuteSchema()
to apply the schema to the database.

return: bool current execution mode
param: bool $mode execute

ContinueOnError( $mode = NULL )   X-Ref
Enables/disables SQL continue on error.

Call this method to enable or disable continuation of SQL execution if an error occurs.
If the mode is set to TRUE (continue), AXMLS will continue to apply SQL to the database, even if an error occurs.
If the mode is set to FALSE (halt), AXMLS will halt execution of generated sql if an error occurs, though parsing
of the schema will continue.

return: bool current continueOnError mode
param: bool $mode execute

ParseSchema( $filename, $returnSchema = FALSE )   X-Ref
Loads an XML schema from a file and converts it to SQL.

Call this method to load the specified schema (see the DTD for the proper format) from
the filesystem and generate the SQL necessary to create the database described.
return: array Array of SQL queries, ready to execute
param: string $file Name of XML schema file.
param: bool $returnSchema Return schema rather than parsing.

ParseSchemaFile( $filename, $returnSchema = FALSE )   X-Ref
Loads an XML schema from a file and converts it to SQL.

Call this method to load the specified schema from a file (see the DTD for the proper format)
and generate the SQL necessary to create the database described by the schema.

return: array Array of SQL queries, ready to execute.
param: string $file Name of XML schema file.
param: bool $returnSchema Return schema rather than parsing.

ParseSchemaString( $xmlstring, $returnSchema = FALSE )   X-Ref
Converts an XML schema string to SQL.

Call this method to parse a string containing an XML schema (see the DTD for the proper format)
and generate the SQL necessary to create the database described by the schema.
return: array Array of SQL queries, ready to execute.
param: string $xmlstring XML schema string.
param: bool $returnSchema Return schema rather than parsing.

RemoveSchema( $filename, $returnSchema = FALSE )   X-Ref
Loads an XML schema from a file and converts it to uninstallation SQL.

Call this method to load the specified schema (see the DTD for the proper format) from
the filesystem and generate the SQL necessary to remove the database described.
return: array Array of SQL queries, ready to execute
param: string $file Name of XML schema file.
param: bool $returnSchema Return schema rather than parsing.

RemoveSchemaString( $schema, $returnSchema = FALSE )   X-Ref
Converts an XML schema string to uninstallation SQL.

Call this method to parse a string containing an XML schema (see the DTD for the proper format)
and generate the SQL necessary to uninstall the database described by the schema.
return: array Array of SQL queries, ready to execute.
param: string $schema XML schema string.
param: bool $returnSchema Return schema rather than parsing.

ExecuteSchema( $sqlArray = NULL, $continueOnErr = NULL )   X-Ref
Applies the current XML schema to the database (post execution).

Call this method to apply the current schema (generally created by calling
ParseSchema() or ParseSchemaString() ) to the database (creating the tables, indexes,
and executing other SQL specified in the schema) after parsing.
returns: integer 0 if failure, 1 if errors, 2 if successful.
param: array $sqlArray Array of SQL statements that will be applied rather than
param: boolean $continueOnErr Continue to apply the schema even if an error occurs.

PrintSQL( $format = 'NONE' )   X-Ref
Returns the current SQL array.

Call this method to fetch the array of SQL queries resulting from
ParseSchema() or ParseSchemaString().

return: array Array of SQL statements or FALSE if an error occurs
param: string $format Format: HTML, TEXT, or NONE (PHP array)

SaveSQL( $filename = './schema.sql' )   X-Ref
Saves the current SQL array to the local filesystem as a list of SQL queries.

Call this method to save the array of SQL queries (generally resulting from a
parsed XML schema) to the filesystem.

return: boolean TRUE if save is successful, else FALSE.
param: string $filename Path and name where the file should be saved.

create_parser()   X-Ref
Create an xml parser

return: object PHP XML parser object

_tag_open( &$parser, $tag, $attributes )   X-Ref
XML Callback to process start elements


_tag_cdata( &$parser, $cdata )   X-Ref
XML Callback to process CDATA elements


_tag_close( &$parser, $tag )   X-Ref
XML Callback to process end elements


ConvertSchemaString( $schema, $newVersion = NULL, $newFile = NULL )   X-Ref
Converts an XML schema string to the specified DTD version.

Call this method to convert a string containing an XML schema to a different AXMLS
DTD version. For instance, to convert a schema created for an pre-1.0 version for
AXMLS (DTD version 0.1) to a newer version of the DTD (e.g. 0.2). If no DTD version
parameter is specified, the schema will be converted to the current DTD version.
If the newFile parameter is provided, the converted schema will be written to the specified
file.
return: string Converted XML schema or FALSE if an error occurs.
param: string $schema String containing XML schema that will be converted.
param: string $newVersion DTD version to convert to.
param: string $newFile File name of (converted) output file.

_file_get_contents($path)   X-Ref
No description

ConvertSchemaFile( $filename, $newVersion = NULL, $newFile = NULL )   X-Ref
Converts an XML schema file to the specified DTD version.

Call this method to convert the specified XML schema file to a different AXMLS
DTD version. For instance, to convert a schema created for an pre-1.0 version for
AXMLS (DTD version 0.1) to a newer version of the DTD (e.g. 0.2). If no DTD version
parameter is specified, the schema will be converted to the current DTD version.
If the newFile parameter is provided, the converted schema will be written to the specified
file.
return: string Converted XML schema or FALSE if an error occurs.
param: string $filename Name of XML schema file that will be converted.
param: string $newVersion DTD version to convert to.
param: string $newFile File name of (converted) output file.

TransformSchema( $schema, $xsl, $schematype='string' )   X-Ref
No description

xslt_error_handler( $parser, $errno, $level, $fields )   X-Ref
Processes XSLT transformation errors

param: object $parser XML parser object
param: integer $errno Error number
param: integer $level Error level
param: array $fields Error information fields

SchemaFileVersion( $filename )   X-Ref
Returns the AXMLS Schema Version of the requested XML schema file.

Call this method to obtain the AXMLS DTD version of the requested XML schema file.
return: string Schema version number or FALSE on error
param: string $filename AXMLS schema file

SchemaStringVersion( $xmlstring )   X-Ref
Returns the AXMLS Schema Version of the provided XML schema string.

Call this method to obtain the AXMLS DTD version of the provided XML schema string.
return: string Schema version number or FALSE on error
param: string $xmlstring XML schema string

ExtractSchema( $data = FALSE )   X-Ref
Extracts an XML schema from an existing database.

Call this method to create an XML schema string from an existing database.
If the data parameter is set to TRUE, AXMLS will include the data from the database
in the schema.

return: string Generated XML schema
param: boolean $data Include data in schema dump

SetPrefix( $prefix = '', $underscore = TRUE )   X-Ref
Sets a prefix for database objects

Call this method to set a standard prefix that will be prepended to all database tables
and indices when the schema is parsed. Calling setPrefix with no arguments clears the prefix.

return: boolean TRUE if successful, else FALSE
param: string $prefix Prefix that will be prepended.
param: boolean $underscore If TRUE, automatically append an underscore character to the prefix.

prefix( $name = '' )   X-Ref
Returns an object name with the current prefix prepended.

return: string    Prefixed name
param: string    $name Name

supportedPlatform( $platform = NULL )   X-Ref
Checks if element references a specific platform

returns: boolean TRUE if platform check succeeds
param: string $platform Requested platform

clearSQL()   X-Ref
Clears the array of generated SQL.


addSQL( $sql = NULL )   X-Ref
Adds SQL into the SQL array.

return: boolean TRUE if successful, else FALSE.
param: mixed $sql SQL to Add

getSQL( $format = NULL, $sqlArray = NULL )   X-Ref
Gets the SQL array in the specified format.

return: mixed SQL
param: string $format Format

Destroy()   X-Ref
Destroys an adoSchema object.

Call this method to clean up after an adoSchema object that is no longer in use.

logMsg( $msg, $title = NULL, $force = FALSE )   X-Ref
Message logging function


Functions that are not part of a class:

_file_get_contents($file)   X-Ref
ADOdb XML Schema (v0.2).

xmlschema is a class that allows the user to quickly and easily
build a database on any ADOdb-supported platform using a simple
XML schema.

This file is part of ADOdb, a Database Abstraction Layer library for PHP.

author: Richard Tango-Lowy
author: Dan Cech