SS_Database
class SS_Database
Abstract database connectivity class.
Sub-classes of this implement the actual database connection libraries
Methods
Get the current connector
Returns the current schema manager
Returns the current query builder
Execute the given SQL parameterised query with the specified arguments
Get the autogenerated ID from the previous INSERT query.
Determines if we are connected to a server AND have a valid database selected.
Returns an escaped string. This string won't be quoted, so would be suitable for appending to other quoted strings.
Wrap a string into DB-specific quotes.
Escapes an identifier (table / database name). Typically the value is simply double quoted. Don't pass in already escaped identifiers in, as this will double escape the value!
Execute a complex manipulation on the database.
Enable supression of database messages.
Clear all data out of the database
Clear all data in a given table
Generate a WHERE clause for text matching.
function to return an SQL datetime expression that can be used with the adapter in use used for querying a datetime in a certain format
function to return an SQL datetime expression that can be used with the adapter in use used for querying a datetime addition
function to return an SQL datetime expression that can be used with the adapter in use used for querying a datetime substraction
Returns true if this database supports collations
Can the database override timezone as a connection setting, or does it use the system timezone exclusively?
Query for the version of the currently connected database
Get the database server type (e.g. mysql, postgresql).
Return the number of rows affected by the previous operation.
The core search engine, used by this class and its subclasses to do fun stuff.
Determines if this database supports transactions
Start a prepared transaction See http://developer.postgresql.org/pgdocs/postgres/sql-set-transaction.html for details on transaction isolation options
Create a savepoint that you can jump back to if you encounter problems
Rollback or revert to a savepoint if your queries encounter problems If you encounter a problem at any point during a transaction, you may need to rollback that particular query, or return to a savepoint
Commit everything inside this transaction so far
Determines if the used database supports application-level locks, which is different from table- or row-level locking.
Returns if the lock is available.
Sets an application-level lock so that no two processes can run at the same time, also called a "cooperative advisory lock".
Remove an application-level lock file to allow another process to run (if the execution aborts (e.g. due to an error) all locks are automatically released).
Instruct the database to generate a live connection
Determine if the database with the specified name exists
Retrieves the list of all databases the user has access to
Change the connection to the specified database, optionally creating the database if it doesn't exist in the current schema.
Drop the database that this object is currently connected to.
Returns the name of the currently selected database
Return SQL expression used to represent the current date/time
Returns the database-specific version of the random() function
No description
No description
No description
Details
at line 33
DBConnector
getConnector()
Get the current connector
at line 42
setConnector(DBConnector $connector)
Injector injection point for connector dependency
at line 58
DBSchemaManager
getSchemaManager()
Returns the current schema manager
at line 67
setSchemaManager(DBSchemaManager $schemaManager)
Injector injection point for schema manager
at line 87
DBQueryBuilder
getQueryBuilder()
Returns the current query builder
at line 96
setQueryBuilder(DBQueryBuilder $queryBuilder)
Injector injection point for schema manager
at line 107
SS_Query
query(string $sql, int $errorLevel = E_USER_ERROR)
Execute the given SQL query.
at line 132
SS_Query
preparedQuery(string $sql, array $parameters, int $errorLevel = E_USER_ERROR)
Execute the given SQL parameterised query with the specified arguments
at line 203
integer
getGeneratedID(string $table)
Get the autogenerated ID from the previous INSERT query.
at line 213
boolean
isActive()
Determines if we are connected to a server AND have a valid database selected.
at line 224
string
escapeString(mixed $value)
Returns an escaped string. This string won't be quoted, so would be suitable for appending to other quoted strings.
at line 234
string
quoteString(mixed $value)
Wrap a string into DB-specific quotes.
at line 246
escapeIdentifier(string $value, string $separator = '.')
Escapes an identifier (table / database name). Typically the value is simply double quoted. Don't pass in already escaped identifiers in, as this will double escape the value!
at line 278
manipulate(array $manipulation)
Execute a complex manipulation on the database.
A manipulation is an array of insert / or update sequences. The keys of the array are table names, and the values are map containing 'command' and 'fields'. Command should be 'insert' or 'update', and fields should be a map of field names to field values, NOT including quotes.
The field values could also be in paramaterised format, such as array('MAX(?,?)' => array(42, 69)), allowing the use of raw SQL values such as array('NOW()' => array()).
at line 329
quiet()
Enable supression of database messages.
at line 336
clearAllData()
Clear all data out of the database
at line 348
clearTable(string $table)
Clear all data in a given table
at line 366
abstract String
comparisonClause(String $field, String $value, boolean $exact = false, boolean $negate = false, boolean $caseSensitive = null, boolean $parameterised = false)
Generate a WHERE clause for text matching.
at line 385
abstract string
formattedDatetimeClause(string $date, string $format)
function to return an SQL datetime expression that can be used with the adapter in use used for querying a datetime in a certain format
at line 406
abstract string
datetimeIntervalClause($date, $interval)
function to return an SQL datetime expression that can be used with the adapter in use used for querying a datetime addition
at line 419
abstract string
datetimeDifferenceClause($date1, $date2)
function to return an SQL datetime expression that can be used with the adapter in use used for querying a datetime substraction
at line 426
abstract boolean
supportsCollations()
Returns true if this database supports collations
at line 434
abstract Boolean
supportsTimezoneOverride()
Can the database override timezone as a connection setting, or does it use the system timezone exclusively?
at line 440
string
getVersion()
Query for the version of the currently connected database
at line 451
abstract string
getDatabaseServer()
Get the database server type (e.g. mysql, postgresql).
This value is passed to the connector as the 'driver' argument when initiating a database connection
at line 457
int
affectedRows()
Return the number of rows affected by the previous operation.
at line 476
abstract PaginatedList
searchEngine(array $classesToSearch, string $keywords, integer $start, integer $pageLength, string $sortBy = "Relevance DESC", string $extraFilter = "", boolean $booleanSearch = false, string $alternativeFileFilter = "", boolean $invertedMatch = false)
The core search engine, used by this class and its subclasses to do fun stuff.
Searches both SiteTree and File.
at line 484
abstract boolean
supportsTransactions()
Determines if this database supports transactions
at line 507
abstract
transactionStart(string|boolean $transactionMode = false, string|boolean $sessionCharacteristics = false)
Start a prepared transaction See http://developer.postgresql.org/pgdocs/postgres/sql-set-transaction.html for details on transaction isolation options
at line 514
abstract
transactionSavepoint(string $savepoint)
Create a savepoint that you can jump back to if you encounter problems
at line 524
abstract
transactionRollback(string|boolean $savepoint = false)
Rollback or revert to a savepoint if your queries encounter problems If you encounter a problem at any point during a transaction, you may need to rollback that particular query, or return to a savepoint
at line 531
abstract
transactionEnd(boolean $chain = false)
Commit everything inside this transaction so far
at line 540
boolean
supportsLocks()
Determines if the used database supports application-level locks, which is different from table- or row-level locking.
See {@link getLock()} for details.
at line 551
boolean
canLock(string $name)
Returns if the lock is available.
See {@link supportsLocks()} to check if locking is generally supported.
at line 572
boolean
getLock(string $name, integer $timeout = 5)
Sets an application-level lock so that no two processes can run at the same time, also called a "cooperative advisory lock".
Return FALSE if acquiring the lock fails; otherwise return TRUE, if lock was acquired successfully. Lock is automatically released if connection to the database is broken (either normally or abnormally), making it less prone to deadlocks than session- or file-based locks. Should be accompanied by a {@link releaseLock()} call after the logic requiring the lock has completed. Can be called multiple times, in which case locks "stack" (PostgreSQL, SQL Server), or auto-releases the previous lock (MySQL).
Note that this might trigger the database to wait for the lock to be released, delaying further execution.
at line 583
boolean
releaseLock(string $name)
Remove an application-level lock file to allow another process to run (if the execution aborts (e.g. due to an error) all locks are automatically released).
at line 599
connect(array $parameters)
Instruct the database to generate a live connection
at line 622
boolean
databaseExists(string $name)
Determine if the database with the specified name exists
at line 631
array
databaseList()
Retrieves the list of all databases the user has access to
at line 647
boolean
selectDatabase(string $name, boolean $create = false, int|boolean $errorLevel = E_USER_ERROR)
Change the connection to the specified database, optionally creating the database if it doesn't exist in the current schema.
at line 672
dropSelectedDatabase()
Drop the database that this object is currently connected to.
Use with caution.
at line 685
string|null
getSelectedDatabase()
Returns the name of the currently selected database
at line 694
abstract string
now()
Return SQL expression used to represent the current date/time
at line 701
abstract string
random()
Returns the database-specific version of the random() function
at line 706
dbDataType($type)
deprecated
deprecated
at line 714
createDatabase()
deprecated
deprecated
at line 724
getConnect($parameters)
deprecated
deprecated
at line 731
prepStringForDB($string)
deprecated
deprecated
at line 739
dropDatabase()
deprecated
deprecated
at line 747
allDatabaseNames()
deprecated
deprecated
at line 755
createTable($table, $fields = null, $indexes = null, $options = null, $advancedOptions = null)
deprecated
deprecated
at line 763
alterTable($table, $newFields = null, $newIndexes = null, $alteredFields = null, $alteredIndexes = null, $alteredOptions = null, $advancedOptions = null)
deprecated
deprecated
at line 777
renameTable($oldTableName, $newTableName)
deprecated
deprecated
at line 785
createField($table, $field, $spec)
deprecated
deprecated
at line 793
renameField($tableName, $oldName, $newName)
deprecated
deprecated
at line 801
currentDatabase()
deprecated
deprecated
at line 809
fieldList($table)
deprecated
deprecated
at line 817
tableList()
deprecated
deprecated
at line 825
hasTable($tableName)
deprecated
deprecated
at line 833
enumValuesForField($tableName, $fieldName)
deprecated
deprecated
at line 841
addslashes($value)
deprecated
deprecated
at line 849
beginSchemaUpdate()
deprecated
deprecated
at line 858
endSchemaUpdate()
deprecated
deprecated
at line 867
cancelSchemaUpdate()
deprecated
deprecated
at line 875
isSchemaUpdating()
deprecated
deprecated
at line 883
doesSchemaNeedUpdating()
deprecated
deprecated
at line 891
transCreateTable($table, $options = null, $advanced_options = null)
deprecated
deprecated
at line 899
transAlterTable($table, $options, $advanced_options)
deprecated
deprecated
at line 907
transCreateField($table, $field, $schema)
deprecated
deprecated
at line 915
transCreateIndex($table, $index, $schema)
deprecated
deprecated
at line 923
transAlterField($table, $field, $schema)
deprecated
deprecated
at line 931
transAlterIndex($table, $index, $schema)
deprecated
deprecated
at line 939
requireTable($table, $fieldSchema = null, $indexSchema = null, $hasAutoIncPK = true, $options = array(), $extensions = false)
deprecated
deprecated
at line 951
dontRequireTable($table)
deprecated
deprecated
at line 959
requireIndex($table, $index, $spec)
deprecated
deprecated
at line 967
hasField($tableName, $fieldName)
deprecated
deprecated
at line 975
requireField($table, $field, $spec)
deprecated
deprecated
at line 983
dontRequireField($table, $fieldName)
deprecated
deprecated
at line 991
sqlQueryToString(SQLExpression $query, $parameters = array())
deprecated
deprecated