ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f87
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 984 of file class.ilDB.php.

Referenced by addIndex().

985  {
986  return false;
987  }
+ 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 946 of file class.ilDB.php.

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

947  {
948  $manager = $this->db->loadModule('Manager');
949 
950  // check index name
951  if (!$this->checkIndexName($a_name))
952  {
953  $this->raisePearError("ilDB Error: addIndex(".$a_table.",".$a_name.")<br />".
954  $this->error_str);
955  }
956 
957  $fields = array();
958  foreach ($a_fields as $f)
959  {
960  $fields[$f] = array();
961  }
962  $definition = array (
963  'fields' => $fields
964  );
965 
966  if (!$a_fulltext)
967  {
968  $r = $manager->createIndex($a_table, $this->constraintName($a_table, $a_name), $definition);
969  }
970  else
971  {
972  if ($this->supportsFulltext())
973  {
974  $this->addFulltextIndex($a_table, $a_fields, $a_name);
975  }
976  }
977 
978  return $this->handleError($r, "addIndex(".$a_table.")");
979  }
raisePearError($a_message, $a_level="")
Raise an error.
Definition: class.ilDB.php:485
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:984
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 896 of file class.ilDB.php.

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

897  {
898  $manager = $this->db->loadModule('Manager');
899 
900  $fields = array();
901  foreach ($a_fields as $f)
902  {
903  $fields[$f] = array();
904  }
905  $definition = array (
906  'primary' => true,
907  'fields' => $fields
908  );
909  $r = $manager->createConstraint($a_table,
910  $this->constraintName($a_table, $this->getPrimaryKeyIdentifier()), $definition);
911 
912  return $this->handleError($r, "addPrimaryKey(".$a_table.")");
913  }
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:918
$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 675 of file class.ilDB.php.

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

676  {
677 
678  $manager = $this->db->loadModule('Manager');
679 
680  if (!$this->checkColumnName($a_column))
681  {
682  $this->raisePearError("ilDB Error: addTableColumn(".$a_table.", ".$a_column.")<br />".
683  $this->error_str);
684  }
685  if (!$this->checkColumnDefinition($a_attributes))
686  {
687  $this->raisePearError("ilDB Error: addTableColumn(".$a_table.", ".$a_column.")<br />".
688  $this->error_str);
689  }
690 
691  $changes = array(
692  "add" => array(
693  $a_column => $a_attributes
694  )
695  );
696 
697  $r = $manager->alterTable($a_table, $changes, false);
698 
699  return $this->handleError($r, "addTableColumn(".$a_table.", ".$a_column.")");
700  }
raisePearError($a_message, $a_level="")
Raise an error.
Definition: class.ilDB.php:485
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 1897 of file class.ilDB.php.

1898  {
1899  if (!is_array($a_arr))
1900  {
1901  $a_arr = array();
1902  }
1903  if ($a_cnt > 0)
1904  {
1905  $type_arr = array_fill(0, $a_cnt, $a_type);
1906  }
1907  else
1908  {
1909  $type_arr = array();
1910  }
1911  return array_merge($a_arr, $type_arr);
1912  }

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

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

1081  {
1082  $manager = $this->db->loadModule('Manager');
1083 
1084  // check index name
1085  if (!$this->checkIndexName($a_name))
1086  {
1087  $this->raisePearError("ilDB Error: addUniqueConstraint(".$a_table.",".$a_name.")<br />".
1088  $this->error_str);
1089  }
1090 
1091  $fields = array();
1092  foreach ($a_fields as $f)
1093  {
1094  $fields[$f] = array();
1095  }
1096  $definition = array (
1097  'unique' => true,
1098  'fields' => $fields
1099  );
1100 
1101  $r = $manager->createConstraint($a_table, $this->constraintName($a_table, $a_name), $definition);
1102 
1103  return $this->handleError($r, "addUniqueConstraint(".$a_table.")");
1104  }
raisePearError($a_message, $a_level="")
Raise an error.
Definition: class.ilDB.php:485
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 654 of file class.ilDB.php.

References $r, and handleError().

655  {
656  if ($a_options == "")
657  {
658  $a_options = array();
659  }
660 
661  $manager = $this->db->loadModule('Manager');
662  $r = $manager->alterTable($a_name, $a_changes, false);
663 
664  return $this->handleError($r, "alterTable(".$a_name.")");
665  }
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 2387 of file class.ilDB.php.

References $res, and handleError().

2388  {
2389  $res = $this->db->autoExecute($a_tablename,$a_fields,$a_mode,$a_where);
2390 
2391  return $this->handleError($res, "autoExecute(".$a_tablename.")");
2392  }
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 2328 of file class.ilDB.php.

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

2329  {
2330  if (!$this->db->supports('transactions'))
2331  {
2332  $this->raisePearError("ilDB::beginTransaction: Transactions are not supported.", $this->error_class->FATAL);
2333  }
2334  $res = $this->db->beginTransaction();
2335 
2336  return $this->handleError($res, "beginTransaction()");
2337  }
raisePearError($a_message, $a_level="")
Raise an error.
Definition: class.ilDB.php:485
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 1186 of file class.ilDB.php.

References checkColumnDefinition(), and checkColumnName().

Referenced by checkTableColumns().

1187  {
1188  if (!$this->checkColumnName($a_col))
1189  {
1190  return false;
1191  }
1192 
1193  if (!$this->checkColumnDefinition($a_def))
1194  {
1195  return false;
1196  }
1197 
1198  return true;
1199  }
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 1206 of file class.ilDB.php.

References $allowed_attributes.

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

