CMS Made Simple API

DataDictionary
in package

AbstractYes

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.

Tags
author

Robert Campbell

copyright

Copyright (c) 2015, Robert Campbell calguy1000@cmsmadesimple.org

since
2.2

Table of Contents

Methods

AddColumnSQL()  : array<string|int, string>
Generate the SQL to add columns to a table.
AlterColumnSQL()  : array<string|int, string>
Change the definition of one column
ChangeTableSQL()  : array<string|int, string>
Add, drop or change columns within a table.
CreateDatabase()  : array<string|int, string>
Create the SQL commands that will result in a database being created.
CreateIndexSQL()  : array<string|int, string>
Generate the SQL to create an index.
CreateTableSQL()  : array<string|int, string>
Generate the SQL to create a new table.
DropColumnSQL()  : array<string|int, string>
Drop one column from a table.
DropIndexSQL()  : array<string|int, string>
Generate the SQL to drop an index
DropTableSQL()  : array<string|int, string>
Drop one table, and all of it's indexes
ExecuteSQLArray()  : int
Given an array of SQL commands execute them in sequence.
MetaColumns()  : array<string|int, string>
Return the list of columns in a table within the currently connected database.
MetaTables()  : array<string|int, string>
Return the list of tables in the currently connected database.
RenameColumnSQL()  : array<string|int, string>
Rename one column in a table.
RenameTableSQL()  : array<string|int, string>
Rename a table.
__construct()  : mixed
Constructor

Methods

AddColumnSQL()

Generate the SQL to add columns to a table.

public AddColumnSQL(string $tabname, string $flds) : array<string|int, string>
Parameters
$tabname : string

The Table name.

$flds : string

The column definitions (using DataDictionary meta types)

Tags
see
CreateTableSQL
Return values
array<string|int, string>

An array of strings suitable for use with the ExecuteSQLArray method

AlterColumnSQL()

Change the definition of one column

public AlterColumnSQL(string $tabname, string $flds[, string $tableflds = '' ][, array<string|int, mixed> $tableoptions = '' ]) : array<string|int, string>
Parameters
$tabname : string

table-name

$flds : string

column-name and type for the changed column.

$tableflds : string = ''

complete defintion of the new table, eg. for postgres, default ''

$tableoptions : array<string|int, mixed> = ''

options for the new table see CreateTableSQL, default ''

Return values
array<string|int, string>

An array of strings suitable for use with the ExecuteSQLArray method

ChangeTableSQL()

Add, drop or change columns within a table.

public ChangeTableSQL(string $tablename, string $flds[, array<string|int, mixed> $tableoptions = false ]) : array<string|int, 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.

Parameters
$tablename : string

The table name

$flds : string

The field definitions

$tableoptions : array<string|int, mixed> = false

Table options

Return values
array<string|int, string>

An array of strings suitable for use with the ExecuteSQLArray method

CreateDatabase()

Create the SQL commands that will result in a database being created.

public CreateDatabase(string $dbname[, mixed $options = false ]) : array<string|int, string>
Parameters
$dbname : string
$options : mixed = false
Return values
array<string|int, string>

An array of strings suitable for use with the ExecuteSQLArray method

CreateIndexSQL()

Generate the SQL to create an index.

public CreateIndexSQL(string $idxname, string $tabname, string|array<string|int, string> $flds[, mixed $idxoptions = false ]) : array<string|int, string>
Parameters
$idxname : string

The index name

$tabname : string

The table name

$flds : string|array<string|int, string>

A list of the table fields to create the index with. Either an array of strings or a comma separated list.

$idxoptions : mixed = false
Return values
array<string|int, string>

An array of strings suitable for use with the ExecuteSQLArray method

CreateTableSQL()

Generate the SQL to create a new table.

public CreateTableSQL(string $tabname, string $flds[, mixed $tableoptions = false ]) : array<string|int, 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:

C
Varchar, capped to 255 characters.
X
Text
XL
LongText
C2
Varchar, capped to 255 characters
XL
LongText
B
LongBlob
D
Date
DT
DateTime
T
Time
TS
Timestamp
L
TinyInt
R / I4 / I
Integer
I1
TinyInt
I2
SmallInt
I4
BigInt
F
Double
N
Numeric

The otheroptions field includes the following options:

AUTO
Auto increment. Also sets NOTNULL.
AUTOINCREMENT
Same as AUTO
KEY
Primary key field. Also sets NOTNULL. Compound keys are supported.
PRImARY
Same as KEY
DEFAULT
The default value. Character strings are auto-quoted unless the string begins with a space. i.e: ' SYSDATE '.
DEF
Same as DEFAULT
CONSTRAINTS
Additional constraints defined at the end of the field definition.
Parameters
$tabname : string

The table name

$flds : string

a comma separated list of field definitions using datadictionary syntax.

$tableoptions : mixed = false

A 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).

Return values
array<string|int, string>

An array of strings suitable for use with the ExecuteSQLArray method

DropColumnSQL()

Drop one column from a table.

public DropColumnSQL(string $tabname, string $flds[, string $tableflds = '' ][, array<string|int, mixed> $tableoptions = '' ]) : array<string|int, string>
Parameters
$tabname : string

table-name

$flds : string

column-name and type for the changed column

$tableflds : string = ''

complete defintion of the new table, eg. for postgres, default ''

$tableoptions : array<string|int, mixed> = ''

options for the new table see CreateTableSQL, default ''

Return values
array<string|int, string>

An array of strings suitable for use with the ExecuteSQLArray method

DropIndexSQL()

Generate the SQL to drop an index

public DropIndexSQL(string $idxname[, string $tabname = NULL ]) : array<string|int, string>
Parameters
$idxname : string

The index name

$tabname : string = NULL

The table name

Return values
array<string|int, string>

An array of strings suitable for use with the ExecuteSQLArray method

DropTableSQL()

Drop one table, and all of it's indexes

public DropTableSQL(string $tabname) : array<string|int, string>
Parameters
$tabname : string

The table name to drop.

Return values
array<string|int, string>

An array of strings suitable for use with the ExecuteSQLArray method

ExecuteSQLArray()

Given an array of SQL commands execute them in sequence.

public ExecuteSQLArray(array<string|int, string> $sql[, bool $continueOnError = true ]) : int
Parameters
$sql : array<string|int, string>

An array of sql commands.

$continueOnError : bool = true

wether to continue on errors or not.

Return values
int

2 for no errors, 1 if an error occured.

MetaColumns()

Return the list of columns in a table within the currently connected database.

public abstract MetaColumns(string $table) : array<string|int, string>
Parameters
$table : string

The table name.

Return values
array<string|int, string>

MetaTables()

Return the list of tables in the currently connected database.

public abstract MetaTables() : array<string|int, string>
Return values
array<string|int, string>

RenameColumnSQL()

Rename one column in a table.

public RenameColumnSQL(string $tabname, string $oldcolumn, string $newcolumn[, string $flds = '' ]) : array<string|int, string>
Parameters
$tabname : string

table-name

$oldcolumn : string

column-name to be renamed

$newcolumn : string

new column-name

$flds : string = ''

complete column-defintion-string like for AddColumnSQL, only used by mysql atm., default=''

Return values
array<string|int, string>

An array of strings suitable for use with the ExecuteSQLArray method

RenameTableSQL()

Rename a table.

public RenameTableSQL(string $tabname, string $newname) : array<string|int, string>
Parameters
$tabname : string

The table name

$newname : string

The new table name

Return values
array<string|int, string>

An array of strings suitable for use with the ExecuteSQLArray method


        
On this page

Search results