ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
ilDB Class Reference

Database Wrapper. More...

+ Inheritance diagram for ilDB:
+ Collaboration diagram for ilDB:

Public Member Functions

 setDBUser ($a_user)
 Set database user. More...
 
 getDBUser ()
 Get database user. More...
 
 setDBPort ($a_port)
 Set database port. More...
 
 getDBPort ()
 Get database port. More...
 
 setDBHost ($a_host)
 Set database host. More...
 
 getDBHost ()
 Get database host. More...
 
 setDBPassword ($a_password)
 Set database password. More...
 
 getDBPassword ()
 Get database password. More...
 
 setDBName ($a_name)
 Set database name. More...
 
 getDBName ()
 Get database name. More...
 
 getDSN ()
 Get DSN. More...
 
 getDBVersion ()
 Get DB version. More...
 
 getDBType ()
 Get DSN. More...
 
 enableResultBuffering ($a_status)
 En/disable result buffering. More...
 
 initFromIniFile ($tmpClientIniFile=null)
 Init db parameters from ini file. More...
 
 connect ($a_return_false_for_error=false)
 Open the connection. More...
 
 doConnect ()
 Standard way to connect to db. More...
 
 disconnect ()
 Disconnect. More...
 
 getHostDSN ()
 Should return a valid value, if host connections are possible (connectHost) to create a new database from scratch. More...
 
 connectHost ()
 Sets up a host connection only (no specific database used). More...
 
 supportsFulltext ()
 
 supportsSlave ()
 Supports slave. More...
 
 supports ($feature)
 
 supportsTransactions ()
 
 useSlave ($a_val=true)
 Use slave. More...
 
 handleError ($a_res, $a_info="", $a_level="")
 Handle MDB2 Errors. More...
 
 raisePearError ($a_message, $a_level="")
 Raise an error. More...
 
 createDatabase ($a_name, $a_charset="utf8", $a_collation="")
 Create database. More...
 
 createTable ( $a_name, $a_definition_array, $a_drop_table=false, $a_ignore_erros=false)
 Create a new table in the database. More...
 
 dropTable ($a_name, $a_error_if_not_existing=true)
 Drop a table. More...
 
 alterTable ($a_name, $a_changes)
 Alter a table in the database This method is DEPRECATED, see http://www.ilias.de/docu/goto.php?target=pg_25354_42&client_id=docu PLEASE USE THE SPECIALIZED METHODS OF THIS CLASS TO CHANGE THE DB SCHEMA. More...
 
 addTableColumn ($a_table, $a_column, $a_attributes)
 Add table column Use this only on aleady "abstracted" tables. More...
 
 dropTableColumn ($a_table, $a_column)
 Drop table column Use this only on aleady "abstracted" tables. More...
 
 modifyTableColumn ($a_table, $a_column, $a_attributes)
 Modify a table column Use this only on aleady "abstracted" tables. More...
 
 renameTableColumn ($a_table, $a_column, $a_new_column)
 Rename a table column Use this only on aleady "abstracted" tables. More...
 
 renameTable ($a_name, $a_new_name)
 Rename a table. More...
 
 addPrimaryKey ($a_table, $a_fields)
 Add a primary key to a table. More...
 
 getPrimaryKeyIdentifier ()
 Primary key identifier. More...
 
 dropPrimaryKey ($a_table)
 Drop a primary key from a table. More...
 
 addFulltextIndex ($a_table, $a_fields, $a_name="in")
 Add fulltext index. More...
 
 isFulltextIndex ($a_table, $a_name)
 Is index a fulltext index? More...
 
 indexExistsByFields ($a_table, $a_fields)
 Check if index exists. More...
 
 dropIndexByFields ($a_table, $a_fields)
 Drop index by field(s) More...
 
 dropIndex ($a_table, $a_name="in")
 Drop an index from a table. More...
 
 addUniqueConstraint ($a_table, $a_fields, $a_name="con")
 Add a unique constraint to a table. More...
 
 dropUniqueConstraint ($a_table, $a_name="con")
 Drop a constraint from a table. More...
 
 dropUniqueConstraintByFields ($a_table, $a_fields)
 Drop constraint by field(s) More...
 
 createSequence ($a_table_name, $a_start=1)
 Create a sequence for a table. More...
 
 dropSequence ($a_table_name)
 Drop a sequence for a table. More...
 
 checkTableName ($a_name)
 Check whether a table name is valid. More...
 
 checkTableColumns ($a_cols)
 Check table columns definition. More...
 
 checkColumn ($a_col, $a_def)
 Check column definition. More...
 
 checkColumnDefinition ($a_def, $a_modify_mode=false)
 Check whether a column definition is valid. More...
 
 checkColumnName ($a_name)
 Check whether a column name is valid. More...
 
 checkIndexName ($a_name)
 Check whether an index name is valid. More...
 
 getAllowedAttributes ()
 
 constraintName ($a_table, $a_constraint)
 Determine contraint name by table name and constraint name. More...
 
 query ($sql, $a_handle_error=true)
 Query. More...
 
 queryF ($a_query, $a_types, $a_values)
 Formatted query (for SELECTS). More...
 
 manipulateF ($a_query, $a_types, $a_values)
 Formatted manupulate (for DELETE, UPDATE, INSERT). More...
 
 logStatement ($sql)
 Helper function, should usually not be called. More...
 
 setLimit ($a_limit, $a_offset=0)
 Set limit and offset for a query. More...
 
 nextId ($a_table_name)
 Get next ID for an index. More...
 
 manipulate ($sql)
 Data manipulation. More...
 
 prepare ($a_query, $a_types=null, $a_result_types=null)
 Prepare a query (SELECT) statement to be used with execute. More...
 
 prepareManip ($a_query, $a_types=null)
 Prepare a data manipulation statement to be used with execute. More...
 
 execute ($a_stmt, $a_data=null)
 Execute a query statement prepared by either prepare() or prepareManip() More...
 
 executeMultiple ($a_stmt, $a_data)
 Execute a query statement prepared by either prepare() or prepareManip() with multiple data arrays. More...
 
 insert ($a_table, $a_columns)
 Convenient method for standard insert statements, example field array: More...
 
 update ($a_table, $a_columns, $a_where)
 Convenient method for standard update statements, example field array: More...
 
 replace ($a_table, $a_pk_columns, $a_other_columns)
 Replace into method. More...
 
 fetchAssoc ($a_set)
 Fetch row as associative array from result set. More...
 
 free ($a_st)
 Free a statement / result set. More...
 
 fetchObject ($a_set)
 Fetch row as object from result set. More...
 
 numRows ($a_set)
 Fetch row as associative array from result set. More...
 
 in ($a_field, $a_values, $negate=false, $a_type="")
 Get abstract in-clause for given array. More...
 
 addTypesToArray ($a_arr, $a_type, $a_cnt)
 Adds a type x times to an array. More...
 
 now ()
 now() More...
 
 concat (array $a_values, $a_allow_null=true)
 Abstraction of SQL function CONCAT. More...
 
 substr ($a_exp, $a_pos=1, $a_len=-1)
 Substring. More...
 
 upper ($a_exp)
 Upper. More...
 
 lower ($a_exp)
 Upper. More...
 
 locate ($a_needle, $a_string, $a_start_pos=1)
 Create locate string. More...
 
 like ($a_col, $a_type, $a_value="?", $case_insensitive=true)
 Like. More...
 
 equals ($a_col, $a_value, $a_type, $a_empty_or_null=false)
 Use this only on text fields. More...
 
 equalsNot ($a_col, $a_value, $a_type, $a_empty_or_null=false)
 Use this only on text fields. More...
 
 fromUnixtime ($a_expr, $a_to_text=true)
 fromUnixtime (makes timestamp out of unix timestamp) More...
 
 unixTimestamp ()
 Unix timestamp. More...
 
 tableExists ($a_table)
 Check, whether a given table exists. More...
 
 tableColumnExists ($a_table, $a_column_name)
 Checks for the existence of a table column. More...
 
 uniqueConstraintExists ($a_table, array $a_fields)
 Checks if a unique constraint exists based on the fields of the unique constraint (not the name) More...
 
 listTables ()
 Get all tables. More...
 
 sequenceExists ($a_sequence)
 Check, whether a given sequence exists. More...
 
 listSequences ()
 Get all sequences. More...
 
 quote ($a_query, $a_type=null)
 Wrapper for quote method. More...
 
 quoteIdentifier ($a_identifier, $check_option=false)
 Quote table and field names. More...
 
 beginTransaction ()
 Begin Transaction. More...
 
 commit ()
 Commit a transaction. More...
 
 rollback ()
 Rollback a transaction. More...
 
 lockTables ($a_tables)
 Abstraction of lock table. More...
 
 unlockTables ()
 Unlock tables locked by previous lock table calls. More...
 
 autoExecute ($a_tablename, $a_fields, $a_mode=MDB2_AUTOQUERY_INSERT, $a_where=false)
 Wrapper for Pear autoExecute. More...
 
 getLastInsertId ()
 Get last insert id. More...
 
 getOne ($sql)
 getOne. More...
 
 getRow ($sql, $mode=ilDBConstants::FETCHMODE_OBJECT)
 getRow. More...
 
 setSubType ($a_value)
 Set sub type. More...
 
 getSubType ()
 Get sub type. More...
 
 migrateAllTablesToEngine ($engine=ilDBConstants::MYSQL_ENGINE_INNODB)
 
 supportsEngineMigration ()
 
 getSequenceName ($table_name)
 
 buildAtomQuery ()
 
 sanitizeMB4StringIfNotSupported ($query)
 
Parameters
$querystring to sanitize, all MB4-Characters like emojis will re replaced with ???
Returns
string sanitized query
More...
 
 doesCollationSupportMB4Strings ()
 
 cast ($a_field_name, $a_dest_type)
 
- Public Member Functions inherited from PEAR
 __construct ($error_class=null)
 Constructor. More...
 
 _PEAR ()
 Destructor (the emulated type of...). More...
 
 registerShutdownFunc ($func, $args=array())
 Use this function to register a shutdown method for static classes. More...
 
 isError ($data, $code=null)
 Tell whether a value is a PEAR error. More...
 
 expectError ($code=' *')
 This method is used to tell which errors you expect to get. More...
 
 popExpect ()
 This method pops one element off the expected error codes stack. More...
 
 _checkDelExpect ($error_code)
 This method checks unsets an error code if available. More...
 
 delExpect ($error_code)
 This method deletes all occurences of the specified element from the expected error codes stack. More...
 
raiseError ($message=null, $code=null, $mode=null, $options=null, $userinfo=null, $error_class=null, $skipmsg=false)
 This method is a wrapper that returns an instance of the configured error class with this object's default error handling applied. More...
 
throwError ($message=null, $code=null, $userinfo=null)
 Simpler form of raiseError with fewer options. More...
 
 staticPushErrorHandling ($mode, $options=null)
 
 staticPopErrorHandling ()
 
 pushErrorHandling ($mode, $options=null)
 Push a new error handler on top of the error handler options stack. More...
 
 popErrorHandling ()
 Pop the last error handler used. More...
 
 loadExtension ($ext)
 OS independant PHP extension load. More...
 
- Public Member Functions inherited from ilDBInterface
 query ($query)
 Run a (read-only) Query on the database. More...
 
 fetchAll ($query_result, $fetch_mode=ilDBConstants::FETCHMODE_ASSOC)
 
 addIndex ($table_name, $fields, $index_name='', $fulltext=false)
 
 substr ($a_exp)
 
 loadModule ($module)
 
 dropFulltextIndex ($a_table, $a_name)
 
 setStorageEngine ($storage_engine)
 
 getStorageEngine ()
 
 groupConcat ($a_field_name, $a_seperator=",", $a_order=null)
 

Static Public Member Functions

static getReservedWords ()
 Get reserved words. More...
 
static isDbError ($a_res)
 Check error. More...
 
static isReservedWord ($a_word)
 Checks whether a word is a reserved word in one of the supported databases. More...
 
- Static Public Member Functions inherited from PEAR
static & getStaticProperty ($class, $var)
 If you have a class that's mostly/entirely static, and you need static properties, you can use this method to simulate them. More...
 
static setErrorHandling ($mode=null, $options=null)
 Sets how errors generated by this object should be handled. More...
 

Data Fields

const LOCK_WRITE = 1
 
const LOCK_READ = 2
 
 $error_class
 
 $db
 
 $result
 
 $allowed_attributes
 
 $sub_type
 
- Data Fields inherited from PEAR
 $_debug = false
 
 $_default_error_mode = null
 
 $_default_error_options = null
 
 $_default_error_handler = ''
 
 $_error_class = 'PEAR_Error'
 
 $_expected_errors = array()
 

Protected Member Functions

 initConnection ()
 Initialize the database connection. More...
 
 initHostConnection ()
 Initialize the host connection (no specific database) More...
 
 loadMDB2Extensions ()
 load additional mdb2 extensions and set their constants More...
 
 getCreateTableOptions ()
 Get options for the create table statement. More...
 

Detailed Description

Database Wrapper.

this class should extend PEAR::DB, add error Management in case of a db-error in any database query the ilDB-class raises an error

Author
Peter Gabriel peter.nosp@m.@gab.nosp@m.riel-.nosp@m.onli.nosp@m.ne.ne.nosp@m.t
Alex Killing alex..nosp@m.kill.nosp@m.ing@g.nosp@m.mx.d.nosp@m.e
Version
$Id$

Definition at line 29 of file class.ilDB.php.

Member Function Documentation

◆ addFulltextIndex()

ilDB::addFulltextIndex (   $a_table,
  $a_fields,
  $a_name = "in" 
)

Add fulltext index.

Implements ilDBInterface.

Definition at line 929 of file class.ilDB.php.

Referenced by dropPrimaryKey().

930  {
931  return false;
932  }
+ Here is the caller graph for this function:

◆ addPrimaryKey()

ilDB::addPrimaryKey (   $a_table,
  $a_fields 
)

Add a primary key to a table.

Parameters
stringtable name
arrayfields for primary key
stringkey name

Implements ilDBInterface.

Definition at line 839 of file class.ilDB.php.

References $r, array, constraintName(), getPrimaryKeyIdentifier(), and handleError().

840  {
841  $manager = $this->db->loadModule('Manager');
842 
843  $fields = array();
844  foreach ($a_fields as $f) {
845  $fields[$f] = array();
846  }
847  $definition = array(
848  'primary' => true,
849  'fields' => $fields
850  );
851  $r = $manager->createConstraint(
852  $a_table,
853  $this->constraintName($a_table, $this->getPrimaryKeyIdentifier()),
854  $definition
855  );
856 
857  return $this->handleError($r, "addPrimaryKey(" . $a_table . ")");
858  }
$r
Definition: example_031.php:79
handleError($a_res, $a_info="", $a_level="")
Handle MDB2 Errors.
Definition: class.ilDB.php:423
Create styles array
The data for the language used.
constraintName($a_table, $a_constraint)
Determine contraint name by table name and constraint name.
getPrimaryKeyIdentifier()
Primary key identifier.
Definition: class.ilDB.php:863
+ Here is the call graph for this function:

◆ addTableColumn()

ilDB::addTableColumn (   $a_table,
  $a_column,
  $a_attributes 
)

Add table column Use this only on aleady "abstracted" tables.

Parameters
stringtable name
stringcolumn name
arrayattributes array("length" => 10, "default" => "t")

Implements ilDBInterface.

Definition at line 637 of file class.ilDB.php.

References $r, array, checkColumnDefinition(), checkColumnName(), handleError(), and raisePearError().

638  {
639  $manager = $this->db->loadModule('Manager');
640 
641  if (!$this->checkColumnName($a_column)) {
642  $this->raisePearError("ilDB Error: addTableColumn(" . $a_table . ", " . $a_column . ")<br />" .
643  $this->error_str);
644  }
645  if (!$this->checkColumnDefinition($a_attributes)) {
646  $this->raisePearError("ilDB Error: addTableColumn(" . $a_table . ", " . $a_column . ")<br />" .
647  $this->error_str);
648  }
649 
650  $changes = array(
651  "add" => array(
652  $a_column => $a_attributes
653  )
654  );
655 
656  $r = $manager->alterTable($a_table, $changes, false);
657 
658  return $this->handleError($r, "addTableColumn(" . $a_table . ", " . $a_column . ")");
659  }
raisePearError($a_message, $a_level="")
Raise an error.
Definition: class.ilDB.php:460
checkColumnDefinition($a_def, $a_modify_mode=false)
Check whether a column definition is valid.
$r
Definition: example_031.php:79
checkColumnName($a_name)
Check whether a column name is valid.
handleError($a_res, $a_info="", $a_level="")
Handle MDB2 Errors.
Definition: class.ilDB.php:423
Create styles array
The data for the language used.
+ Here is the call graph for this function:

◆ addTypesToArray()

ilDB::addTypesToArray (   $a_arr,
  $a_type,
  $a_cnt 
)

Adds a type x times to an array.

Definition at line 1798 of file class.ilDB.php.

References $a_type, and array.

1799  {
1800  if (!is_array($a_arr)) {
1801  $a_arr = array();
1802  }
1803  if ($a_cnt > 0) {
1804  $type_arr = array_fill(0, $a_cnt, $a_type);
1805  } else {
1806  $type_arr = array();
1807  }
1808  return array_merge($a_arr, $type_arr);
1809  }
$a_type
Definition: workflow.php:92
Create styles array
The data for the language used.

◆ addUniqueConstraint()

ilDB::addUniqueConstraint (   $a_table,
  $a_fields,
  $a_name = "con" 
)

Add a unique constraint to a table.

Parameters
stringtable name
arrayfields being unique
stringindex name

Definition at line 1015 of file class.ilDB.php.

References $r, array, checkIndexName(), constraintName(), handleError(), and raisePearError().

1016  {
1017  $manager = $this->db->loadModule('Manager');
1018 
1019  // check index name
1020  if (!$this->checkIndexName($a_name)) {
1021  $this->raisePearError("ilDB Error: addUniqueConstraint(" . $a_table . "," . $a_name . ")<br />" .
1022  $this->error_str);
1023  }
1024 
1025  $fields = array();
1026  foreach ($a_fields as $f) {
1027  $fields[$f] = array();
1028  }
1029  $definition = array(
1030  'unique' => true,
1031  'fields' => $fields
1032  );
1033 
1034  $r = $manager->createConstraint($a_table, $this->constraintName($a_table, $a_name), $definition);
1035 
1036  return $this->handleError($r, "addUniqueConstraint(" . $a_table . ")");
1037  }
raisePearError($a_message, $a_level="")
Raise an error.
Definition: class.ilDB.php:460
checkIndexName($a_name)
Check whether an index name is valid.
$r
Definition: example_031.php:79
handleError($a_res, $a_info="", $a_level="")
Handle MDB2 Errors.
Definition: class.ilDB.php:423
Create styles array
The data for the language used.
constraintName($a_table, $a_constraint)
Determine contraint name by table name and constraint name.
+ Here is the call graph for this function:

◆ alterTable()

ilDB::alterTable (   $a_name,
  $a_changes 
)

Alter a table in the database This method is DEPRECATED, see http://www.ilias.de/docu/goto.php?target=pg_25354_42&client_id=docu PLEASE USE THE SPECIALIZED METHODS OF THIS CLASS TO CHANGE THE DB SCHEMA.

Definition at line 617 of file class.ilDB.php.

References $r, array, and handleError().

618  {
619  if ($a_options == "") {
620  $a_options = array();
621  }
622 
623  $manager = $this->db->loadModule('Manager');
624  $r = $manager->alterTable($a_name, $a_changes, false);
625 
626  return $this->handleError($r, "alterTable(" . $a_name . ")");
627  }
$r
Definition: example_031.php:79
handleError($a_res, $a_info="", $a_level="")
Handle MDB2 Errors.
Definition: class.ilDB.php:423
Create styles array
The data for the language used.
+ Here is the call graph for this function:

◆ autoExecute()

ilDB::autoExecute (   $a_tablename,
  $a_fields,
  $a_mode = MDB2_AUTOQUERY_INSERT,
  $a_where = false 
)

Wrapper for Pear autoExecute.

Parameters
stringtablename
arrayfields values
intMDB2_AUTOQUERY_INSERT or MDB2_AUTOQUERY_UPDATE
stringwhere condition (e.g. "obj_id = '7' AND ref_id = '5'")
Returns
mixed a new DB_result/DB_OK or a DB_Error, if fail

Definition at line 2233 of file class.ilDB.php.

References $res, and handleError().

2234  {
2235  $res = $this->db->autoExecute($a_tablename, $a_fields, $a_mode, $a_where);
2236 
2237  return $this->handleError($res, "autoExecute(" . $a_tablename . ")");
2238  }
foreach($_POST as $key=> $value) $res
handleError($a_res, $a_info="", $a_level="")
Handle MDB2 Errors.
Definition: class.ilDB.php:423
+ Here is the call graph for this function:

◆ beginTransaction()

ilDB::beginTransaction ( )

Begin Transaction.

Please note that we currently do not use savepoints.

Returns
boolean MDB2_OK on success

Implements ilDBInterface.

Definition at line 2173 of file class.ilDB.php.

References $res, handleError(), and raisePearError().

2174  {
2175  if (!$this->db->supports('transactions')) {
2176  $this->raisePearError("ilDB::beginTransaction: Transactions are not supported.", $this->error_class->FATAL);
2177  }
2178  $res = $this->db->beginTransaction();
2179 
2180  return $this->handleError($res, "beginTransaction()");
2181  }
raisePearError($a_message, $a_level="")
Raise an error.
Definition: class.ilDB.php:460
foreach($_POST as $key=> $value) $res
handleError($a_res, $a_info="", $a_level="")
Handle MDB2 Errors.
Definition: class.ilDB.php:423
+ Here is the call graph for this function:

◆ buildAtomQuery()

ilDB::buildAtomQuery ( )
Returns

Implements ilDBInterface.

Definition at line 2373 of file class.ilDB.php.

2374  {
2375  require_once('./Services/Database/classes/Atom/class.ilAtomQueryLock.php');
2376 
2377  return new ilAtomQueryLock($this);
2378  }
Class ilAtomQueryLock.

◆ cast()

ilDB::cast (   $a_field_name,
  $a_dest_type 
)

Implements ilDBInterface.

Definition at line 2413 of file class.ilDB.php.

2414  {
2415  $manager = $this->db->loadModule('Manager');
2416  return $manager->getQueryUtils()->cast($a_field_name, $a_dest_type);
2417  }

◆ checkColumn()

ilDB::checkColumn (   $a_col,
  $a_def 
)

Check column definition.

Definition at line 1164 of file class.ilDB.php.

References checkColumnDefinition(), and checkColumnName().

Referenced by checkTableColumns().

1165  {
1166  if (!$this->checkColumnName($a_col)) {
1167  return false;
1168  }
1169 
1170  if (!$this->checkColumnDefinition($a_def)) {
1171  return false;
1172  }
1173 
1174  return true;
1175  }
checkColumnDefinition($a_def, $a_modify_mode=false)
Check whether a column definition is valid.
checkColumnName($a_name)
Check whether a column name is valid.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ checkColumnDefinition()

ilDB::checkColumnDefinition (   $a_def,
  $a_modify_mode = false 
)

Check whether a column definition is valid.

Parameters
arraydefinition array

Definition at line 1182 of file class.ilDB.php.

References $allowed_attributes, and array.

Referenced by addTableColumn(), checkColumn(), and modifyTableColumn().

1183  {
1184  // check valid type
1185  if (!in_array($a_def["type"], array("text", "integer", "float", "date", "time", "timestamp", "clob", "blob"))) {
1186  switch ($a_def["type"]) {
1187  case "boolean":
1188  $this->error_str = "Invalid column type '" . $a_def["type"] . "'. Use integer(1) instead.";
1189  break;
1190 
1191  case "decimal":
1192  $this->error_str = "Invalid column type '" . $a_def["type"] . "'. Use float or integer instead.";
1193  break;
1194 
1195  default:
1196  $this->error_str = "Invalid column type '" . $a_def["type"] . "'. Allowed types are: " .
1197  "text, integer, float, date, time, timestamp, clob and blob.";
1198  }
1199  }
1200 
1201  // check used attributes
1203 
1204  foreach ($a_def as $k => $v) {
1205  if ($k != "type" && !in_array($k, $allowed_attributes[$a_def["type"]])) {
1206  $this->error_str = "Attribute '" . $k . "' is not allowed for column type '" . $a_def["type"] . "'.";
1207  return false;
1208  }
1209  }
1210 
1211  // type specific checks
1212  switch ($a_def["type"]) {
1213  case "text":
1214  if ($a_def["length"] < 1 || $a_def["length"] > 4000) {
1215  if (!$a_modify_mode || isset($a_def["length"])) {
1216  $this->error_str = "Invalid length '" . $a_def["length"] . "' for type text." .
1217  " Length must be >=1 and <= 4000.";
1218  return false;
1219  }
1220  }
1221  break;
1222 
1223  case "integer":
1224  if (!in_array($a_def["length"], array(1, 2, 3, 4, 8))) {
1225  if (!$a_modify_mode || isset($a_def["length"])) {
1226  $this->error_str = "Invalid length '" . $a_def["length"] . "' for type integer." .
1227  " Length must be 1, 2, 3, 4 or 8 (bytes).";
1228  return false;
1229  }
1230  }
1231  if ($a_def["unsigned"]) {
1232  $this->error_str = "Unsigned attribut must not be true for type integer.";
1233  return false;
1234  }
1235  break;
1236  }
1237 
1238  return true;
1239  }
$allowed_attributes
Definition: class.ilDB.php:55
Create styles array
The data for the language used.
+ Here is the caller graph for this function:

◆ checkColumnName()

ilDB::checkColumnName (   $a_name)

Check whether a column name is valid.

Parameters
string$a_name

Definition at line 1246 of file class.ilDB.php.

References isReservedWord(), and substr().

Referenced by addTableColumn(), checkColumn(), and renameTableColumn().

1247  {
1248  if (!preg_match("/^[a-z]+[_a-z0-9]*$/", $a_name)) {
1249  $this->error_str = "Invalid column name '" . $a_name . "'. Column name must only contain _a-z0-9 and must start with a-z.";
1250  return false;
1251  }
1252 
1253  if ($this->isReservedWord($a_name)) {
1254  $this->error_str = "Invalid column name '" . $a_name . "' (Reserved Word).";
1255  return false;
1256  }
1257 
1258  if (strtolower(substr($a_name, 0, 4)) == "sys_") {
1259  $this->error_str = "Invalid column name '" . $a_name . "'. Name must not start with 'sys_'.";
1260  return false;
1261  }
1262 
1263  if (strlen($a_name) > 30) {
1264  $this->error_str = "Invalid column name '" . $a_name . "'. Maximum column identifer length is 30 bytes.";
1265  return false;
1266  }
1267 
1268  return true;
1269  }
substr($a_exp, $a_pos=1, $a_len=-1)
Substring.
static isReservedWord($a_word)
Checks whether a word is a reserved word in one of the supported databases.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ checkIndexName()

ilDB::checkIndexName (   $a_name)

Check whether an index name is valid.

Parameters
string$a_name

Definition at line 1276 of file class.ilDB.php.

References isReservedWord().

Referenced by addUniqueConstraint(), and dropPrimaryKey().

1277  {
1278  if (!preg_match("/^[a-z]+[_a-z0-9]*$/", $a_name)) {
1279  $this->error_str = "Invalid column name '" . $a_name . "'. Column name must only contain _a-z0-9 and must start with a-z.";
1280  return false;
1281  }
1282 
1283  if ($this->isReservedWord($a_name)) {
1284  $this->error_str = "Invalid column name '" . $a_name . "' (Reserved Word).";
1285  return false;
1286  }
1287 
1288  if (strlen($a_name) > 3) {
1289  $this->error_str = "Invalid index name '" . $a_name . "'. Maximum index identifer length is 3 bytes.";
1290  return false;
1291  }
1292 
1293  return true;
1294  }
static isReservedWord($a_word)
Checks whether a word is a reserved word in one of the supported databases.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ checkTableColumns()

ilDB::checkTableColumns (   $a_cols)

Check table columns definition.

Parameters
arraydefinition array

Definition at line 1150 of file class.ilDB.php.

References $def, and checkColumn().

Referenced by createTable().

1151  {
1152  foreach ($a_cols as $col => $def) {
1153  if (!$this->checkColumn($col, $def)) {
1154  return false;
1155  }
1156  }
1157 
1158  return true;
1159  }
$def
Definition: croninfo.php:21
checkColumn($a_col, $a_def)
Check column definition.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ checkTableName()

ilDB::checkTableName (   $a_name)

Check whether a table name is valid.

Parameters
string$a_name

Implements ilDBInterface.

Definition at line 1120 of file class.ilDB.php.

References isReservedWord(), and substr().

Referenced by createTable(), and renameTable().

1121  {
1122  if (!preg_match("/^[a-z]+[_a-z0-9]*$/", $a_name)) {
1123  $this->error_str = "Table name must only contain _a-z0-9 and must start with a-z.";
1124  return false;
1125  }
1126 
1127  if ($this->isReservedWord($a_name)) {
1128  $this->error_str = "Invalid table name '" . $a_name . "' (Reserved Word).";
1129  return false;
1130  }
1131 
1132  if (strtolower(substr($a_name, 0, 4)) == "sys_") {
1133  $this->error_str = "Invalid table name '" . $a_name . "'. Name must not start with 'sys_'.";
1134  return false;
1135  }
1136 
1137  if (strlen($a_name) > 22) {
1138  $this->error_str = "Invalid table name '" . $a_name . "'. Maximum table identifer length is 22 bytes.";
1139  return false;
1140  }
1141 
1142  return true;
1143  }
substr($a_exp, $a_pos=1, $a_len=-1)
Substring.
static isReservedWord($a_word)
Checks whether a word is a reserved word in one of the supported databases.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ commit()

