ILIAS  release_4-4 Revision
ilDB Class Reference

Database Wrapper. More...

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

Public Member Functions

 ilDB ()
 constructor More...
 
 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...
 
 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...
 
 addIndex ($a_table, $a_fields, $a_name="in", $a_fulltext=false)
 Add an index to 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...
 
 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 ($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...
 
 optimizeTable ($a_table)
 Optimize Table. 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, $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)
 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=DB_FETCHMODE_OBJECT)
 getRow. More...
 
 setSubType ($a_value)
 Set sub type. More...
 
 getSubType ()
 Get sub type. More...
 
- Public Member Functions inherited from PEAR
 PEAR ($error_class=null)
 Constructor. More...
 
 _PEAR ()
 Destructor (the emulated type of...). More...
 
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...
 
 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...
 
 setErrorHandling ($mode=null, $options=null)
 Sets how errors generated by this object should be handled. 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...
 

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

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

Member Function Documentation

◆ addFulltextIndex()

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

Add fulltext index.

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

Referenced by addIndex().

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

◆ addIndex()

ilDB::addIndex (   $a_table,
  $a_fields,
  $a_name = "in",
  $a_fulltext = false 
)

Add an index to a table.

Parameters
stringtable name
arrayfields for index
stringindex name

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

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

901  {
902  $manager = $this->db->loadModule('Manager');
903 
904  // check index name
905  if (!$this->checkIndexName($a_name))
906  {
907  $this->raisePearError("ilDB Error: addIndex(".$a_table.",".$a_name.")<br />".
908  $this->error_str);
909  }
910 
911  $fields = array();
912  foreach ($a_fields as $f)
913  {
914  $fields[$f] = array();
915  }
916  $definition = array (
917  'fields' => $fields
918  );
919 
920  if (!$a_fulltext)
921  {
922  $r = $manager->createIndex($a_table, $this->constraintName($a_table, $a_name), $definition);
923  }
924  else
925  {
926  if ($this->supportsFulltext())
927  {
928  $this->addFulltextIndex($a_table, $a_fields, $a_name);
929  }
930  }
931 
932  return $this->handleError($r, "addIndex(".$a_table.")");
933  }
raisePearError($a_message, $a_level="")
Raise an error.
Definition: class.ilDB.php:439
checkIndexName($a_name)
Check whether an index name is valid.
addFulltextIndex($a_table, $a_fields, $a_name="in")
Add fulltext index.
Definition: class.ilDB.php:938
supportsFulltext()
Definition: class.ilDB.php:368
handleError($a_res, $a_info="", $a_level="")
Handle MDB2 Errors.
Definition: class.ilDB.php:405
constraintName($a_table, $a_constraint)
Determine contraint name by table name and constraint name.
$r
+ Here is the call graph for this function:

◆ addPrimaryKey()

ilDB::addPrimaryKey (   $a_table,
  $a_fields 
)

Add a primary key to a table.

Parameters
stringtable name
arrayfields for primary key
stringkey name

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

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

851  {
852  $manager = $this->db->loadModule('Manager');
853 
854  $fields = array();
855  foreach ($a_fields as $f)
856  {
857  $fields[$f] = array();
858  }
859  $definition = array (
860  'primary' => true,
861  'fields' => $fields
862  );
863  $r = $manager->createConstraint($a_table,
864  $this->constraintName($a_table, $this->getPrimaryKeyIdentifier()), $definition);
865 
866  return $this->handleError($r, "addPrimaryKey(".$a_table.")");
867  }
handleError($a_res, $a_info="", $a_level="")
Handle MDB2 Errors.
Definition: class.ilDB.php:405
constraintName($a_table, $a_constraint)
Determine contraint name by table name and constraint name.
getPrimaryKeyIdentifier()
Primary key identifier.
Definition: class.ilDB.php:872
$r
+ 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")

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

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

630  {
631 
632  $manager = $this->db->loadModule('Manager');
633 
634  if (!$this->checkColumnName($a_column))
635  {
636  $this->raisePearError("ilDB Error: addTableColumn(".$a_table.", ".$a_column.")<br />".
637  $this->error_str);
638  }
639  if (!$this->checkColumnDefinition($a_attributes))
640  {
641  $this->raisePearError("ilDB Error: addTableColumn(".$a_table.", ".$a_column.")<br />".
642  $this->error_str);
643  }
644 
645  $changes = array(
646  "add" => array(
647  $a_column => $a_attributes
648  )
649  );
650 
651  $r = $manager->alterTable($a_table, $changes, false);
652 
653  return $this->handleError($r, "addTableColumn(".$a_table.", ".$a_column.")");
654  }
raisePearError($a_message, $a_level="")
Raise an error.
Definition: class.ilDB.php:439
checkColumnDefinition($a_def, $a_modify_mode=false)
Check whether a column definition is valid.
checkColumnName($a_name)
Check whether a column name is valid.
handleError($a_res, $a_info="", $a_level="")
Handle MDB2 Errors.
Definition: class.ilDB.php:405
$r
+ 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 1848 of file class.ilDB.php.

1849  {
1850  if (!is_array($a_arr))
1851  {
1852  $a_arr = array();
1853  }
1854  if ($a_cnt > 0)
1855  {
1856  $type_arr = array_fill(0, $a_cnt, $a_type);
1857  }
1858  else
1859  {
1860  $type_arr = array();
1861  }
1862  return array_merge($a_arr, $type_arr);
1863  }

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

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

1035  {
1036  $manager = $this->db->loadModule('Manager');
1037 
1038  // check index name
1039  if (!$this->checkIndexName($a_name))
1040  {
1041  $this->raisePearError("ilDB Error: addUniqueConstraint(".$a_table.",".$a_name.")<br />".
1042  $this->error_str);
1043  }
1044 
1045  $fields = array();
1046  foreach ($a_fields as $f)
1047  {
1048  $fields[$f] = array();
1049  }
1050  $definition = array (
1051  'unique' => true,
1052  'fields' => $fields
1053  );
1054 
1055  $r = $manager->createConstraint($a_table, $this->constraintName($a_table, $a_name), $definition);
1056 
1057  return $this->handleError($r, "addUniqueConstraint(".$a_table.")");
1058  }
raisePearError($a_message, $a_level="")
Raise an error.
Definition: class.ilDB.php:439
checkIndexName($a_name)
Check whether an index name is valid.
handleError($a_res, $a_info="", $a_level="")
Handle MDB2 Errors.
Definition: class.ilDB.php:405
constraintName($a_table, $a_constraint)
Determine contraint name by table name and constraint name.
$r
+ 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 608 of file class.ilDB.php.

References $r, and handleError().

609  {
610  if ($a_options == "")
611  {
612  $a_options = array();
613  }
614 
615  $manager = $this->db->loadModule('Manager');
616  $r = $manager->alterTable($a_name, $a_changes, false);
617 
618  return $this->handleError($r, "alterTable(".$a_name.")");
619  }
handleError($a_res, $a_info="", $a_level="")
Handle MDB2 Errors.
Definition: class.ilDB.php:405
$r
+ 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 2338 of file class.ilDB.php.

References $res, and handleError().

2339  {
2340  $res = $this->db->autoExecute($a_tablename,$a_fields,$a_mode,$a_where);
2341 
2342  return $this->handleError($res, "autoExecute(".$a_tablename.")");
2343  }
handleError($a_res, $a_info="", $a_level="")
Handle MDB2 Errors.
Definition: class.ilDB.php:405
+ 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

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

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

2280  {
2281  if (!$this->db->supports('transactions'))
2282  {
2283  $this->raisePearError("ilDB::beginTransaction: Transactions are not supported.", $this->error_class->FATAL);
2284  }
2285  $res = $this->db->beginTransaction();
2286 
2287  return $this->handleError($res, "beginTransaction()");
2288  }
raisePearError($a_message, $a_level="")
Raise an error.
Definition: class.ilDB.php:439
handleError($a_res, $a_info="", $a_level="")
Handle MDB2 Errors.
Definition: class.ilDB.php:405
+ Here is the call graph for this function:

◆ checkColumn()

ilDB::checkColumn (   $a_col,
  $a_def 
)

Check column definition.

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

References checkColumnDefinition(), and checkColumnName().

Referenced by checkTableColumns().

1141  {
1142  if (!$this->checkColumnName($a_col))
1143  {
1144  return false;
1145  }
1146 
1147  if (!$this->checkColumnDefinition($a_def))
1148  {
1149  return false;
1150  }
1151 
1152  return true;
1153  }
checkColumnDefinition($a_def, $a_modify_mode=false)
Check whether a column definition is valid.
checkColumnName($a_name)
Check whether a column name is valid.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ checkColumnDefinition()

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

Check whether a column definition is valid.

Parameters
arraydefinition array

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

References $allowed_attributes.

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