1207  {
1208  // check valid type
1209  if (!in_array($a_def["type"], array("text", "integer", "float", "date", "time", "timestamp", "clob", "blob")))
1210  {
1211  switch ($a_def["type"])
1212  {
1213  case "boolean":
1214  $this->error_str = "Invalid column type '".$a_def["type"]."'. Use integer(1) instead.";
1215  break;
1216 
1217  case "decimal":
1218  $this->error_str = "Invalid column type '".$a_def["type"]."'. Use float or integer instead.";
1219  break;
1220 
1221  default:
1222  $this->error_str = "Invalid column type '".$a_def["type"]."'. Allowed types are: ".
1223  "text, integer, float, date, time, timestamp, clob and blob.";
1224  }
1225  }
1226 
1227  // check used attributes
1229 
1230  foreach ($a_def as $k => $v)
1231  {
1232  if ($k != "type" && !in_array($k, $allowed_attributes[$a_def["type"]]))
1233  {
1234  $this->error_str = "Attribute '".$k."' is not allowed for column type '".$a_def["type"]."'.";
1235  return false;
1236  }
1237  }
1238 
1239  // type specific checks
1240  switch ($a_def["type"])
1241  {
1242  case "text":
1243  if ($a_def["length"] < 1 || $a_def["length"] > 4000)
1244  {
1245  if (!$a_modify_mode || isset($a_def["length"]))
1246  {
1247  $this->error_str = "Invalid length '".$a_def["length"]."' for type text.".
1248  " Length must be >=1 and <= 4000.";
1249  return false;
1250  }
1251  }
1252  break;
1253 
1254  case "integer":
1255  if (!in_array($a_def["length"], array(1, 2, 3, 4, 8)))
1256  {
1257  if (!$a_modify_mode || isset($a_def["length"]))
1258  {
1259  $this->error_str = "Invalid length '".$a_def["length"]."' for type integer.".
1260  " Length must be 1, 2, 3, 4 or 8 (bytes).";
1261  return false;
1262  }
1263  }
1264  if ($a_def["unsigned"])
1265  {
1266  $this->error_str = "Unsigned attribut must not be true for type integer.";
1267  return false;
1268  }
1269  break;
1270  }
1271 
1272  return true;
1273  }
$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 1280 of file class.ilDB.php.

References isReservedWord(), and substr().

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

1281  {
1282  if (!preg_match ("/^[a-z]+[_a-z0-9]*$/", $a_name))
1283  {
1284  $this->error_str = "Invalid column name '".$a_name."'. Column name must only contain _a-z0-9 and must start with a-z.";
1285  return false;
1286  }
1287 
1288  if ($this->isReservedWord($a_name))
1289  {
1290  $this->error_str = "Invalid column name '".$a_name."' (Reserved Word).";
1291  return false;
1292  }
1293 
1294  if (strtolower(substr($a_name, 0, 4)) == "sys_")
1295  {
1296  $this->error_str = "Invalid column name '".$a_name."'. Name must not start with 'sys_'.";
1297  return false;
1298  }
1299 
1300  if (strlen($a_name) > 30)
1301  {
1302  $this->error_str = "Invalid column name '".$a_name."'. Maximum column identifer lenght is 30 bytes.";
1303  return false;
1304  }
1305 
1306  return true;
1307  }
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 1314 of file class.ilDB.php.

References isReservedWord().

Referenced by addIndex(), and addUniqueConstraint().

1315  {
1316  if (!preg_match ("/^[a-z]+[_a-z0-9]*$/", $a_name))
1317  {
1318  $this->error_str = "Invalid column name '".$a_name."'. Column name must only contain _a-z0-9 and must start with a-z.";
1319  return false;
1320  }
1321 
1322  if ($this->isReservedWord($a_name))
1323  {
1324  $this->error_str = "Invalid column name '".$a_name."' (Reserved Word).";
1325  return false;
1326  }
1327 
1328  if (strlen($a_name) > 3)
1329  {
1330  $this->error_str = "Invalid index name '".$a_name."'. Maximum index identifer lenght is 3 bytes.";
1331  return false;
1332  }
1333 
1334  return true;
1335  }
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 1170 of file class.ilDB.php.

References checkColumn().

Referenced by createTable().

1171  {
1172  foreach ($a_cols as $col => $def)
1173  {
1174  if (!$this->checkColumn($col, $def))
1175  {
1176  return false;
1177  }
1178  }
1179 
1180  return true;
1181  }
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 1136 of file class.ilDB.php.

References isReservedWord(), and substr().

Referenced by createTable(), and renameTable().

1137  {
1138  if (!preg_match ("/^[a-z]+[_a-z0-9]*$/", $a_name))
1139  {
1140  $this->error_str = "Table name must only contain _a-z0-9 and must start with a-z.";
1141  return false;
1142  }
1143 
1144  if ($this->isReservedWord($a_name))
1145  {
1146  $this->error_str = "Invalid table name '".$a_name."' (Reserved Word).";
1147  return false;
1148  }
1149 
1150  if (strtolower(substr($a_name, 0, 4)) == "sys_")
1151  {
1152  $this->error_str = "Invalid table name '".$a_name."'. Name must not start with 'sys_'.";
1153  return false;
1154  }
1155 
1156  if (strlen($a_name) > 22)
1157  {
1158  $this->error_str = "Invalid table name '".$a_name."'. Maximum table identifer lenght is 22 bytes.";
1159  return false;
1160  }
1161 
1162  return true;
1163  }
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 2342 of file class.ilDB.php.

References $res, and handleError().

2343  {
2344  $res = $this->db->commit();
2345 
2346  return $this->handleError($res, "commit()");
2347  }
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 1933 of file class.ilDB.php.

1934  {
1935  if(!count($a_values))
1936  {
1937  return ' ';
1938  }
1939 
1940  $concat = ' CONCAT(';
1941  $first = true;
1942  foreach($a_values as $field_info)
1943  {
1944  $val = $field_info[0];
1945 
1946  if(!$first)
1947  {
1948  $concat .= ',';
1949  }
1950 
1951  if($a_allow_null)
1952  {
1953  $concat .= 'COALESCE(';
1954  }
1955  $concat .= $val;
1956 
1957  if($a_allow_null)
1958  {
1959  $concat .= ",''";
1960  $concat .= ')';
1961  }
1962 
1963  $first = false;
1964  }
1965  $concat .= ') ';
1966  return $concat;
1967  }

◆ 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:485
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:500
getDSN()
Get DSN.
Error Handling & global info handling uses PEAR error class.
static isDbError($a_res)
Check error.
Definition: class.ilDB.php:515
+ 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:485
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:500
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:515
+ 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 1347 of file class.ilDB.php.

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

1348  {
1349  return $a_constraint;
1350  }
+ Here is the caller graph for this function:

◆ createDatabase()

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

Create database.

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

References query().

528  {
529  if ($a_collation != "")
530  {
531  $sql = "CREATE DATABASE ".$a_name.
532  " CHARACTER SET ".$a_charset.
533  " COLLATE ".$a_collation;
534  }
535  else
536  {
537  $sql = "CREATE DATABASE ".$a_name.
538  " CHARACTER SET ".$a_charset;
539  }
540 
541  return $this->query($sql, false);
542  }
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 1109 of file class.ilDB.php.

