ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 ()
 @inheritDoc More...
 
 cast ($a_field_name, $a_dest_type)
 @inheritDoc More...
 
- 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
 doesCollationSupportMB4Strings ()
 
 sanitizeMB4StringIfNotSupported ($query)
 
 initFromIniFile ($tmpClientIniFile=null)
 
 connect ($return_false_on_error=false)
 
 nextId ($table_name)
 
 createTable ($table_name, $fields, $drop_table=false, $ignore_erros=false)
 
 addPrimaryKey ($table_name, $primary_keys)
 
 createSequence ($table_name, $start=1)
 
 getSequenceName ($table_name)
 
 tableExists ($table_name)
 
 tableColumnExists ($table_name, $column_name)
 
 addTableColumn ($table_name, $column_name, $attributes)
 
 dropTable ($table_name, $error_if_not_existing=true)
 
 renameTable ($old_name, $new_name)
 
 query ($query)
 
 fetchAll ($query_result, $fetch_mode=ilDBConstants::FETCHMODE_ASSOC)
 
 dropSequence ($table_name)
 
 dropTableColumn ($table_name, $column_name)
 
 renameTableColumn ($table_name, $column_old_name, $column_new_name)
 
 insert ($table_name, $values)
 
 fetchObject ($query_result)
 
 update ($table_name, $values, $where)
 
 manipulate ($query)
 
 fetchAssoc ($query_result)
 
 numRows ($query_result)
 
 quote ($value, $type)
 
 addIndex ($table_name, $fields, $index_name='', $fulltext=false)
 
 indexExistsByFields ($table_name, $fields)
 
 getDSN ()
 Get DSN. More...
 
 getDBType ()
 Get DSN. More...
 
 lockTables ($tables)
 Abstraction of lock table. More...
 
 unlockTables ()
 Unlock tables locked by previous lock table calls. More...
 
 in ($field, $values, $negate=false, $type="")
 
 queryF ($query, $types, $values)
 
 manipulateF ($query, $types, $values)
 
 useSlave ($bool)
 Return false iff slave is not supported. More...
 
 setLimit ($limit, $offset)
 
 like ($column, $type, $value="?", $case_insensitive=true)
 Generate a like subquery. More...
 
 now ()
 
 replace ($table, $primaryKeys, $otherColumns)
 Replace into method. More...
 
 equals ($columns, $value, $type, $emptyOrNull=false)
 
 setDBUser ($user)
 
 setDBPort ($port)
 
 setDBPassword ($password)
 
 setDBHost ($host)
 
 upper ($a_exp)
 
 lower ($a_exp)
 
 substr ($a_exp)
 
 prepareManip ($a_query, $a_types=null)
 
 enableResultBuffering ($a_status)
 
 execute ($stmt, $data=array())
 
 sequenceExists ($sequence)
 
 listSequences ()
 
 supports ($feature)
 
 supportsFulltext ()
 
 supportsSlave ()
 
 supportsTransactions ()
 
 listTables ()
 
 loadModule ($module)
 
 getAllowedAttributes ()
 
 concat (array $values, $allow_null=true)
 
 locate ($a_needle, $a_string, $a_start_pos=1)
 
 quoteIdentifier ($identifier, $check_option=false)
 
 modifyTableColumn ($table, $column, $attributes)
 
 free ($a_st)
 
 checkTableName ($a_name)
 
 beginTransaction ()
 
 commit ()
 
 rollback ()
 
 constraintName ($a_table, $a_constraint)
 
 dropIndex ($a_table, $a_name="i1")
 
 createDatabase ($a_name, $a_charset="utf8", $a_collation="")
 
 dropIndexByFields ($table_name, $afields)
 
 getPrimaryKeyIdentifier ()
 
 addFulltextIndex ($table_name, $afields, $a_name='in')
 
 dropFulltextIndex ($a_table, $a_name)
 
 isFulltextIndex ($a_table, $a_name)
 
 setStorageEngine ($storage_engine)
 
 getStorageEngine ()
 
 buildAtomQuery ()
 
 groupConcat ($a_field_name, $a_seperator=",", $a_order=NULL)
 
 cast ($a_field_name, $a_dest_type)
 

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...
 
static getReservedWords ()
 Get reserved words. More...
 
static isReservedWord ($a_word)
 

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.

Reimplemented in ilDBMySQL.

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

963 {
964 return false;
965 }

◆ 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 871 of file class.ilDB.php.

872 {
873 $manager = $this->db->loadModule('Manager');
874
875 $fields = array();
876 foreach ($a_fields as $f)
877 {
878 $fields[$f] = array();
879 }
880 $definition = array (
881 'primary' => true,
882 'fields' => $fields
883 );
884 $r = $manager->createConstraint($a_table,
885 $this->constraintName($a_table, $this->getPrimaryKeyIdentifier()), $definition);
886
887 return $this->handleError($r, "addPrimaryKey(".$a_table.")");
888 }
getPrimaryKeyIdentifier()
Primary key identifier.
Definition: class.ilDB.php:893
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.
$r
Definition: example_031.php:79

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

+ 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 649 of file class.ilDB.php.

650 {
651
652 $manager = $this->db->loadModule('Manager');
653
654 if (!$this->checkColumnName($a_column))
655 {
656 $this->raisePearError("ilDB Error: addTableColumn(".$a_table.", ".$a_column.")<br />".
657 $this->error_str);
658 }
659 if (!$this->checkColumnDefinition($a_attributes))
660 {
661 $this->raisePearError("ilDB Error: addTableColumn(".$a_table.", ".$a_column.")<br />".
662 $this->error_str);
663 }
664
665 $changes = array(
666 "add" => array(
667 $a_column => $a_attributes
668 )
669 );
670
671 $r = $manager->alterTable($a_table, $changes, false);
672
673 return $this->handleError($r, "addTableColumn(".$a_table.", ".$a_column.")");
674 }
checkColumnDefinition($a_def, $a_modify_mode=false)
Check whether a column definition is valid.
checkColumnName($a_name)
Check whether a column name is valid.
raisePearError($a_message, $a_level="")
Raise an error.
Definition: class.ilDB.php:459

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

+ 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 1919 of file class.ilDB.php.

1920 {
1921 if (!is_array($a_arr))
1922 {
1923 $a_arr = array();
1924 }
1925 if ($a_cnt > 0)
1926 {
1927 $type_arr = array_fill(0, $a_cnt, $a_type);
1928 }
1929 else
1930 {
1931 $type_arr = array();
1932 }
1933 return array_merge($a_arr, $type_arr);
1934 }
$a_type
Definition: workflow.php:93

References $a_type.

◆ 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 1058 of file class.ilDB.php.

1059 {
1060 $manager = $this->db->loadModule('Manager');
1061
1062 // check index name
1063 if (!$this->checkIndexName($a_name))
1064 {
1065 $this->raisePearError("ilDB Error: addUniqueConstraint(".$a_table.",".$a_name.")<br />".
1066 $this->error_str);
1067 }
1068
1069 $fields = array();
1070 foreach ($a_fields as $f)
1071 {
1072 $fields[$f] = array();
1073 }
1074 $definition = array (
1075 'unique' => true,
1076 'fields' => $fields
1077 );
1078
1079 $r = $manager->createConstraint($a_table, $this->constraintName($a_table, $a_name), $definition);
1080
1081 return $this->handleError($r, "addUniqueConstraint(".$a_table.")");
1082 }
checkIndexName($a_name)
Check whether an index name is valid.

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

+ 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 628 of file class.ilDB.php.

629 {
630 if ($a_options == "")
631 {
632 $a_options = array();
633 }
634
635 $manager = $this->db->loadModule('Manager');
636 $r = $manager->alterTable($a_name, $a_changes, false);
637
638 return $this->handleError($r, "alterTable(".$a_name.")");
639 }

References $r, and handleError().

+ 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 2403 of file class.ilDB.php.

2404 {
2405 $res = $this->db->autoExecute($a_tablename,$a_fields,$a_mode,$a_where);
2406
2407 return $this->handleError($res, "autoExecute(".$a_tablename.")");
2408 }

References $res, and handleError().

+ 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 2342 of file class.ilDB.php.