1161  {
1162  // check valid type
1163  if (!in_array($a_def["type"], array("text", "integer", "float", "date", "time", "timestamp", "clob", "blob")))
1164  {
1165  switch ($a_def["type"])
1166  {
1167  case "boolean":
1168  $this->error_str = "Invalid column type '".$a_def["type"]."'. Use integer(1) instead.";
1169  break;
1170 
1171  case "decimal":
1172  $this->error_str = "Invalid column type '".$a_def["type"]."'. Use float or integer instead.";
1173  break;
1174 
1175  default:
1176  $this->error_str = "Invalid column type '".$a_def["type"]."'. Allowed types are: ".
1177  "text, integer, float, date, time, timestamp, clob and blob.";
1178  }
1179  }
1180 
1181  // check used attributes
1183 
1184  foreach ($a_def as $k => $v)
1185  {
1186  if ($k != "type" && !in_array($k, $allowed_attributes[$a_def["type"]]))
1187  {
1188  $this->error_str = "Attribute '".$k."' is not allowed for column type '".$a_def["type"]."'.";
1189  return false;
1190  }
1191  }
1192 
1193  // type specific checks
1194  switch ($a_def["type"])
1195  {
1196  case "text":
1197  if ($a_def["length"] < 1 || $a_def["length"] > 4000)
1198  {
1199  if (!$a_modify_mode || isset($a_def["length"]))
1200  {
1201  $this->error_str = "Invalid length '".$a_def["length"]."' for type text.".
1202  " Length must be >=1 and <= 4000.";
1203  return false;
1204  }
1205  }
1206  break;
1207 
1208  case "integer":
1209  if (!in_array($a_def["length"], array(1, 2, 3, 4, 8)))
1210  {
1211  if (!$a_modify_mode || isset($a_def["length"]))
1212  {
1213  $this->error_str = "Invalid length '".$a_def["length"]."' for type integer.".
1214  " Length must be 1, 2, 3, 4 or 8 (bytes).";
1215  return false;
1216  }
1217  }
1218  if ($a_def["unsigned"])
1219  {
1220  $this->error_str = "Unsigned attribut must not be true for type integer.";
1221  return false;
1222  }
1223  break;
1224  }
1225 
1226  return true;
1227  }
$allowed_attributes
Definition: class.ilDB.php:54
+ 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 1234 of file class.ilDB.php.

References isReservedWord(), and substr().

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

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

◆ checkIndexName()

ilDB::checkIndexName (   $a_name)

Check whether an index name is valid.

Parameters
string$a_name

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

References isReservedWord().

Referenced by addIndex(), and addUniqueConstraint().

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

◆ checkTableColumns()

ilDB::checkTableColumns (   $a_cols)

Check table columns definition.

Parameters
arraydefinition array

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

References checkColumn().

Referenced by createTable().

1125  {
1126  foreach ($a_cols as $col => $def)
1127  {
1128  if (!$this->checkColumn($col, $def))
1129  {
1130  return false;
1131  }
1132  }
1133 
1134  return true;
1135  }
checkColumn($a_col, $a_def)
Check column definition.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ checkTableName()

ilDB::checkTableName (   $a_name)

Check whether a table name is valid.

Parameters
string$a_name

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

References isReservedWord(), and substr().

Referenced by createTable(), and renameTable().

1091  {
1092  if (!preg_match ("/^[a-z]+[_a-z0-9]*$/", $a_name))
1093  {
1094  $this->error_str = "Table name must only contain _a-z0-9 and must start with a-z.";
1095  return false;
1096  }
1097 
1098  if ($this->isReservedWord($a_name))
1099  {
1100  $this->error_str = "Invalid table name '".$a_name."' (Reserved Word).";
1101  return false;
1102  }
1103 
1104  if (strtolower(substr($a_name, 0, 4)) == "sys_")
1105  {
1106  $this->error_str = "Invalid table name '".$a_name."'. Name must not start with 'sys_'.";
1107  return false;
1108  }
1109 
1110  if (strlen($a_name) > 22)
1111  {
1112  $this->error_str = "Invalid table name '".$a_name."'. Maximum table identifer lenght is 22 bytes.";
1113  return false;
1114  }
1115 
1116  return true;
1117  }
substr($a_exp, $a_pos=1, $a_len=-1)
Substring.
static isReservedWord($a_word)
Checks whether a word is a reserved word in one of the supported databases.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ commit()

ilDB::commit ( )

Commit a transaction.

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

References $res, and handleError().

2294  {
2295  $res = $this->db->commit();
2296 
2297  return $this->handleError($res, "commit()");
2298  }
handleError($a_res, $a_info="", $a_level="")
Handle MDB2 Errors.
Definition: class.ilDB.php:405
+ Here is the call graph for this function:

◆ concat()

ilDB::concat (   $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

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

1885  {
1886  if(!count($a_values))
1887  {
1888  return ' ';
1889  }
1890 
1891  $concat = ' CONCAT(';
1892  $first = true;
1893  foreach($a_values as $field_info)
1894  {
1895  $val = $field_info[0];
1896 
1897  if(!$first)
1898  {
1899  $concat .= ',';
1900  }
1901 
1902  if($a_allow_null)
1903  {
1904  $concat .= 'COALESCE(';
1905  }
1906  $concat .= $val;
1907 
1908  if($a_allow_null)
1909  {
1910  $concat .= ",''";
1911  $concat .= ')';
1912  }
1913 
1914  $first = false;
1915  }
1916  $concat .= ') ';
1917  return $concat;
1918  }

◆ connect()

ilDB::connect (   $a_return_false_for_error = false)

Open the connection.

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

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

242  {
243  //set up error handling
244  $this->error_class = new ilErrorHandling();
245  $this->setErrorHandling(PEAR_ERROR_CALLBACK, array($this->error_class,'errorHandler'));
246 //echo $this->getDSN();
247  //check dsn
248  if ($this->getDSN() == "")
249  {
250  $this->raisePearError("No DSN given");
251  }
252 
253  //connect to database
254  $this->doConnect();
255 
256  if ($a_return_false_for_error && MDB2::isError($this->db))
257  {
258  return false;
259  }
260 
261  $this->loadMDB2Extensions();
262 
263  // set empty value portability to PEAR::DB behaviour
264  if (!$this->isDbError($this->db))
265  {
266  $this->db->setOption('portability', MDB2_PORTABILITY_ALL);
267  }
268  //check error
269  $this->handleError($this->db);
270 
271  // anything, that must be done to initialize the connection
272  $this->initConnection();
273 
274  return true;
275  }
raisePearError($a_message, $a_level="")
Raise an error.
Definition: class.ilDB.php:439
setErrorHandling($mode=null, $options=null)
Sets how errors generated by this object should be handled.
Definition: PEAR.php:335
const PEAR_ERROR_CALLBACK
Definition: PEAR.php:35
isError($data, $code=null)
Tell whether a value is a MDB2 error.
Definition: MDB2.php:594
doConnect()
Standard way to connect to db.
Definition: class.ilDB.php:280
initConnection()
Initialize the database connection.
Definition: class.ilDB.php:301
const MDB2_PORTABILITY_ALL
Portability: turn on all portability features.
Definition: MDB2.php:210
handleError($a_res, $a_info="", $a_level="")
Handle MDB2 Errors.
Definition: class.ilDB.php:405
loadMDB2Extensions()
load additional mdb2 extensions and set their constants
Definition: class.ilDB.php:454
getDSN()
Get DSN.
Error Handling & global info handling uses PEAR error class.
static isDbError($a_res)
Check error.
Definition: class.ilDB.php:469
+ 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 320 of file class.ilDB.php.

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

321  {
322  //set up error handling
323  $this->error_class = new ilErrorHandling();
324  $this->setErrorHandling(PEAR_ERROR_CALLBACK, array($this->error_class,'errorHandler'));
325 
326  //check dsn
327  if ($this->getHostDSN() == "")
328  {
329  $this->raisePearError("No Host DSN given");
330  }
331 
332  //connect to database
333  $this->db = MDB2::connect($this->getHostDSN(),
334  array("use_transactions" => true));
335  if ($a_return_false_for_error && MDB2::isError($this->db))
336  {
337  return false;
338  }
339 
340  $this->loadMDB2Extensions();
341 
342  // set empty value portability to PEAR::DB behaviour
343  if (!$this->isDbError($this->db))
344  {
345  $cur = ($this->db->getOption("portability") & MDB2_PORTABILITY_EMPTY_TO_NULL);
346  $this->db->setOption("portability", $this->db->getOption("portability") - $cur);
347 
348  $cur = ($this->db->getOption("portability") & MDB2_PORTABILITY_FIX_CASE);
349  $this->db->setOption("portability", $this->db->getOption("portability") - $cur);
350  }
351 
352  //check error
353  $this->handleError($this->db);
354 
355  // anything, that must be done to initialize the connection
356  $this->initHostConnection();
357 
358  return true;
359  }
raisePearError($a_message, $a_level="")
Raise an error.
Definition: class.ilDB.php:439
setErrorHandling($mode=null, $options=null)
Sets how errors generated by this object should be handled.
Definition: PEAR.php:335
const PEAR_ERROR_CALLBACK
Definition: PEAR.php:35
isError($data, $code=null)
Tell whether a value is a MDB2 error.
Definition: MDB2.php:594
const MDB2_PORTABILITY_EMPTY_TO_NULL
Portability: convert empty values to null strings in data output by query*() and fetch*().
Definition: MDB2.php:198
& connect($dsn, $options=false)
Create a new MDB2 connection object and connect to the specified database.
Definition: MDB2.php:431
initHostConnection()
Initialize the host connection (no specific database)
Definition: class.ilDB.php:364
handleError($a_res, $a_info="", $a_level="")
Handle MDB2 Errors.
Definition: class.ilDB.php:405
loadMDB2Extensions()
load additional mdb2 extensions and set their constants
Definition: class.ilDB.php:454
Error Handling & global info handling uses PEAR error class.
getHostDSN()
Should return a valid value, if host connections are possible (connectHost) to create a new database ...
Definition: class.ilDB.php:311
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:158
static isDbError($a_res)
Check error.
Definition: class.ilDB.php:469
+ 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)

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

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

1302  {
1303  return $a_constraint;
1304  }
+ Here is the caller graph for this function:

◆ createDatabase()

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

Create database.

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

References query().

482  {
483  if ($a_collation != "")
484  {
485  $sql = "CREATE DATABASE ".$a_name.
486  " CHARACTER SET ".$a_charset.
487  " COLLATE ".$a_collation;
488  }
489  else
490  {
491  $sql = "CREATE DATABASE ".$a_name.
492  " CHARACTER SET ".$a_charset;
493  }
494 
495  return $this->query($sql, false);
496  }
query($sql, $a_handle_error=true)
Query.
+ Here is the call graph for this function:

◆ createSequence()

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

Create a sequence for a table.

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

References $r, and handleError().

1064  {
1065  $manager = $this->db->loadModule('Manager');
1066 
1067  $r = $manager->createSequence($a_table_name, $a_start);
1068 
1069  return $this->handleError($r, "createSequence(".$a_table_name.")");
1070  }
handleError($a_res, $a_info="", $a_level="")
Handle MDB2 Errors.
Definition: class.ilDB.php:405
$r
+ 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

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

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

508  {
509  // check table name
510  if (!$this->checkTableName($a_name) && !$a_ignore_erros)
511  {
512  $this->raisePearError("ilDB Error: createTable(".$a_name.")<br />".
513  $this->error_str);
514  }
515 
516  // check definition array
517  if (!$this->checkTableColumns($a_definition_array) && !$a_ignore_erros)
518  {
519  $this->raisePearError("ilDB Error: createTable(".$a_name.")<br />".
520  $this->error_str);
521  }
522 
523  if ($a_drop_table)
524  {
525  $this->dropTable($a_name, false);
526  }
527 
528  $options = $this->getCreateTableOptions();
529 
530  $manager = $this->db->loadModule('Manager');
531  $r = $manager->createTable($a_name, $a_definition_array, $options);
532 
533  return $this->handleError($r, "createTable(".$a_name.")");
534  }
raisePearError($a_message, $a_level="")
Raise an error.
Definition: class.ilDB.php:439
checkTableColumns($a_cols)
Check table columns definition.
dropTable($a_name, $a_error_if_not_existing=true)
Drop a table.
Definition: class.ilDB.php:552
checkTableName($a_name)
Check whether a table name is valid.
if(!is_array($argv)) $options
handleError($a_res, $a_info="", $a_level="")
Handle MDB2 Errors.
Definition: class.ilDB.php:405
getCreateTableOptions()
Get options for the create table statement.
Definition: class.ilDB.php:541
$r
+ Here is the call graph for this function:

◆ disconnect()

ilDB::disconnect ( )

Disconnect.

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

290  {
291  $this->db->disconnect();
292  }

◆ doConnect()

ilDB::doConnect ( )

Standard way to connect to db.

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

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

Referenced by connect().

281  {
282  $this->db = MDB2::connect($this->getDSN(),
283  array("use_transactions" => true));
284  }
& connect($dsn, $options=false)
Create a new MDB2 connection object and connect to the specified database.
Definition: MDB2.php:431
getDSN()
Get DSN.
+ Here is the call graph for this function:
+ 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

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

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

Referenced by dropIndexByFields().

1012  {
1013  $manager = $this->db->loadModule('Manager');
1014 
1015  if (!$this->isFulltextIndex($a_table, $a_name))
1016  {
1017  $r = $manager->dropIndex($a_table, $this->constraintName($a_table, $a_name));
1018  }
1019  else
1020  {
1021  $this->dropFulltextIndex($a_table, $a_name);
1022  }
1023 
1024  return $this->handleError($r, "dropIndex(".$a_table.")");
1025  }
isFulltextIndex($a_table, $a_name)
Is index a fulltext index?
Definition: class.ilDB.php:946
handleError($a_res, $a_info="", $a_level="")
Handle MDB2 Errors.
Definition: class.ilDB.php:405
constraintName($a_table, $a_constraint)
Determine contraint name by table name and constraint name.
$r
+ 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

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

References dropIndex().

984  {
985  $manager = $this->db->loadModule('Manager');
986  $reverse = $this->db->loadModule('Reverse');
987  if($manager)
988  {
989  foreach($manager->listTableIndexes($a_table) as $idx_name)
990  {
991  $def = $reverse->getTableIndexDefinition($a_table,$idx_name);
992  $idx_fields = array_keys((array) $def['fields']);
993 
994  if($idx_fields === $a_fields)
995  {
996  return $this->dropIndex($a_table, $idx_name);
997  }
998  }
999  }
1000  return false;
1001 
1002  }
dropIndex($a_table, $a_name="in")
Drop an index from a table.
+ Here is the call graph for this function:

◆ dropPrimaryKey()

ilDB::dropPrimaryKey (   $a_table)

Drop a primary key from a table.

Parameters
stringtable name
stringkey name

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

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

884  {
885  $manager = $this->db->loadModule('Manager');
886 
887  $r = $manager->dropConstraint($a_table,
888  $this->constraintName($a_table, $this->getPrimaryKeyIdentifier()), true);
889 
890  return $this->handleError($r, "dropPrimaryKey(".$a_table.")");
891  }
handleError($a_res, $a_info="", $a_level="")
Handle MDB2 Errors.
Definition: class.ilDB.php:405
constraintName($a_table, $a_constraint)
Determine contraint name by table name and constraint name.
getPrimaryKeyIdentifier()
Primary key identifier.
Definition: class.ilDB.php:872
$r
+ Here is the call graph for this function:

◆ dropSequence()

ilDB::dropSequence (   $a_table_name)

Drop a sequence for a table.

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

References $r, and handleError().

1077  {
1078  $manager = $this->db->loadModule('Manager');
1079 
1080  $r = $manager->dropSequence($a_table_name);
1081 
1082  return $this->handleError($r, "dropSequence(".$a_table_name.")");
1083  }
handleError($a_res, $a_info="", $a_level="")
Handle MDB2 Errors.
Definition: class.ilDB.php:405
$r
+ 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

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

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

Referenced by createTable().

553  {
554  if (!$a_error_if_not_existing)
555  {
556  $tables = $this->listTables();
557  if (!in_array($a_name, $tables))
558  {
559  return;
560  }
561  }
562 
563  $manager = $this->db->loadModule('Manager');
564 
565  if ($this->getDBType() == "oracle")
566  {
567  // drop table constraints
568  $constraints = $manager->listTableConstraints($a_name);
569  $this->handleError($constraints, "dropTable(".$a_name."), listTableConstraints");
570  foreach ($constraints as $c)
571  {
572  if (substr($c, 0, 4) != "sys_")
573  {
574  $r = $manager->dropConstraint($a_name, $c);
575  $this->handleError($r, "dropTable(".$a_name."), dropConstraint");
576  }
577  }
578 
579  // drop table indexes
580  $indexes = $manager->listTableIndexes($a_name);
581  $this->handleError($indexes, "dropTable(".$a_name."), listTableIndexes");
582  foreach ($indexes as $i)
583  {
584  $r = $manager->dropIndex($a_name, $i);
585  $this->handleError($r, "dropTable(".$a_name."), dropIndex");
586  }
587  }
588 
589  // drop sequence
590  $seqs = $manager->listSequences();
591  if (in_array($a_name, $seqs))
592  {
593  $r = $manager->dropSequence($a_name);
594  $this->handleError($r, "dropTable(".$a_name."), dropSequence");
595  }
596 
597  // drop table
598  $r = $manager->dropTable($a_name);
599 
600  return $this->handleError($r, "dropTable(".$a_name.")");
601  }
substr($a_exp, $a_pos=1, $a_len=-1)
Substring.
listTables()
Get all tables.
handleError($a_res, $a_info="", $a_level="")
Handle MDB2 Errors.
Definition: class.ilDB.php:405
getDBType()
Get DSN.
$r
+ 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

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

References $r, and handleError().

664  {
665 
666  $manager = $this->db->loadModule('Manager');
667 
668  $changes = array(
669  "remove" => array(
670  $a_column => array()
671  )
672  );
673 
674  $r = $manager->alterTable($a_table, $changes, false);
675 
676  return $this->handleError($r, "dropTableColumn(".$a_table.", ".$a_column.")");
677  }
handleError($a_res, $a_info="", $a_level="")
Handle MDB2 Errors.
Definition: class.ilDB.php:405
$r
+ Here is the call graph for this function:

◆ enableResultBuffering()

ilDB::enableResultBuffering (   $a_status)

En/disable result buffering.

Parameters
bool$a_status

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

210  {
211  $this->db->setOption('result_buffering',$a_status);
212  }

◆ equals()

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

Use this only on text fields.

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

References quote().

2020  {
2021  if (!$a_empty_or_null || $a_value != "")
2022  {
2023  return $a_col." = ".$this->quote($a_value, $a_type);
2024  }
2025  else
2026  {
2027  return "(".$a_col." = '' OR $a_col IS NULL)";
2028  }
2029  }
quote($a_query, $a_type=null)
Wrapper for quote method.
+ Here is the call graph for this function:

◆ equalsNot()

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

Use this only on text fields.

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

References quote().

2035  {
2036  if (!$a_empty_or_null)
2037  {
2038  return $a_col." <> ".$this->quote($a_value, $a_type);
2039  }
2040  if ($a_value != "")
2041  {
2042  return "(".$a_col." <> ".$this->quote($a_value, $a_type). " OR ".
2043  $a_col." IS NULL)";
2044  }
2045  else
2046  {
2047  return "(".$a_col." <> '' AND $a_col IS NOT NULL)";
2048  }
2049  }
quote($a_query, $a_type=null)
Wrapper for quote method.
+ Here is the call graph for this function:

◆ execute()

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

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

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

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

References $res, and handleError().

1538  {
1539  $res = $a_stmt->execute($a_data);
1540 
1541  return $this->handleError($res, "execute(".$a_stmt->query.")");
1542  }
handleError($a_res, $a_info="", $a_level="")
Handle MDB2 Errors.
Definition: class.ilDB.php:405
+ 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 1553 of file class.ilDB.php.

References $res, and handleError().

1554  {
1555  $res = $this->db->extended->executeMultiple($a_stmt,$a_data);
1556 
1557  return $this->handleError($res, "executeMultiple(".$a_stmt->query.")");
1558  }
handleError($a_res, $a_info="", $a_level="")
Handle MDB2 Errors.
Definition: class.ilDB.php:405
+ Here is the call graph for this function:

◆ fetchAssoc()

ilDB::fetchAssoc (   $a_set)

Fetch row as associative array from result set.

Parameters
objectresult set

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

References DB_FETCHMODE_ASSOC.

Referenced by ilObjiLincUser\__init(), ilObjTestAccess\_getPassedUsers(), assQuestion\_getQuestionTitle(), SurveyQuestion\_getQuestionType(), assQuestion\_getQuestionType(), SurveyQuestion\_getTitle(), ilSetting\_lookupValue(), assOrderingHorizontal\calculateReachedPoints(), assFlashQuestion\calculateReachedPoints(), assTextSubset\calculateReachedPoints(), assSingleChoice\calculateReachedPoints(), assMultipleChoice\calculateReachedPoints(), assOrderingQuestion\calculateReachedPoints(), assJavaApplet\calculateReachedPoints(), assImagemapQuestion\calculateReachedPoints(), assMatchingQuestion\calculateReachedPoints(), assClozeTest\calculateReachedPoints(), ilParticipant\checkLastAdmin(), ilObjTest\createRandomSolutions(), db_pwassist_session_find(), db_pwassist_session_read(), ilForum\deletePost(), assFileUpload\deleteUploadedFiles(), ilObjSCORM2004LearningModule\exportSelected(), ilSCORM13Player\getADLActDataInit(), ilSurveyPhrasesGUI\getCategoriesForPhrase(), ilObjForum\getDiskUsage(), ilObjTest\getEnableArchiving(), ilObjSurvey\getExistingQuestions(), ilSCORM2004DeleteData\getGlobalToSystemObjectiveIdStringForPackage(), assNumeric\getMaximumPoints(), ilForumTopic\getNestedSetPostChildren(), ilForumXMLParser\getNewForumPk(), ilObjTestDynamicQuestionSetConfig\getPoolQuestionChangeListener(), ilObjSurvey\getQuestionblockQuestionIds(), ilObjSurveyQuestionPool\getQuestionInfos(), ilObjQuestionPool\getQuestiontype(), ilObjSurveyQuestionPool\getQuestiontype(), ilObjSurvey\getQuestionType(), assQuestion\getQuestionTypeFromDb(), assJavaApplet\getReachedInformation(), ilSCORM13Player\getScope(), ilObjSurvey\getSurveyQuestions(), ilSCORM13Player\getSuspendDataInit(), ilSoapTestAdministration\getTestUserData(), assFileUpload\getUploadedFiles(), ilSoapUserAdministration\getUserIdBySid(), assSingleChoice\isComplete(), ilDBMySQL\isFulltextIndex(), assOrderingHorizontal\loadFromDb(), SurveyTextQuestion\loadFromDb(), SurveyMultipleChoiceQuestion\loadFromDb(), assFileUpload\loadFromDb(), assFlashQuestion\loadFromDb(), assTextQuestion\loadFromDb(), assTextSubset\loadFromDb(), assOrderingQuestion\loadFromDb(), assErrorText\loadFromDb(), assClozeTest\loadFromDb(), SurveySingleChoiceQuestion\loadFromDb(), assSingleChoice\loadFromDb(), ASS_MarkSchema\loadFromDb(), assMultipleChoice\loadFromDb(), SurveyMetricQuestion\loadFromDb(), assMatchingQuestion\loadFromDb(), assJavaApplet\loadFromDb(), assImagemapQuestion\loadFromDb(), SurveyMatrixQuestion\loadFromDb(), assFormulaQuestion\loadFromDb(), ilObjSurvey\loadFromDb(), assQuestion\loadFromDb(), ilTestSequence\loadQuestions(), ilObjTest\loadQuestions(), ilObjSurvey\loadQuestionsFromDb(), ilObjForum\lookupForumIdByRefId(), ilObjSurveyQuestionPool\purgeQuestions(), ilObjRole\read(), ilObjUser\read(), ilSCORM13Player\readGObjectiveInit(), ilSCORM2004DeleteData\removeCMIDataForNodes(), ilSCORM2004DeleteData\removeCMIDataForPackage(), ilSCORM2004DeleteData\removeCMIDataForUser(), ilSCORM2004DeleteData\removeCMIDataForUserAndPackage(), ilSCORM13Package\removeCPData(), assNumeric\saveToDb(), and ilTestArchiver\updateTestArchive().

1773  {
1774  return $a_set->fetchRow(DB_FETCHMODE_ASSOC);
1775  }
const DB_FETCHMODE_ASSOC
Definition: class.ilDB.php:10
+ Here is the caller graph for this function:

◆ fetchObject()

ilDB::fetchObject (   $a_set)

Fetch row as object from result set.

Parameters
objectresult set

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

References DB_FETCHMODE_OBJECT.

Referenced by ilObjDataCollection\doRead(), ilObjTest\getExistingQuestions(), ilObjTest\getQuestionType(), ilObjTest\insertQuestion(), ilObjTest\loadFromDb(), ilObjTest\questionMoveDown(), ilObjTest\questionMoveUp(), and ilObjiLincCourse\read().

1791  {
1792  return $a_set->fetchRow(DB_FETCHMODE_OBJECT);
1793  }
const DB_FETCHMODE_OBJECT
Definition: class.ilDB.php:11
+ Here is the caller graph for this function:

◆ free()

ilDB::free (   $a_st)

Free a statement / result set.

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

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

1781  {
1782  return $a_st->free();
1783  }
+ Here is the caller graph for this function:

◆ fromUnixtime()

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

fromUnixtime (makes timestamp out of unix timestamp)

Parameters
stringexpression
booleantypecasting to text y/n

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

2058  {
2059  return "FROM_UNIXTIME(".$a_expr.")";
2060  }

◆ getAllowedAttributes()

ilDB::getAllowedAttributes ( )

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

References $allowed_attributes.

1292  {
1294  }
$allowed_attributes
Definition: class.ilDB.php:54

◆ getCreateTableOptions()

ilDB::getCreateTableOptions ( )
protected

Get options for the create table statement.

Returns
array

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

Referenced by createTable().

542  {
543  return array();
544  }
+ Here is the caller graph for this function:

◆ getDBHost()

ilDB::getDBHost ( )

Get database host.

Parameters
stringdatabase host

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

References $db_host.

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

134  {
135  return $this->db_host;
136  }
+ Here is the caller graph for this function:

◆ getDBName()

ilDB::getDBName ( )

Get database name.

Parameters
stringdatabase name

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

References $db_name, and getDSN().

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

174  {
175  return $this->db_name;
176  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getDBPassword()

ilDB::getDBPassword ( )

Get database password.

Parameters
stringdatabase password

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

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

154  {
155  return $this->db_password;
156  }
+ Here is the caller graph for this function:

◆ getDBPort()

ilDB::getDBPort ( )

Get database port.

Parameters
stringdatabase port

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

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

114  {
115  return $this->db_port;
116  }
+ Here is the caller graph for this function:

◆ getDBType()

ilDB::getDBType ( )
abstract

Get DSN.

This must be overwritten in DBMS specific class.

Referenced by dropTable(), and getDBVersion().

+ Here is the caller graph for this function:

◆ getDBUser()

ilDB::getDBUser ( )

Get database user.

Parameters
stringdatabase user

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

References $db_user.

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

94  {
95  return $this->db_user;
96  }
+ Here is the caller graph for this function:

◆ getDBVersion()

ilDB::getDBVersion ( )

Get DB version.

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

References getDBType(), and getReservedWords().

187  {
188  return "Unknown";
189  }
+ Here is the call graph for this function:

◆ getDSN()

ilDB::getDSN ( )
abstract

Get DSN.

This must be overwritten in DBMS specific class.

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

+ Here is the caller graph for this function:

◆ getHostDSN()

ilDB::getHostDSN ( )

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

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

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

Referenced by connectHost().

312  {
313  return false;
314  }
+ Here is the caller graph for this function:

◆ getLastInsertId()

ilDB::getLastInsertId ( )

Get last insert id.

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

References $res, and MDB2\isError().

2355  {
2356  $res = $this->db->lastInsertId();
2357  if(MDB2::isError($res))
2358  {
2359  return false;
2360  }
2361  return $res;
2362  }
isError($data, $code=null)
Tell whether a value is a MDB2 error.
Definition: MDB2.php:594
+ 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 2373 of file class.ilDB.php.

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

2374  {
2375  //$r = $this->db->getOne($sql);
2376  $set = $this->db->query($sql);
2377 
2378  $this->handleError($set, "getOne(".$sql.")");
2379 
2380  if (!MDB2::isError($set))
2381  {
2382  $r = $set->fetchRow(DB_FETCHMODE_ASSOC);
2383 
2384  return $r[0];
2385  }
2386  }
isError($data, $code=null)
Tell whether a value is a MDB2 error.
Definition: MDB2.php:594
const DB_FETCHMODE_ASSOC
Definition: class.ilDB.php:10
handleError($a_res, $a_info="", $a_level="")
Handle MDB2 Errors.
Definition: class.ilDB.php:405
$r
+ Here is the call graph for this function:

◆ getPrimaryKeyIdentifier()

ilDB::getPrimaryKeyIdentifier ( )

Primary key identifier.

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

Referenced by addPrimaryKey(), and dropPrimaryKey().

873  {
874  return "PRIMARY";
875  }
+ Here is the caller graph for this function:

◆ getReservedWords()

static ilDB::getReservedWords ( )
staticabstract

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.

Referenced by getDBVersion().

+ Here is the caller graph for this function:

◆ getRow()

ilDB::getRow (   $sql,
  $mode = DB_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 2397 of file class.ilDB.php.

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

2398  {
2399  $set = $this->query($sql);
2400  $r = $set->fetchRow($mode);
2401  //$r = $this->db->getrow($sql,$mode);
2402 
2403  $this->handleError($r, "getRow(".$sql.")");
2404 
2405  return $r;
2406  } //end function
query($sql, $a_handle_error=true)
Query.
handleError($a_res, $a_info="", $a_level="")
Handle MDB2 Errors.
Definition: class.ilDB.php:405
$r
+ Here is the call graph for this function:

◆ getSubType()

ilDB::getSubType ( )

Get sub type.

Returns
string

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

References $sub_type.

Referenced by ilDBMySQL\isMySQLi().

2424  {
2425  return $this->sub_type;
2426  }
$sub_type
Definition: class.ilDB.php:65
+ 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 405 of file class.ilDB.php.

References $ilLog, MDB2\isError(), and raisePearError().

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

406  {
407  global $ilLog;
408 
409  if (MDB2::isError($a_res))
410  {
411  if ($a_level == "")
412  {
413  $a_level = $this->error_class->FATAL;
414  }
415 
416  // Show stack
417  try
418  {
419  throw new Exception();
420  }
421  catch(Exception $e)
422  {
423  $stack = $e->getTraceAsString();
424  }
425 
426  if(is_object($ilLog))
427  $ilLog->logStack();
428  $this->raisePearError("ilDB Error: ".$a_info."<br />".
429  $a_res->getMessage()."<br />".$a_res->getUserInfo()."<br />".$stack, $a_level);
430 
431  }
432 
433  return $a_res;
434  }
raisePearError($a_message, $a_level="")
Raise an error.
Definition: class.ilDB.php:439
isError($data, $code=null)
Tell whether a value is a MDB2 error.
Definition: MDB2.php:594
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ilDB()

ilDB::ilDB ( )

constructor

set up database conncetion and the errorhandling

Parameters
stringdsn database-connection-string for pear-db

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

75  {
76  }

◆ 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);

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

1821  {
1822  if (count($a_values) == 0)
1823  {
1824  return " 1=2 "; // return a false statement on empty array
1825  }
1826  if ($a_type == "") // untyped: used ? for prepare/execute
1827  {
1828  $str = $a_field.(($negate) ? " NOT" : "")." IN (?".str_repeat(",?", count($a_values) - 1).")";
1829  }
1830  else // typed, use values for query/manipulate
1831  {
1832  $str = $a_field.(($negate) ? " NOT" : "")." IN (";
1833  $sep = "";
1834  foreach ($a_values as $v)
1835  {
1836  $str.= $sep.$this->quote($v, $a_type);
1837  $sep = ",";
1838  }
1839  $str.= ")";
1840  }
1841 
1842  return $str;
1843  }

◆ indexExistsByFields()

ilDB::indexExistsByFields (   $a_table,
  $a_fields 
)

Check if index exists.

Parameters
type$a_table
type$a_fields

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

958  {
959  $manager = $this->db->loadModule('Manager');
960  $reverse = $this->db->loadModule('Reverse');
961  if($manager)
962  {
963  foreach($manager->listTableIndexes($a_table) as $idx_name)
964  {
965  $def = $reverse->getTableIndexDefinition($a_table,$idx_name);
966  $idx_fields = array_keys((array) $def['fields']);
967 
968  if($idx_fields === $a_fields)
969  {
970  return true;
971  }
972  }
973  }
974  return false;
975  }

◆ initConnection()

ilDB::initConnection ( )
protected

Initialize the database connection.

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

Referenced by connect().

302  {
303  }
+ 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

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

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

219  {
220  global $ilClientIniFile;
221 
222  //overwrite global client ini file if local parameter is set
223  if (is_object($tmpClientIniFile))
224  $clientIniFile = $tmpClientIniFile;
225  else
226  $clientIniFile = $ilClientIniFile;
227 
228  if (is_object($clientIniFile ))
229  {
230  $this->setDBUser($clientIniFile ->readVariable("db", "user"));
231  $this->setDBHost($clientIniFile ->readVariable("db", "host"));
232  $this->setDBPort($clientIniFile ->readVariable("db", "port"));
233  $this->setDBPassword($clientIniFile ->readVariable("db", "pass"));
234  $this->setDBName($clientIniFile ->readVariable("db", "name"));
235  }
236  }
setDBUser($a_user)
Set database user.
Definition: class.ilDB.php:83
setDBPort($a_port)
Set database port.
Definition: class.ilDB.php:103
setDBName($a_name)
Set database name.
Definition: class.ilDB.php:163
setDBPassword($a_password)
Set database password.
Definition: class.ilDB.php:143
setDBHost($a_host)
Set database host.
Definition: class.ilDB.php:123
+ Here is the call graph for this function:

◆ initHostConnection()

ilDB::initHostConnection ( )
protected

Initialize the host connection (no specific database)

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

Referenced by connectHost().

365  {
366  }
+ 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))

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

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

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

1567  {
1568  $fields = array();
1569  $field_values = array();
1570  $placeholders = array();
1571  $types = array();
1572  $values = array();
1573  $lobs = false;
1574  $lob = array();
1575  foreach ($a_columns as $k => $col)
1576  {
1577  $fields[] = $k;
1578  $placeholders[] = "%s";
1579  $placeholders2[] = ":$k";
1580  $types[] = $col[0];
1581 
1582  // integer auto-typecast (this casts bool values to integer)
1583  if ($col[0] == 'integer' && !is_null($col[1]))
1584  {
1585  $col[1] = (int) $col[1];
1586  }
1587 
1588  $values[] = $col[1];
1589  $field_values[$k] = $col[1];
1590  if ($col[0] == "blob" || $col[0] == "clob")
1591  {
1592  $lobs = true;
1593  $lob[$k] = $k;
1594  }
1595  }
1596  if ($lobs) // lobs -> use prepare execute (autoexecute broken in PEAR 2.4.1)
1597  {
1598  $st = $this->db->prepare("INSERT INTO ".$a_table." (".implode($fields,",").") VALUES (".
1599  implode($placeholders2,",").")", $types, MDB2_PREPARE_MANIP, $lob);
1600 
1601  $this->handleError($st, "insert / prepare/execute(".$a_table.")");
1602 
1603  $r = $st->execute($field_values);
1604 
1605 
1606  //$r = $this->db->extended->autoExecute($a_table, $field_values, MDB2_AUTOQUERY_INSERT, null, $types);
1607  $this->handleError($r, "insert / prepare/execute(".$a_table.")");
1608  $this->free($st);
1609  }
1610  else // if no lobs are used, take simple manipulateF
1611  {
1612  $q = "INSERT INTO ".$a_table." (".implode($fields,",").") VALUES (".
1613  implode($placeholders,",").")";
1614  $r = $this->manipulateF($q, $types, $values);
1615  }
1616  return $r;
1617  }
manipulateF($a_query, $a_types, $a_values)
Formatted manupulate (for DELETE, UPDATE, INSERT).
const MDB2_PREPARE_MANIP
These are just helper constants to more verbosely express parameters to prepare() ...
Definition: MDB2.php:109
free($a_st)
Free a statement / result set.
handleError($a_res, $a_info="", $a_level="")
Handle MDB2 Errors.
Definition: class.ilDB.php:405
$r
+ 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 469 of file class.ilDB.php.

References MDB2\isError().

Referenced by connect(), connectHost(), ilNestedSetXML\export(), and loadMDB2Extensions().

470  {
471  return MDB2::isError($a_res);
472  }
isError($data, $code=null)
Tell whether a value is a MDB2 error.
Definition: MDB2.php:594
+ 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?

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

Referenced by dropIndex().

947  {
948  return false;
949  }
+ 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.

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

References ilDBPostgreSQL\getReservedWords(), ilDBOracle\getReservedWords(), and ilDBMySQL\getReservedWords().

Referenced by checkColumnName(), checkIndexName(), and checkTableName().

1311  {
1312  include_once("./Services/Database/classes/class.ilDBMySQL.php");
1313  $mysql_reserved_words = ilDBMySQL::getReservedWords();
1314  if (in_array(strtoupper($a_word), $mysql_reserved_words))
1315  {
1316  return true;
1317  }
1318  include_once("./Services/Database/classes/class.ilDBOracle.php");
1319  $oracle_reserved_words = ilDBOracle::getReservedWords();
1320  if (in_array(strtoupper($a_word), $oracle_reserved_words))
1321  {
1322  return true;
1323  }
1324  include_once("./Services/Database/classes/class.ilDBPostgreSQL.php");
1325  $postgres_reserved_words = ilDBPostgreSQL::getReservedWords();
1326  if (in_array(strtoupper($a_word), $postgres_reserved_words))
1327  {
1328  return true;
1329  }
1330  }
static getReservedWords()
Get reserved words.
static getReservedWords()
Get reserved words.
static getReservedWords()
Get reserved words.
+ Here is the call graph for this function:
+ 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)

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

References quote(), and raisePearError().

1984  {
1985  if (!in_array($a_type, array("text", "clob", "blob")))
1986  {
1987  $this->raisePearError("Like: Invalid column type '".$a_type."'.", $this->error_class->FATAL);
1988  }
1989  if ($a_value == "?")
1990  {
1991  if ($case_insensitive)
1992  {
1993  return "UPPER(".$a_col.") LIKE(UPPER(?))";
1994  }
1995  else
1996  {
1997  return $a_col ." LIKE(?)";
1998  }
1999  }
2000  else
2001  {
2002  if ($case_insensitive)
2003  {
2004  // Always quote as text
2005  return " UPPER(".$a_col.") LIKE(UPPER(".$this->quote($a_value, 'text')."))";
2006  }
2007  else
2008  {
2009  // Always quote as text
2010  return " ".$a_col." LIKE(".$this->quote($a_value, 'text').")";
2011  }
2012  }
2013  }
raisePearError($a_message, $a_level="")
Raise an error.
Definition: class.ilDB.php:439
quote($a_query, $a_type=null)
Wrapper for quote method.
+ Here is the call graph for this function:

◆ listSequences()

ilDB::listSequences ( )

Get all sequences.

Returns
array Array of sequence names

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

References $r, and MDB2\isError().

Referenced by sequenceExists().

2216  {
2217  $manager = $this->db->loadModule('Manager');
2218  $r = $manager->listSequences();
2219 
2220  if (!MDB2::isError($r))
2221  {
2222  return $r;
2223  }
2224 
2225  return false;
2226  }
isError($data, $code=null)
Tell whether a value is a MDB2 error.
Definition: MDB2.php:594
$r
+ 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

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

References $r, and MDB2\isError().

Referenced by dropTable(), and tableExists().

2178  {
2179  $manager = $this->db->loadModule('Manager');
2180  $r = $manager->listTables();
2181 
2182  if (!MDB2::isError($r))
2183  {
2184  return $r;
2185  }
2186 
2187  return false;
2188  }
isError($data, $code=null)
Tell whether a value is a MDB2 error.
Definition: MDB2.php:594
$r
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ loadMDB2Extensions()

ilDB::loadMDB2Extensions ( )
protected

load additional mdb2 extensions and set their constants

protected

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

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

Referenced by connect(), and connectHost().

455  {
456  if (!$this->isDbError($this->db))
457  {
458  $this->db->loadModule('Extended');
459  define('DB_AUTOQUERY_SELECT',MDB2_AUTOQUERY_SELECT);
460  define('DB_AUTOQUERY_INSERT',MDB2_AUTOQUERY_INSERT);
461  define('DB_AUTOQUERY_UPDATE',MDB2_AUTOQUERY_UPDATE);
462  define('DB_AUTOQUERY_DELETE',MDB2_AUTOQUERY_DELETE);
463  }
464  }
const MDB2_AUTOQUERY_SELECT
Definition: Extended.php:59
const MDB2_AUTOQUERY_DELETE
Definition: Extended.php:58
const MDB2_AUTOQUERY_UPDATE
Definition: Extended.php:57
const MDB2_AUTOQUERY_INSERT
Used by autoPrepare()
Definition: Extended.php:56
static isDbError($a_res)
Check error.
Definition: class.ilDB.php:469
+ 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

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

1966  {
1967  $locate = ' LOCATE( ';
1968  $locate .= $a_needle;
1969  $locate .= ',';
1970  $locate .= $a_string;
1971  $locate .= ',';
1972  $locate .= $a_start_pos;
1973  $locate .= ') ';
1974  return $locate;
1975  }

◆ lockTables()

ilDB::lockTables (   $a_tables)
abstract

Abstraction of lock table.

Parameters
arraytable definitions
Returns

Referenced by rollback().

+ Here is the caller graph for this function:

◆ logStatement()

ilDB::logStatement (   $sql)

Helper function, should usually not be called.

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

References substr().

1421  {
1422  $pos1 = strpos(strtolower($sql), "from ");
1423  $table = "";
1424  if ($pos1 > 0)
1425  {
1426  $tablef = substr($sql, $pos1+5);
1427  $pos2 = strpos(strtolower($tablef), " ");
1428  if ($pos2 > 0)
1429  {
1430  $table =substr($tablef, 0, $pos2);
1431  }
1432  else
1433  {
1434  $table = $tablef;
1435  }
1436  }
1437  if (trim($table) != "")
1438  {
1439  if (!is_array($this->ttt) || !in_array($table, $this->ttt))
1440  {
1441  echo "<br>".$table;
1442  $this->ttt[] = $table;
1443  }
1444  }
1445  else
1446  {
1447  echo "<br><b>".$sql."</b>";
1448  }
1449  }
substr($a_exp, $a_pos=1, $a_len=-1)
Substring.
+ Here is the call graph for this function:

◆ lower()

ilDB::lower (   $a_exp)

Upper.

Parameters
stringexpression
Returns
string upper sql string

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

1954  {
1955  return " LOWER(".$a_exp.") ";
1956  }

◆ 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

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

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

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

1483  {
1484  global $ilBench;
1485 
1486  if (is_object($ilBench))
1487  {
1488  $ilBench->startDbBench($sql);
1489  }
1490  $r = $this->db->exec($sql);
1491  if (is_object($ilBench))
1492  {
1493  $ilBench->stopDbBench();
1494  }
1495 
1496  return $this->handleError($r, "manipulate(".$sql.")");
1497  }
handleError($a_res, $a_info="", $a_level="")
Handle MDB2 Errors.
Definition: class.ilDB.php:405
global $ilBench
Definition: ilias.php:18
$r
+ 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

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

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

Referenced by ilObjForum\getDiskUsage(), insert(), replace(), and update().

1401  {
1402  if (!is_array($a_types) || !is_array($a_values) ||
1403  count($a_types) != count($a_values))
1404  {
1405  $this->raisePearError("ilDB::manipulateF: types and values must be arrays of same size. ($a_query)");
1406  }
1407  $quoted_values = array();
1408  foreach($a_types as $k => $t)
1409  {
1410  $quoted_values[] = $this->quote($a_values[$k], $t);
1411  }
1412  $query = vsprintf($a_query, $quoted_values);
1413 
1414  return $this->manipulate($query);
1415  }
raisePearError($a_message, $a_level="")
Raise an error.
Definition: class.ilDB.php:439
quote($a_query, $a_type=null)
Wrapper for quote method.
manipulate($sql)
Data manipulation.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ 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")

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

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

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

◆ nextId()

ilDB::nextId (   $a_table_name)

Get next ID for an index.

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

References $r, and handleError().

Referenced by ilObjTest\insertQuestion().

1463  {
1464  // we do not create missing sequences automatically here
1465  // otherwise misspelled statements result in additional tables
1466  // please create sequences explicitly in the db update script
1467  $r = $this->db->nextId($a_table_name, false);
1468 
1469  return $this->handleError($r, "nextId(".$a_table_name.")");
1470  }
handleError($a_res, $a_info="", $a_level="")
Handle MDB2 Errors.
Definition: class.ilDB.php:405
$r
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ now()

ilDB::now ( )

now()

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

1870  {
1871  return "now()";
1872  }

◆ numRows()

ilDB::numRows (   $a_set)

Fetch row as associative array from result set.

Parameters
objectresult set

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

1801  {
1802  return $a_set->numRows();
1803  }

◆ optimizeTable()

ilDB::optimizeTable (   $a_table)

Optimize Table.

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

2074  {
2075  // needs to be overwritten in DBMS specific class
2076  // if necessary and possible
2077  }

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

References $res, and handleError().

Referenced by ilShopVatsList\_isVATAlreadyCreated().

1508  {
1509  $res = $this->db->prepare($a_query, $a_types, $a_result_types);
1510 
1511  return $this->handleError($res, "prepare(".$a_query.")");
1512  }
handleError($a_res, $a_info="", $a_level="")
Handle MDB2 Errors.
Definition: class.ilDB.php:405
+ Here is the call graph for this function:
+ Here is the caller 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.

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

References $res, handleError(), and MDB2_PREPARE_MANIP.

1523  {
1524  $res = $this->db->prepare($a_query, $a_types, MDB2_PREPARE_MANIP);
1525 
1526  return $this->handleError($res, "prepareManip(".$a_query.")");
1527  }
const MDB2_PREPARE_MANIP
These are just helper constants to more verbosely express parameters to prepare() ...
Definition: MDB2.php:109
handleError($a_res, $a_info="", $a_level="")
Handle MDB2 Errors.
Definition: class.ilDB.php:405
+ 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
object DB

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

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

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

1348  {
1349  global $ilBench;
1350 
1351  if (is_object($ilBench))
1352  {
1353  $ilBench->startDbBench($sql);
1354  }
1355  $r = $this->db->query($sql);
1356  if (is_object($ilBench))
1357  {
1358  $ilBench->stopDbBench();
1359  }
1360 
1361  if ($a_handle_error)
1362  {
1363  return $this->handleError($r, "query(".$sql.")");
1364  }
1365 
1366  return $r;
1367  }
handleError($a_res, $a_info="", $a_level="")
Handle MDB2 Errors.
Definition: class.ilDB.php:405
global $ilBench
Definition: ilias.php:18
$r
+ 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

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

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

Referenced by ilObjTestDynamicQuestionSetConfig\getPoolQuestionChangeListener(), ilObjSCORMTracking\syncGlobalStatus(), and ilSCORM2004StoreData\syncGlobalStatus().

1377  {
1378  if (!is_array($a_types) || !is_array($a_values) ||
1379  count($a_types) != count($a_values))
1380  {
1381  $this->raisePearError("ilDB::queryF: Types and values must be arrays of same size. ($a_query)");
1382  }
1383  $quoted_values = array();
1384  foreach($a_types as $k => $t)
1385  {
1386  $quoted_values[] = $this->quote($a_values[$k], $t);
1387  }
1388  $query = vsprintf($a_query, $quoted_values);
1389 
1390  return $this->query($query);
1391  }
raisePearError($a_message, $a_level="")
Raise an error.
Definition: class.ilDB.php:439
query($sql, $a_handle_error=true)
Query.
quote($a_query, $a_type=null)
Wrapper for quote method.
+ 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.

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

References raisePearError().

Referenced by MDB2_Statement_pgsql\_execute(), MDB2_Statement_mysql\_execute(), MDB2_Statement_mysqli\_execute(), equals(), equalsNot(), ilTree\getNodeDataByType(), ilTree\getPathFull(), ilDBOracle\like(), like(), manipulateF(), queryF(), ilDBPostgreSQL\replace(), ilDBOracle\replace(), ilRbacReview\searchRolesByMailboxAddressList(), update(), and ilTestArchiver\updateTestArchive().

2237  {
2238  if ($a_query == "" && is_null($a_type))
2239  {
2240  $a_query = "";
2241  }
2242 
2243  // Performance fix
2244  if($a_type == 'integer' && !is_null($a_query))
2245  {
2246  return (int) $a_query;
2247  }
2248 
2249  if ($a_type == "blob" || $a_type == "clob")
2250  {
2251  $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);
2252  }
2253 
2254  return $this->db->quote($a_query, $a_type);
2255  }
raisePearError($a_message, $a_level="")
Raise an error.
Definition: class.ilDB.php:439
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ quoteIdentifier()

ilDB::quoteIdentifier (   $a_identifier)

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.

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

2265  {
2266  return $this->db->quoteIdentifier($a_identifier);
2267  }

◆ raisePearError()

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

Raise an error.

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

References PEAR\raiseError().

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

440  {
441  if ($a_level == "")
442  {
443  $a_level = $this->error_class->FATAL;
444  }
445 //echo "<br>-ilDB:raising-$a_message-$a_level-";
446  $this->raiseError($a_message, $a_level);
447  }
& raiseError($message=null, $code=null, $mode=null, $options=null, $userinfo=null, $error_class=null, $skipmsg=false)
This method is a wrapper that returns an instance of the configured error class with this object&#39;s de...
Definition: PEAR.php:524
+ 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

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

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

824  {
825  // check table name
826  if (!$this->checkTableName($a_new_name))
827  {
828  $this->raisePearError("ilDB Error: renameTable(".$a_name.",".$a_new_name.")<br />".
829  $this->error_str);
830  }
831 
832  $manager = $this->db->loadModule('Manager');
833  $r = $manager->alterTable($a_name, array("name" => $a_new_name), false);
834 
835  $query = "UPDATE abstraction_progress ".
836  "SET table_name = ".$this->db->quote($a_new_name,'text')." ".
837  "WHERE table_name = ".$this->db->quote($a_name,'text');
838  $this->db->query($query);
839 
840  return $this->handleError($r, "renameTable(".$a_name.",".$a_new_name.")");
841  }
raisePearError($a_message, $a_level="")
Raise an error.
Definition: class.ilDB.php:439
checkTableName($a_name)
Check whether a table name is valid.
handleError($a_res, $a_info="", $a_level="")
Handle MDB2 Errors.
Definition: class.ilDB.php:405
$r
+ 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

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

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

774  {
775  // check table name
776  if (!$this->checkColumnName($a_new_column))
777  {
778  $this->raisePearError("ilDB Error: renameTableColumn(".$a_table.",".$a_column.",".$a_new_column.")<br />".
779  $this->error_str);
780  }
781 
782  $manager = $this->db->loadModule('Manager');
783  $reverse = $this->db->loadModule('Reverse');
784  $def = $reverse->getTableFieldDefinition($a_table, $a_column);
785 
786  $this->handleError($def, "renameTableColumn(".$a_table.",".$a_column.",".$a_new_column.")");
787 
788  if (is_file("./Services/Database/classes/class.ilDBAnalyzer.php"))
789  {
790  include_once("./Services/Database/classes/class.ilDBAnalyzer.php");
791  }
792  else
793  {
794  include_once("../Services/Database/classes/class.ilDBAnalyzer.php");
795  }
796 
797  $analyzer = new ilDBAnalyzer();
798  $best_alt = $analyzer->getBestDefinitionAlternative($def);
799  $def = $def[$best_alt];
800  unset($def["nativetype"]);
801  unset($def["mdb2type"]);
802 
803  $f["definition"] = $def;
804  $f["name"] = $a_new_column;
805 
806  $changes = array(
807  "rename" => array(
808  $a_column => $f
809  )
810  );
811 
812  $r = $manager->alterTable($a_table, $changes, false);
813 
814  return $this->handleError($r, "renameTableColumn(".$a_table.",".$a_column.",".$a_new_column.")");
815  }
raisePearError($a_message, $a_level="")
Raise an error.
Definition: class.ilDB.php:439
checkColumnName($a_name)
Check whether a column name is valid.
handleError($a_res, $a_info="", $a_level="")
Handle MDB2 Errors.
Definition: class.ilDB.php:405
This class gives all kind of DB information using the MDB2 manager and reverse module.
$r
+ 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" => ...)

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

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

1717  {
1718  // this is the mysql implementation
1719  $a_columns = array_merge($a_pk_columns, $a_other_columns);
1720  $fields = array();
1721  $field_values = array();
1722  $placeholders = array();
1723  $types = array();
1724  $values = array();
1725  $lobs = false;
1726  $lob = array();
1727  foreach ($a_columns as $k => $col)
1728  {
1729  $fields[] = $k;
1730  $placeholders[] = "%s";
1731  $placeholders2[] = ":$k";
1732  $types[] = $col[0];
1733 
1734  // integer auto-typecast (this casts bool values to integer)
1735  if ($col[0] == 'integer' && !is_null($col[1]))
1736  {
1737  $col[1] = (int) $col[1];
1738  }
1739 
1740  $values[] = $col[1];
1741  $field_values[$k] = $col[1];
1742  if ($col[0] == "blob" || $col[0] == "clob")
1743  {
1744  $lobs = true;
1745  $lob[$k] = $k;
1746  }
1747  }
1748  if ($lobs) // lobs -> use prepare execute (autoexecute broken in PEAR 2.4.1)
1749  {
1750  $st = $this->db->prepare("REPLACE INTO ".$a_table." (".implode($fields,",").") VALUES (".
1751  implode($placeholders2,",").")", $types, MDB2_PREPARE_MANIP, $lob);
1752  $this->handleError($st, "insert / prepare/execute(".$a_table.")");
1753  $r = $st->execute($field_values);
1754  //$r = $this->db->extended->autoExecute($a_table, $field_values, MDB2_AUTOQUERY_INSERT, null, $types);
1755  $this->handleError($r, "insert / prepare/execute(".$a_table.")");
1756  $this->free($st);
1757  }
1758  else // if no lobs are used, take simple manipulateF
1759  {
1760  $q = "REPLACE INTO ".$a_table." (".implode($fields,",").") VALUES (".
1761  implode($placeholders,",").")";
1762  $r = $this->manipulateF($q, $types, $values);
1763  }
1764  return $r;
1765  }
manipulateF($a_query, $a_types, $a_values)
Formatted manupulate (for DELETE, UPDATE, INSERT).
const MDB2_PREPARE_MANIP
These are just helper constants to more verbosely express parameters to prepare() ...
Definition: MDB2.php:109
free($a_st)
Free a statement / result set.
handleError($a_res, $a_info="", $a_level="")
Handle MDB2 Errors.
Definition: class.ilDB.php:405
$r
+ Here is the call graph for this function:

◆ rollback()

ilDB::rollback ( )

Rollback a transaction.

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

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

2304  {
2305  $res = $this->db->rollback();
2306 
2307  return $this->handleError($res, "rollback()");
2308  }
handleError($a_res, $a_info="", $a_level="")
Handle MDB2 Errors.
Definition: class.ilDB.php:405
+ 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

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

References listSequences().

2197  {
2198  $sequences = $this->listSequences();
2199 
2200  if (is_array($sequences))
2201  {
2202  if (in_array($a_sequence, $sequences))
2203  {
2204  return true;
2205  }
2206  }
2207  return false;
2208  }
listSequences()
Get all sequences.
+ Here is the call graph for this function:

◆ setDBHost()

ilDB::setDBHost (   $a_host)

Set database host.

Parameters
stringdatabase host

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

Referenced by initFromIniFile().

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

◆ setDBName()

ilDB::setDBName (   $a_name)

Set database name.

Parameters
stringdatabase name

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

Referenced by initFromIniFile().

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

◆ setDBPassword()

ilDB::setDBPassword (   $a_password)

Set database password.

Parameters
stringdatabase password

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

Referenced by initFromIniFile().

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

◆ setDBPort()

ilDB::setDBPort (   $a_port)

Set database port.

Parameters
stringdatabase port

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

Referenced by initFromIniFile().

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

◆ setDBUser()

ilDB::setDBUser (   $a_user)

Set database user.

Parameters
stringdatabase user

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

Referenced by initFromIniFile().

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

◆ setLimit()

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

Set limit and offset for a query.

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

Referenced by ilForum\deletePost(), and ilObjTest\getUnfilteredEvaluationData().

1455  {
1456  $this->db->setLimit($a_limit, $a_offset);
1457  }
+ Here is the caller graph for this function:

◆ setSubType()

ilDB::setSubType (   $a_value)

Set sub type.

Parameters
string$a_value

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

2414  {
2415  $this->sub_type = (string)$a_value;
2416  }

◆ substr()

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

Substring.

Parameters

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

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

1927  {
1928  $lenstr = "";
1929  if ($a_len > -1)
1930  {
1931  $lenstr = ", ".$a_len;
1932  }
1933  return " SUBSTR(".$a_exp.", ".$a_pos.$lenstr.") ";
1934  }
+ Here is the caller graph for this function:

◆ supportsFulltext()

ilDB::supportsFulltext ( )

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

Referenced by addIndex().

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

◆ supportsSlave()

ilDB::supportsSlave ( )

Supports slave.

Parameters

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

Referenced by useSlave().

380  {
381  return false;
382  }
+ 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

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

References $r, and MDB2\isError().

2111  {
2112 
2113  $column_visibility = false;
2114  $manager = $this->db->loadModule('Manager');
2115  $r = $manager->listTableFields($a_table);
2116 
2117  if (!MDB2::isError($r))
2118  {
2119  foreach($r as $field)
2120  {
2121  if ($field == $a_column_name)
2122  {
2123  $column_visibility = true;
2124  }
2125  }
2126  }
2127 
2128  return $column_visibility;
2129  }
isError($data, $code=null)
Tell whether a value is a MDB2 error.
Definition: MDB2.php:594
$r
+ 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

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

References listTables().

2090  {
2091  $tables = $this->listTables();
2092 
2093  if (is_array($tables))
2094  {
2095  if (in_array($a_table, $tables))
2096  {
2097  return true;
2098  }
2099  }
2100  return false;
2101  }
listTables()
Get all tables.
+ Here is the call graph for this function:

◆ uniqueConstraintExists()

ilDB::uniqueConstraintExists (   $a_table,
  $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 2138 of file class.ilDB.php.

2139  {
2140  if (is_file("./Services/Database/classes/class.ilDBAnalyzer.php"))
2141  {
2142  include_once("./Services/Database/classes/class.ilDBAnalyzer.php");
2143  }
2144  else
2145  {
2146  include_once("../Services/Database/classes/class.ilDBAnalyzer.php");
2147  }
2148  $analyzer = new ilDBAnalyzer();
2149  $cons = $analyzer->getConstraintsInformation($a_table);
2150  foreach ($cons as $c)
2151  {
2152  if ($c["type"] == "unique" && count($a_fields) == count($c["fields"]))
2153  {
2154  $all_in = true;
2155  foreach ($a_fields as $f)
2156  {
2157  if (!isset($c["fields"][$f]))
2158  {
2159  $all_in = false;
2160  }
2161  }
2162  if ($all_in)
2163  {
2164  return true;
2165  }
2166  }
2167  }
2168  return false;
2169  }
This class gives all kind of DB information using the MDB2 manager and reverse module.

◆ unixTimestamp()

ilDB::unixTimestamp ( )

Unix timestamp.

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

2066  {
2067  return "UNIX_TIMESTAMP()";
2068  }

◆ unlockTables()

ilDB::unlockTables ( )
abstract

Unlock tables locked by previous lock table calls.

Returns

Referenced by rollback().

+ Here is the caller graph for this function:

◆ update()

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

Convenient method for standard update statements, example field array:

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

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

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

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

Referenced by ilECSCmsTreeCommandQueueHandler\handleUpdate().

1628  {
1629  $fields = array();
1630  $field_values = array();
1631  $placeholders = array();
1632  $types = array();
1633  $values = array();
1634  $lobs = false;
1635  $lob = array();
1636  foreach ($a_columns as $k => $col)
1637  {
1638  $fields[] = $k;
1639  $placeholders[] = "%s";
1640  $placeholders2[] = ":$k";
1641  $types[] = $col[0];
1642 
1643  // integer auto-typecast (this casts bool values to integer)
1644  if ($col[0] == 'integer' && !is_null($col[1]))
1645  {
1646  $col[1] = (int) $col[1];
1647  }
1648 
1649  $values[] = $col[1];
1650  $field_values[$k] = $col[1];
1651  if ($col[0] == "blob" || $col[0] == "clob")
1652  {
1653  $lobs = true;
1654  $lob[$k] = $k;
1655  }
1656  }
1657 
1658  if ($lobs)
1659  {
1660  $q = "UPDATE ".$a_table." SET ";
1661  $lim = "";
1662  foreach ($fields as $k => $field)
1663  {
1664  $q.= $lim.$field." = ".$placeholders2[$k];
1665  $lim = ", ";
1666  }
1667  $q.= " WHERE ";
1668  $lim = "";
1669  foreach ($a_where as $k => $col)
1670  {
1671  $q.= $lim.$k." = ".$this->quote($col[1], $col[0]);
1672  $lim = " AND ";
1673  }
1674  $st = $this->db->prepare($q, $types, MDB2_PREPARE_MANIP, $lob);
1675  $r = $st->execute($field_values);
1676 
1677  //$r = $this->db->extended->autoExecute($a_table, $field_values, MDB2_AUTOQUERY_INSERT, null, $types);
1678  $this->handleError($r, "update / prepare/execute(".$a_table.")");
1679  $this->free($st);
1680  }
1681  else
1682  {
1683  foreach ($a_where as $k => $col)
1684  {
1685  $types[] = $col[0];
1686  $values[] = $col[1];
1687  $field_values[$k] = $col;
1688  }
1689  $q = "UPDATE ".$a_table." SET ";
1690  $lim = "";
1691  foreach ($fields as $k => $field)
1692  {
1693  $q.= $lim.$field." = ".$placeholders[$k];
1694  $lim = ", ";
1695  }
1696  $q.= " WHERE ";
1697  $lim = "";
1698  foreach ($a_where as $k => $col)
1699  {
1700  $q.= $lim.$k." = %s";
1701  $lim = " AND ";
1702  }
1703 
1704  $r = $this->manipulateF($q, $types, $values);
1705  }
1706  return $r;
1707  }
manipulateF($a_query, $a_types, $a_values)
Formatted manupulate (for DELETE, UPDATE, INSERT).
quote($a_query, $a_type=null)
Wrapper for quote method.
const MDB2_PREPARE_MANIP
These are just helper constants to more verbosely express parameters to prepare() ...
Definition: MDB2.php:109
free($a_st)
Free a statement / result set.
handleError($a_res, $a_info="", $a_level="")
Handle MDB2 Errors.
Definition: class.ilDB.php:405
$r
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ upper()

ilDB::upper (   $a_exp)

Upper.

Parameters
stringexpression
Returns
string upper sql string

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

1943  {
1944  return " UPPER(".$a_exp.") ";
1945  }

◆ useSlave()

ilDB::useSlave (   $a_val = true)

Use slave.

Parameters

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

References supportsSlave().

391  {
392  if (!$this->supportsSlave())
393  {
394  return false;
395  }
396  $this->use_slave = $a_val;
397  }
supportsSlave()
Supports slave.
Definition: class.ilDB.php:379
+ 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 54 of file class.ilDB.php.

Referenced by checkColumnDefinition(), and getAllowedAttributes().

◆ $db

ilDB::$db

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

◆ $error_class

ilDB::$error_class

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

◆ $result

ilDB::$result

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

◆ $sub_type

ilDB::$sub_type

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

Referenced by getSubType().

◆ LOCK_READ

const ilDB::LOCK_READ = 2

◆ LOCK_WRITE


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