A class defining methods to work directly with database tables.
This file is based on the DataDictionary base class from the adodb_lite library which was in turn a fork of the adodb library at approximately 2004.
Credits and kudos to the authors of those packages.
package |
CMS |
---|---|
author |
Robert Campbell |
copyright |
Copyright (c) 2015, Robert Campbell calguy1000@cmsmadesimple.org |
since | 2.2 |
__construct(\CMSMS\Database\Connection $conn)
MetaTables() : array<mixed,string>
array<mixed,string>
MetaColumns(string $table) : array<mixed,string>
string
$tableThe table name.
array<mixed,string>
ExecuteSQLArray(array<mixed,string> $sql, boolean $continueOnError = true) : integer
array<mixed,string>
$sqlAn array of sql commands.
boolean
$continueOnErrorwether to continue on errors or not.
integer
2 for no errors, 1 if an error occured.
CreateDatabase(string $dbname, $options = false) : array<mixed,string>
string
$dbname
$options array<mixed,string>
An array of strings suitable for use with the ExecuteSQLArray method
CreateIndexSQL(string $idxname, string $tabname, string|array<mixed,string> $flds, $idxoptions = false) : array<mixed,string>
string
$idxnameThe index name
string
$tabnameThe table name
string|array<mixed,string>
$fldsA list of the table fields to create the index with. Either an array of strings or a comma separated list.
$idxoptions array<mixed,string>
An array of strings suitable for use with the ExecuteSQLArray method
DropIndexSQL(string $idxname, string $tabname = NULL) : array<mixed,string>
string
$idxnameThe index name
string
$tabnameThe table name
array<mixed,string>
An array of strings suitable for use with the ExecuteSQLArray method
AddColumnSQL(string $tabname, string $flds) : array<mixed,string>
string
$tabnameThe Table name.
string
$fldsThe column definitions (using DataDictionary meta types)
array<mixed,string>
An array of strings suitable for use with the ExecuteSQLArray method
AlterColumnSQL(string $tabname, string $flds, string $tableflds = '', \CMSMS\Database\array/string $tableoptions = '') : array<mixed,string>
string
$tabnametable-name
string
$fldscolumn-name and type for the changed column.
string
$tablefldscomplete defintion of the new table, eg. for postgres, default ''
\CMSMS\Database\array/string
$tableoptionsoptions for the new table see CreateTableSQL, default ''
array<mixed,string>
An array of strings suitable for use with the ExecuteSQLArray method
RenameColumnSQL(string $tabname, string $oldcolumn, string $newcolumn, string $flds = '') : array<mixed,string>
string
$tabnametable-name
string
$oldcolumncolumn-name to be renamed
string
$newcolumnnew column-name
string
$fldscomplete column-defintion-string like for AddColumnSQL, only used by mysql atm., default=''
array<mixed,string>
An array of strings suitable for use with the ExecuteSQLArray method
DropColumnSQL(string $tabname, string $flds, string $tableflds = '', \CMSMS\Database\array/string $tableoptions = '') : array<mixed,string>
string
$tabnametable-name
string
$fldscolumn-name and type for the changed column
string
$tablefldscomplete defintion of the new table, eg. for postgres, default ''
\CMSMS\Database\array/string
$tableoptionsoptions for the new table see CreateTableSQL, default ''
array<mixed,string>
An array of strings suitable for use with the ExecuteSQLArray method
DropTableSQL(string $tabname) : array<mixed,string>
string
$tabnameThe table name to drop.
array<mixed,string>
An array of strings suitable for use with the ExecuteSQLArray method
RenameTableSQL(string $tabname, string $newname) : array<mixed,string>
string
$tabnameThe table name
string
$newnameThe new table name
array<mixed,string>
An array of strings suitable for use with the ExecuteSQLArray method
CreateTableSQL(string $tabname, string $flds, mixed $tableoptions = false) : array<mixed,string>
The flds string is a comma separated of field definitions, where each definition is of the form fieldname type columnsize otheroptions
The type fields are codes that map to real database types as follows:
The otheroptions field includes the following options:
string
$tabnameThe table name
string
$fldsa comma separated list of field definitions using datadictionary syntax.
mixed
$tableoptionsA string specifying table options (database driver specific) for the table creation command. Or an associative array of table options, keys being the database type (as available).
array<mixed,string>
An array of strings suitable for use with the ExecuteSQLArray method
ChangeTableSQL(string $tablename, string $flds, array $tableoptions = false) : array<mixed,string>
This function changes/adds new fields to your table. You don't have to know if the col is new or not. It will check on its own.
string
$tablenameThe table name
string
$fldsThe field definitions
array
$tableoptionsTable options
array<mixed,string>
An array of strings suitable for use with the ExecuteSQLArray method