2343 {
2344 if (!$this->db->supports('transactions'))
2345 {
2346 $this->raisePearError("ilDB::beginTransaction: Transactions are not supported.", $this->error_class->FATAL);
2347 }
2348 $res = $this->db->beginTransaction();
2349
2350 return $this->handleError($res, "beginTransaction()");
2351 }

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

+ Here is the call graph for this function:

◆ buildAtomQuery()

ilDB::buildAtomQuery ( )
Returns
\ilAtomQuery

Implements ilDBInterface.

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

2543 {
2544 require_once('./Services/Database/classes/Atom/class.ilAtomQueryLock.php');
2545
2546 return new ilAtomQueryLock($this);
2547 }
Class ilAtomQueryLock.

◆ cast()

ilDB::cast (   $a_field_name,
  $a_dest_type 
)

@inheritDoc

Implements ilDBInterface.

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

2580 {
2581 $manager = $this->db->loadModule('Manager');
2582 return $manager->getQueryUtils()->cast($a_field_name, $a_dest_type);
2583 }

◆ checkColumn()

ilDB::checkColumn (   $a_col,
  $a_def 
)

Check column definition.

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

1222 {
1223 if (!$this->checkColumnName($a_col))
1224 {
1225 return false;
1226 }
1227
1228 if (!$this->checkColumnDefinition($a_def))
1229 {
1230 return false;
1231 }
1232
1233 return true;
1234 }

References checkColumnDefinition(), and checkColumnName().

Referenced by checkTableColumns().

+ 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 1241 of file class.ilDB.php.

1242 {
1243 // check valid type
1244 if (!in_array($a_def["type"], array("text", "integer", "float", "date", "time", "timestamp", "clob", "blob")))
1245 {
1246 switch ($a_def["type"])
1247 {
1248 case "boolean":
1249 $this->error_str = "Invalid column type '".$a_def["type"]."'. Use integer(1) instead.";
1250 break;
1251
1252 case "decimal":
1253 $this->error_str = "Invalid column type '".$a_def["type"]."'. Use float or integer instead.";
1254 break;
1255
1256 default:
1257 $this->error_str = "Invalid column type '".$a_def["type"]."'. Allowed types are: ".
1258 "text, integer, float, date, time, timestamp, clob and blob.";
1259 }
1260 }
1261
1262 // check used attributes
1264
1265 foreach ($a_def as $k => $v)
1266 {
1267 if ($k != "type" && !in_array($k, $allowed_attributes[$a_def["type"]]))
1268 {
1269 $this->error_str = "Attribute '".$k."' is not allowed for column type '".$a_def["type"]."'.";
1270 return false;
1271 }
1272 }
1273
1274 // type specific checks
1275 switch ($a_def["type"])
1276 {
1277 case "text":
1278 if ($a_def["length"] < 1 || $a_def["length"] > 4000)
1279 {
1280 if (!$a_modify_mode || isset($a_def["length"]))
1281 {
1282 $this->error_str = "Invalid length '".$a_def["length"]."' for type text.".
1283 " Length must be >=1 and <= 4000.";
1284 return false;
1285 }
1286 }
1287 break;
1288
1289 case "integer":
1290 if (!in_array($a_def["length"], array(1, 2, 3, 4, 8)))
1291 {
1292 if (!$a_modify_mode || isset($a_def["length"]))
1293 {
1294 $this->error_str = "Invalid length '".$a_def["length"]."' for type integer.".
1295 " Length must be 1, 2, 3, 4 or 8 (bytes).";
1296 return false;
1297 }
1298 }
1299 if ($a_def["unsigned"])
1300 {
1301 $this->error_str = "Unsigned attribut must not be true for type integer.";
1302 return false;
1303 }
1304 break;
1305 }
1306
1307 return true;
1308 }
$allowed_attributes
Definition: class.ilDB.php:55

References $allowed_attributes.

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

+ 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 1315 of file class.ilDB.php.

1316 {
1317 if (!preg_match ("/^[a-z]+[_a-z0-9]*$/", $a_name))
1318 {
1319 $this->error_str = "Invalid column name '".$a_name."'. Column name must only contain _a-z0-9 and must start with a-z.";
1320 return false;
1321 }
1322
1323 if ($this->isReservedWord($a_name))
1324 {
1325 $this->error_str = "Invalid column name '".$a_name."' (Reserved Word).";
1326 return false;
1327 }
1328
1329 if (strtolower(substr($a_name, 0, 4)) == "sys_")
1330 {
1331 $this->error_str = "Invalid column name '".$a_name."'. Name must not start with 'sys_'.";
1332 return false;
1333 }
1334
1335 if (strlen($a_name) > 30)
1336 {
1337 $this->error_str = "Invalid column name '".$a_name."'. Maximum column identifer length is 30 bytes.";
1338 return false;
1339 }
1340
1341 return true;
1342 }
static isReservedWord($a_word)
Checks whether a word is a reserved word in one of the supported databases.
substr($a_exp, $a_pos=1, $a_len=-1)
Substring.

References isReservedWord(), and substr().

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

+ 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 1349 of file class.ilDB.php.

1350 {
1351 if (!preg_match ("/^[a-z]+[_a-z0-9]*$/", $a_name))
1352 {
1353 $this->error_str = "Invalid column name '".$a_name."'. Column name must only contain _a-z0-9 and must start with a-z.";
1354 return false;
1355 }
1356
1357 if ($this->isReservedWord($a_name))
1358 {
1359 $this->error_str = "Invalid column name '".$a_name."' (Reserved Word).";
1360 return false;
1361 }
1362
1363 if (strlen($a_name) > 3)
1364 {
1365 $this->error_str = "Invalid index name '".$a_name."'. Maximum index identifer length is 3 bytes.";
1366 return false;
1367 }
1368
1369 return true;
1370 }

References isReservedWord().

Referenced by addUniqueConstraint().

+ 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 1205 of file class.ilDB.php.

1206 {
1207 foreach ($a_cols as $col => $def)
1208 {
1209 if (!$this->checkColumn($col, $def))
1210 {
1211 return false;
1212 }
1213 }
1214
1215 return true;
1216 }
checkColumn($a_col, $a_def)
Check column definition.

References checkColumn().

Referenced by createTable().

+ 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 1171 of file class.ilDB.php.

1172 {
1173 if (!preg_match ("/^[a-z]+[_a-z0-9]*$/", $a_name))
1174 {
1175 $this->error_str = "Table name must only contain _a-z0-9 and must start with a-z.";
1176 return false;
1177 }
1178
1179 if ($this->isReservedWord($a_name))
1180 {
1181 $this->error_str = "Invalid table name '".$a_name."' (Reserved Word).";
1182 return false;
1183 }
1184
1185 if (strtolower(substr($a_name, 0, 4)) == "sys_")
1186 {
1187 $this->error_str = "Invalid table name '".$a_name."'. Name must not start with 'sys_'.";
1188 return false;
1189 }
1190
1191 if (strlen($a_name) > 22)
1192 {
1193 $this->error_str = "Invalid table name '".$a_name."'. Maximum table identifer length is 22 bytes.";
1194 return false;
1195 }
1196
1197 return true;
1198 }

References isReservedWord(), and substr().

Referenced by createTable(), and renameTable().

+ 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 2356 of file class.ilDB.php.

2357 {
2358 $res = $this->db->commit();
2359
2360 return $this->handleError($res, "commit()");
2361 }

References $res, and handleError().

+ 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.

Reimplemented in ilDBOracle.

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

1956 {
1957 if(!count($a_values))
1958 {
1959 return ' ';
1960 }
1961
1962 $concat = ' CONCAT(';
1963 $first = true;
1964 foreach($a_values as $field_info)
1965 {
1966 $val = $field_info[0];
1967
1968 if(!$first)
1969 {
1970 $concat .= ',';
1971 }
1972
1973 if($a_allow_null)
1974 {
1975 $concat .= 'COALESCE(';
1976 }
1977 $concat .= $val;
1978
1979 if($a_allow_null)
1980 {
1981 $concat .= ",''";
1982 $concat .= ')';
1983 }
1984
1985 $first = false;
1986 }
1987 $concat .= ') ';
1988 return $concat;
1989 }

◆ connect()

ilDB::connect (   $a_return_false_for_error = false)

Open the connection.

Implements ilDBInterface.

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

234 {
235 //set up error handling
236 $this->error_class = new ilErrorHandling();
237 $this->setErrorHandling(PEAR_ERROR_CALLBACK, array($this->error_class,'errorHandler'));
238//echo $this->getDSN();
239 //check dsn
240 if ($this->getDSN() == "")
241 {
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 {
250 return false;
251 }
252
253 $this->loadMDB2Extensions();
254
255 // set empty value portability to PEAR::DB behaviour
256 if (!$this->isDbError($this->db))
257 {
258 $this->db->setOption('portability', MDB2_PORTABILITY_ALL);
259 }
260 //check error
261 $this->handleError($this->db);
262
263 // anything, that must be done to initialize the connection
264 $this->initConnection();
265
266 return true;
267 }
const MDB2_PORTABILITY_ALL
Portability: turn on all portability features.
Definition: MDB2.php:215
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
getDSN()
Get DSN.
doConnect()
Standard way to connect to db.
Definition: class.ilDB.php:272
static isDbError($a_res)
Check error.
Definition: class.ilDB.php:489
initConnection()
Initialize the database connection.
Definition: class.ilDB.php:293
loadMDB2Extensions()
load additional mdb2 extensions and set their constants
Definition: class.ilDB.php:474

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

+ 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.

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 {
321 $this->raisePearError("No Host DSN given");
322 }
323
324 //connect to database
325 $this->db = MDB2::connect($this->getHostDSN(),
326 array("use_transactions" => true));
327 if ($a_return_false_for_error && MDB2::isError($this->db))
328 {
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 {
337 $cur = ($this->db->getOption("portability") & MDB2_PORTABILITY_EMPTY_TO_NULL);
338 $this->db->setOption("portability", $this->db->getOption("portability") - $cur);
339
340 $cur = ($this->db->getOption("portability") & MDB2_PORTABILITY_FIX_CASE);
341 $this->db->setOption("portability", $this->db->getOption("portability") - $cur);
342 }
343
344 //check error
345 $this->handleError($this->db);
346
347 // anything, that must be done to initialize the connection
348 $this->initHostConnection();
349
350 return true;
351 }
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
const MDB2_PORTABILITY_EMPTY_TO_NULL
Portability: convert empty values to null strings in data output by query*() and fetch*().
Definition: MDB2.php:203
& 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:356
getHostDSN()
Should return a valid value, if host connections are possible (connectHost) to create a new database ...
Definition: class.ilDB.php:303

References 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().

+ 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.

Reimplemented in ilDBOracle, and ilDBPostgreSQL.

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

1383 {
1384 return $a_constraint;
1385 }

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

+ 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 501 of file class.ilDB.php.

502 {
503 if ($a_collation != "")
504 {
505 $sql = "CREATE DATABASE ".$a_name.
506 " CHARACTER SET ".$a_charset.
507 " COLLATE ".$a_collation;
508 }
509 else
510 {
511 $sql = "CREATE DATABASE ".$a_name.
512 " CHARACTER SET ".$a_charset;
513 }
514
515 return $this->query($sql, false);
516 }
query($sql, $a_handle_error=true)
Query.

References 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 1144 of file class.ilDB.php.

1145 {
1146 $manager = $this->db->loadModule('Manager');
1147
1148 $r = $manager->createSequence($a_table_name, $a_start);
1149
1150 return $this->handleError($r, "createSequence(".$a_table_name.")");
1151 }

References $r, and handleError().

+ 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 526 of file class.ilDB.php.

528 {
529 // check table name
530 if (!$this->checkTableName($a_name) && !$a_ignore_erros)
531 {
532 $this->raisePearError("ilDB Error: createTable(".$a_name.")<br />".
533 $this->error_str);
534 }
535
536 // check definition array
537 if (!$this->checkTableColumns($a_definition_array) && !$a_ignore_erros)
538 {
539 $this->raisePearError("ilDB Error: createTable(".$a_name.")<br />".
540 $this->error_str);
541 }
542
543 if ($a_drop_table)
544 {
545 $this->dropTable($a_name, false);
546 }
547
549
550 $manager = $this->db->loadModule('Manager');
551 $r = $manager->createTable($a_name, $a_definition_array, $options);
552
553 return $this->handleError($r, "createTable(".$a_name.")");
554 }
checkTableColumns($a_cols)
Check table columns definition.
checkTableName($a_name)
Check whether a table name is valid.
getCreateTableOptions()
Get options for the create table statement.
Definition: class.ilDB.php:561
dropTable($a_name, $a_error_if_not_existing=true)
Drop a table.
Definition: class.ilDB.php:572
if(!is_array($argv)) $options

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

+ 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.

Reimplemented in ilDBMySQL, and ilDBOracle.

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

273 {
274 $this->db = MDB2::connect($this->getDSN(),
275 array("use_transactions" => true));
276 }

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

Referenced by connect().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ doesCollationSupportMB4Strings()

ilDB::doesCollationSupportMB4Strings ( )

@inheritDoc

Implements ilDBInterface.

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

2572 {
2573 return false;
2574 }

Referenced by sanitizeMB4StringIfNotSupported().

+ 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 1035 of file class.ilDB.php.

1036 {
1037 $manager = $this->db->loadModule('Manager');
1038
1039 if (!$this->isFulltextIndex($a_table, $a_name))
1040 {
1041 $r = $manager->dropIndex($a_table, $this->constraintName($a_table, $a_name));
1042 }
1043 else
1044 {
1045 $this->dropFulltextIndex($a_table, $a_name);
1046 }
1047
1048 return $this->handleError($r, "dropIndex(".$a_table.")");
1049 }
isFulltextIndex($a_table, $a_name)
Is index a fulltext index?
Definition: class.ilDB.php:970
dropFulltextIndex($a_table, $a_name)

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

Referenced by dropIndexByFields().

+ 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 1007 of file class.ilDB.php.

1008 {
1009 $manager = $this->db->loadModule('Manager');
1010 $reverse = $this->db->loadModule('Reverse');
1011 if($manager)
1012 {
1013 foreach($manager->listTableIndexes($a_table) as $idx_name)
1014 {
1015 $def = $reverse->getTableIndexDefinition($a_table,$idx_name);
1016 $idx_fields = array_keys((array) $def['fields']);
1017
1018 if($idx_fields === $a_fields)
1019 {
1020 return $this->dropIndex($a_table, $idx_name);
1021 }
1022 }
1023 }
1024 return false;
1025
1026 }
dropIndex($a_table, $a_name="in")
Drop an index from a table.

References dropIndex().

+ 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

Reimplemented in ilDBOracle.

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

905 {
906 $manager = $this->db->loadModule('Manager');
907
908 $r = $manager->dropConstraint($a_table,
909 $this->constraintName($a_table, $this->getPrimaryKeyIdentifier()), true);
910
911 return $this->handleError($r, "dropPrimaryKey(".$a_table.")");
912 }

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

+ 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 1157 of file class.ilDB.php.

1158 {
1159 $manager = $this->db->loadModule('Manager');
1160
1161 $r = $manager->dropSequence($a_table_name);
1162
1163 return $this->handleError($r, "dropSequence(".$a_table_name.")");
1164 }

References $r, and handleError().

+ 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 572 of file class.ilDB.php.

573 {
574 if (!$a_error_if_not_existing)
575 {
576 $tables = $this->listTables();
577 if (!in_array($a_name, $tables))
578 {
579 return;
580 }
581 }
582
583 $manager = $this->db->loadModule('Manager');
584
585 if ($this->getDBType() == "oracle")
586 {
587 // drop table constraints
588 $constraints = $manager->listTableConstraints($a_name);
589 $this->handleError($constraints, "dropTable(".$a_name."), listTableConstraints");
590 foreach ($constraints as $c)
591 {
592 if (substr($c, 0, 4) != "sys_")
593 {
594 $r = $manager->dropConstraint($a_name, $c);
595 $this->handleError($r, "dropTable(".$a_name."), dropConstraint");
596 }
597 }
598
599 // drop table indexes
600 $indexes = $manager->listTableIndexes($a_name);
601 $this->handleError($indexes, "dropTable(".$a_name."), listTableIndexes");
602 foreach ($indexes as $i)
603 {
604 $r = $manager->dropIndex($a_name, $i);
605 $this->handleError($r, "dropTable(".$a_name."), dropIndex");
606 }
607 }
608
609 // drop sequence
610 $seqs = $manager->listSequences();
611 if (in_array($a_name, $seqs))
612 {
613 $r = $manager->dropSequence($a_name);
614 $this->handleError($r, "dropTable(".$a_name."), dropSequence");
615 }
616
617 // drop table
618 $r = $manager->dropTable($a_name);
619
620 return $this->handleError($r, "dropTable(".$a_name.")");
621 }
listTables()
Get all tables.
getDBType()
Get DSN.

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

Referenced by createTable().

+ 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 683 of file class.ilDB.php.

684 {
685
686 $manager = $this->db->loadModule('Manager');
687
688 $changes = array(
689 "remove" => array(
690 $a_column => array()
691 )
692 );
693
694 $r = $manager->alterTable($a_table, $changes, false);
695
696 return $this->handleError($r, "dropTableColumn(".$a_table.", ".$a_column.")");
697 }

References $r, and handleError().

+ 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 1091 of file class.ilDB.php.

1092 {
1093 $manager = $this->db->loadModule('Manager');
1094
1095 $r = $manager->dropConstraint(
1096 $a_table, $this->constraintName($a_table, $a_name), false
1097 );
1098
1099 return $this->handleError($r, "dropUniqueConstraint(".$a_table.")");
1100 }

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

Referenced by dropUniqueConstraintByFields().

+ 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 1108 of file class.ilDB.php.

1109 {
1110 if (is_file("./Services/Database/classes/class.ilDBAnalyzer.php"))
1111 {
1112 include_once("./Services/Database/classes/class.ilDBAnalyzer.php");
1113 }
1114 else
1115 {
1116 include_once("../Services/Database/classes/class.ilDBAnalyzer.php");
1117 }
1118 $analyzer = new ilDBAnalyzer();
1119 $cons = $analyzer->getConstraintsInformation($a_table);
1120 foreach ($cons as $c)
1121 {
1122 if ($c["type"] == "unique" && count($a_fields) == count($c["fields"]))
1123 {
1124 $all_in = true;
1125 foreach ($a_fields as $f)
1126 {
1127 if (!isset($c["fields"][$f]))
1128 {
1129 $all_in = false;
1130 }
1131 }
1132 if ($all_in)
1133 {
1134 return $this->dropUniqueConstraint($a_table, $c['name']);
1135 }
1136 }
1137 }
1138 return false;
1139 }
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.

References dropUniqueConstraint().

+ 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 201 of file class.ilDB.php.

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

◆ 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 2090 of file class.ilDB.php.

2091 {
2092 if (!$a_empty_or_null || $a_value != "")
2093 {
2094 return $a_col." = ".$this->quote($a_value, $a_type);
2095 }
2096 else
2097 {
2098 return "(".$a_col." = '' OR $a_col IS NULL)";
2099 }
2100 }
quote($a_query, $a_type=null)
Wrapper for quote method.

References $a_type, and quote().

+ 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 2105 of file class.ilDB.php.

2106 {
2107 if (!$a_empty_or_null)
2108 {
2109 return $a_col." <> ".$this->quote($a_value, $a_type);
2110 }
2111 if ($a_value != "")
2112 {
2113 return "(".$a_col." <> ".$this->quote($a_value, $a_type). " OR ".
2114 $a_col." IS NULL)";
2115 }
2116 else
2117 {
2118 return "(".$a_col." <> '' AND $a_col IS NOT NULL)";
2119 }
2120 }

References $a_type, and quote().

+ 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 1605 of file class.ilDB.php.

1606 {
1607 $res = $a_stmt->execute($a_data);
1608
1609 return $this->handleError($res, "execute(".$a_stmt->query.")");
1610 }

References $res, and handleError().

+ 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 1621 of file class.ilDB.php.

1622 {
1623 $res = $this->db->extended->executeMultiple($a_stmt,$a_data);
1624
1625 return $this->handleError($res, "executeMultiple(".$a_stmt->query.")");
1626 }

References $res, and handleError().

+ 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 1840 of file class.ilDB.php.

1841 {
1842 return $a_set->fetchRow(ilDBConstants::FETCHMODE_ASSOC);
1843 }

References ilDBConstants\FETCHMODE_ASSOC.

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

+ 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 1858 of file class.ilDB.php.

1859 {
1860 return $a_set->fetchRow(ilDBConstants::FETCHMODE_OBJECT);
1861 }

References ilDBConstants\FETCHMODE_OBJECT.

◆ free()

ilDB::free (   $a_st)

Free a statement / result set.

Implements ilDBInterface.

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

1849 {
1850 return $a_st->free();
1851 }

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

+ 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

Reimplemented in ilDBOracle.

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

2129 {
2130 return "FROM_UNIXTIME(".$a_expr.")";
2131 }

◆ getAllowedAttributes()

ilDB::getAllowedAttributes ( )
Returns
array

Implements ilDBInterface.

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

1373 {
1375 }

References $allowed_attributes.

◆ getCreateTableOptions()

ilDB::getCreateTableOptions ( )
protected

Get options for the create table statement.

Returns
array

Reimplemented in ilDBInnoDB, and ilDBMySQL.

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

562 {
563 return array();
564 }

Referenced by createTable().

+ 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.

124 {
125 return $this->db_host;
126 }

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

+ 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.

164 {
165 return $this->db_name;
166 }

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

+ 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.

144 {
145 return $this->db_password;
146 }

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

+ 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.

104 {
105 return $this->db_port;
106 }

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

+ Here is the caller graph for this function:

◆ getDBType()

ilDB::getDBType ( )
abstract

Get DSN.

This must be overwritten in DBMS specific class.

Implements ilDBInterface.

Reimplemented in ilDBInnoDB, ilDBMySQL, ilDBOracle, and ilDBPostgreSQL.

Referenced by dropTable().

+ 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.

84 {
85 return $this->db_user;
86 }

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

+ Here is the caller graph for this function:

◆ getDBVersion()

ilDB::getDBVersion ( )

Get DB version.

Reimplemented in ilDBMySQL, and ilDBOracle.

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

177 {
178 return "Unknown";
179 }

◆ getDSN()

ilDB::getDSN ( )
abstract

Get DSN.

This must be overwritten in DBMS specific class.

Implements ilDBInterface.

Reimplemented in ilDBMySQL, ilDBOracle, and ilDBPostgreSQL.

Referenced by connect(), and doConnect().

+ 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)

Reimplemented in ilDBMySQL.

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

304 {
305 return false;
306 }

Referenced by connectHost().

+ Here is the caller graph for this function:

◆ getLastInsertId()

ilDB::getLastInsertId ( )

Get last insert id.

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

2420 {
2421 $res = $this->db->lastInsertId();
2422 if(MDB2::isError($res))
2423 {
2424 return false;
2425 }
2426 return $res;
2427 }

References $res, and MDB2\isError().

+ 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 2438 of file class.ilDB.php.

2439 {
2440 //$r = $this->db->getOne($sql);
2441 $set = $this->db->query($sql);
2442
2443 $this->handleError($set, "getOne(".$sql.")");
2444
2445 if (!MDB2::isError($set))
2446 {
2447 $r = $set->fetchRow(ilDBConstants::FETCHMODE_ASSOC);
2448
2449 return $r[0];
2450 }
2451 }

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

+ Here is the call graph for this function:

◆ getPrimaryKeyIdentifier()

ilDB::getPrimaryKeyIdentifier ( )

Primary key identifier.

Implements ilDBInterface.

Reimplemented in ilDBOracle, and ilDBPostgreSQL.

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

894 {
895 return "PRIMARY";
896 }

Referenced by addPrimaryKey(), and dropPrimaryKey().

+ 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.

Reimplemented in ilDBMySQL, ilDBOracle, and ilDBPostgreSQL.

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

192 {
193 return array();
194 }

◆ 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 2462 of file class.ilDB.php.

2463 {
2464 $set = $this->query($sql);
2465 $r = $set->fetchRow($mode);
2466 //$r = $this->db->getrow($sql,$mode);
2467
2468 $this->handleError($r, "getRow(".$sql.")");
2469
2470 return $r;
2471 } //end function

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

+ Here is the call graph for this function:

◆ getSequenceName()

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

Implements ilDBInterface.

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

2535 {
2536 return $this->db->getSequenceName($table_name);
2537 }

◆ getSubType()

ilDB::getSubType ( )

Get sub type.

Returns
string

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

2506 {
2507 return $this->sub_type;
2508 }
$sub_type
Definition: class.ilDB.php:66

References $sub_type.

Referenced by ilDBMySQL\isMySQLi().

+ 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.

423 {
424 global $ilLog;
425
426 if (MDB2::isError($a_res)) {
427 if ($a_level == "") {
428 $a_level = $this->error_class->FATAL;
429 }
430
431 // :TODO: ADT (jluetzen)
432
433 // if(!$this->exception)
434 if (true) {
435 // Show stack
436 try {
437 throw new Exception();
438 } catch (Exception $e) {
439 $stack = $e->getTraceAsString();
440 }
441
442 if (is_object($ilLog)) {
443 $ilLog->logStack();
444 }
445// $this->raisePearError("ilDB Error: " . $a_info . "<br />" . $a_res->getMessage() . "<br />" . $a_res->getUserInfo() . "<br />"
446// . $stack, $a_level);
447
448 throw new ilDatabaseException("ilDB Error: " . $a_info . "<br />" . $a_res->getMessage() . "<br />" . $a_res->getUserInfo() . "<br />"
449 . $stack, $a_level);
450 }
451 }
452
453 return $a_res;
454 }
Class ilDatabaseException.

References $ilLog, and MDB2\isError().

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

+ 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.

Reimplemented in ilDBOracle.

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

1889 {
1890 if (count($a_values) == 0)
1891 {
1892 // BEGIN fixed mantis #0014191:
1893 //return " 1=2 "; // return a false statement on empty array
1894 return $negate ? ' 1=1 ' : ' 1=2 ';
1895 // END fixed mantis #0014191:
1896 }
1897 if ($a_type == "") // untyped: used ? for prepare/execute
1898 {
1899 $str = $a_field.(($negate) ? " NOT" : "")." IN (?".str_repeat(",?", count($a_values) - 1).")";
1900 }
1901 else // typed, use values for query/manipulate
1902 {
1903 $str = $a_field.(($negate) ? " NOT" : "")." IN (";
1904 $sep = "";
1905 foreach ($a_values as $v)
1906 {
1907 $str.= $sep.$this->quote($v, $a_type);
1908 $sep = ",";
1909 }
1910 $str.= ")";
1911 }
1912
1913 return $str;
1914 }

References $a_type.

◆ indexExistsByFields()

ilDB::indexExistsByFields (   $a_table,
  $a_fields 
)

Check if index exists.

Parameters
type$a_table
type$a_fields

Implements ilDBInterface.

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

982 {
983 $manager = $this->db->loadModule('Manager');
984 $reverse = $this->db->loadModule('Reverse');
985 if($manager)
986 {
987 foreach($manager->listTableIndexes($a_table) as $idx_name)
988 {
989 $def = $reverse->getTableIndexDefinition($a_table,$idx_name);
990 $idx_fields = array_keys((array) $def['fields']);
991
992 if($idx_fields === $a_fields)
993 {
994 return true;
995 }
996 }
997 }
998 return false;
999 }

◆ initConnection()

ilDB::initConnection ( )
protected

Initialize the database connection.

Reimplemented in ilDBInnoDB, ilDBMySQL, ilDBOracle, and ilDBPostgreSQL.

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

294 {
295 }

Referenced by connect().

+ 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.

Reimplemented in ilDBMySQL.

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

211 {
212 global $ilClientIniFile;
213
214 //overwrite global client ini file if local parameter is set
215 if (is_object($tmpClientIniFile))
216 $clientIniFile = $tmpClientIniFile;
217 else
218 $clientIniFile = $ilClientIniFile;
219
220 if (is_object($clientIniFile ))
221 {
222 $this->setDBUser($clientIniFile ->readVariable("db", "user"));
223 $this->setDBHost($clientIniFile ->readVariable("db", "host"));
224 $this->setDBPort($clientIniFile ->readVariable("db", "port"));
225 $this->setDBPassword($clientIniFile ->readVariable("db", "pass"));
226 $this->setDBName($clientIniFile ->readVariable("db", "name"));
227 }
228 }
readVariable($a_group, $a_var_name)
reads a single variable from a group @access public
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
setDBHost($a_host)
Set database host.
Definition: class.ilDB.php:113
setDBPassword($a_password)
Set database password.
Definition: class.ilDB.php:133

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

+ Here is the call graph for this function:

◆ initHostConnection()

ilDB::initHostConnection ( )
protected

Initialize the host connection (no specific database)

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

357 {
358 }

Referenced by connectHost().

+ 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 1634 of file class.ilDB.php.

1635 {
1636 $fields = array();
1637 $field_values = array();
1638 $placeholders = array();
1639 $types = array();
1640 $values = array();
1641 $lobs = false;
1642 $lob = array();
1643 foreach ($a_columns as $k => $col)
1644 {
1645 $fields[] = $k;
1646 $placeholders[] = "%s";
1647 $placeholders2[] = ":$k";
1648 $types[] = $col[0];
1649
1650 // integer auto-typecast (this casts bool values to integer)
1651 if ($col[0] == 'integer' && !is_null($col[1]))
1652 {
1653 $col[1] = (int) $col[1];
1654 }
1655
1656 $values[] = $col[1];
1657 $field_values[$k] = $col[1];
1658 if ($col[0] == "blob" || $col[0] == "clob")
1659 {
1660 $lobs = true;
1661 $lob[$k] = $k;
1662 }
1663 }
1664 if ($lobs) // lobs -> use prepare execute (autoexecute broken in PEAR 2.4.1)
1665 {
1666 $st = $this->db->prepare("INSERT INTO ".$a_table." (".implode($fields,",").") VALUES (".
1667 implode($placeholders2,",").")", $types, MDB2_PREPARE_MANIP, $lob);
1668
1669 $this->handleError($st, "insert / prepare/execute(".$a_table.")");
1670
1671 $r = $st->execute($field_values);
1672
1673
1674 //$r = $this->db->extended->autoExecute($a_table, $field_values, MDB2_AUTOQUERY_INSERT, null, $types);
1675 $this->handleError($r, "insert / prepare/execute(".$a_table.")");
1676 $this->free($st);
1677 }
1678 else // if no lobs are used, take simple manipulateF
1679 {
1680 $q = "INSERT INTO ".$a_table." (".implode($fields,",").") VALUES (".
1681 implode($placeholders,",").")";
1682 $r = $this->manipulateF($q, $types, $values);
1683 }
1684 return $r;
1685 }
const MDB2_PREPARE_MANIP
These are just helper constants to more verbosely express parameters to prepare()
Definition: MDB2.php:114
manipulateF($a_query, $a_types, $a_values)
Formatted manupulate (for DELETE, UPDATE, INSERT).
free($a_st)
Free a statement / result set.

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

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

+ 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 489 of file class.ilDB.php.

490 {
491 return MDB2::isError($a_res);
492 }

References MDB2\isError().

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

+ 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.

Reimplemented in ilDBMySQL.

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

971 {
972 return false;
973 }

Referenced by dropIndex().

+ 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 1391 of file class.ilDB.php.

1392 {
1393 require_once('./Services/Database/classes/PDO/FieldDefinition/class.ilDBPdoMySQLFieldDefinition.php');
1394 global $DIC;
1395 $ilDBPdoMySQLFieldDefinition = new ilDBPdoMySQLFieldDefinition($DIC['ilDB']);
1396
1397 return $ilDBPdoMySQLFieldDefinition->isReserved($a_word);
1398 }
Class ilDBPdoMySQLFieldDefinition.
global $DIC

References $DIC.

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

+ 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.

Reimplemented in ilDBOracle.

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

2055 {
2056 if (!in_array($a_type, array("text", "clob", "blob")))
2057 {
2058 $this->raisePearError("Like: Invalid column type '".$a_type."'.", $this->error_class->FATAL);
2059 }
2060 if ($a_value == "?")
2061 {
2062 if ($case_insensitive)
2063 {
2064 return "UPPER(".$a_col.") LIKE(UPPER(?))";
2065 }
2066 else
2067 {
2068 return $a_col ." LIKE(?)";
2069 }
2070 }
2071 else
2072 {
2073 if ($case_insensitive)
2074 {
2075 // Always quote as text
2076 return " UPPER(".$a_col.") LIKE(UPPER(".$this->quote($a_value, 'text')."))";
2077 }
2078 else
2079 {
2080 // Always quote as text
2081 return " ".$a_col." LIKE(".$this->quote($a_value, 'text').")";
2082 }
2083 }
2084 }

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

+ 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 2278 of file class.ilDB.php.

2279 {
2280 $manager = $this->db->loadModule('Manager');
2281 $r = $manager->listSequences();
2282
2283 if (!MDB2::isError($r))
2284 {
2285 return $r;
2286 }
2287
2288 return false;
2289 }

References $r, and MDB2\isError().

Referenced by sequenceExists().

+ 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 2240 of file class.ilDB.php.

2241 {
2242 $manager = $this->db->loadModule('Manager');
2243 $r = $manager->listTables();
2244
2245 if (!MDB2::isError($r))
2246 {
2247 return $r;
2248 }
2249
2250 return false;
2251 }

References $r, and MDB2\isError().

Referenced by dropTable(), and tableExists().

+ 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

@access protected

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

475 {
476 if (!$this->isDbError($this->db))
477 {
478 $this->db->loadModule('Extended');
479 define('DB_AUTOQUERY_SELECT',MDB2_AUTOQUERY_SELECT);
480 define('DB_AUTOQUERY_INSERT',MDB2_AUTOQUERY_INSERT);
481 define('DB_AUTOQUERY_UPDATE',MDB2_AUTOQUERY_UPDATE);
482 define('DB_AUTOQUERY_DELETE',MDB2_AUTOQUERY_DELETE);
483 }
484 }
const MDB2_AUTOQUERY_UPDATE
Definition: Extended.php:57
const MDB2_AUTOQUERY_SELECT
Definition: Extended.php:59
const MDB2_AUTOQUERY_INSERT
Used by autoPrepare()
Definition: Extended.php:56
const MDB2_AUTOQUERY_DELETE
Definition: Extended.php:58

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

Referenced by connect(), and connectHost().

+ 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.

Reimplemented in ilDBOracle.

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

2037 {
2038 $locate = ' LOCATE( ';
2039 $locate .= $a_needle;
2040 $locate .= ',';
2041 $locate .= $a_string;
2042 $locate .= ',';
2043 $locate .= $a_start_pos;
2044 $locate .= ') ';
2045 return $locate;
2046 }

◆ lockTables()

ilDB::lockTables (   $a_tables)
abstract

Abstraction of lock table.

Parameters
arraytable definitions
Deprecated:
Use ilAtomQuery instead
Returns

Implements ilDBInterface.

Reimplemented in ilDBMySQL, ilDBOracle, and ilDBPostgreSQL.

◆ logStatement()

ilDB::logStatement (   $sql)

Helper function, should usually not be called.

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

1489 {
1490 $pos1 = strpos(strtolower($sql), "from ");
1491 $table = "";
1492 if ($pos1 > 0)
1493 {
1494 $tablef = substr($sql, $pos1+5);
1495 $pos2 = strpos(strtolower($tablef), " ");
1496 if ($pos2 > 0)
1497 {
1498 $table =substr($tablef, 0, $pos2);
1499 }
1500 else
1501 {
1502 $table = $tablef;
1503 }
1504 }
1505 if (trim($table) != "")
1506 {
1507 if (!is_array($this->ttt) || !in_array($table, $this->ttt))
1508 {
1509 echo "<br>".$table;
1510 $this->ttt[] = $table;
1511 }
1512 }
1513 else
1514 {
1515 echo "<br><b>".$sql."</b>";
1516 }
1517 }

References substr().

+ 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 2024 of file class.ilDB.php.

2025 {
2026 return " LOWER(".$a_exp.") ";
2027 }

◆ 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 1550 of file class.ilDB.php.

1551 {
1552 global $ilBench;
1553
1554 if (is_object($ilBench))
1555 {
1556 $ilBench->startDbBench($sql);
1557 }
1558 $r = $this->db->exec($sql);
1559 if (is_object($ilBench))
1560 {
1561 $ilBench->stopDbBench();
1562 }
1563
1564 return $this->handleError($r, "manipulate(".$sql.")");
1565 }
global $ilBench
Definition: ilias.php:18

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

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

+ 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 1468 of file class.ilDB.php.

1469 {
1470 if (!is_array($a_types) || !is_array($a_values) ||
1471 count($a_types) != count($a_values))
1472 {
1473 $this->raisePearError("ilDB::manipulateF: types and values must be arrays of same size. ($a_query)");
1474 }
1475 $quoted_values = array();
1476 foreach($a_types as $k => $t)
1477 {
1478 $quoted_values[] = $this->quote($a_values[$k], $t);
1479 }
1480 $query = vsprintf($a_query, $quoted_values);
1481
1482 return $this->manipulate($query);
1483 }
manipulate($sql)
Data manipulation.

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

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

+ 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 2516 of file class.ilDB.php.

2517 {
2518 return array();
2519 }

◆ 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 707 of file class.ilDB.php.

708 {
709 $manager = $this->db->loadModule('Manager');
710 $reverse = $this->db->loadModule('Reverse');
711 $def = $reverse->getTableFieldDefinition($a_table, $a_column);
712
713 $this->handleError($def, "modifyTableColumn(".$a_table.")");
714
715 if (is_file("./Services/Database/classes/class.ilDBAnalyzer.php"))
716 {
717 include_once("./Services/Database/classes/class.ilDBAnalyzer.php");
718 }
719 else
720 {
721 include_once("../Services/Database/classes/class.ilDBAnalyzer.php");
722 }
723 $analyzer = new ilDBAnalyzer();
724 $best_alt = $analyzer->getBestDefinitionAlternative($def);
725 $def = $def[$best_alt];
726 unset($def["nativetype"]);
727 unset($def["mdb2type"]);
728
729 // check attributes
730 $type = ($a_attributes["type"] != "")
731 ? $a_attributes["type"]
732 : $def["type"];
733 foreach ($def as $k => $v)
734 {
735 if ($k != "type" && !in_array($k, $this->allowed_attributes[$type]))
736 {
737 unset($def[$k]);
738 }
739 }
740 $check_array = $def;
741 foreach ($a_attributes as $k => $v)
742 {
743 $check_array[$k] = $v;
744 }
745 if (!$this->checkColumnDefinition($check_array, true))
746 {
747 $this->raisePearError("ilDB Error: modifyTableColumn(".$a_table.", ".$a_column.")<br />".
748 $this->error_str);
749 }
750
751 // oracle workaround: do not set null, if null already given
752 if ($this->getDbType() == "oracle")
753 {
754 if ($def["notnull"] == true && ($a_attributes["notnull"] == true
755 || !isset($a_attributes["notnull"])))
756 {
757 unset($def["notnull"]);
758 unset($a_attributes["notnull"]);
759 }
760 if ($def["notnull"] == false && ($a_attributes["notnull"] == false
761 || !isset($a_attributes["notnull"])))
762 {
763 unset($def["notnull"]);
764 unset($a_attributes["notnull"]);
765 }
766 }
767 foreach ($a_attributes as $a => $v)
768 {
769 $def[$a] = $v;
770 }
771
772 $a_attributes["definition"] = $def;
773
774 $changes = array(
775 "change" => array(
776 $a_column => $a_attributes
777 )
778 );
779
780 $r = $manager->alterTable($a_table, $changes, false);
781
782 return $this->handleError($r, "modifyTableColumn(".$a_table.")");
783 }

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

+ 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 1530 of file class.ilDB.php.

1531 {
1532 // we do not create missing sequences automatically here
1533 // otherwise misspelled statements result in additional tables
1534 // please create sequences explicitly in the db update script
1535 $r = $this->db->nextId($a_table_name, false);
1536
1537 return $this->handleError($r, "nextId(".$a_table_name.")");
1538 }

References $r, and handleError().

+ Here is the call graph for this function:

◆ now()

ilDB::now ( )

now()

Implements ilDBInterface.

Reimplemented in ilDBMySQL, ilDBOracle, and ilDBPostgreSQL.

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

1941 {
1942 return "now()";
1943 }

◆ numRows()

ilDB::numRows (   $a_set)

Fetch row as associative array from result set.

Parameters
objectresult set

Implements ilDBInterface.

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

1869 {
1870 return $a_set->numRows();
1871 }

◆ 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.

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

1576 {
1577 $res = $this->db->prepare($a_query, $a_types, $a_result_types);
1578
1579 return $this->handleError($res, "prepare(".$a_query.")");
1580 }

References $res, and handleError().

+ 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 1590 of file class.ilDB.php.

1591 {
1592 $res = $this->db->prepare($a_query, $a_types, MDB2_PREPARE_MANIP);
1593
1594 return $this->handleError($res, "prepareManip(".$a_query.")");
1595 }

References $res, handleError(), and MDB2_PREPARE_MANIP.

+ 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

Reimplemented in ilDBMySQL.

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

1416 {
1417 global $ilBench;
1418
1419 if (is_object($ilBench))
1420 {
1421 $ilBench->startDbBench($sql);
1422 }
1423 $r = $this->db->query($sql);
1424 if (is_object($ilBench))
1425 {
1426 $ilBench->stopDbBench();
1427 }
1428
1429 if ($a_handle_error)
1430 {
1431 return $this->handleError($r, "query(".$sql.")");
1432 }
1433
1434 return $r;
1435 }

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

+ 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 1444 of file class.ilDB.php.

1445 {
1446 if (!is_array($a_types) || !is_array($a_values) ||
1447 count($a_types) != count($a_values))
1448 {
1449 $this->raisePearError("ilDB::queryF: Types and values must be arrays of same size. ($a_query)");
1450 }
1451 $quoted_values = array();
1452 foreach($a_types as $k => $t)
1453 {
1454 $quoted_values[] = $this->quote($a_values[$k], $t);
1455 }
1456 $query = vsprintf($a_query, $quoted_values);
1457
1458 return $this->query($query);
1459 }

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

Referenced by assLongMenu\loadFromDb().

+ 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 2299 of file class.ilDB.php.

2300 {
2301 if ($a_query == "" && is_null($a_type))
2302 {
2303 $a_query = "";
2304 }
2305
2306 // Performance fix
2307 if($a_type == 'integer' && !is_null($a_query))
2308 {
2309 return (int) $a_query;
2310 }
2311
2312 if ($a_type == "blob" || $a_type == "clob")
2313 {
2314 $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);
2315 }
2316
2317 return $this->db->quote($a_query, $a_type);
2318 }

References $a_type, and raisePearError().

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

+ 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 2327 of file class.ilDB.php.

2328 {
2329 return $this->db->quoteIdentifier($a_identifier);
2330 }

◆ raisePearError()

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

Raise an error.

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

460 {
461 if ($a_level == "")
462 {
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's de...
Definition: PEAR.php:522

References PEAR\raiseError().

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

+ 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 843 of file class.ilDB.php.

844 {
845 // check table name
846 if (!$this->checkTableName($a_new_name))
847 {
848 $this->raisePearError("ilDB Error: renameTable(".$a_name.",".$a_new_name.")<br />".
849 $this->error_str);
850 }
851
852 $manager = $this->db->loadModule('Manager');
853 $r = $manager->alterTable($a_name, array("name" => $a_new_name), false);
854
855 // The abstraction_progress is no longer used in ILIAS, see http://www.ilias.de/mantis/view.php?id=19513
856 // $query = "UPDATE abstraction_progress ".
857 // "SET table_name = ".$this->db->quote($a_new_name,'text')." ".
858 // "WHERE table_name = ".$this->db->quote($a_name,'text');
859 // $this->db->query($query);
860
861 return $this->handleError($r, "renameTable(".$a_name.",".$a_new_name.")");
862 }

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

+ 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 793 of file class.ilDB.php.

794 {
795 // check table name
796 if (!$this->checkColumnName($a_new_column))
797 {
798 $this->raisePearError("ilDB Error: renameTableColumn(".$a_table.",".$a_column.",".$a_new_column.")<br />".
799 $this->error_str);
800 }
801
802 $manager = $this->db->loadModule('Manager');
803 $reverse = $this->db->loadModule('Reverse');
804 $def = $reverse->getTableFieldDefinition($a_table, $a_column);
805
806 $this->handleError($def, "renameTableColumn(".$a_table.",".$a_column.",".$a_new_column.")");
807
808 if (is_file("./Services/Database/classes/class.ilDBAnalyzer.php"))
809 {
810 include_once("./Services/Database/classes/class.ilDBAnalyzer.php");
811 }
812 else
813 {
814 include_once("../Services/Database/classes/class.ilDBAnalyzer.php");
815 }
816
817 $analyzer = new ilDBAnalyzer();
818 $best_alt = $analyzer->getBestDefinitionAlternative($def);
819 $def = $def[$best_alt];
820 unset($def["nativetype"]);
821 unset($def["mdb2type"]);
822
823 $f["definition"] = $def;
824 $f["name"] = $a_new_column;
825
826 $changes = array(
827 "rename" => array(
828 $a_column => $f
829 )
830 );
831
832 $r = $manager->alterTable($a_table, $changes, false);
833
834 return $this->handleError($r, "renameTableColumn(".$a_table.",".$a_column.",".$a_new_column.")");
835 }

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

+ 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.

Reimplemented in ilDBOracle, and ilDBPostgreSQL.

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

1785 {
1786 // this is the mysql implementation
1787 $a_columns = array_merge($a_pk_columns, $a_other_columns);
1788 $fields = array();
1789 $field_values = array();
1790 $placeholders = array();
1791 $types = array();
1792 $values = array();
1793 $lobs = false;
1794 $lob = array();
1795 foreach ($a_columns as $k => $col)
1796 {
1797 $fields[] = $k;
1798 $placeholders[] = "%s";
1799 $placeholders2[] = ":$k";
1800 $types[] = $col[0];
1801
1802 // integer auto-typecast (this casts bool values to integer)
1803 if ($col[0] == 'integer' && !is_null($col[1]))
1804 {
1805 $col[1] = (int) $col[1];
1806 }
1807
1808 $values[] = $col[1];
1809 $field_values[$k] = $col[1];
1810 if ($col[0] == "blob" || $col[0] == "clob")
1811 {
1812 $lobs = true;
1813 $lob[$k] = $k;
1814 }
1815 }
1816 if ($lobs) // lobs -> use prepare execute (autoexecute broken in PEAR 2.4.1)
1817 {
1818 $st = $this->db->prepare("REPLACE INTO ".$a_table." (".implode($fields,",").") VALUES (".
1819 implode($placeholders2,",").")", $types, MDB2_PREPARE_MANIP, $lob);
1820 $this->handleError($st, "insert / prepare/execute(".$a_table.")");
1821 $r = $st->execute($field_values);
1822 //$r = $this->db->extended->autoExecute($a_table, $field_values, MDB2_AUTOQUERY_INSERT, null, $types);
1823 $this->handleError($r, "insert / prepare/execute(".$a_table.")");
1824 $this->free($st);
1825 }
1826 else // if no lobs are used, take simple manipulateF
1827 {
1828 $q = "REPLACE INTO ".$a_table." (".implode($fields,",").") VALUES (".
1829 implode($placeholders,",").")";
1830 $r = $this->manipulateF($q, $types, $values);
1831 }
1832 return $r;
1833 }

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

+ Here is the call graph for this function:

◆ rollback()

ilDB::rollback ( )

Rollback a transaction.

Implements ilDBInterface.

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

2367 {
2368 $res = $this->db->rollback();
2369
2370 return $this->handleError($res, "rollback()");
2371 }

References $res, and handleError().

+ 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 2553 of file class.ilDB.php.

2554 {
2555 if (!$this->doesCollationSupportMB4Strings()) {
2556 $query_replaced = preg_replace(
2557 '/[\x{10000}-\x{10FFFF}]/u', ilDBConstants::MB4_REPLACEMENT, $query
2558 );
2559 if (!empty($query_replaced)) {
2560 return $query_replaced;
2561 }
2562 }
2563
2564 return $query;
2565 }
doesCollationSupportMB4Strings()
@inheritDoc

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

+ 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 2259 of file class.ilDB.php.

2260 {
2261 $sequences = $this->listSequences();
2262
2263 if (is_array($sequences))
2264 {
2265 if (in_array($a_sequence, $sequences))
2266 {
2267 return true;
2268 }
2269 }
2270 return false;
2271 }
listSequences()
Get all sequences.

References listSequences().

+ 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.

114 {
115 $this->db_host = $a_host;
116 }

Referenced by initFromIniFile().

+ 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.

154 {
155 $this->db_name = $a_name;
156 }

Referenced by initFromIniFile().

+ 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.

134 {
135 $this->db_password = $a_password;
136 }

Referenced by initFromIniFile().

+ 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.

94 {
95 $this->db_port = $a_port;
96 }

Referenced by initFromIniFile().

+ 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.

74 {
75 $this->db_user = $a_user;
76 }

Referenced by initFromIniFile().

+ 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 1522 of file class.ilDB.php.

1523 {
1524 $this->db->setLimit($a_limit, $a_offset);
1525 }

◆ setSubType()

ilDB::setSubType (   $a_value)

Set sub type.

Parameters
string$a_value

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

2496 {
2497 $this->sub_type = (string)$a_value;
2498 }

◆ substr()

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

Substring.

Parameters

return

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

1998 {
1999 $lenstr = "";
2000 if ($a_len > -1)
2001 {
2002 $lenstr = ", ".$a_len;
2003 }
2004 return " SUBSTR(".$a_exp.", ".$a_pos.$lenstr.") ";
2005 }

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

+ Here is the caller graph for this function:

◆ supports()

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

Implements ilDBInterface.

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

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 }
supportsTransactions()
Definition: class.ilDB.php:397
supportsSlave()
Supports slave.
Definition: class.ilDB.php:371
supportsFulltext()
Definition: class.ilDB.php:360

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

+ Here is the call graph for this function:

◆ supportsEngineMigration()

ilDB::supportsEngineMigration ( )
Returns
bool

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

2526 {
2527 return false;
2528 }

◆ supportsFulltext()

ilDB::supportsFulltext ( )
Returns
bool

Implements ilDBInterface.

Reimplemented in ilDBInnoDB, ilDBMySQL, ilDBOracle, and ilDBPostgreSQL.

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

361 {
362 return false;
363 }

Referenced by supports().

+ Here is the caller graph for this function:

◆ supportsSlave()

ilDB::supportsSlave ( )

Supports slave.

Parameters

return

Implements ilDBInterface.

Reimplemented in ilDBMySQL.

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

372 {
373 return false;
374 }

Referenced by supports(), and useSlave().

+ Here is the caller graph for this function:

◆ supportsTransactions()

ilDB::supportsTransactions ( )
Returns
bool

Implements ilDBInterface.

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

397 {
398 // we generally do not want ilDB to support transactions, only PDO-instances
399 return false;
400 }

Referenced by supports().

+ 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 2173 of file class.ilDB.php.

2174 {
2175
2176 $column_visibility = false;
2177 $manager = $this->db->loadModule('Manager');
2178 $r = $manager->listTableFields($a_table);
2179
2180 if (!MDB2::isError($r))
2181 {
2182 foreach($r as $field)
2183 {
2184 if ($field == $a_column_name)
2185 {
2186 $column_visibility = true;
2187 }
2188 }
2189 }
2190
2191 return $column_visibility;
2192 }

References $r, and MDB2\isError().

+ 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 2152 of file class.ilDB.php.

2153 {
2154 $tables = $this->listTables();
2155
2156 if (is_array($tables))
2157 {
2158 if (in_array($a_table, $tables))
2159 {
2160 return true;
2161 }
2162 }
2163 return false;
2164 }

References listTables().

+ 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 2201 of file class.ilDB.php.

2202 {
2203 if (is_file("./Services/Database/classes/class.ilDBAnalyzer.php"))
2204 {
2205 include_once("./Services/Database/classes/class.ilDBAnalyzer.php");
2206 }
2207 else
2208 {
2209 include_once("../Services/Database/classes/class.ilDBAnalyzer.php");
2210 }
2211 $analyzer = new ilDBAnalyzer();
2212 $cons = $analyzer->getConstraintsInformation($a_table);
2213 foreach ($cons as $c)
2214 {
2215 if ($c["type"] == "unique" && count($a_fields) == count($c["fields"]))
2216 {
2217 $all_in = true;
2218 foreach ($a_fields as $f)
2219 {
2220 if (!isset($c["fields"][$f]))
2221 {
2222 $all_in = false;
2223 }
2224 }
2225 if ($all_in)
2226 {
2227 return true;
2228 }
2229 }
2230 }
2231 return false;
2232 }

◆ unixTimestamp()

ilDB::unixTimestamp ( )

Unix timestamp.

Reimplemented in ilDBOracle.

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

2137 {
2138 return "UNIX_TIMESTAMP()";
2139 }

◆ unlockTables()

ilDB::unlockTables ( )
abstract

Unlock tables locked by previous lock table calls.

Deprecated:
Use ilAtomQuery instead
Returns

Implements ilDBInterface.

Reimplemented in ilDBMySQL, ilDBOracle, and ilDBPostgreSQL.

◆ 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 1695 of file class.ilDB.php.

1696 {
1697 $fields = array();
1698 $field_values = array();
1699 $placeholders = array();
1700 $types = array();
1701 $values = array();
1702 $lobs = false;
1703 $lob = array();
1704 foreach ($a_columns as $k => $col)
1705 {
1706 $fields[] = $k;
1707 $placeholders[] = "%s";
1708 $placeholders2[] = ":$k";
1709 $types[] = $col[0];
1710
1711 // integer auto-typecast (this casts bool values to integer)
1712 if ($col[0] == 'integer' && !is_null($col[1]))
1713 {
1714 $col[1] = (int) $col[1];
1715 }
1716
1717 $values[] = $col[1];
1718 $field_values[$k] = $col[1];
1719 if ($col[0] == "blob" || $col[0] == "clob")
1720 {
1721 $lobs = true;
1722 $lob[$k] = $k;
1723 }
1724 }
1725
1726 if ($lobs)
1727 {
1728 $q = "UPDATE ".$a_table." SET ";
1729 $lim = "";
1730 foreach ($fields as $k => $field)
1731 {
1732 $q.= $lim.$field." = ".$placeholders2[$k];
1733 $lim = ", ";
1734 }
1735 $q.= " WHERE ";
1736 $lim = "";
1737 foreach ($a_where as $k => $col)
1738 {
1739 $q.= $lim.$k." = ".$this->quote($col[1], $col[0]);
1740 $lim = " AND ";
1741 }
1742 $st = $this->db->prepare($q, $types, MDB2_PREPARE_MANIP, $lob);
1743 $r = $st->execute($field_values);
1744
1745 //$r = $this->db->extended->autoExecute($a_table, $field_values, MDB2_AUTOQUERY_INSERT, null, $types);
1746 $this->handleError($r, "update / prepare/execute(".$a_table.")");
1747 $this->free($st);
1748 }
1749 else
1750 {
1751 foreach ($a_where as $k => $col)
1752 {
1753 $types[] = $col[0];
1754 $values[] = $col[1];
1755 $field_values[$k] = $col;
1756 }
1757 $q = "UPDATE ".$a_table." SET ";
1758 $lim = "";
1759 foreach ($fields as $k => $field)
1760 {
1761 $q.= $lim.$field." = ".$placeholders[$k];
1762 $lim = ", ";
1763 }
1764 $q.= " WHERE ";
1765 $lim = "";
1766 foreach ($a_where as $k => $col)
1767 {
1768 $q.= $lim.$k." = %s";
1769 $lim = " AND ";
1770 }
1771
1772 $r = $this->manipulateF($q, $types, $values);
1773 }
1774 return $r;
1775 }

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

+ 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 2013 of file class.ilDB.php.

2014 {
2015 return " UPPER(".$a_exp.") ";
2016 }

◆ useSlave()

ilDB::useSlave (   $a_val = true)

Use slave.

Parameters

return

Implements ilDBInterface.

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

409 {
410 if (!$this->supportsSlave())
411 {
412 return false;
413 }
414 $this->use_slave = $a_val;
415 }

References supportsSlave().

+ Here is the call graph for this function:

Field Documentation

◆ $allowed_attributes

ilDB::$allowed_attributes
Initial value:
= array(
"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: