OC_DB

class OC_DB
This class manages the access to the database. It basically is a wrapper for
Doctrine with some adaptions.
Source:lib/private/legacy/OC_DB.php#37

Methods

public static OC_DB::prepare($query, $limit=\null, $offset=\null, $isManipulation=\null)
Prepare a SQL query
Source:

lib/private/legacy/OC_DB.php#51

Parameters:
  • $query (string) Query string
  • $limit (int | null)
  • $offset (int | null)
  • $isManipulation (bool | null)
Throws:

\OC\DatabaseException

Returns:

\OC_DB_StatementWrapper prepared SQL query

Deprecated:

21.0.0 Please use \OCP\IDBConnection::getQueryBuilder() instead

SQL query via Doctrine prepare(), needs to be execute()’d!

public static OC_DB::isManipulation($sql)
tries to guess the type of statement based on the first 10 characters
the current check allows some whitespace but does not work with IF EXISTS or other more complex statements
Source:

lib/private/legacy/OC_DB.php#76

Parameters:
  • $sql (string)
Returns:

bool

public static OC_DB::executeAudited($stmt, $parameters=[])
execute a prepared statement, on error write log and throw exception
Source:

lib/private/legacy/OC_DB.php#111

Parameters:
  • $stmt (mixed) OC_DB_StatementWrapper, an array with ‘sql’ and optionally ‘limit’ and ‘offset’ keys
  • $parameters (array)
Returns:

\OC_DB_StatementWrapper

Throws:

\OC\DatabaseException

Deprecated:

21.0.0 Please use \OCP\IDBConnection::getQueryBuilder() instead

public static OC_DB::raiseExceptionOnError($result, $message=\null)
check if a result is an error and throws an exception, works with \Doctrine\DBAL\Exception
Source:

lib/private/legacy/OC_DB.php#158

Parameters:
  • $result (mixed)
  • $message (string)
Returns:

void

Throws:

\OC\DatabaseException

public static OC_DB::getErrorMessage()
returns the error code and message as a string for logging
works with DoctrineException
Source:lib/private/legacy/OC_DB.php#174
Returns:string
public static OC_DB::tableExists($table)
Checks if a table exists in the database - the database prefix will be prepended
Source:

lib/private/legacy/OC_DB.php#186

Parameters:
  • $table (string)
Returns:

bool

Throws:

\OC\DatabaseException