ilDB::commit ( )

Commit a transaction.

Implements ilDBInterface.

Definition at line 2186 of file class.ilDB.php.

References $res, and handleError().

2187  {
2188  $res = $this->db->commit();
2189 
2190  return $this->handleError($res, "commit()");
2191  }
foreach($_POST as $key=> $value) $res
handleError($a_res, $a_info="", $a_level="")
Handle MDB2 Errors.
Definition: class.ilDB.php:423
+ Here is the call graph for this function:

◆ concat()

ilDB::concat ( array  $a_values,
  $a_allow_null = true 
)

Abstraction of SQL function CONCAT.

Parameters
array$a_valuesarray( array('title','text'), array('description','clob'), array('some text','text');
bool$a_allow_null
Returns

Implements ilDBInterface.

Definition at line 1830 of file class.ilDB.php.

1831  {
1832  if (!count($a_values)) {
1833  return ' ';
1834  }
1835 
1836  $concat = ' CONCAT(';
1837  $first = true;
1838  foreach ($a_values as $field_info) {
1839  $val = $field_info[0];
1840 
1841  if (!$first) {
1842  $concat .= ',';
1843  }
1844 
1845  if ($a_allow_null) {
1846  $concat .= 'COALESCE(';
1847  }
1848  $concat .= $val;
1849 
1850  if ($a_allow_null) {
1851  $concat .= ",''";
1852  $concat .= ')';
1853  }
1854 
1855  $first = false;
1856  }
1857  $concat .= ') ';
1858  return $concat;
1859  }

◆ connect()

ilDB::connect (   $a_return_false_for_error = false)

Open the connection.

Implements ilDBInterface.

Definition at line 234 of file class.ilDB.php.

References array, doConnect(), getDSN(), handleError(), initConnection(), isDbError(), MDB2\isError(), loadMDB2Extensions(), MDB2_PORTABILITY_ALL, PEAR_ERROR_CALLBACK, raisePearError(), and PEAR\setErrorHandling().

235  {
236  //set up error handling
237  $this->error_class = new ilErrorHandling();
238  $this->setErrorHandling(PEAR_ERROR_CALLBACK, array($this->error_class,'errorHandler'));
239  //echo $this->getDSN();
240  //check dsn
241  if ($this->getDSN() == "") {
242  $this->raisePearError("No DSN given");
243  }
244 
245  //connect to database
246  $this->doConnect();
247 
248  if ($a_return_false_for_error && MDB2::isError($this->db)) {
249  return false;
250  }
251 
252  $this->loadMDB2Extensions();
253 
254  // set empty value portability to PEAR::DB behaviour
255  if (!$this->isDbError($this->db)) {
256  $this->db->setOption('portability', MDB2_PORTABILITY_ALL);
257  }
258  //check error
259  $this->handleError($this->db);
260 
261  // anything, that must be done to initialize the connection
262  $this->initConnection();
263 
264  return true;
265  }
raisePearError($a_message, $a_level="")
Raise an error.
Definition: class.ilDB.php:460
const PEAR_ERROR_CALLBACK
Definition: PEAR.php:35
isError($data, $code=null)
Tell whether a value is a MDB2 error.
Definition: MDB2.php:599
static setErrorHandling($mode=null, $options=null)
Sets how errors generated by this object should be handled.
Definition: PEAR.php:337
doConnect()
Standard way to connect to db.
Definition: class.ilDB.php:270
initConnection()
Initialize the database connection.
Definition: class.ilDB.php:293
const MDB2_PORTABILITY_ALL
Portability: turn on all portability features.
Definition: MDB2.php:215
handleError($a_res, $a_info="", $a_level="")
Handle MDB2 Errors.
Definition: class.ilDB.php:423
loadMDB2Extensions()
load additional mdb2 extensions and set their constants
Definition: class.ilDB.php:474
getDSN()
Get DSN.
Create styles array
The data for the language used.
static isDbError($a_res)
Check error.
Definition: class.ilDB.php:488
+ Here is the call graph for this function:

◆ connectHost()

ilDB::connectHost ( )

Sets up a host connection only (no specific database used).

This is optional during the setup procudure to create databases from scratch.

Definition at line 312 of file class.ilDB.php.

References array, MDB2\connect(), getHostDSN(), handleError(), initHostConnection(), isDbError(), MDB2\isError(), loadMDB2Extensions(), MDB2_PORTABILITY_EMPTY_TO_NULL, MDB2_PORTABILITY_FIX_CASE, PEAR_ERROR_CALLBACK, raisePearError(), and PEAR\setErrorHandling().

313  {
314  //set up error handling
315  $this->error_class = new ilErrorHandling();
316  $this->setErrorHandling(PEAR_ERROR_CALLBACK, array($this->error_class,'errorHandler'));
317 
318  //check dsn
319  if ($this->getHostDSN() == "") {
320  $this->raisePearError("No Host DSN given");
321  }
322 
323  //connect to database
324  $this->db = MDB2::connect(
325  $this->getHostDSN(),
326  array("use_transactions" => true)
327  );
328  if ($a_return_false_for_error && MDB2::isError($this->db)) {
329  return false;
330  }
331 
332  $this->loadMDB2Extensions();
333 
334  // set empty value portability to PEAR::DB behaviour
335  if (!$this->isDbError($this->db)) {
336  $cur = ($this->db->getOption("portability") & MDB2_PORTABILITY_EMPTY_TO_NULL);
337  $this->db->setOption("portability", $this->db->getOption("portability") - $cur);
338 
339  $cur = ($this->db->getOption("portability") & MDB2_PORTABILITY_FIX_CASE);
340  $this->db->setOption("portability", $this->db->getOption("portability") - $cur);
341  }
342 
343  //check error
344  $this->handleError($this->db);
345 
346  // anything, that must be done to initialize the connection
347  $this->initHostConnection();
348 
349  return true;
350  }
raisePearError($a_message, $a_level="")
Raise an error.
Definition: class.ilDB.php:460
const PEAR_ERROR_CALLBACK
Definition: PEAR.php:35
isError($data, $code=null)
Tell whether a value is a MDB2 error.
Definition: MDB2.php:599
const MDB2_PORTABILITY_EMPTY_TO_NULL
Portability: convert empty values to null strings in data output by query*() and fetch*().
Definition: MDB2.php:203
static setErrorHandling($mode=null, $options=null)
Sets how errors generated by this object should be handled.
Definition: PEAR.php:337
& connect($dsn, $options=false)
Create a new MDB2 connection object and connect to the specified database.
Definition: MDB2.php:436
initHostConnection()
Initialize the host connection (no specific database)
Definition: class.ilDB.php:355
handleError($a_res, $a_info="", $a_level="")
Handle MDB2 Errors.
Definition: class.ilDB.php:423
loadMDB2Extensions()
load additional mdb2 extensions and set their constants
Definition: class.ilDB.php:474
Create styles array
The data for the language used.
getHostDSN()
Should return a valid value, if host connections are possible (connectHost) to create a new database ...
Definition: class.ilDB.php:303
const MDB2_PORTABILITY_FIX_CASE
Portability: convert names of tables and fields to case defined in the "field_case" option when using...
Definition: MDB2.php:163
static isDbError($a_res)
Check error.
Definition: class.ilDB.php:488
+ Here is the call graph for this function:

◆ constraintName()

ilDB::constraintName (   $a_table,
  $a_constraint 
)

Determine contraint name by table name and constraint name.

In MySQL these are "unique" per table, but they must be "globally" unique in oracle. (so this one is overwritten there)

Implements ilDBInterface.

Definition at line 1306 of file class.ilDB.php.

Referenced by ilDBMySQL\addFulltextIndex(), addPrimaryKey(), addUniqueConstraint(), ilDBMySQL\dropFulltextIndex(), dropIndex(), dropPrimaryKey(), and dropUniqueConstraint().

1307  {
1308  return $a_constraint;
1309  }
+ Here is the caller graph for this function:

◆ createDatabase()

ilDB::createDatabase (   $a_name,
  $a_charset = "utf8",
  $a_collation = "" 
)

Create database.

Implements ilDBInterface.

Definition at line 500 of file class.ilDB.php.

References query().

501  {
502  if ($a_collation != "") {
503  $sql = "CREATE DATABASE " . $a_name .
504  " CHARACTER SET " . $a_charset .
505  " COLLATE " . $a_collation;
506  } else {
507  $sql = "CREATE DATABASE " . $a_name .
508  " CHARACTER SET " . $a_charset;
509  }
510 
511  return $this->query($sql, false);
512  }
query($sql, $a_handle_error=true)
Query.
+ Here is the call graph for this function:

◆ createSequence()

ilDB::createSequence (   $a_table_name,
  $a_start = 1 
)

Create a sequence for a table.

Implements ilDBInterface.

Definition at line 1093 of file class.ilDB.php.

References $r, and handleError().

1094  {
1095  $manager = $this->db->loadModule('Manager');
1096 
1097  $r = $manager->createSequence($a_table_name, $a_start);
1098 
1099  return $this->handleError($r, "createSequence(" . $a_table_name . ")");
1100  }
$r
Definition: example_031.php:79
handleError($a_res, $a_info="", $a_level="")
Handle MDB2 Errors.
Definition: class.ilDB.php:423
+ Here is the call graph for this function:

◆ createTable()

ilDB::createTable (   $a_name,
  $a_definition_array,
  $a_drop_table = false,
  $a_ignore_erros = false 
)

Create a new table in the database.

Parameters
stringtable name
arraydefinition array: array("col1" => array("type" => "text", ...))
booleandrop table automatically, if it already exists

Implements ilDBInterface.

Definition at line 522 of file class.ilDB.php.

References $options, $r, checkTableColumns(), checkTableName(), dropTable(), getCreateTableOptions(), handleError(), and raisePearError().

527  {
528  // check table name
529  if (!$this->checkTableName($a_name) && !$a_ignore_erros) {
530  $this->raisePearError("ilDB Error: createTable(" . $a_name . ")<br />" .
531  $this->error_str);
532  }
533 
534  // check definition array
535  if (!$this->checkTableColumns($a_definition_array) && !$a_ignore_erros) {
536  $this->raisePearError("ilDB Error: createTable(" . $a_name . ")<br />" .
537  $this->error_str);
538  }
539 
540  if ($a_drop_table) {
541  $this->dropTable($a_name, false);
542  }
543 
544  $options = $this->getCreateTableOptions();
545 
546  $manager = $this->db->loadModule('Manager');
547  $r = $manager->createTable($a_name, $a_definition_array, $options);
548 
549  return $this->handleError($r, "createTable(" . $a_name . ")");
550  }
raisePearError($a_message, $a_level="")
Raise an error.
Definition: class.ilDB.php:460
checkTableColumns($a_cols)
Check table columns definition.
dropTable($a_name, $a_error_if_not_existing=true)
Drop a table.
Definition: class.ilDB.php:568
$r
Definition: example_031.php:79
checkTableName($a_name)
Check whether a table name is valid.
handleError($a_res, $a_info="", $a_level="")
Handle MDB2 Errors.
Definition: class.ilDB.php:423
getCreateTableOptions()
Get options for the create table statement.
Definition: class.ilDB.php:557
if(!isset($_REQUEST['ReturnTo'])) if(!isset($_REQUEST['AuthId'])) $options
Definition: as_login.php:20
+ Here is the call graph for this function:

◆ disconnect()

ilDB::disconnect ( )

Disconnect.

Definition at line 281 of file class.ilDB.php.

282  {
283  $this->db->disconnect();
284  }

◆ doConnect()

ilDB::doConnect ( )

Standard way to connect to db.

Definition at line 270 of file class.ilDB.php.

References array, MDB2\connect(), and getDSN().

Referenced by connect().

271  {
272  $this->db = MDB2::connect(
273  $this->getDSN(),
274  array("use_transactions" => true)
275  );
276  }
& connect($dsn, $options=false)
Create a new MDB2 connection object and connect to the specified database.
Definition: MDB2.php:436
getDSN()
Get DSN.
Create styles array
The data for the language used.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ doesCollationSupportMB4Strings()

ilDB::doesCollationSupportMB4Strings ( )

Implements ilDBInterface.

Definition at line 2404 of file class.ilDB.php.

Referenced by sanitizeMB4StringIfNotSupported().

2405  {
2406  return false;
2407  }
+ Here is the caller graph for this function:

◆ dropIndex()

ilDB::dropIndex (   $a_table,
  $a_name = "in" 
)

Drop an index from a table.

Note: The index must have been created using MDB2

Parameters
stringtable name
stringindex name

Implements ilDBInterface.

Definition at line 995 of file class.ilDB.php.

References $r, constraintName(), ilDBInterface\dropFulltextIndex(), handleError(), and isFulltextIndex().

Referenced by dropIndexByFields().

996  {
997  $manager = $this->db->loadModule('Manager');
998 
999  if (!$this->isFulltextIndex($a_table, $a_name)) {
1000  $r = $manager->dropIndex($a_table, $this->constraintName($a_table, $a_name));
1001  } else {
1002  $this->dropFulltextIndex($a_table, $a_name);
1003  }
1004 
1005  return $this->handleError($r, "dropIndex(" . $a_table . ")");
1006  }
isFulltextIndex($a_table, $a_name)
Is index a fulltext index?
Definition: class.ilDB.php:937
$r
Definition: example_031.php:79
handleError($a_res, $a_info="", $a_level="")
Handle MDB2 Errors.
Definition: class.ilDB.php:423
constraintName($a_table, $a_constraint)
Determine contraint name by table name and constraint name.
dropFulltextIndex($a_table, $a_name)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ dropIndexByFields()

ilDB::dropIndexByFields (   $a_table,
  $a_fields 
)

Drop index by field(s)

Parameters
type$a_table
type$a_fields
Returns
boolean

Implements ilDBInterface.

Definition at line 971 of file class.ilDB.php.

References $def, array, and dropIndex().

972  {
973  $manager = $this->db->loadModule('Manager');
974  $reverse = $this->db->loadModule('Reverse');
975  if ($manager) {
976  foreach ($manager->listTableIndexes($a_table) as $idx_name) {
977  $def = $reverse->getTableIndexDefinition($a_table, $idx_name);
978  $idx_fields = array_keys((array) $def['fields']);
979 
980  if ($idx_fields === $a_fields) {
981  return $this->dropIndex($a_table, $idx_name);
982  }
983  }
984  }
985  return false;
986  }
dropIndex($a_table, $a_name="in")
Drop an index from a table.
Definition: class.ilDB.php:995
Create styles array
The data for the language used.
$def
Definition: croninfo.php:21
+ Here is the call graph for this function:

◆ dropPrimaryKey()

ilDB::dropPrimaryKey (   $a_table)

Drop a primary key from a table.

Parameters
stringtable name
stringkey name

Definition at line 874 of file class.ilDB.php.

References $r, addFulltextIndex(), ilDBInterface\addIndex(), array, checkIndexName(), constraintName(), getPrimaryKeyIdentifier(), handleError(), raisePearError(), and supportsFulltext().

875  {
876  $manager = $this->db->loadModule('Manager');
877 
878  $r = $manager->dropConstraint(
879  $a_table,
880  $this->constraintName($a_table, $this->getPrimaryKeyIdentifier()),
881  true
882  );
883 
884  return $this->handleError($r, "dropPrimaryKey(" . $a_table . ")");
885  }
$r
Definition: example_031.php:79
handleError($a_res, $a_info="", $a_level="")
Handle MDB2 Errors.
Definition: class.ilDB.php:423
constraintName($a_table, $a_constraint)
Determine contraint name by table name and constraint name.
getPrimaryKeyIdentifier()
Primary key identifier.
Definition: class.ilDB.php:863
+ Here is the call graph for this function:

◆ dropSequence()

ilDB::dropSequence (   $a_table_name)

Drop a sequence for a table.

Implements ilDBInterface.

Definition at line 1106 of file class.ilDB.php.

References $r, and handleError().

1107  {
1108  $manager = $this->db->loadModule('Manager');
1109 
1110  $r = $manager->dropSequence($a_table_name);
1111 
1112  return $this->handleError($r, "dropSequence(" . $a_table_name . ")");
1113  }
$r
Definition: example_031.php:79
handleError($a_res, $a_info="", $a_level="")
Handle MDB2 Errors.
Definition: class.ilDB.php:423
+ Here is the call graph for this function:

◆ dropTable()

ilDB::dropTable (   $a_name,
  $a_error_if_not_existing = true 
)

Drop a table.

Parameters
stringtable name
booleanraise an error, if table not exists

Implements ilDBInterface.

Definition at line 568 of file class.ilDB.php.

References $i, $r, getDBType(), handleError(), listTables(), and substr().

Referenced by createTable().

569  {
570  if (!$a_error_if_not_existing) {
571  $tables = $this->listTables();
572  if (!in_array($a_name, $tables)) {
573  return;
574  }
575  }
576 
577  $manager = $this->db->loadModule('Manager');
578 
579  if ($this->getDBType() == "oracle") {
580  // drop table constraints
581  $constraints = $manager->listTableConstraints($a_name);
582  $this->handleError($constraints, "dropTable(" . $a_name . "), listTableConstraints");
583  foreach ($constraints as $c) {
584  if (substr($c, 0, 4) != "sys_") {
585  $r = $manager->dropConstraint($a_name, $c);
586  $this->handleError($r, "dropTable(" . $a_name . "), dropConstraint");
587  }
588  }
589 
590  // drop table indexes
591  $indexes = $manager->listTableIndexes($a_name);
592  $this->handleError($indexes, "dropTable(" . $a_name . "), listTableIndexes");
593  foreach ($indexes as $i) {
594  $r = $manager->dropIndex($a_name, $i);
595  $this->handleError($r, "dropTable(" . $a_name . "), dropIndex");
596  }
597  }
598 
599  // drop sequence
600  $seqs = $manager->listSequences();
601  if (in_array($a_name, $seqs)) {
602  $r = $manager->dropSequence($a_name);
603  $this->handleError($r, "dropTable(" . $a_name . "), dropSequence");
604  }
605 
606  // drop table
607  $r = $manager->dropTable($a_name);
608 
609  return $this->handleError($r, "dropTable(" . $a_name . ")");
610  }
$r
Definition: example_031.php:79
substr($a_exp, $a_pos=1, $a_len=-1)
Substring.
listTables()
Get all tables.
handleError($a_res, $a_info="", $a_level="")
Handle MDB2 Errors.
Definition: class.ilDB.php:423
getDBType()
Get DSN.
$i
Definition: disco.tpl.php:19
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ dropTableColumn()

ilDB::dropTableColumn (   $a_table,
  $a_column 
)

Drop table column Use this only on aleady "abstracted" tables.

Parameters
stringtable name
stringcolumn name

Implements ilDBInterface.

Definition at line 668 of file class.ilDB.php.

References $r, array, and handleError().

669  {
670  $manager = $this->db->loadModule('Manager');
671 
672  $changes = array(
673  "remove" => array(
674  $a_column => array()
675  )
676  );
677 
678  $r = $manager->alterTable($a_table, $changes, false);
679 
680  return $this->handleError($r, "dropTableColumn(" . $a_table . ", " . $a_column . ")");
681  }
$r
Definition: example_031.php:79
handleError($a_res, $a_info="", $a_level="")
Handle MDB2 Errors.
Definition: class.ilDB.php:423
Create styles array
The data for the language used.
+ Here is the call graph for this function:

◆ dropUniqueConstraint()

ilDB::dropUniqueConstraint (   $a_table,
  $a_name = "con" 
)

Drop a constraint from a table.

Note: The constraint must have been created using MDB2

Parameters
stringtable name
stringconstraint name

Definition at line 1046 of file class.ilDB.php.

References $r, constraintName(), and handleError().

Referenced by dropUniqueConstraintByFields().

1047  {
1048  $manager = $this->db->loadModule('Manager');
1049 
1050  $r = $manager->dropConstraint(
1051  $a_table,
1052  $this->constraintName($a_table, $a_name),
1053  false
1054  );
1055 
1056  return $this->handleError($r, "dropUniqueConstraint(" . $a_table . ")");
1057  }
$r
Definition: example_031.php:79
handleError($a_res, $a_info="", $a_level="")
Handle MDB2 Errors.
Definition: class.ilDB.php:423
constraintName($a_table, $a_constraint)
Determine contraint name by table name and constraint name.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ dropUniqueConstraintByFields()

ilDB::dropUniqueConstraintByFields (   $a_table,
  $a_fields 
)

Drop constraint by field(s)

Parameters
stringtable name
arrayfields array

Definition at line 1065 of file class.ilDB.php.

References dropUniqueConstraint().

1066  {
1067  if (is_file("./Services/Database/classes/class.ilDBAnalyzer.php")) {
1068  include_once("./Services/Database/classes/class.ilDBAnalyzer.php");
1069  } else {
1070  include_once("../Services/Database/classes/class.ilDBAnalyzer.php");
1071  }
1072  $analyzer = new ilDBAnalyzer();
1073  $cons = $analyzer->getConstraintsInformation($a_table);
1074  foreach ($cons as $c) {
1075  if ($c["type"] == "unique" && count($a_fields) == count($c["fields"])) {
1076  $all_in = true;
1077  foreach ($a_fields as $f) {
1078  if (!isset($c["fields"][$f])) {
1079  $all_in = false;
1080  }
1081  }
1082  if ($all_in) {
1083  return $this->dropUniqueConstraint($a_table, $c['name']);
1084  }
1085  }
1086  }
1087  return false;
1088  }
This class gives all kind of DB information using the MDB2 manager and reverse module.
dropUniqueConstraint($a_table, $a_name="con")
Drop a constraint from a table.
+ Here is the call graph for this function:

◆ enableResultBuffering()

ilDB::enableResultBuffering (   $a_status)

En/disable result buffering.

Parameters
bool$a_status

Implements ilDBInterface.

Definition at line 202 of file class.ilDB.php.

203  {
204  $this->db->setOption('result_buffering', $a_status);
205  }

◆ equals()

ilDB::equals (   $a_col,
  $a_value,
  $a_type,
  $a_empty_or_null = false 
)

Use this only on text fields.

Implements ilDBInterface.

Definition at line 1949 of file class.ilDB.php.

References $a_type, and quote().

1950  {
1951  if (!$a_empty_or_null || $a_value != "") {
1952  return $a_col . " = " . $this->quote($a_value, $a_type);
1953  } else {
1954  return "(" . $a_col . " = '' OR $a_col IS NULL)";
1955  }
1956  }
$a_type
Definition: workflow.php:92
quote($a_query, $a_type=null)
Wrapper for quote method.
+ Here is the call graph for this function:

◆ equalsNot()

ilDB::equalsNot (   $a_col,
  $a_value,
  $a_type,
  $a_empty_or_null = false 
)

Use this only on text fields.

Definition at line 1961 of file class.ilDB.php.

References $a_type, and quote().

1962  {
1963  if (!$a_empty_or_null) {
1964  return $a_col . " <> " . $this->quote($a_value, $a_type);
1965  }
1966  if ($a_value != "") {
1967  return "(" . $a_col . " <> " . $this->quote($a_value, $a_type) . " OR " .
1968  $a_col . " IS NULL)";
1969  } else {
1970  return "(" . $a_col . " <> '' AND $a_col IS NOT NULL)";
1971  }
1972  }
$a_type
Definition: workflow.php:92
quote($a_query, $a_type=null)
Wrapper for quote method.
+ Here is the call graph for this function:

◆ execute()

ilDB::execute (   $a_stmt,
  $a_data = null 
)

Execute a query statement prepared by either prepare() or prepareManip()

Parameters
objectResource handle of the prepared query.
arrayArray of data (to be used for placeholders)
Returns
mixed A result handle or MDB2_OK on success, a MDB2 error on failure

Implements ilDBInterface.

Definition at line 1512 of file class.ilDB.php.

References $res, and handleError().

1513  {
1514  $res = $a_stmt->execute($a_data);
1515 
1516  return $this->handleError($res, "execute(" . $a_stmt->query . ")");
1517  }
foreach($_POST as $key=> $value) $res
handleError($a_res, $a_info="", $a_level="")
Handle MDB2 Errors.
Definition: class.ilDB.php:423
+ Here is the call graph for this function:

◆ executeMultiple()

ilDB::executeMultiple (   $a_stmt,
  $a_data 
)

Execute a query statement prepared by either prepare() or prepareManip() with multiple data arrays.

Parameters
objectResource handle of the prepared query.
arrayArray of array of data (to be used for placeholders)
Returns
mixed A result handle or MDB2_OK on success, a MDB2 error on failure

Definition at line 1528 of file class.ilDB.php.

References $res, and handleError().

1529  {
1530  $res = $this->db->extended->executeMultiple($a_stmt, $a_data);
1531 
1532  return $this->handleError($res, "executeMultiple(" . $a_stmt->query . ")");
1533  }
foreach($_POST as $key=> $value) $res
handleError($a_res, $a_info="", $a_level="")
Handle MDB2 Errors.
Definition: class.ilDB.php:423
+ Here is the call graph for this function:

◆ fetchAssoc()

ilDB::fetchAssoc (   $a_set)

Fetch row as associative array from result set.

Parameters
mixedresult set

Implements ilDBInterface.

Definition at line 1724 of file class.ilDB.php.

References ilDBConstants\FETCHMODE_ASSOC.

Referenced by assLongMenu\calculateReachedPoints(), assLongMenu\getCorrectAnswersForGap(), assLongMenu\getCorrectAnswersForQuestionSolution(), assLongMenu\getPointsForGap(), ilDBMySQL\isFulltextIndex(), assLongMenu\loadCorrectAnswerData(), assLongMenu\loadFromDb(), and ilTestArchiver\updateTestArchive().

1725  {
1726  return $a_set->fetchRow(ilDBConstants::FETCHMODE_ASSOC);
1727  }
+ Here is the caller graph for this function:

◆ fetchObject()

ilDB::fetchObject (   $a_set)

Fetch row as object from result set.

Parameters
objectresult set

Implements ilDBInterface.

Definition at line 1742 of file class.ilDB.php.

References ilDBConstants\FETCHMODE_OBJECT.

1743  {
1744  return $a_set->fetchRow(ilDBConstants::FETCHMODE_OBJECT);
1745  }

◆ free()

ilDB::free (   $a_st)

Free a statement / result set.

Implements ilDBInterface.

Definition at line 1732 of file class.ilDB.php.

Referenced by insert(), replace(), and update().

1733  {
1734  return $a_st->free();
1735  }
+ Here is the caller graph for this function:

◆ fromUnixtime()

ilDB::fromUnixtime (   $a_expr,
  $a_to_text = true 
)

fromUnixtime (makes timestamp out of unix timestamp)

Parameters
stringexpression
booleantypecasting to text y/n

Definition at line 1980 of file class.ilDB.php.

1981  {
1982  return "FROM_UNIXTIME(" . $a_expr . ")";
1983  }

◆ getAllowedAttributes()

ilDB::getAllowedAttributes ( )
Returns
array

Implements ilDBInterface.

Definition at line 1296 of file class.ilDB.php.

References $allowed_attributes.

1297  {
1299  }
$allowed_attributes
Definition: class.ilDB.php:55

◆ getCreateTableOptions()

ilDB::getCreateTableOptions ( )
protected

Get options for the create table statement.

Returns
array

Definition at line 557 of file class.ilDB.php.

References array.

Referenced by createTable().

558  {
559  return array();
560  }
Create styles array
The data for the language used.
+ Here is the caller graph for this function:

◆ getDBHost()

ilDB::getDBHost ( )

Get database host.

Parameters
stringdatabase host

Definition at line 123 of file class.ilDB.php.

Referenced by ilDBOracle\getDSN(), ilDBPostgreSQL\getDSN(), and ilDBMySQL\getDSN().

124  {
125  return $this->db_host;
126  }
+ Here is the caller graph for this function:

◆ getDBName()

ilDB::getDBName ( )

Get database name.

Parameters
stringdatabase name

Definition at line 163 of file class.ilDB.php.

References getDSN().

Referenced by ilDBOracle\getDSN(), ilDBPostgreSQL\getDSN(), and ilDBMySQL\getDSN().

164  {
165  return $this->db_name;
166  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getDBPassword()

ilDB::getDBPassword ( )

Get database password.

Parameters
stringdatabase password

Definition at line 143 of file class.ilDB.php.

Referenced by ilDBOracle\getDSN(), ilDBPostgreSQL\getDSN(), ilDBMySQL\getDSN(), and ilDBMySQL\getHostDSN().

144  {
145  return $this->db_password;
146  }
+ Here is the caller graph for this function:

◆ getDBPort()

ilDB::getDBPort ( )

Get database port.

Parameters
stringdatabase port

Definition at line 103 of file class.ilDB.php.

Referenced by ilDBOracle\getDSN(), and ilDBMySQL\getDSN().

104  {
105  return $this->db_port;
106  }
+ Here is the caller graph for this function:

◆ getDBType()

ilDB::getDBType ( )
abstract

Get DSN.

This must be overwritten in DBMS specific class.

Implements ilDBInterface.

Referenced by dropTable(), and getDBVersion().

+ Here is the caller graph for this function:

◆ getDBUser()

ilDB::getDBUser ( )

Get database user.

Parameters
stringdatabase user

Definition at line 83 of file class.ilDB.php.

Referenced by ilDBOracle\getDSN(), ilDBPostgreSQL\getDSN(), ilDBMySQL\getDSN(), and ilDBMySQL\getHostDSN().

84  {
85  return $this->db_user;
86  }
+ Here is the caller graph for this function:

◆ getDBVersion()

ilDB::getDBVersion ( )

Get DB version.

Definition at line 176 of file class.ilDB.php.

References getDBType().

177  {
178  return "Unknown";
179  }
+ Here is the call graph for this function:

◆ getDSN()

ilDB::getDSN ( )
abstract

Get DSN.

This must be overwritten in DBMS specific class.

Implements ilDBInterface.

Referenced by connect(), doConnect(), and getDBName().

+ Here is the caller graph for this function:

◆ getHostDSN()

ilDB::getHostDSN ( )

Should return a valid value, if host connections are possible (connectHost) to create a new database from scratch.

Returns
string host dsn (similar to dsn WITHOUT a specific database name)

Definition at line 303 of file class.ilDB.php.

Referenced by connectHost().

304  {
305  return false;
306  }
+ Here is the caller graph for this function:

◆ getLastInsertId()

ilDB::getLastInsertId ( )

Get last insert id.

Definition at line 2249 of file class.ilDB.php.

References $res, and MDB2\isError().

2250  {
2251  $res = $this->db->lastInsertId();
2252  if (MDB2::isError($res)) {
2253  return false;
2254  }
2255  return $res;
2256  }
isError($data, $code=null)
Tell whether a value is a MDB2 error.
Definition: MDB2.php:599
foreach($_POST as $key=> $value) $res
+ Here is the call graph for this function:

◆ getOne()

ilDB::getOne (   $sql)

getOne.

DEPRECATED. Should not be used anymore.

this is the wrapper itself. Runs a query and returns the first column of the first row or in case of an error, jump to errorpage

Parameters
string
Returns
object DB

Definition at line 2267 of file class.ilDB.php.

References $r, ilDBConstants\FETCHMODE_ASSOC, handleError(), and MDB2\isError().

2268  {
2269  //$r = $this->db->getOne($sql);
2270  $set = $this->db->query($sql);
2271 
2272  $this->handleError($set, "getOne(" . $sql . ")");
2273 
2274  if (!MDB2::isError($set)) {
2275  $r = $set->fetchRow(ilDBConstants::FETCHMODE_ASSOC);
2276 
2277  return $r[0];
2278  }
2279  }
isError($data, $code=null)
Tell whether a value is a MDB2 error.
Definition: MDB2.php:599
$r
Definition: example_031.php:79
handleError($a_res, $a_info="", $a_level="")
Handle MDB2 Errors.
Definition: class.ilDB.php:423
+ Here is the call graph for this function:

◆ getPrimaryKeyIdentifier()

ilDB::getPrimaryKeyIdentifier ( )

Primary key identifier.

Implements ilDBInterface.

Definition at line 863 of file class.ilDB.php.

Referenced by addPrimaryKey(), and dropPrimaryKey().

864  {
865  return "PRIMARY";
866  }
+ Here is the caller graph for this function:

◆ getReservedWords()

static ilDB::getReservedWords ( )
static

Get reserved words.

This must be overwritten in DBMS specific class. This is mainly used to check whether a new identifier can be problematic because it is a reserved word. So createTable / alterTable usually check these.

Implements ilDBInterface.

Definition at line 192 of file class.ilDB.php.

References array.

193  {
194  return array();
195  }
Create styles array
The data for the language used.

◆ getRow()

ilDB::getRow (   $sql,
  $mode = ilDBConstants::FETCHMODE_OBJECT 
)

getRow.

DEPRECATED. Should not be used anymore

this is the wrapper itself. query a string, and return the resultobject, or in case of an error, jump to errorpage

Parameters
string
Returns
object DB

Definition at line 2290 of file class.ilDB.php.

References $data, $r, array, ilDBInterface\fetchAll(), ilDBConstants\FETCHMODE_ASSOC, handleError(), and query().

2291  {
2292  $set = $this->query($sql);
2293  $r = $set->fetchRow($mode);
2294  //$r = $this->db->getrow($sql,$mode);
2295 
2296  $this->handleError($r, "getRow(" . $sql . ")");
2297 
2298  return $r;
2299  } //end function
query($sql, $a_handle_error=true)
Query.
$r
Definition: example_031.php:79
handleError($a_res, $a_info="", $a_level="")
Handle MDB2 Errors.
Definition: class.ilDB.php:423
+ Here is the call graph for this function:

◆ getSequenceName()

ilDB::getSequenceName (   $table_name)
Parameters
$table_name
Returns
string

Implements ilDBInterface.

Definition at line 2364 of file class.ilDB.php.

2365  {
2366  return $this->db->getSequenceName($table_name);
2367  }

◆ getSubType()

ilDB::getSubType ( )

Get sub type.

Returns
string

Definition at line 2334 of file class.ilDB.php.

References $sub_type.

Referenced by ilDBMySQL\isMySQLi().

2335  {
2336  return $this->sub_type;
2337  }
$sub_type
Definition: class.ilDB.php:66
+ Here is the caller graph for this function:

◆ handleError()

ilDB::handleError (   $a_res,
  $a_info = "",
  $a_level = "" 
)

Handle MDB2 Errors.

Parameters
mixedresult set or anything that is a MDB2::error if something went wrong

Definition at line 423 of file class.ilDB.php.

References $ilLog, and MDB2\isError().

Referenced by addPrimaryKey(), addTableColumn(), addUniqueConstraint(), alterTable(), autoExecute(), beginTransaction(), commit(), connect(), connectHost(), createSequence(), createTable(), dropIndex(), ilDBOracle\dropPrimaryKey(), dropPrimaryKey(), dropSequence(), dropTable(), dropTableColumn(), dropUniqueConstraint(), execute(), executeMultiple(), getOne(), getRow(), insert(), manipulate(), modifyTableColumn(), nextId(), prepare(), prepareManip(), ilDBMySQL\query(), query(), renameTable(), renameTableColumn(), ilDBPostgreSQL\replace(), ilDBOracle\replace(), replace(), rollback(), and update().

424  {
425  global $ilLog;
426 
427  if (MDB2::isError($a_res)) {
428  if ($a_level == "") {
429  $a_level = $this->error_class->FATAL;
430  }
431 
432  // :TODO: ADT (jluetzen)
433 
434  // if(!$this->exception)
435  if (true) {
436  // Show stack
437  try {
438  throw new Exception();
439  } catch (Exception $e) {
440  $stack = $e->getTraceAsString();
441  }
442 
443  if (is_object($ilLog)) {
444  $ilLog->logStack();
445  }
446  // $this->raisePearError("ilDB Error: " . $a_info . "<br />" . $a_res->getMessage() . "<br />" . $a_res->getUserInfo() . "<br />"
447  // . $stack, $a_level);
448 
449  throw new ilDatabaseException("ilDB Error: " . $a_info . "<br />" . $a_res->getMessage() . "<br />" . $a_res->getUserInfo() . "<br />"
450  . $stack, $a_level);
451  }
452  }
453 
454  return $a_res;
455  }
isError($data, $code=null)
Tell whether a value is a MDB2 error.
Definition: MDB2.php:599
Class ilDatabaseException.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ in()

ilDB::in (   $a_field,
  $a_values,
  $negate = false,
  $a_type = "" 
)

Get abstract in-clause for given array.

Returns an array "field_name IN (?,?,?,...)" depending on the size of the array

Example: $ids = array(10,12,18); $st = $ilDB->prepare("SELECT * FROM table ". "WHERE ".$ilDB->in("id", $ids), $ilDB->addTypesToArray($types, "integer", count($ids))); $set = $ilDB->execute($st, $ids);

Implements ilDBInterface.

Definition at line 1772 of file class.ilDB.php.

References $a_type, and quote().

1773  {
1774  if (count($a_values) == 0) {
1775  // BEGIN fixed mantis #0014191:
1776  //return " 1=2 "; // return a false statement on empty array
1777  return $negate ? ' 1=1 ' : ' 1=2 ';
1778  // END fixed mantis #0014191:
1779  }
1780  if ($a_type == "") { // untyped: used ? for prepare/execute
1781  $str = $a_field . (($negate) ? " NOT" : "") . " IN (?" . str_repeat(",?", count($a_values) - 1) . ")";
1782  } else { // typed, use values for query/manipulate
1783  $str = $a_field . (($negate) ? " NOT" : "") . " IN (";
1784  $sep = "";
1785  foreach ($a_values as $v) {
1786  $str.= $sep . $this->quote($v, $a_type);
1787  $sep = ",";
1788  }
1789  $str.= ")";
1790  }
1791 
1792  return $str;
1793  }
$a_type
Definition: workflow.php:92
quote($a_query, $a_type=null)
Wrapper for quote method.
+ Here is the call graph for this function:

◆ indexExistsByFields()

ilDB::indexExistsByFields (   $a_table,
  $a_fields 
)

Check if index exists.

Parameters
type$a_table
type$a_fields

Implements ilDBInterface.

Definition at line 948 of file class.ilDB.php.

References $def, and array.

949  {
950  $manager = $this->db->loadModule('Manager');
951  $reverse = $this->db->loadModule('Reverse');
952  if ($manager) {
953  foreach ($manager->listTableIndexes($a_table) as $idx_name) {
954  $def = $reverse->getTableIndexDefinition($a_table, $idx_name);
955  $idx_fields = array_keys((array) $def['fields']);
956 
957  if ($idx_fields === $a_fields) {
958  return true;
959  }
960  }
961  }
962  return false;
963  }
Create styles array
The data for the language used.
$def
Definition: croninfo.php:21

◆ initConnection()

ilDB::initConnection ( )
protected

Initialize the database connection.

Definition at line 293 of file class.ilDB.php.

Referenced by connect().

294  {
295  }
+ Here is the caller graph for this function:

◆ initFromIniFile()

ilDB::initFromIniFile (   $tmpClientIniFile = null)

Init db parameters from ini file.

Parameters
$tmpClientIniFileoverwrite global client ini file if is set to an object

Implements ilDBInterface.

Definition at line 211 of file class.ilDB.php.

References setDBHost(), setDBName(), setDBPassword(), setDBPort(), and setDBUser().

212  {
213  global $ilClientIniFile;
214 
215  //overwrite global client ini file if local parameter is set
216  if (is_object($tmpClientIniFile)) {
217  $clientIniFile = $tmpClientIniFile;
218  } else {
219  $clientIniFile = $ilClientIniFile;
220  }
221 
222  if (is_object($clientIniFile)) {
223  $this->setDBUser($clientIniFile ->readVariable("db", "user"));
224  $this->setDBHost($clientIniFile ->readVariable("db", "host"));
225  $this->setDBPort($clientIniFile ->readVariable("db", "port"));
226  $this->setDBPassword($clientIniFile ->readVariable("db", "pass"));
227  $this->setDBName($clientIniFile ->readVariable("db", "name"));
228  }
229  }
setDBUser($a_user)
Set database user.
Definition: class.ilDB.php:73
setDBPort($a_port)
Set database port.
Definition: class.ilDB.php:93
setDBName($a_name)
Set database name.
Definition: class.ilDB.php:153
setDBPassword($a_password)
Set database password.
Definition: class.ilDB.php:133
setDBHost($a_host)
Set database host.
Definition: class.ilDB.php:113
+ Here is the call graph for this function:

◆ initHostConnection()

ilDB::initHostConnection ( )
protected

Initialize the host connection (no specific database)

Definition at line 355 of file class.ilDB.php.

Referenced by connectHost().

356  {
357  }
+ Here is the caller graph for this function:

◆ insert()

ilDB::insert (   $a_table,
  $a_columns 
)

Convenient method for standard insert statements, example field array:

array("field1" => array("text", $name), "field2" => array("integer", $id))

Implements ilDBInterface.

Definition at line 1541 of file class.ilDB.php.

References $r, array, free(), handleError(), manipulateF(), and MDB2_PREPARE_MANIP.

Referenced by ilDBPostgreSQL\replace(), and ilDBOracle\replace().

1542  {
1543  $fields = array();
1544  $field_values = array();
1545  $placeholders = array();
1546  $types = array();
1547  $values = array();
1548  $lobs = false;
1549  $lob = array();
1550  foreach ($a_columns as $k => $col) {
1551  $fields[] = $k;
1552  $placeholders[] = "%s";
1553  $placeholders2[] = ":$k";
1554  $types[] = $col[0];
1555 
1556  // integer auto-typecast (this casts bool values to integer)
1557  if ($col[0] == 'integer' && !is_null($col[1])) {
1558  $col[1] = (int) $col[1];
1559  }
1560 
1561  $values[] = $col[1];
1562  $field_values[$k] = $col[1];
1563  if ($col[0] == "blob" || $col[0] == "clob") {
1564  $lobs = true;
1565  $lob[$k] = $k;
1566  }
1567  }
1568  if ($lobs) { // lobs -> use prepare execute (autoexecute broken in PEAR 2.4.1)
1569  $st = $this->db->prepare("INSERT INTO " . $a_table . " (" . implode($fields, ",") . ") VALUES (" .
1570  implode($placeholders2, ",") . ")", $types, MDB2_PREPARE_MANIP, $lob);
1571 
1572  $this->handleError($st, "insert / prepare/execute(" . $a_table . ")");
1573 
1574  $r = $st->execute($field_values);
1575 
1576 
1577  //$r = $this->db->extended->autoExecute($a_table, $field_values, MDB2_AUTOQUERY_INSERT, null, $types);
1578  $this->handleError($r, "insert / prepare/execute(" . $a_table . ")");
1579  $this->free($st);
1580  } else { // if no lobs are used, take simple manipulateF
1581  $q = "INSERT INTO " . $a_table . " (" . implode($fields, ",") . ") VALUES (" .
1582  implode($placeholders, ",") . ")";
1583  $r = $this->manipulateF($q, $types, $values);
1584  }
1585  return $r;
1586  }
manipulateF($a_query, $a_types, $a_values)
Formatted manupulate (for DELETE, UPDATE, INSERT).
$r
Definition: example_031.php:79
const MDB2_PREPARE_MANIP
These are just helper constants to more verbosely express parameters to prepare() ...
Definition: MDB2.php:114
free($a_st)
Free a statement / result set.
handleError($a_res, $a_info="", $a_level="")
Handle MDB2 Errors.
Definition: class.ilDB.php:423
Create styles array
The data for the language used.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isDbError()

static ilDB::isDbError (   $a_res)
static

Check error.

Definition at line 488 of file class.ilDB.php.

References MDB2\isError().

Referenced by connect(), connectHost(), and loadMDB2Extensions().

489  {
490  return MDB2::isError($a_res);
491  }
isError($data, $code=null)
Tell whether a value is a MDB2 error.
Definition: MDB2.php:599
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isFulltextIndex()

ilDB::isFulltextIndex (   $a_table,
  $a_name 
)

Is index a fulltext index?

Implements ilDBInterface.

Definition at line 937 of file class.ilDB.php.

Referenced by dropIndex().

938  {
939  return false;
940  }
+ Here is the caller graph for this function:

◆ isReservedWord()

static ilDB::isReservedWord (   $a_word)
static

Checks whether a word is a reserved word in one of the supported databases.

Implements ilDBInterface.

Definition at line 1315 of file class.ilDB.php.

References $DIC.

Referenced by checkColumnName(), checkIndexName(), checkTableName(), and ilDatabaseReservedWordsTest\testReservedMDB2().

1316  {
1317  require_once('./Services/Database/classes/PDO/FieldDefinition/class.ilDBPdoMySQLFieldDefinition.php');
1318  global $DIC;
1319  $ilDBPdoMySQLFieldDefinition = new ilDBPdoMySQLFieldDefinition($DIC['ilDB']);
1320 
1321  return $ilDBPdoMySQLFieldDefinition->isReserved($a_word);
1322  }
global $DIC
Definition: saml.php:7
Class ilDBPdoMySQLFieldDefinition.
+ Here is the caller graph for this function:

◆ like()

ilDB::like (   $a_col,
  $a_type,
  $a_value = "?",
  $case_insensitive = true 
)

Like.

Parameters
stringcolumn type; must be "text" or "clob" ("blob" added for lng_data)

Implements ilDBInterface.

Definition at line 1923 of file class.ilDB.php.

References $a_type, array, quote(), and raisePearError().

1924  {
1925  if (!in_array($a_type, array("text", "clob", "blob"))) {
1926  $this->raisePearError("Like: Invalid column type '" . $a_type . "'.", $this->error_class->FATAL);
1927  }
1928  if ($a_value == "?") {
1929  if ($case_insensitive) {
1930  return "UPPER(" . $a_col . ") LIKE(UPPER(?))";
1931  } else {
1932  return $a_col . " LIKE(?)";
1933  }
1934  } else {
1935  if ($case_insensitive) {
1936  // Always quote as text
1937  return " UPPER(" . $a_col . ") LIKE(UPPER(" . $this->quote($a_value, 'text') . "))";
1938  } else {
1939  // Always quote as text
1940  return " " . $a_col . " LIKE(" . $this->quote($a_value, 'text') . ")";
1941  }
1942  }
1943  }
raisePearError($a_message, $a_level="")
Raise an error.
Definition: class.ilDB.php:460
$a_type
Definition: workflow.php:92
quote($a_query, $a_type=null)
Wrapper for quote method.
Create styles array
The data for the language used.
+ Here is the call graph for this function:

◆ listSequences()

ilDB::listSequences ( )

Get all sequences.

Returns
array Array of sequence names

Implements ilDBInterface.

Definition at line 2113 of file class.ilDB.php.

References $r, and MDB2\isError().

Referenced by sequenceExists().

2114  {
2115  $manager = $this->db->loadModule('Manager');
2116  $r = $manager->listSequences();
2117 
2118  if (!MDB2::isError($r)) {
2119  return $r;
2120  }
2121 
2122  return false;
2123  }
isError($data, $code=null)
Tell whether a value is a MDB2 error.
Definition: MDB2.php:599
$r
Definition: example_031.php:79
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ listTables()

ilDB::listTables ( )

Get all tables.

Returns
array Array of table names

Implements ilDBInterface.

Definition at line 2078 of file class.ilDB.php.

References $r, and MDB2\isError().

Referenced by dropTable(), and tableExists().

2079  {
2080  $manager = $this->db->loadModule('Manager');
2081  $r = $manager->listTables();
2082 
2083  if (!MDB2::isError($r)) {
2084  return $r;
2085  }
2086 
2087  return false;
2088  }
isError($data, $code=null)
Tell whether a value is a MDB2 error.
Definition: MDB2.php:599
$r
Definition: example_031.php:79
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ loadMDB2Extensions()

ilDB::loadMDB2Extensions ( )
protected

load additional mdb2 extensions and set their constants

protected

Definition at line 474 of file class.ilDB.php.

References isDbError(), MDB2_AUTOQUERY_DELETE, MDB2_AUTOQUERY_INSERT, MDB2_AUTOQUERY_SELECT, and MDB2_AUTOQUERY_UPDATE.

Referenced by connect(), and connectHost().

475  {
476  if (!$this->isDbError($this->db)) {
477  $this->db->loadModule('Extended');
478  define('DB_AUTOQUERY_SELECT', MDB2_AUTOQUERY_SELECT);
479  define('DB_AUTOQUERY_INSERT', MDB2_AUTOQUERY_INSERT);
480  define('DB_AUTOQUERY_UPDATE', MDB2_AUTOQUERY_UPDATE);
481  define('DB_AUTOQUERY_DELETE', MDB2_AUTOQUERY_DELETE);
482  }
483  }
const MDB2_AUTOQUERY_SELECT
Definition: Extended.php:59
const MDB2_AUTOQUERY_DELETE
Definition: Extended.php:58
const MDB2_AUTOQUERY_UPDATE
Definition: Extended.php:57
const MDB2_AUTOQUERY_INSERT
Used by autoPrepare()
Definition: Extended.php:56
static isDbError($a_res)
Check error.
Definition: class.ilDB.php:488
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ locate()

ilDB::locate (   $a_needle,
  $a_string,
  $a_start_pos = 1 
)

Create locate string.

Parameters
string$a_needle
string$a_string
int$a_start_pos[optional]
Returns

Implements ilDBInterface.

Definition at line 1905 of file class.ilDB.php.

1906  {
1907  $locate = ' LOCATE( ';
1908  $locate .= $a_needle;
1909  $locate .= ',';
1910  $locate .= $a_string;
1911  $locate .= ',';
1912  $locate .= $a_start_pos;
1913  $locate .= ') ';
1914  return $locate;
1915  }

◆ lockTables()

ilDB::lockTables (   $a_tables)
abstract

Abstraction of lock table.

Parameters
arraytable definitions
Deprecated:
Use ilAtomQuery instead
Returns

Implements ilDBInterface.

Referenced by rollback().

+ Here is the caller graph for this function:

◆ logStatement()

ilDB::logStatement (   $sql)

Helper function, should usually not be called.

Definition at line 1405 of file class.ilDB.php.

References $table, and substr().

1406  {
1407  $pos1 = strpos(strtolower($sql), "from ");
1408  $table = "";
1409  if ($pos1 > 0) {
1410  $tablef = substr($sql, $pos1+5);
1411  $pos2 = strpos(strtolower($tablef), " ");
1412  if ($pos2 > 0) {
1413  $table =substr($tablef, 0, $pos2);
1414  } else {
1415  $table = $tablef;
1416  }
1417  }
1418  if (trim($table) != "") {
1419  if (!is_array($this->ttt) || !in_array($table, $this->ttt)) {
1420  echo "<br>" . $table;
1421  $this->ttt[] = $table;
1422  }
1423  } else {
1424  echo "<br><b>" . $sql . "</b>";
1425  }
1426  }
substr($a_exp, $a_pos=1, $a_len=-1)
Substring.
if(empty($password)) $table
Definition: pwgen.php:24
+ Here is the call graph for this function:

◆ lower()

ilDB::lower (   $a_exp)

Upper.

Parameters
stringexpression
Returns
string upper sql string

Implements ilDBInterface.

Definition at line 1893 of file class.ilDB.php.

1894  {
1895  return " LOWER(" . $a_exp . ") ";
1896  }

◆ manipulate()

ilDB::manipulate (   $sql)

Data manipulation.

This statement should be used for DELETE, UPDATE and INSERT statements.

Example:

  • "DELETE * FROM data WHERE id =".$ilDB->quote($id, "integer");
Parameters
stringDML string
Returns
int affected rows

Implements ilDBInterface.

Definition at line 1459 of file class.ilDB.php.

References $ilBench, $r, and handleError().

Referenced by manipulateF(), ilDBPostgreSQL\replace(), and ilDBOracle\replace().

1460  {
1461  global $ilBench;
1462 
1463  if (is_object($ilBench)) {
1464  $ilBench->startDbBench($sql);
1465  }
1466  $r = $this->db->exec($sql);
1467  if (is_object($ilBench)) {
1468  $ilBench->stopDbBench();
1469  }
1470 
1471  return $this->handleError($r, "manipulate(" . $sql . ")");
1472  }
$r
Definition: example_031.php:79
handleError($a_res, $a_info="", $a_level="")
Handle MDB2 Errors.
Definition: class.ilDB.php:423
global $ilBench
Definition: ilias.php:18
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ manipulateF()

ilDB::manipulateF (   $a_query,
  $a_types,
  $a_values 
)

Formatted manupulate (for DELETE, UPDATE, INSERT).

Use s as placeholder!

Parameters
stringquery
arraytype array
arraayvalue array

Implements ilDBInterface.

Definition at line 1387 of file class.ilDB.php.

References $query, $t, array, manipulate(), quote(), and raisePearError().

Referenced by assLongMenu\clearAnswerSpecificDataFromDb(), insert(), replace(), assLongMenu\saveAdditionalQuestionDataToDb(), and update().

1388  {
1389  if (!is_array($a_types) || !is_array($a_values) ||
1390  count($a_types) != count($a_values)) {
1391  $this->raisePearError("ilDB::manipulateF: types and values must be arrays of same size. ($a_query)");
1392  }
1393  $quoted_values = array();
1394  foreach ($a_types as $k => $t) {
1395  $quoted_values[] = $this->quote($a_values[$k], $t);
1396  }
1397  $query = vsprintf($a_query, $quoted_values);
1398 
1399  return $this->manipulate($query);
1400  }
raisePearError($a_message, $a_level="")
Raise an error.
Definition: class.ilDB.php:460
quote($a_query, $a_type=null)
Wrapper for quote method.
$query
Create styles array
The data for the language used.
manipulate($sql)
Data manipulation.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ migrateAllTablesToEngine()

ilDB::migrateAllTablesToEngine (   $engine = ilDBConstants::MYSQL_ENGINE_INNODB)
Parameters
string$engine
Returns
array

Definition at line 2345 of file class.ilDB.php.

References array.

2346  {
2347  return array();
2348  }
Create styles array
The data for the language used.

◆ modifyTableColumn()

ilDB::modifyTableColumn (   $a_table,
  $a_column,
  $a_attributes 
)

Modify a table column Use this only on aleady "abstracted" tables.

Parameters
stringtable name
stringcolumn name
arrayattributes to be changed, e.g. array("length" => 10, "default" => "t")

Implements ilDBInterface.

Definition at line 691 of file class.ilDB.php.

References $def, $r, $type, array, checkColumnDefinition(), handleError(), and raisePearError().

692  {
693  $manager = $this->db->loadModule('Manager');
694  $reverse = $this->db->loadModule('Reverse');
695  $def = $reverse->getTableFieldDefinition($a_table, $a_column);
696 
697  $this->handleError($def, "modifyTableColumn(" . $a_table . ")");
698 
699  if (is_file("./Services/Database/classes/class.ilDBAnalyzer.php")) {
700  include_once("./Services/Database/classes/class.ilDBAnalyzer.php");
701  } else {
702  include_once("../Services/Database/classes/class.ilDBAnalyzer.php");
703  }
704  $analyzer = new ilDBAnalyzer();
705  $best_alt = $analyzer->getBestDefinitionAlternative($def);
706  $def = $def[$best_alt];
707  unset($def["nativetype"]);
708  unset($def["mdb2type"]);
709 
710  // check attributes
711  $type = ($a_attributes["type"] != "")
712  ? $a_attributes["type"]
713  : $def["type"];
714  foreach ($def as $k => $v) {
715  if ($k != "type" && !in_array($k, $this->allowed_attributes[$type])) {
716  unset($def[$k]);
717  }
718  }
719  $check_array = $def;
720  foreach ($a_attributes as $k => $v) {
721  $check_array[$k] = $v;
722  }
723  if (!$this->checkColumnDefinition($check_array, true)) {
724  $this->raisePearError("ilDB Error: modifyTableColumn(" . $a_table . ", " . $a_column . ")<br />" .
725  $this->error_str);
726  }
727 
728  // oracle workaround: do not set null, if null already given
729  if ($this->getDbType() == "oracle") {
730  if ($def["notnull"] == true && ($a_attributes["notnull"] == true
731  || !isset($a_attributes["notnull"]))) {
732  unset($def["notnull"]);
733  unset($a_attributes["notnull"]);
734  }
735  if ($def["notnull"] == false && ($a_attributes["notnull"] == false
736  || !isset($a_attributes["notnull"]))) {
737  unset($def["notnull"]);
738  unset($a_attributes["notnull"]);
739  }
740  }
741  foreach ($a_attributes as $a => $v) {
742  $def[$a] = $v;
743  }
744 
745  $a_attributes["definition"] = $def;
746 
747  $changes = array(
748  "change" => array(
749  $a_column => $a_attributes
750  )
751  );
752 
753  $r = $manager->alterTable($a_table, $changes, false);
754 
755  return $this->handleError($r, "modifyTableColumn(" . $a_table . ")");
756  }
raisePearError($a_message, $a_level="")
Raise an error.
Definition: class.ilDB.php:460
$type
checkColumnDefinition($a_def, $a_modify_mode=false)
Check whether a column definition is valid.
$r
Definition: example_031.php:79
handleError($a_res, $a_info="", $a_level="")
Handle MDB2 Errors.
Definition: class.ilDB.php:423
Create styles array
The data for the language used.
$def
Definition: croninfo.php:21
This class gives all kind of DB information using the MDB2 manager and reverse module.
+ Here is the call graph for this function:

◆ nextId()

ilDB::nextId (   $a_table_name)

Get next ID for an index.

Implements ilDBInterface.

Definition at line 1439 of file class.ilDB.php.

References $r, and handleError().

1440  {
1441  // we do not create missing sequences automatically here
1442  // otherwise misspelled statements result in additional tables
1443  // please create sequences explicitly in the db update script
1444  $r = $this->db->nextId($a_table_name, false);
1445 
1446  return $this->handleError($r, "nextId(" . $a_table_name . ")");
1447  }
$r
Definition: example_031.php:79
handleError($a_res, $a_info="", $a_level="")
Handle MDB2 Errors.
Definition: class.ilDB.php:423
+ Here is the call graph for this function:

◆ now()

ilDB::now ( )

now()

Implements ilDBInterface.

Definition at line 1815 of file class.ilDB.php.

1816  {
1817  return "now()";
1818  }

◆ numRows()

ilDB::numRows (   $a_set)

Fetch row as associative array from result set.

Parameters
objectresult set

Implements ilDBInterface.

Definition at line 1752 of file class.ilDB.php.

1753  {
1754  return $a_set->numRows();
1755  }

◆ prepare()

ilDB::prepare (   $a_query,
  $a_types = null,
  $a_result_types = null 
)

Prepare a query (SELECT) statement to be used with execute.

Parameters
StringQuery String
ArrayPlaceholder Types
Returns
Resource handle for the prepared query on success, a MDB2 error on failure.

Implements ilDBInterface.

Definition at line 1482 of file class.ilDB.php.

References $res, and handleError().

1483  {
1484  $res = $this->db->prepare($a_query, $a_types, $a_result_types);
1485 
1486  return $this->handleError($res, "prepare(" . $a_query . ")");
1487  }
foreach($_POST as $key=> $value) $res
handleError($a_res, $a_info="", $a_level="")
Handle MDB2 Errors.
Definition: class.ilDB.php:423
+ Here is the call graph for this function:

◆ prepareManip()

ilDB::prepareManip (   $a_query,
  $a_types = null 
)

Prepare a data manipulation statement to be used with execute.

Parameters
StringQuery String
ArrayPlaceholder Types
Returns
Resource handle for the prepared query on success, a MDB2 error on failure.

Implements ilDBInterface.

Definition at line 1497 of file class.ilDB.php.

References $res, handleError(), and MDB2_PREPARE_MANIP.

1498  {
1499  $res = $this->db->prepare($a_query, $a_types, MDB2_PREPARE_MANIP);
1500 
1501  return $this->handleError($res, "prepareManip(" . $a_query . ")");
1502  }
const MDB2_PREPARE_MANIP
These are just helper constants to more verbosely express parameters to prepare() ...
Definition: MDB2.php:114
foreach($_POST as $key=> $value) $res
handleError($a_res, $a_info="", $a_level="")
Handle MDB2 Errors.
Definition: class.ilDB.php:423
+ Here is the call graph for this function:

◆ query()

ilDB::query (   $sql,
  $a_handle_error = true 
)

Query.

Example:

  • "SELECT * FROM data"

For multiple similar queries/manipulations you may use prepare() and execute().

Parameters
string
Returns
ilPDOStatement DB

Definition at line 1339 of file class.ilDB.php.

References $ilBench, $r, and handleError().

Referenced by ilCourseArchives\__read(), ilRbacSystem\checkAccessOfUser(), createDatabase(), ilRbacReview\getOperation(), ilRbacReview\getOperations(), ilRbacReview\getOperationsOnTypeString(), getRow(), ilDBOracle\initConnection(), ilRbacReview\isDeleted(), ilRbacSystem\preloadRbacPaCache(), queryF(), ilParticipants\readSubscriberData(), ilParticipants\readSubscribers(), ilRbacReview\roleExists(), and ilTestArchiver\updateTestArchive().

1340  {
1341  global $ilBench;
1342 
1343  if (is_object($ilBench)) {
1344  $ilBench->startDbBench($sql);
1345  }
1346  $r = $this->db->query($sql);
1347  if (is_object($ilBench)) {
1348  $ilBench->stopDbBench();
1349  }
1350 
1351  if ($a_handle_error) {
1352  return $this->handleError($r, "query(" . $sql . ")");
1353  }
1354 
1355  return $r;
1356  }
$r
Definition: example_031.php:79
handleError($a_res, $a_info="", $a_level="")
Handle MDB2 Errors.
Definition: class.ilDB.php:423
global $ilBench
Definition: ilias.php:18
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ queryF()

ilDB::queryF (   $a_query,
  $a_types,
  $a_values 
)

Formatted query (for SELECTS).

Use s as placeholder!

Parameters
stringquery
arraytype array
arraayvalue array

Implements ilDBInterface.

Definition at line 1365 of file class.ilDB.php.

References $query, $t, array, query(), quote(), and raisePearError().

Referenced by assLongMenu\loadFromDb().

1366  {
1367  if (!is_array($a_types) || !is_array($a_values) ||
1368  count($a_types) != count($a_values)) {
1369  $this->raisePearError("ilDB::queryF: Types and values must be arrays of same size. ($a_query)");
1370  }
1371  $quoted_values = array();
1372  foreach ($a_types as $k => $t) {
1373  $quoted_values[] = $this->quote($a_values[$k], $t);
1374  }
1375  $query = vsprintf($a_query, $quoted_values);
1376 
1377  return $this->query($query);
1378  }
raisePearError($a_message, $a_level="")
Raise an error.
Definition: class.ilDB.php:460
query($sql, $a_handle_error=true)
Query.
quote($a_query, $a_type=null)
Wrapper for quote method.
$query
Create styles array
The data for the language used.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ quote()

ilDB::quote (   $a_query,
  $a_type = null 
)

Wrapper for quote method.

Implements ilDBInterface.

Definition at line 2133 of file class.ilDB.php.

References $a_type, and raisePearError().

Referenced by equals(), equalsNot(), ilRbacReview\getAssignableChildRoles(), ilTree\getNodeDataByType(), ilTree\getPathFull(), ilDBPostgreSQL\groupConcat(), ilDBMySQL\groupConcat(), in(), ilDBOracle\like(), like(), manipulateF(), queryF(), ilDBPostgreSQL\replace(), ilDBOracle\replace(), update(), and ilTestArchiver\updateTestArchive().

2134  {
2135  if ($a_query == "" && is_null($a_type)) {
2136  $a_query = "";
2137  }
2138 
2139  // Performance fix
2140  if ($a_type == 'integer' && !is_null($a_query)) {
2141  return (int) $a_query;
2142  }
2143 
2144  if ($a_type == "blob" || $a_type == "clob") {
2145  $this->raisePearError("ilDB::quote: Quoting not allowed on type '" . $a_type . "'. Please use ilDB->insert and ilDB->update to write clobs.", $this->error_class->FATAL);
2146  }
2147 
2148  return $this->db->quote($a_query, $a_type);
2149  }
raisePearError($a_message, $a_level="")
Raise an error.
Definition: class.ilDB.php:460
$a_type
Definition: workflow.php:92
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ quoteIdentifier()

ilDB::quoteIdentifier (   $a_identifier,
  $check_option = false 
)

Quote table and field names.

Note: IF POSSIBLE, THIS METHOD SHOULD NOT BE USED. Rename your table or field, if it conflicts with a reserved word.

Implements ilDBInterface.

Definition at line 2158 of file class.ilDB.php.

2159  {
2160  return $this->db->quoteIdentifier($a_identifier);
2161  }

◆ raisePearError()

ilDB::raisePearError (   $a_message,
  $a_level = "" 
)

Raise an error.

Definition at line 460 of file class.ilDB.php.

References PEAR\raiseError().

Referenced by addTableColumn(), addUniqueConstraint(), beginTransaction(), connect(), connectHost(), createTable(), dropPrimaryKey(), ilDBOracle\like(), like(), manipulateF(), modifyTableColumn(), queryF(), quote(), renameTable(), and renameTableColumn().

461  {
462  if ($a_level == "") {
463  $a_level = $this->error_class->FATAL;
464  }
465  //echo "<br>-ilDB:raising-$a_message-$a_level-";
466  $this->raiseError($a_message, $a_level);
467  }
& raiseError($message=null, $code=null, $mode=null, $options=null, $userinfo=null, $error_class=null, $skipmsg=false)
This method is a wrapper that returns an instance of the configured error class with this object&#39;s de...
Definition: PEAR.php:522
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ renameTable()

ilDB::renameTable (   $a_name,
  $a_new_name 
)

Rename a table.

Parameters
stringold table name
stringnew table name

Implements ilDBInterface.

Definition at line 812 of file class.ilDB.php.

References $r, array, checkTableName(), handleError(), and raisePearError().

813  {
814  // check table name
815  if (!$this->checkTableName($a_new_name)) {
816  $this->raisePearError("ilDB Error: renameTable(" . $a_name . "," . $a_new_name . ")<br />" .
817  $this->error_str);
818  }
819 
820  $manager = $this->db->loadModule('Manager');
821  $r = $manager->alterTable($a_name, array("name" => $a_new_name), false);
822 
823  // The abstraction_progress is no longer used in ILIAS, see http://www.ilias.de/mantis/view.php?id=19513
824  // $query = "UPDATE abstraction_progress ".
825  // "SET table_name = ".$this->db->quote($a_new_name,'text')." ".
826  // "WHERE table_name = ".$this->db->quote($a_name,'text');
827  // $this->db->query($query);
828 
829  return $this->handleError($r, "renameTable(" . $a_name . "," . $a_new_name . ")");
830  }
raisePearError($a_message, $a_level="")
Raise an error.
Definition: class.ilDB.php:460
$r
Definition: example_031.php:79
checkTableName($a_name)
Check whether a table name is valid.
handleError($a_res, $a_info="", $a_level="")
Handle MDB2 Errors.
Definition: class.ilDB.php:423
Create styles array
The data for the language used.
+ Here is the call graph for this function:

◆ renameTableColumn()

ilDB::renameTableColumn (   $a_table,
  $a_column,
  $a_new_column 
)

Rename a table column Use this only on aleady "abstracted" tables.

Parameters
stringtable name
stringold column name
stringnew column name

Implements ilDBInterface.

Definition at line 766 of file class.ilDB.php.

References $def, $r, array, checkColumnName(), handleError(), and raisePearError().

767  {
768  // check table name
769  if (!$this->checkColumnName($a_new_column)) {
770  $this->raisePearError("ilDB Error: renameTableColumn(" . $a_table . "," . $a_column . "," . $a_new_column . ")<br />" .
771  $this->error_str);
772  }
773 
774  $manager = $this->db->loadModule('Manager');
775  $reverse = $this->db->loadModule('Reverse');
776  $def = $reverse->getTableFieldDefinition($a_table, $a_column);
777 
778  $this->handleError($def, "renameTableColumn(" . $a_table . "," . $a_column . "," . $a_new_column . ")");
779 
780  if (is_file("./Services/Database/classes/class.ilDBAnalyzer.php")) {
781  include_once("./Services/Database/classes/class.ilDBAnalyzer.php");
782  } else {
783  include_once("../Services/Database/classes/class.ilDBAnalyzer.php");
784  }
785 
786  $analyzer = new ilDBAnalyzer();
787  $best_alt = $analyzer->getBestDefinitionAlternative($def);
788  $def = $def[$best_alt];
789  unset($def["nativetype"]);
790  unset($def["mdb2type"]);
791 
792  $f["definition"] = $def;
793  $f["name"] = $a_new_column;
794 
795  $changes = array(
796  "rename" => array(
797  $a_column => $f
798  )
799  );
800 
801  $r = $manager->alterTable($a_table, $changes, false);
802 
803  return $this->handleError($r, "renameTableColumn(" . $a_table . "," . $a_column . "," . $a_new_column . ")");
804  }
raisePearError($a_message, $a_level="")
Raise an error.
Definition: class.ilDB.php:460
$r
Definition: example_031.php:79
checkColumnName($a_name)
Check whether a column name is valid.
handleError($a_res, $a_info="", $a_level="")
Handle MDB2 Errors.
Definition: class.ilDB.php:423
Create styles array
The data for the language used.
$def
Definition: croninfo.php:21
This class gives all kind of DB information using the MDB2 manager and reverse module.
+ Here is the call graph for this function:

◆ replace()

ilDB::replace (   $a_table,
  $a_pk_columns,
  $a_other_columns 
)

Replace into method.

Parameters
stringtable name
arrayprimary key values: array("field1" => array("text", $name), "field2" => ...)
arrayother values: array("field1" => array("text", $name), "field2" => ...)

Implements ilDBInterface.

Definition at line 1674 of file class.ilDB.php.

References $r, array, free(), handleError(), manipulateF(), and MDB2_PREPARE_MANIP.

1675  {
1676  // this is the mysql implementation
1677  $a_columns = array_merge($a_pk_columns, $a_other_columns);
1678  $fields = array();
1679  $field_values = array();
1680  $placeholders = array();
1681  $types = array();
1682  $values = array();
1683  $lobs = false;
1684  $lob = array();
1685  foreach ($a_columns as $k => $col) {
1686  $fields[] = $k;
1687  $placeholders[] = "%s";
1688  $placeholders2[] = ":$k";
1689  $types[] = $col[0];
1690 
1691  // integer auto-typecast (this casts bool values to integer)
1692  if ($col[0] == 'integer' && !is_null($col[1])) {
1693  $col[1] = (int) $col[1];
1694  }
1695 
1696  $values[] = $col[1];
1697  $field_values[$k] = $col[1];
1698  if ($col[0] == "blob" || $col[0] == "clob") {
1699  $lobs = true;
1700  $lob[$k] = $k;
1701  }
1702  }
1703  if ($lobs) { // lobs -> use prepare execute (autoexecute broken in PEAR 2.4.1)
1704  $st = $this->db->prepare("REPLACE INTO " . $a_table . " (" . implode($fields, ",") . ") VALUES (" .
1705  implode($placeholders2, ",") . ")", $types, MDB2_PREPARE_MANIP, $lob);
1706  $this->handleError($st, "insert / prepare/execute(" . $a_table . ")");
1707  $r = $st->execute($field_values);
1708  //$r = $this->db->extended->autoExecute($a_table, $field_values, MDB2_AUTOQUERY_INSERT, null, $types);
1709  $this->handleError($r, "insert / prepare/execute(" . $a_table . ")");
1710  $this->free($st);
1711  } else { // if no lobs are used, take simple manipulateF
1712  $q = "REPLACE INTO " . $a_table . " (" . implode($fields, ",") . ") VALUES (" .
1713  implode($placeholders, ",") . ")";
1714  $r = $this->manipulateF($q, $types, $values);
1715  }
1716  return $r;
1717  }
manipulateF($a_query, $a_types, $a_values)
Formatted manupulate (for DELETE, UPDATE, INSERT).
$r
Definition: example_031.php:79
const MDB2_PREPARE_MANIP
These are just helper constants to more verbosely express parameters to prepare() ...
Definition: MDB2.php:114
free($a_st)
Free a statement / result set.
handleError($a_res, $a_info="", $a_level="")
Handle MDB2 Errors.
Definition: class.ilDB.php:423
Create styles array
The data for the language used.
+ Here is the call graph for this function:

◆ rollback()

ilDB::rollback ( )

Rollback a transaction.

Implements ilDBInterface.

Definition at line 2196 of file class.ilDB.php.

References $res, handleError(), lockTables(), and unlockTables().

2197  {
2198  $res = $this->db->rollback();
2199 
2200  return $this->handleError($res, "rollback()");
2201  }
foreach($_POST as $key=> $value) $res
handleError($a_res, $a_info="", $a_level="")
Handle MDB2 Errors.
Definition: class.ilDB.php:423
+ Here is the call graph for this function:

◆ sanitizeMB4StringIfNotSupported()

ilDB::sanitizeMB4StringIfNotSupported (   $query)

Parameters
$querystring to sanitize, all MB4-Characters like emojis will re replaced with ???
Returns
string sanitized query

Implements ilDBInterface.

Definition at line 2384 of file class.ilDB.php.

References $query, doesCollationSupportMB4Strings(), and ilDBConstants\MB4_REPLACEMENT.

2385  {
2386  if (!$this->doesCollationSupportMB4Strings()) {
2387  $query_replaced = preg_replace(
2388  '/[\x{10000}-\x{10FFFF}]/u',
2390  $query
2391  );
2392  if (!empty($query_replaced)) {
2393  return $query_replaced;
2394  }
2395  }
2396 
2397  return $query;
2398  }
doesCollationSupportMB4Strings()
$query
+ Here is the call graph for this function:

◆ sequenceExists()

ilDB::sequenceExists (   $a_sequence)

Check, whether a given sequence exists.

Parameters
stringsequence name
Returns
boolean true, if sequence exists

Implements ilDBInterface.

Definition at line 2096 of file class.ilDB.php.

References listSequences().

2097  {
2098  $sequences = $this->listSequences();
2099 
2100  if (is_array($sequences)) {
2101  if (in_array($a_sequence, $sequences)) {
2102  return true;
2103  }
2104  }
2105  return false;
2106  }
listSequences()
Get all sequences.
+ Here is the call graph for this function:

◆ setDBHost()

ilDB::setDBHost (   $a_host)

Set database host.

Parameters
stringdatabase host

Implements ilDBInterface.

Definition at line 113 of file class.ilDB.php.

Referenced by initFromIniFile().

114  {
115  $this->db_host = $a_host;
116  }
+ Here is the caller graph for this function:

◆ setDBName()

ilDB::setDBName (   $a_name)

Set database name.

Parameters
stringdatabase name

Definition at line 153 of file class.ilDB.php.

Referenced by initFromIniFile().

154  {
155  $this->db_name = $a_name;
156  }
+ Here is the caller graph for this function:

◆ setDBPassword()

ilDB::setDBPassword (   $a_password)

Set database password.

Parameters
stringdatabase password

Implements ilDBInterface.

Definition at line 133 of file class.ilDB.php.

Referenced by initFromIniFile().

134  {
135  $this->db_password = $a_password;
136  }
+ Here is the caller graph for this function:

◆ setDBPort()

ilDB::setDBPort (   $a_port)

Set database port.

Parameters
stringdatabase port

Implements ilDBInterface.

Definition at line 93 of file class.ilDB.php.

Referenced by initFromIniFile().

94  {
95  $this->db_port = $a_port;
96  }
+ Here is the caller graph for this function:

◆ setDBUser()

ilDB::setDBUser (   $a_user)

Set database user.

Parameters
stringdatabase user

Implements ilDBInterface.

Definition at line 73 of file class.ilDB.php.

Referenced by initFromIniFile().

74  {
75  $this->db_user = $a_user;
76  }
+ Here is the caller graph for this function:

◆ setLimit()

ilDB::setLimit (   $a_limit,
  $a_offset = 0 
)

Set limit and offset for a query.

Implements ilDBInterface.

Definition at line 1431 of file class.ilDB.php.

1432  {
1433  $this->db->setLimit($a_limit, $a_offset);
1434  }

◆ setSubType()

ilDB::setSubType (   $a_value)

Set sub type.

Parameters
string$a_value

Definition at line 2324 of file class.ilDB.php.

References string.

2325  {
2326  $this->sub_type = (string) $a_value;
2327  }
Add rich text string

◆ substr()

ilDB::substr (   $a_exp,
  $a_pos = 1,
  $a_len = -1 
)

Substring.

Parameters

Definition at line 1867 of file class.ilDB.php.

Referenced by checkColumnName(), checkTableName(), dropTable(), logStatement(), and ilDBMySQL\setMaxAllowedPacket().

1868  {
1869  $lenstr = "";
1870  if ($a_len > -1) {
1871  $lenstr = ", " . $a_len;
1872  }
1873  return " SUBSTR(" . $a_exp . ", " . $a_pos . $lenstr . ") ";
1874  }
+ Here is the caller graph for this function:

◆ supports()

ilDB::supports (   $feature)
Parameters
$feature
Returns
bool

Implements ilDBInterface.

Definition at line 379 of file class.ilDB.php.

References supportsFulltext(), supportsSlave(), and supportsTransactions().

380  {
381  switch ($feature) {
382  case 'transaction':
383  return $this->supportsTransactions();
384  case 'fulltext':
385  return $this->supportsFulltext();
386  case 'slave':
387  return $this->supportsSlave();
388  default:
389  return false;
390  }
391  }
supportsFulltext()
Definition: class.ilDB.php:359
supportsSlave()
Supports slave.
Definition: class.ilDB.php:370
supportsTransactions()
Definition: class.ilDB.php:397
+ Here is the call graph for this function:

◆ supportsEngineMigration()

ilDB::supportsEngineMigration ( )
Returns
bool

Definition at line 2354 of file class.ilDB.php.

2355  {
2356  return false;
2357  }

◆ supportsFulltext()

ilDB::supportsFulltext ( )
Returns
bool

Implements ilDBInterface.

Definition at line 359 of file class.ilDB.php.

Referenced by dropPrimaryKey(), and supports().

360  {
361  return false;
362  }
+ Here is the caller graph for this function:

◆ supportsSlave()

ilDB::supportsSlave ( )

Supports slave.

Parameters

Implements ilDBInterface.

Definition at line 370 of file class.ilDB.php.

Referenced by supports(), and useSlave().

371  {
372  return false;
373  }
+ Here is the caller graph for this function:

◆ supportsTransactions()

ilDB::supportsTransactions ( )
Returns
bool

Implements ilDBInterface.

Definition at line 397 of file class.ilDB.php.

Referenced by supports().

398  {
399  // we generally do not want ilDB to support transactions, only PDO-instances
400  return false;
401  }
+ Here is the caller graph for this function:

◆ tableColumnExists()

ilDB::tableColumnExists (   $a_table,
  $a_column_name 
)

Checks for the existence of a table column.

Parameters
string$a_tableThe table name which should be examined
string$a_column_nameThe name of the column
Returns
boolean TRUE if the table column exists, FALSE otherwise

Implements ilDBInterface.

Definition at line 2023 of file class.ilDB.php.

References $r, and MDB2\isError().

2024  {
2025  $column_visibility = false;
2026  $manager = $this->db->loadModule('Manager');
2027  $r = $manager->listTableFields($a_table);
2028 
2029  if (!MDB2::isError($r)) {
2030  foreach ($r as $field) {
2031  if ($field == $a_column_name) {
2032  $column_visibility = true;
2033  }
2034  }
2035  }
2036 
2037  return $column_visibility;
2038  }
isError($data, $code=null)
Tell whether a value is a MDB2 error.
Definition: MDB2.php:599
$r
Definition: example_031.php:79
+ Here is the call graph for this function:

◆ tableExists()

ilDB::tableExists (   $a_table)

Check, whether a given table exists.

Parameters
stringtable name
Returns
boolean true, if table exists

Implements ilDBInterface.

Definition at line 2004 of file class.ilDB.php.

References listTables().

2005  {
2006  $tables = $this->listTables();
2007 
2008  if (is_array($tables)) {
2009  if (in_array($a_table, $tables)) {
2010  return true;
2011  }
2012  }
2013  return false;
2014  }
listTables()
Get all tables.
+ Here is the call graph for this function:

◆ uniqueConstraintExists()

ilDB::uniqueConstraintExists (   $a_table,
array  $a_fields 
)

Checks if a unique constraint exists based on the fields of the unique constraint (not the name)

Parameters
string$a_tabletable name
array$a_fieldsarray of field names (strings)
Returns
bool false if no unique constraint with the given fields exists

Definition at line 2047 of file class.ilDB.php.

2048  {
2049  if (is_file("./Services/Database/classes/class.ilDBAnalyzer.php")) {
2050  include_once("./Services/Database/classes/class.ilDBAnalyzer.php");
2051  } else {
2052  include_once("../Services/Database/classes/class.ilDBAnalyzer.php");
2053  }
2054  $analyzer = new ilDBAnalyzer();
2055  $cons = $analyzer->getConstraintsInformation($a_table);
2056  foreach ($cons as $c) {
2057  if ($c["type"] == "unique" && count($a_fields) == count($c["fields"])) {
2058  $all_in = true;
2059  foreach ($a_fields as $f) {
2060  if (!isset($c["fields"][$f])) {
2061  $all_in = false;
2062  }
2063  }
2064  if ($all_in) {
2065  return true;
2066  }
2067  }
2068  }
2069  return false;
2070  }
This class gives all kind of DB information using the MDB2 manager and reverse module.

◆ unixTimestamp()

ilDB::unixTimestamp ( )

Unix timestamp.

Definition at line 1988 of file class.ilDB.php.

1989  {
1990  return "UNIX_TIMESTAMP()";
1991  }

◆ unlockTables()

ilDB::unlockTables ( )
abstract

Unlock tables locked by previous lock table calls.

Deprecated:
Use ilAtomQuery instead
Returns

Implements ilDBInterface.

Referenced by rollback().

+ Here is the caller graph for this function:

◆ update()

ilDB::update (   $a_table,
  $a_columns,
  $a_where 
)

Convenient method for standard update statements, example field array:

array("field1" => array("text", $name), // will use "%s" "field2" => array("integer", $id), // will use "%s"

Example where array: array("id" => array("integer", $id))

Implements ilDBInterface.

Definition at line 1596 of file class.ilDB.php.

References $r, array, free(), handleError(), manipulateF(), MDB2_PREPARE_MANIP, and quote().

1597  {
1598  $fields = array();
1599  $field_values = array();
1600  $placeholders = array();
1601  $types = array();
1602  $values = array();
1603  $lobs = false;
1604  $lob = array();
1605  foreach ($a_columns as $k => $col) {
1606  $fields[] = $k;
1607  $placeholders[] = "%s";
1608  $placeholders2[] = ":$k";
1609  $types[] = $col[0];
1610 
1611  // integer auto-typecast (this casts bool values to integer)
1612  if ($col[0] == 'integer' && !is_null($col[1])) {
1613  $col[1] = (int) $col[1];
1614  }
1615 
1616  $values[] = $col[1];
1617  $field_values[$k] = $col[1];
1618  if ($col[0] == "blob" || $col[0] == "clob") {
1619  $lobs = true;
1620  $lob[$k] = $k;
1621  }
1622  }
1623 
1624  if ($lobs) {
1625  $q = "UPDATE " . $a_table . " SET ";
1626  $lim = "";
1627  foreach ($fields as $k => $field) {
1628  $q.= $lim . $field . " = " . $placeholders2[$k];
1629  $lim = ", ";
1630  }
1631  $q.= " WHERE ";
1632  $lim = "";
1633  foreach ($a_where as $k => $col) {
1634  $q.= $lim . $k . " = " . $this->quote($col[1], $col[0]);
1635  $lim = " AND ";
1636  }
1637  $st = $this->db->prepare($q, $types, MDB2_PREPARE_MANIP, $lob);
1638  $r = $st->execute($field_values);
1639 
1640  //$r = $this->db->extended->autoExecute($a_table, $field_values, MDB2_AUTOQUERY_INSERT, null, $types);
1641  $this->handleError($r, "update / prepare/execute(" . $a_table . ")");
1642  $this->free($st);
1643  } else {
1644  foreach ($a_where as $k => $col) {
1645  $types[] = $col[0];
1646  $values[] = $col[1];
1647  $field_values[$k] = $col;
1648  }
1649  $q = "UPDATE " . $a_table . " SET ";
1650  $lim = "";
1651  foreach ($fields as $k => $field) {
1652  $q.= $lim . $field . " = " . $placeholders[$k];
1653  $lim = ", ";
1654  }
1655  $q.= " WHERE ";
1656  $lim = "";
1657  foreach ($a_where as $k => $col) {
1658  $q.= $lim . $k . " = %s";
1659  $lim = " AND ";
1660  }
1661 
1662  $r = $this->manipulateF($q, $types, $values);
1663  }
1664  return $r;
1665  }
manipulateF($a_query, $a_types, $a_values)
Formatted manupulate (for DELETE, UPDATE, INSERT).
quote($a_query, $a_type=null)
Wrapper for quote method.
$r
Definition: example_031.php:79
const MDB2_PREPARE_MANIP
These are just helper constants to more verbosely express parameters to prepare() ...
Definition: MDB2.php:114
free($a_st)
Free a statement / result set.
handleError($a_res, $a_info="", $a_level="")
Handle MDB2 Errors.
Definition: class.ilDB.php:423
Create styles array
The data for the language used.
+ Here is the call graph for this function:

◆ upper()

ilDB::upper (   $a_exp)

Upper.

Parameters
stringexpression
Returns
string upper sql string

Implements ilDBInterface.

Definition at line 1882 of file class.ilDB.php.

1883  {
1884  return " UPPER(" . $a_exp . ") ";
1885  }

◆ useSlave()

ilDB::useSlave (   $a_val = true)

Use slave.

Parameters

Implements ilDBInterface.

Definition at line 409 of file class.ilDB.php.

References supportsSlave().

410  {
411  if (!$this->supportsSlave()) {
412  return false;
413  }
414  $this->use_slave = $a_val;
415  }
supportsSlave()
Supports slave.
Definition: class.ilDB.php:370
+ Here is the call graph for this function:

Field Documentation

◆ $allowed_attributes

ilDB::$allowed_attributes
Initial value:
"text" => array("length", "notnull", "default", "fixed"),
"integer" => array("length", "notnull", "default", "unsigned"),
"float" => array("notnull", "default"),
"date" => array("notnull", "default"),
"time" => array("notnull", "default"),
"timestamp" => array("notnull", "default"),
"clob" => array("notnull", "default"),
"blob" => array("notnull", "default")
)

Definition at line 55 of file class.ilDB.php.

Referenced by checkColumnDefinition(), and getAllowedAttributes().

◆ $db

ilDB::$db

Definition at line 46 of file class.ilDB.php.

◆ $error_class

ilDB::$error_class

Definition at line 40 of file class.ilDB.php.

◆ $result

ilDB::$result

Definition at line 52 of file class.ilDB.php.

◆ $sub_type

ilDB::$sub_type

Definition at line 66 of file class.ilDB.php.

Referenced by getSubType().

◆ LOCK_READ

const ilDB::LOCK_READ = 2

Definition at line 32 of file class.ilDB.php.

◆ LOCK_WRITE

const ilDB::LOCK_WRITE = 1

Definition at line 31 of file class.ilDB.php.


The documentation for this class was generated from the following file: