$Table
$Table : \SmartTable
Columns contain all of the column properties and no user/db data. It's strictly structural. Data is contained in Cells
$Table : \SmartTable
$DataType : string
$DefaultTimezone : string
$PossibleValues : array
$RegexCheck : string
GetMaxLength() : integer
Uses the column's $MaxSize property to determine what that maximum number of characters that are allowed in this column, regardless of data type (i.e. decimals are different than regular MaxSize)
Returns the maximum number of characters this column can hold. If no MaxSize is set, returns null.
__construct(string $columnName) : \SmartColumn
Constructor
string | $columnName | The name of the column. You should never really call this explicitly. Instead, do a $SmartDatabase['TABLE_NAME']['COLUMN_NAME'] to get the column (i.e. $db['Products']['Price']). |
AddRelation(string $tableName, string $columnName, boolean $addRelationOnRelatedColumn = true) : boolean
Adds a relation to this column. Returns true if success, false if the relation already exists.
string | $tableName | The related table's name |
string | $columnName | The related column's name |
boolean | $addRelationOnRelatedColumn | [optional] If true (default), the related column will be updated with the relation too. If false, you will need to add this relation to the related column by hand. |
true if success, false if the relation already existed.
RemoveRelation(string $tableName, string $columnName, boolean $removeRelationOnRelatedColumn = true) : boolean
Removes a relation from this column. Returns true if success, false if the column was not found as a current relation.
string | $tableName | The related table's name |
string | $columnName | The related column's name |
boolean | $removeRelationOnRelatedColumn | [optional] If true (default), the related column will have this relation removed as well. If false, you will need to remove the relation on the related column by hand. |
true if success, false if the column was not found as a current relation.
HasRelation(string $tableName, string $columnName) : boolean
Returns true if a relation exists between this column and the passed $tableName, $columnName. false otherwise
string | $tableName | |
string | $columnName |
true if a relation exists between this column and the passed $tableName, $columnName. false otherwise
GetAliases(array $options = null) : array
Returns an array of all aliases. array($key=alias => $val=true);
$options = array(
'names-only' => false, //if true, the returned array will just be an array of alias names
)
array | $options | [optional] See description |
All aliases of this Column
RemoveAlias(string $alias) : boolean
Removes an alias from the column. Returns true if success, false if the column alias does not currently exist.
string | $alias | The alias to remove from this column |
true if success, false if the column alias does not exist.
NormalizeValue(mixed $value) : mixed
If the column is a special data type, the value from the database may need to be normalized for use.
Serialized Columns are unserialized. 'Set' datatype columns are converted from CSV (internal) to a PHP array Timestamp Columns will have the timestamp abbreviation appended to the database value (only if a $DefaultTimezone is set on the Database or Column level).
mixed | $value |
the normalized value based on the Column's data type
GetAllValues(array $options = null) : mixed
Gets all values in all rows for this column, optionally unique and sorted. Optionally in an assoc with the primary key column value as the assoc's key value. Alternatively, if the option 'return-count-only'=true, returns an integer of number of rows selected.
Options are as follows:
$options = array(
'sort-by'=>null, //Either a string of the column to sort ASC by, or an assoc array of "ColumnName"=>"ASC"|"DESC" to sort by. An exception will be thrown if a column does not exist.
'get-unique'=>false, //If true, only unique values will be returned. Note: array keys in the returned array will NOT be the key column when this is true)
'return-assoc'=>false, //if true, the returned assoc-array will have the row's primary key column value as its key and the row as its value. ie array("2"=>$row,...) instead of just array($row,...);
'limit'=>null, // With one argument (ie $limit="10"), the value specifies the number of rows to return from the beginning of the result set
// With two arguments (ie $limit="100,10"), the first argument specifies the offset of the first row to return, and the second specifies the maximum number of rows to return. The offset of the initial row is 0 (not 1):
'return-count'=>null, //OUT variable only. integer. after this function is executed, this variable will be set with the number of values being returned. Usage ex: array('return-count'=>&$count)
'return-count-only'=>false, //if true, the return-count will be returned instead of the rows. A good optimization if you dont need to read any data from the rows and just need the rowcount of the search.
}
array | $options | [optional] See description |
An array of key-value pairs. The keys are either 1: nothing, or 2: the primary key (if 'return-assoc' option is TRUE and 'get-unique' option is false and the table has a primary key), and the values are the actual column values. Alternatively, if the option 'return-count-only'=true, returns an integer of number of rows selected.
GetMaxValue(array $lookupAssoc = null, array $options = null) : mixed
Returns the maximum value for this column as stored in the db. returns null if no rows are in the table. Shortcut for GetAggregate('max',.
..)
array | $lookupAssoc | An assoc-array of column=>value to filter for max value. For example: array("column1"=>"lookupVal", "column2"=>"lookupVal", ...) |
array | $options | [optional] (none yet) |
The maximum value of the column, optionally filtered by $lookupAssoc
GetMinValue(array $lookupAssoc = null, array $options = null) : mixed
Returns the minimum value for this column as stored in the db. returns null if no rows are in the table. Shortcut for GetAggregate('min',.
..)
array | $lookupAssoc | An assoc-array of column=>value to filter for max value. For example: array("column1"=>"lookupVal", "column2"=>"lookupVal", ...) |
array | $options | [optional] (none yet) |
The minimum value of the column, optionally filtered by $lookupAssoc
GetAggregateValue(string $aggregateFunction, array $lookupAssoc = null, array $options = null) : mixed
Runs an aggregate function over a column and returns the value. Function names include: "max", "min", "sum", "avg", "count-distinct" TODO: Currently has hard coded SQL for MySQL.
.. need to move this to the DbManager at some point, somehow
string | $aggregateFunction | The function to run on the column: "max", "min", "sum", "avg", "num-distinct" |
array | $lookupAssoc | An assoc-array of column=>value to filter for max value. For example: array("column1"=>"lookupVal", "column2"=>"lookupVal", ...) |
array | $options | [optional] (none yet) |
The aggregate value of the column, optionally filtered by $lookupAssoc
LookupRows(mixed $value, array $options = null) : mixed
Looks up an array of all Row instances that match the given column $value, or an empty array if there is no match. Alternatively, if the option 'return-count-only'=true, returns an integer of number of rows selected.
To execute this function, this table must have a primary key.
Options are as follows:
$options = array(
'sort-by'=>null, //Either a string of the column to sort ASC by, or an assoc array of "ColumnName"=>"ASC"|"DESC" to sort by. An exception will be thrown if a column does not exist.
'return-assoc'=>false, //if true, the returned assoc-array will have the row's primary key column value as its key and the row as its value. ie array("2"=>$row,...) instead of just array($row,...);
'callback'=>null, //function - if set, this function will be invoked for each row and the full result set will NOT be returned- only the LAST ROW in the set will be returned (if there is one). the function's signature should be function($row, $i){} where $row is the actual SmartRow, and $i is the 1-based index of the row being returned
'return-next-row'=>null, //OUT variable. integer. if you set this parameter in the $options array, then this function will return only 1 row of the result set at a time. If there are no rows selected or left to iterate over, null is returned.
// THIS PARAMETER MUST BE PASSED BY REFERENCE - i.e. array( "return-next-row" => &$curCount ) - the incoming value of this parameter doesn't matter and will be overwritten)
// After this function is executed, this OUT variable will be set with the number of rows that have been returned thus far.
// Each consecutive call to this function with the 'return-next-row' option set will return the next row in the result set, and also increment the 'return-next-row' variable to the number of rows that have been returned thus far
'limit'=>null, // With one argument (ie $limit="10"), the value specifies the number of rows to return from the beginning of the result set
// With two arguments (ie $limit="100,10"), the first argument specifies the offset of the first row to return, and the second specifies the maximum number of rows to return. The offset of the initial row is 0 (not 1):
'return-count'=>null, //OUT variable only. integer. after this function is executed, this variable will be set with the number of rows being returned. Usage ex: array('return-count'=>&$count)
'return-count-only'=>false, //if true, the return-count will be returned instead of the rows. A good optimization if you dont need to read any data from the rows and just need the rowcount of the search.
}
mixed | $value | The $value to lookup in this column |
array | $options | [optional] See description |
Gets an array of all Row instances that match the given $value, or an empty array if there is no match. Alternatively, if the option 'return-count-only'=true, returns an integer of number of rows selected.
LookupRow(mixed $value) : \SmartRow
Looks up an a row that matches the given column $value. If there is no match, an instance is still returned but ->Exists() will be false. The returned row will have the searched column=>value set by default (excluding auto-increment primary key columns) To execute this function, this table must have a primary key. Throws an exception if more than 1 row is returned.
mixed | $value | The $value to lookup in this column |
Looks up an a row instance that matches the given column $value. If there is no match, an instance is still returned but ->Exists() will be false. The returned row will have the searched column=>value set by default (excluding auto-increment primary key columns when the row does not exist)
DeleteRows(mixed $value, array $options = null) : integer
Deletes all rows with where the column value matches the passed $value
$options are as follows:
$options = array(
'skip-callbacks'=>false //If true, all row-level "Delete" callbacks will be skipped. This can substantially improve the performance of very large bulk deletions.
}
mixed | $value | the value to look-up in this column |
array | $options | [optional] See description |
the number of rows deleted
SetAllValues(mixed $value, array $options = null) : integer
Sets the given $value to the column for every row in the table. Returns the number of rows affected.
Options are as follows:
$options = array(
'skip-callbacks'=>false, //If true, all row-level callbacks AND error-checking will be skipped. This can substantially improve the performance on very large tables.
'skip-error-checking'=>false //Only available in conjunction with 'skip-callbacks'=true. If both of these options are true, all row-level error checking will be skipped when each updated Row is Commit()'ed.
}
mixed | $value | The scalar value to set in this column for every row in the table |
array | $options | [optional] See description |
the number of rows affected
VerifyValueType(object $value, $options = null) : \nothing.
Anytime we set the value of this cell, we need to fix boolean types to '1' and '0' and make sure we're not setting to an object.
Options are as follows:
$options = array(
'skip-serialized-data'=>false, //If true, serialized data will be left as-is (i.e. for using strings in lookup assocs)
'skip-force-set-to-csv'=>false //if true, SET data is returned as a CSV. SmartDb uses a CSV internally, as MySQL does basically.
}
object | $value | modifies this value BY REFERENCE |
$options |
GetSortedSet(mixed $setData, boolean $forceCsv = false) : mixed
Orders the given $setData according to the column's PossibleValues array because SET ordering matters for mysql in WHERE clauses and etc. see mysql doc https://dev.mysql.com/doc/refman/5.7/en/set.html An EMPTY array set or empty string always becomes NULL! SETs are case-insensitive and auto-trim!
mixed | $setData | can be an array of all selected values or a CSV of selected values from our PossibleValues |
boolean | $forceCsv | if true, a CSV will be returned instead of array. smart db works with a CSV internally (as does MySQL) |
if invalid set data is provided that is not in the column's PossibleValues array
the sorted set data as array or csv
VerifySet(mixed $setData) : boolean
Returns boolean, true if the passed $setData is in the column's PossibleValues array, false otherwise. These are case-insensitive and auto-trim!
mixed | $setData | either an array of SET values to check, or a CSV of the values. These are case-insensitive and auto-trim! |
true if passed $setData is in the column's PossibleValues array, false otherwise.
GetDefaultFormObjectName(string $nameSuffix = '') : string
Returns the default html name attribute that will be used when getting a form object for this cell
string | $nameSuffix | [optional] A suffix to add the the end of the column name |
The default html name attribute that will be used when getting a form object for this cell
GetDefaultFormObjectId(string $nameSuffix = '') : string
Returns the default html ID attribute that will be used when getting a form object for this cell
string | $nameSuffix | [optional] A suffix to add the the end of the column name |
The default name html ID attribute that will be used when getting a form object for this cell