References $r, and handleError().

1110  {
1111  $manager = $this->db->loadModule('Manager');
1112 
1113  $r = $manager->createSequence($a_table_name, $a_start);
1114 
1115  return $this->handleError($r, "createSequence(".$a_table_name.")");
1116  }
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 552 of file class.ilDB.php.

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

554  {
555  // check table name
556  if (!$this->checkTableName($a_name) && !$a_ignore_erros)
557  {
558  $this->raisePearError("ilDB Error: createTable(".$a_name.")<br />".
559  $this->error_str);
560  }
561 
562  // check definition array
563  if (!$this->checkTableColumns($a_definition_array) && !$a_ignore_erros)
564  {
565  $this->raisePearError("ilDB Error: createTable(".$a_name.")<br />".
566  $this->error_str);
567  }
568 
569  if ($a_drop_table)
570  {
571  $this->dropTable($a_name, false);
572  }
573 
574  $options = $this->getCreateTableOptions();
575 
576  $manager = $this->db->loadModule('Manager');
577  $r = $manager->createTable($a_name, $a_definition_array, $options);
578 
579  return $this->handleError($r, "createTable(".$a_name.")");
580  }
raisePearError($a_message, $a_level="")
Raise an error.
Definition: class.ilDB.php:485
checkTableColumns($a_cols)
Check table columns definition.
dropTable($a_name, $a_error_if_not_existing=true)
Drop a table.
Definition: class.ilDB.php:598
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:587
$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 1057 of file class.ilDB.php.

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

Referenced by dropIndexByFields().

1058  {
1059  $manager = $this->db->loadModule('Manager');
1060 
1061  if (!$this->isFulltextIndex($a_table, $a_name))
1062  {
1063  $r = $manager->dropIndex($a_table, $this->constraintName($a_table, $a_name));
1064  }
1065  else
1066  {
1067  $this->dropFulltextIndex($a_table, $a_name);
1068  }
1069 
1070  return $this->handleError($r, "dropIndex(".$a_table.")");
1071  }
isFulltextIndex($a_table, $a_name)
Is index a fulltext index?
Definition: class.ilDB.php:992
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 1029 of file class.ilDB.php.

References dropIndex().

1030  {
1031  $manager = $this->db->loadModule('Manager');
1032  $reverse = $this->db->loadModule('Reverse');
1033  if($manager)
1034  {
1035  foreach($manager->listTableIndexes($a_table) as $idx_name)
1036  {
1037  $def = $reverse->getTableIndexDefinition($a_table,$idx_name);
1038  $idx_fields = array_keys((array) $def['fields']);
1039 
1040  if($idx_fields === $a_fields)
1041  {
1042  return $this->dropIndex($a_table, $idx_name);
1043  }
1044  }
1045  }
1046  return false;
1047 
1048  }
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 929 of file class.ilDB.php.

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

930  {
931  $manager = $this->db->loadModule('Manager');
932 
933  $r = $manager->dropConstraint($a_table,
934  $this->constraintName($a_table, $this->getPrimaryKeyIdentifier()), true);
935 
936  return $this->handleError($r, "dropPrimaryKey(".$a_table.")");
937  }
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:918
$r
+ Here is the call graph for this function:

◆ dropSequence()

ilDB::dropSequence (   $a_table_name)

Drop a sequence for a table.

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

References $r, and handleError().

1123  {
1124  $manager = $this->db->loadModule('Manager');
1125 
1126  $r = $manager->dropSequence($a_table_name);
1127 
1128  return $this->handleError($r, "dropSequence(".$a_table_name.")");
1129  }
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 598 of file class.ilDB.php.

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

Referenced by createTable().

599  {
600  if (!$a_error_if_not_existing)
601  {
602  $tables = $this->listTables();
603  if (!in_array($a_name, $tables))
604  {
605  return;
606  }
607  }
608 
609  $manager = $this->db->loadModule('Manager');
610 
611  if ($this->getDBType() == "oracle")
612  {
613  // drop table constraints
614  $constraints = $manager->listTableConstraints($a_name);
615  $this->handleError($constraints, "dropTable(".$a_name."), listTableConstraints");
616  foreach ($constraints as $c)
617  {
618  if (substr($c, 0, 4) != "sys_")
619  {
620  $r = $manager->dropConstraint($a_name, $c);
621  $this->handleError($r, "dropTable(".$a_name."), dropConstraint");
622  }
623  }
624 
625  // drop table indexes
626  $indexes = $manager->listTableIndexes($a_name);
627  $this->handleError($indexes, "dropTable(".$a_name."), listTableIndexes");
628  foreach ($indexes as $i)
629  {
630  $r = $manager->dropIndex($a_name, $i);
631  $this->handleError($r, "dropTable(".$a_name."), dropIndex");
632  }
633  }
634 
635  // drop sequence
636  $seqs = $manager->listSequences();
637  if (in_array($a_name, $seqs))
638  {
639  $r = $manager->dropSequence($a_name);
640  $this->handleError($r, "dropTable(".$a_name."), dropSequence");
641  }
642 
643  // drop table
644  $r = $manager->dropTable($a_name);
645 
646  return $this->handleError($r, "dropTable(".$a_name.")");
647  }
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 709 of file class.ilDB.php.

References $r, and handleError().

710  {
711 
712  $manager = $this->db->loadModule('Manager');
713 
714  $changes = array(
715  "remove" => array(
716  $a_column => array()
717  )
718  );
719 
720  $r = $manager->alterTable($a_table, $changes, false);
721 
722  return $this->handleError($r, "dropTableColumn(".$a_table.", ".$a_column.")");
723  }
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 2068 of file class.ilDB.php.

References quote().

2069  {
2070  if (!$a_empty_or_null || $a_value != "")
2071  {
2072  return $a_col." = ".$this->quote($a_value, $a_type);
2073  }
2074  else
2075  {
2076  return "(".$a_col." = '' OR $a_col IS NULL)";
2077  }
2078  }
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 2083 of file class.ilDB.php.

References quote().

2084  {
2085  if (!$a_empty_or_null)
2086  {
2087  return $a_col." <> ".$this->quote($a_value, $a_type);
2088  }
2089  if ($a_value != "")
2090  {
2091  return "(".$a_col." <> ".$this->quote($a_value, $a_type). " OR ".
2092  $a_col." IS NULL)";
2093  }
2094  else
2095  {
2096  return "(".$a_col." <> '' AND $a_col IS NOT NULL)";
2097  }
2098  }
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 1583 of file class.ilDB.php.

References $res, and handleError().

1584  {
1585  $res = $a_stmt->execute($a_data);
1586 
1587  return $this->handleError($res, "execute(".$a_stmt->query.")");
1588  }
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 1599 of file class.ilDB.php.

References $res, and handleError().

1600  {
1601  $res = $this->db->extended->executeMultiple($a_stmt,$a_data);
1602 
1603  return $this->handleError($res, "executeMultiple(".$a_stmt->query.")");
1604  }
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 1818 of file class.ilDB.php.

References DB_FETCHMODE_ASSOC.

Referenced by ilObjTestDynamicQuestionSetConfig\getPoolQuestionChangeListener(), ilDBMySQL\isFulltextIndex(), and ilTestArchiver\updateTestArchive().

1819  {
1820  return $a_set->fetchRow(DB_FETCHMODE_ASSOC);
1821  }
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 1836 of file class.ilDB.php.

References DB_FETCHMODE_OBJECT.

1837  {
1838  return $a_set->fetchRow(DB_FETCHMODE_OBJECT);
1839  }
const DB_FETCHMODE_OBJECT
Definition: class.ilDB.php:11

◆ free()

ilDB::free (   $a_st)

Free a statement / result set.

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

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

1827  {
1828  return $a_st->free();
1829  }
+ 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 2106 of file class.ilDB.php.

2107  {
2108  return "FROM_UNIXTIME(".$a_expr.")";
2109  }

◆ getAllowedAttributes()

ilDB::getAllowedAttributes ( )

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

References $allowed_attributes.

1338  {
1340  }
$allowed_attributes
Definition: class.ilDB.php:54

◆ getCreateTableOptions()

ilDB::getCreateTableOptions ( )
protected

Get options for the create table statement.

Returns
array

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

Referenced by createTable().

588  {
589  return array();
590  }
+ 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 2403 of file class.ilDB.php.

References $res, and MDB2\isError().

2404  {
2405  $res = $this->db->lastInsertId();
2406  if(MDB2::isError($res))
2407  {
2408  return false;
2409  }
2410  return $res;
2411  }
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 2422 of file class.ilDB.php.

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

2423  {
2424  //$r = $this->db->getOne($sql);
2425  $set = $this->db->query($sql);
2426 
2427  $this->handleError($set, "getOne(".$sql.")");
2428 
2429  if (!MDB2::isError($set))
2430  {
2431  $r = $set->fetchRow(DB_FETCHMODE_ASSOC);
2432 
2433  return $r[0];
2434  }
2435  }
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 918 of file class.ilDB.php.

Referenced by addPrimaryKey(), and dropPrimaryKey().

919  {
920  return "PRIMARY";
921  }
+ 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 2446 of file class.ilDB.php.

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

2447  {
2448  $set = $this->query($sql);
2449  $r = $set->fetchRow($mode);
2450  //$r = $this->db->getrow($sql,$mode);
2451 
2452  $this->handleError($r, "getRow(".$sql.")");
2453 
2454  return $r;
2455  } //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 2472 of file class.ilDB.php.

References $sub_type.

Referenced by ilDBMySQL\isMySQLi().

2473  {
2474  return $this->sub_type;
2475  }
$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  // :TODO: ADT (jluetzen)
417 
418  // if(!$this->exception)
419  if(true)
420  {
421  // Show stack
422  try
423  {
424  throw new Exception();
425  }
426  catch(Exception $e)
427  {
428  $stack = $e->getTraceAsString();
429  }
430 
431  if(is_object($ilLog))
432  $ilLog->logStack();
433  $this->raisePearError("ilDB Error: ".$a_info."<br />".
434  $a_res->getMessage()."<br />".$a_res->getUserInfo()."<br />".$stack, $a_level);
435  }
436  /*
437  else
438  {
439  $error = $this->db->errorInfo($a_res->getCode());
440 
441  $mess = $a_info.
442  " ### ".$a_res->getMessage().
443  " ### ".$a_res->getUserInfo();
444 
445  $exception = new $this->exception($a_res->getUserInfo(), $error[0]);
446 
447  if($exception instanceof ilADTDBException)
448  {
449  // try to find offending column (primary is set AS "PRIMARY")
450  if($error[0] == MDB2_ERROR_CONSTRAINT && $error[1] == 1062)
451  {
452  $col = explode("'", $error[2]);
453  array_pop($col);
454  $col = array_pop($col);
455  $exception->setColumn($col);
456  }
457  }
458 
459  throw $exception;
460  }
461  */
462  }
463  /* :TODO: mysql(i) warnings (experimental, jluetzen)
464  else if(DEVMODE && $this instanceof ilDBMySQL)
465  {
466  $j = mysqli_warning_count($this->db->connection);
467  if($j > 0)
468  {
469  $e = mysqli_get_warnings($this->db->connection);
470  for($i = 0; $i < $j; $i++)
471  {
472  trigger_error("MYSQLi warning: "."(".$e->errno.") ".$e->message, E_USER_NOTICE);
473  $e->next();
474  }
475  }
476  }
477  */
478 
479  return $a_res;
480  }
raisePearError($a_message, $a_level="")
Raise an error.
Definition: class.ilDB.php:485
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 1866 of file class.ilDB.php.

1867  {
1868  if (count($a_values) == 0)
1869  {
1870  // BEGIN fixed mantis #0014191:
1871  //return " 1=2 "; // return a false statement on empty array
1872  return $negate ? ' 1=1 ' : ' 1=2 ';
1873  // END fixed mantis #0014191:
1874  }
1875  if ($a_type == "") // untyped: used ? for prepare/execute
1876  {
1877  $str = $a_field.(($negate) ? " NOT" : "")." IN (?".str_repeat(",?", count($a_values) - 1).")";
1878  }
1879  else // typed, use values for query/manipulate
1880  {
1881  $str = $a_field.(($negate) ? " NOT" : "")." IN (";
1882  $sep = "";
1883  foreach ($a_values as $v)
1884  {
1885  $str.= $sep.$this->quote($v, $a_type);
1886  $sep = ",";
1887  }
1888  $str.= ")";
1889  }
1890 
1891  return $str;
1892  }

◆ indexExistsByFields()

ilDB::indexExistsByFields (   $a_table,
  $a_fields 
)

Check if index exists.

Parameters
type$a_table
type$a_fields

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

1004  {
1005  $manager = $this->db->loadModule('Manager');
1006  $reverse = $this->db->loadModule('Reverse');
1007  if($manager)
1008  {
1009  foreach($manager->listTableIndexes($a_table) as $idx_name)
1010  {
1011  $def = $reverse->getTableIndexDefinition($a_table,$idx_name);
1012  $idx_fields = array_keys((array) $def['fields']);
1013 
1014  if($idx_fields === $a_fields)
1015  {
1016  return true;
1017  }
1018  }
1019  }
1020  return false;
1021  }

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

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

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

1613  {
1614  $fields = array();
1615  $field_values = array();
1616  $placeholders = array();
1617  $types = array();
1618  $values = array();
1619  $lobs = false;
1620  $lob = array();
1621  foreach ($a_columns as $k => $col)
1622  {
1623  $fields[] = $k;
1624  $placeholders[] = "%s";
1625  $placeholders2[] = ":$k";
1626  $types[] = $col[0];
1627 
1628  // integer auto-typecast (this casts bool values to integer)
1629  if ($col[0] == 'integer' && !is_null($col[1]))
1630  {
1631  $col[1] = (int) $col[1];
1632  }
1633 
1634  $values[] = $col[1];
1635  $field_values[$k] = $col[1];
1636  if ($col[0] == "blob" || $col[0] == "clob")
1637  {
1638  $lobs = true;
1639  $lob[$k] = $k;
1640  }
1641  }
1642  if ($lobs) // lobs -> use prepare execute (autoexecute broken in PEAR 2.4.1)
1643  {
1644  $st = $this->db->prepare("INSERT INTO ".$a_table." (".implode($fields,",").") VALUES (".
1645  implode($placeholders2,",").")", $types, MDB2_PREPARE_MANIP, $lob);
1646 
1647  $this->handleError($st, "insert / prepare/execute(".$a_table.")");
1648 
1649  $r = $st->execute($field_values);
1650 
1651 
1652  //$r = $this->db->extended->autoExecute($a_table, $field_values, MDB2_AUTOQUERY_INSERT, null, $types);
1653  $this->handleError($r, "insert / prepare/execute(".$a_table.")");
1654  $this->free($st);
1655  }
1656  else // if no lobs are used, take simple manipulateF
1657  {
1658  $q = "INSERT INTO ".$a_table." (".implode($fields,",").") VALUES (".
1659  implode($placeholders,",").")";
1660  $r = $this->manipulateF($q, $types, $values);
1661  }
1662  return $r;
1663  }
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 515 of file class.ilDB.php.

References MDB2\isError().

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

516  {
517  return MDB2::isError($a_res);
518  }
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 992 of file class.ilDB.php.

Referenced by dropIndex().

993  {
994  return false;
995  }
+ 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 1356 of file class.ilDB.php.

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

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

1357  {
1358  include_once("./Services/Database/classes/class.ilDBMySQL.php");
1359  $mysql_reserved_words = ilDBMySQL::getReservedWords();
1360  if (in_array(strtoupper($a_word), $mysql_reserved_words))
1361  {
1362  return true;
1363  }
1364  include_once("./Services/Database/classes/class.ilDBOracle.php");
1365  $oracle_reserved_words = ilDBOracle::getReservedWords();
1366  if (in_array(strtoupper($a_word), $oracle_reserved_words))
1367  {
1368  return true;
1369  }
1370  include_once("./Services/Database/classes/class.ilDBPostgreSQL.php");
1371  $postgres_reserved_words = ilDBPostgreSQL::getReservedWords();
1372  if (in_array(strtoupper($a_word), $postgres_reserved_words))
1373  {
1374  return true;
1375  }
1376  }
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 2032 of file class.ilDB.php.

References quote(), and raisePearError().

2033  {
2034  if (!in_array($a_type, array("text", "clob", "blob")))
2035  {
2036  $this->raisePearError("Like: Invalid column type '".$a_type."'.", $this->error_class->FATAL);
2037  }
2038  if ($a_value == "?")
2039  {
2040  if ($case_insensitive)
2041  {
2042  return "UPPER(".$a_col.") LIKE(UPPER(?))";
2043  }
2044  else
2045  {
2046  return $a_col ." LIKE(?)";
2047  }
2048  }
2049  else
2050  {
2051  if ($case_insensitive)
2052  {
2053  // Always quote as text
2054  return " UPPER(".$a_col.") LIKE(UPPER(".$this->quote($a_value, 'text')."))";
2055  }
2056  else
2057  {
2058  // Always quote as text
2059  return " ".$a_col." LIKE(".$this->quote($a_value, 'text').")";
2060  }
2061  }
2062  }
raisePearError($a_message, $a_level="")
Raise an error.
Definition: class.ilDB.php:485
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 2264 of file class.ilDB.php.

References $r, and MDB2\isError().

Referenced by sequenceExists().

2265  {
2266  $manager = $this->db->loadModule('Manager');
2267  $r = $manager->listSequences();
2268 
2269  if (!MDB2::isError($r))
2270  {
2271  return $r;
2272  }
2273 
2274  return false;
2275  }
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 2226 of file class.ilDB.php.

References $r, and MDB2\isError().

Referenced by dropTable(), and tableExists().

2227  {
2228  $manager = $this->db->loadModule('Manager');
2229  $r = $manager->listTables();
2230 
2231  if (!MDB2::isError($r))
2232  {
2233  return $r;
2234  }
2235 
2236  return false;
2237  }
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 500 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().

501  {
502  if (!$this->isDbError($this->db))
503  {
504  $this->db->loadModule('Extended');
505  define('DB_AUTOQUERY_SELECT',MDB2_AUTOQUERY_SELECT);
506  define('DB_AUTOQUERY_INSERT',MDB2_AUTOQUERY_INSERT);
507  define('DB_AUTOQUERY_UPDATE',MDB2_AUTOQUERY_UPDATE);
508  define('DB_AUTOQUERY_DELETE',MDB2_AUTOQUERY_DELETE);
509  }
510  }
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:515
+ 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 2014 of file class.ilDB.php.

2015  {
2016  $locate = ' LOCATE( ';
2017  $locate .= $a_needle;
2018  $locate .= ',';
2019  $locate .= $a_string;
2020  $locate .= ',';
2021  $locate .= $a_start_pos;
2022  $locate .= ') ';
2023  return $locate;
2024  }

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

References substr().

1467  {
1468  $pos1 = strpos(strtolower($sql), "from ");
1469  $table = "";
1470  if ($pos1 > 0)
1471  {
1472  $tablef = substr($sql, $pos1+5);
1473  $pos2 = strpos(strtolower($tablef), " ");
1474  if ($pos2 > 0)
1475  {
1476  $table =substr($tablef, 0, $pos2);
1477  }
1478  else
1479  {
1480  $table = $tablef;
1481  }
1482  }
1483  if (trim($table) != "")
1484  {
1485  if (!is_array($this->ttt) || !in_array($table, $this->ttt))
1486  {
1487  echo "<br>".$table;
1488  $this->ttt[] = $table;
1489  }
1490  }
1491  else
1492  {
1493  echo "<br><b>".$sql."</b>";
1494  }
1495  }
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 2002 of file class.ilDB.php.

2003  {
2004  return " LOWER(".$a_exp.") ";
2005  }

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

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

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

1529  {
1530  global $ilBench;
1531 
1532  if (is_object($ilBench))
1533  {
1534  $ilBench->startDbBench($sql);
1535  }
1536  $r = $this->db->exec($sql);
1537  if (is_object($ilBench))
1538  {
1539  $ilBench->stopDbBench();
1540  }
1541 
1542  return $this->handleError($r, "manipulate(".$sql.")");
1543  }
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 1446 of file class.ilDB.php.

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

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

1447  {
1448  if (!is_array($a_types) || !is_array($a_values) ||
1449  count($a_types) != count($a_values))
1450  {
1451  $this->raisePearError("ilDB::manipulateF: types and values must be arrays of same size. ($a_query)");
1452  }
1453  $quoted_values = array();
1454  foreach($a_types as $k => $t)
1455  {
1456  $quoted_values[] = $this->quote($a_values[$k], $t);
1457  }
1458  $query = vsprintf($a_query, $quoted_values);
1459 
1460  return $this->manipulate($query);
1461  }
raisePearError($a_message, $a_level="")
Raise an error.
Definition: class.ilDB.php:485
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 733 of file class.ilDB.php.

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

734  {
735  $manager = $this->db->loadModule('Manager');
736  $reverse = $this->db->loadModule('Reverse');
737  $def = $reverse->getTableFieldDefinition($a_table, $a_column);
738 
739  $this->handleError($def, "modifyTableColumn(".$a_table.")");
740 
741  if (is_file("./Services/Database/classes/class.ilDBAnalyzer.php"))
742  {
743  include_once("./Services/Database/classes/class.ilDBAnalyzer.php");
744  }
745  else
746  {
747  include_once("../Services/Database/classes/class.ilDBAnalyzer.php");
748  }
749  $analyzer = new ilDBAnalyzer();
750  $best_alt = $analyzer->getBestDefinitionAlternative($def);
751  $def = $def[$best_alt];
752  unset($def["nativetype"]);
753  unset($def["mdb2type"]);
754 
755  // check attributes
756  $type = ($a_attributes["type"] != "")
757  ? $a_attributes["type"]
758  : $def["type"];
759  foreach ($def as $k => $v)
760  {
761  if ($k != "type" && !in_array($k, $this->allowed_attributes[$type]))
762  {
763  unset($def[$k]);
764  }
765  }
766  $check_array = $def;
767  foreach ($a_attributes as $k => $v)
768  {
769  $check_array[$k] = $v;
770  }
771  if (!$this->checkColumnDefinition($check_array, true))
772  {
773  $this->raisePearError("ilDB Error: modifyTableColumn(".$a_table.", ".$a_column.")<br />".
774  $this->error_str);
775  }
776 
777  // oracle workaround: do not set null, if null already given
778  if ($this->getDbType() == "oracle")
779  {
780  if ($def["notnull"] == true && ($a_attributes["notnull"] == true
781  || !isset($a_attributes["notnull"])))
782  {
783  unset($def["notnull"]);
784  unset($a_attributes["notnull"]);
785  }
786  if ($def["notnull"] == false && ($a_attributes["notnull"] == false
787  || !isset($a_attributes["notnull"])))
788  {
789  unset($def["notnull"]);
790  unset($a_attributes["notnull"]);
791  }
792  }
793  foreach ($a_attributes as $a => $v)
794  {
795  $def[$a] = $v;
796  }
797 
798  $a_attributes["definition"] = $def;
799 
800  $changes = array(
801  "change" => array(
802  $a_column => $a_attributes
803  )
804  );
805 
806  $r = $manager->alterTable($a_table, $changes, false);
807 
808  return $this->handleError($r, "modifyTableColumn(".$a_table.")");
809  }
raisePearError($a_message, $a_level="")
Raise an error.
Definition: class.ilDB.php:485
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 1508 of file class.ilDB.php.

References $r, and handleError().

1509  {
1510  // we do not create missing sequences automatically here
1511  // otherwise misspelled statements result in additional tables
1512  // please create sequences explicitly in the db update script
1513  $r = $this->db->nextId($a_table_name, false);
1514 
1515  return $this->handleError($r, "nextId(".$a_table_name.")");
1516  }
handleError($a_res, $a_info="", $a_level="")
Handle MDB2 Errors.
Definition: class.ilDB.php:405
$r
+ Here is the call graph for this function:

◆ now()

ilDB::now ( )

now()

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

1919  {
1920  return "now()";
1921  }

◆ numRows()

ilDB::numRows (   $a_set)

Fetch row as associative array from result set.

Parameters
objectresult set

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

1847  {
1848  return $a_set->numRows();
1849  }

◆ optimizeTable()

ilDB::optimizeTable (   $a_table)

Optimize Table.

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

2123  {
2124  // needs to be overwritten in DBMS specific class
2125  // if necessary and possible
2126  }

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

References $res, and handleError().

1554  {
1555  $res = $this->db->prepare($a_query, $a_types, $a_result_types);
1556 
1557  return $this->handleError($res, "prepare(".$a_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:

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

References $res, handleError(), and MDB2_PREPARE_MANIP.

1569  {
1570  $res = $this->db->prepare($a_query, $a_types, MDB2_PREPARE_MANIP);
1571 
1572  return $this->handleError($res, "prepareManip(".$a_query.")");
1573  }
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 1393 of file class.ilDB.php.

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

Referenced by ilCourseArchives\__read(), ilRbacSystem\checkAccessOfUser(), createDatabase(), 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().

1394  {
1395  global $ilBench;
1396 
1397  if (is_object($ilBench))
1398  {
1399  $ilBench->startDbBench($sql);
1400  }
1401  $r = $this->db->query($sql);
1402  if (is_object($ilBench))
1403  {
1404  $ilBench->stopDbBench();
1405  }
1406 
1407  if ($a_handle_error)
1408  {
1409  return $this->handleError($r, "query(".$sql.")");
1410  }
1411 
1412  return $r;
1413  }
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 1422 of file class.ilDB.php.

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

Referenced by ilObjTestDynamicQuestionSetConfig\getPoolQuestionChangeListener().

1423  {
1424  if (!is_array($a_types) || !is_array($a_values) ||
1425  count($a_types) != count($a_values))
1426  {
1427  $this->raisePearError("ilDB::queryF: Types and values must be arrays of same size. ($a_query)");
1428  }
1429  $quoted_values = array();
1430  foreach($a_types as $k => $t)
1431  {
1432  $quoted_values[] = $this->quote($a_values[$k], $t);
1433  }
1434  $query = vsprintf($a_query, $quoted_values);
1435 
1436  return $this->query($query);
1437  }
raisePearError($a_message, $a_level="")
Raise an error.
Definition: class.ilDB.php:485
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 2285 of file class.ilDB.php.

References raisePearError().

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

2286  {
2287  if ($a_query == "" && is_null($a_type))
2288  {
2289  $a_query = "";
2290  }
2291 
2292  // Performance fix
2293  if($a_type == 'integer' && !is_null($a_query))
2294  {
2295  return (int) $a_query;
2296  }
2297 
2298  if ($a_type == "blob" || $a_type == "clob")
2299  {
2300  $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);
2301  }
2302 
2303  return $this->db->quote($a_query, $a_type);
2304  }
raisePearError($a_message, $a_level="")
Raise an error.
Definition: class.ilDB.php:485
+ 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 2313 of file class.ilDB.php.

2314  {
2315  return $this->db->quoteIdentifier($a_identifier);
2316  }

◆ raisePearError()

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

Raise an error.

Definition at line 485 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().

486  {
487  if ($a_level == "")
488  {
489  $a_level = $this->error_class->FATAL;
490  }
491 //echo "<br>-ilDB:raising-$a_message-$a_level-";
492  $this->raiseError($a_message, $a_level);
493  }
& 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 869 of file class.ilDB.php.

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

870  {
871  // check table name
872  if (!$this->checkTableName($a_new_name))
873  {
874  $this->raisePearError("ilDB Error: renameTable(".$a_name.",".$a_new_name.")<br />".
875  $this->error_str);
876  }
877 
878  $manager = $this->db->loadModule('Manager');
879  $r = $manager->alterTable($a_name, array("name" => $a_new_name), false);
880 
881  $query = "UPDATE abstraction_progress ".
882  "SET table_name = ".$this->db->quote($a_new_name,'text')." ".
883  "WHERE table_name = ".$this->db->quote($a_name,'text');
884  $this->db->query($query);
885 
886  return $this->handleError($r, "renameTable(".$a_name.",".$a_new_name.")");
887  }
raisePearError($a_message, $a_level="")
Raise an error.
Definition: class.ilDB.php:485
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 819 of file class.ilDB.php.

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

820  {
821  // check table name
822  if (!$this->checkColumnName($a_new_column))
823  {
824  $this->raisePearError("ilDB Error: renameTableColumn(".$a_table.",".$a_column.",".$a_new_column.")<br />".
825  $this->error_str);
826  }
827 
828  $manager = $this->db->loadModule('Manager');
829  $reverse = $this->db->loadModule('Reverse');
830  $def = $reverse->getTableFieldDefinition($a_table, $a_column);
831 
832  $this->handleError($def, "renameTableColumn(".$a_table.",".$a_column.",".$a_new_column.")");
833 
834  if (is_file("./Services/Database/classes/class.ilDBAnalyzer.php"))
835  {
836  include_once("./Services/Database/classes/class.ilDBAnalyzer.php");
837  }
838  else
839  {
840  include_once("../Services/Database/classes/class.ilDBAnalyzer.php");
841  }
842 
843  $analyzer = new ilDBAnalyzer();
844  $best_alt = $analyzer->getBestDefinitionAlternative($def);
845  $def = $def[$best_alt];
846  unset($def["nativetype"]);
847  unset($def["mdb2type"]);
848 
849  $f["definition"] = $def;
850  $f["name"] = $a_new_column;
851 
852  $changes = array(
853  "rename" => array(
854  $a_column => $f
855  )
856  );
857 
858  $r = $manager->alterTable($a_table, $changes, false);
859 
860  return $this->handleError($r, "renameTableColumn(".$a_table.",".$a_column.",".$a_new_column.")");
861  }
raisePearError($a_message, $a_level="")
Raise an error.
Definition: class.ilDB.php:485
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 1762 of file class.ilDB.php.

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

1763  {
1764  // this is the mysql implementation
1765  $a_columns = array_merge($a_pk_columns, $a_other_columns);
1766  $fields = array();
1767  $field_values = array();
1768  $placeholders = array();
1769  $types = array();
1770  $values = array();
1771  $lobs = false;
1772  $lob = array();
1773  foreach ($a_columns as $k => $col)
1774  {
1775  $fields[] = $k;
1776  $placeholders[] = "%s";
1777  $placeholders2[] = ":$k";
1778  $types[] = $col[0];
1779 
1780  // integer auto-typecast (this casts bool values to integer)
1781  if ($col[0] == 'integer' && !is_null($col[1]))
1782  {
1783  $col[1] = (int) $col[1];
1784  }
1785 
1786  $values[] = $col[1];
1787  $field_values[$k] = $col[1];
1788  if ($col[0] == "blob" || $col[0] == "clob")
1789  {
1790  $lobs = true;
1791  $lob[$k] = $k;
1792  }
1793  }
1794  if ($lobs) // lobs -> use prepare execute (autoexecute broken in PEAR 2.4.1)
1795  {
1796  $st = $this->db->prepare("REPLACE INTO ".$a_table." (".implode($fields,",").") VALUES (".
1797  implode($placeholders2,",").")", $types, MDB2_PREPARE_MANIP, $lob);
1798  $this->handleError($st, "insert / prepare/execute(".$a_table.")");
1799  $r = $st->execute($field_values);
1800  //$r = $this->db->extended->autoExecute($a_table, $field_values, MDB2_AUTOQUERY_INSERT, null, $types);
1801  $this->handleError($r, "insert / prepare/execute(".$a_table.")");
1802  $this->free($st);
1803  }
1804  else // if no lobs are used, take simple manipulateF
1805  {
1806  $q = "REPLACE INTO ".$a_table." (".implode($fields,",").") VALUES (".
1807  implode($placeholders,",").")";
1808  $r = $this->manipulateF($q, $types, $values);
1809  }
1810  return $r;
1811  }
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 2352 of file class.ilDB.php.

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

2353  {
2354  $res = $this->db->rollback();
2355 
2356  return $this->handleError($res, "rollback()");
2357  }
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 2245 of file class.ilDB.php.

References listSequences().

2246  {
2247  $sequences = $this->listSequences();
2248 
2249  if (is_array($sequences))
2250  {
2251  if (in_array($a_sequence, $sequences))
2252  {
2253  return true;
2254  }
2255  }
2256  return false;
2257  }
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 1500 of file class.ilDB.php.

1501  {
1502  $this->db->setLimit($a_limit, $a_offset);
1503  }

◆ setSubType()

ilDB::setSubType (   $a_value)

Set sub type.

Parameters
string$a_value

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

2463  {
2464  $this->sub_type = (string)$a_value;
2465  }

◆ substr()

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

Substring.

Parameters

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

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

1976  {
1977  $lenstr = "";
1978  if ($a_len > -1)
1979  {
1980  $lenstr = ", ".$a_len;
1981  }
1982  return " SUBSTR(".$a_exp.", ".$a_pos.$lenstr.") ";
1983  }
+ 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 2159 of file class.ilDB.php.

References $r, and MDB2\isError().

2160  {
2161 
2162  $column_visibility = false;
2163  $manager = $this->db->loadModule('Manager');
2164  $r = $manager->listTableFields($a_table);
2165 
2166  if (!MDB2::isError($r))
2167  {
2168  foreach($r as $field)
2169  {
2170  if ($field == $a_column_name)
2171  {
2172  $column_visibility = true;
2173  }
2174  }
2175  }
2176 
2177  return $column_visibility;
2178  }
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 2138 of file class.ilDB.php.

References listTables().

2139  {
2140  $tables = $this->listTables();
2141 
2142  if (is_array($tables))
2143  {
2144  if (in_array($a_table, $tables))
2145  {
2146  return true;
2147  }
2148  }
2149  return false;
2150  }
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 2187 of file class.ilDB.php.

2188  {
2189  if (is_file("./Services/Database/classes/class.ilDBAnalyzer.php"))
2190  {
2191  include_once("./Services/Database/classes/class.ilDBAnalyzer.php");
2192  }
2193  else
2194  {
2195  include_once("../Services/Database/classes/class.ilDBAnalyzer.php");
2196  }
2197  $analyzer = new ilDBAnalyzer();
2198  $cons = $analyzer->getConstraintsInformation($a_table);
2199  foreach ($cons as $c)
2200  {
2201  if ($c["type"] == "unique" && count($a_fields) == count($c["fields"]))
2202  {
2203  $all_in = true;
2204  foreach ($a_fields as $f)
2205  {
2206  if (!isset($c["fields"][$f]))
2207  {
2208  $all_in = false;
2209  }
2210  }
2211  if ($all_in)
2212  {
2213  return true;
2214  }
2215  }
2216  }
2217  return false;
2218  }
This class gives all kind of DB information using the MDB2 manager and reverse module.

◆ unixTimestamp()

ilDB::unixTimestamp ( )

Unix timestamp.

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

2115  {
2116  return "UNIX_TIMESTAMP()";
2117  }

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

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

1674  {
1675  $fields = array();
1676  $field_values = array();
1677  $placeholders = array();
1678  $types = array();
1679  $values = array();
1680  $lobs = false;
1681  $lob = array();
1682  foreach ($a_columns as $k => $col)
1683  {
1684  $fields[] = $k;
1685  $placeholders[] = "%s";
1686  $placeholders2[] = ":$k";
1687  $types[] = $col[0];
1688 
1689  // integer auto-typecast (this casts bool values to integer)
1690  if ($col[0] == 'integer' && !is_null($col[1]))
1691  {
1692  $col[1] = (int) $col[1];
1693  }
1694 
1695  $values[] = $col[1];
1696  $field_values[$k] = $col[1];
1697  if ($col[0] == "blob" || $col[0] == "clob")
1698  {
1699  $lobs = true;
1700  $lob[$k] = $k;
1701  }
1702  }
1703 
1704  if ($lobs)
1705  {
1706  $q = "UPDATE ".$a_table." SET ";
1707  $lim = "";
1708  foreach ($fields as $k => $field)
1709  {
1710  $q.= $lim.$field." = ".$placeholders2[$k];
1711  $lim = ", ";
1712  }
1713  $q.= " WHERE ";
1714  $lim = "";
1715  foreach ($a_where as $k => $col)
1716  {
1717  $q.= $lim.$k." = ".$this->quote($col[1], $col[0]);
1718  $lim = " AND ";
1719  }
1720  $st = $this->db->prepare($q, $types, MDB2_PREPARE_MANIP, $lob);
1721  $r = $st->execute($field_values);
1722 
1723  //$r = $this->db->extended->autoExecute($a_table, $field_values, MDB2_AUTOQUERY_INSERT, null, $types);
1724  $this->handleError($r, "update / prepare/execute(".$a_table.")");
1725  $this->free($st);
1726  }
1727  else
1728  {
1729  foreach ($a_where as $k => $col)
1730  {
1731  $types[] = $col[0];
1732  $values[] = $col[1];
1733  $field_values[$k] = $col;
1734  }
1735  $q = "UPDATE ".$a_table." SET ";
1736  $lim = "";
1737  foreach ($fields as $k => $field)
1738  {
1739  $q.= $lim.$field." = ".$placeholders[$k];
1740  $lim = ", ";
1741  }
1742  $q.= " WHERE ";
1743  $lim = "";
1744  foreach ($a_where as $k => $col)
1745  {
1746  $q.= $lim.$k." = %s";
1747  $lim = " AND ";
1748  }
1749 
1750  $r = $this->manipulateF($q, $types, $values);
1751  }
1752  return $r;
1753  }
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:

◆ upper()

ilDB::upper (   $a_exp)

Upper.

Parameters
stringexpression
Returns
string upper sql string

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

1992  {
1993  return " UPPER(".$a_exp.") ";
1994  }

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