ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
arConnectorDB Class Reference

Class arConnectorDB. More...

+ Inheritance diagram for arConnectorDB:
+ Collaboration diagram for arConnectorDB:

Public Member Functions

 checkConnection (ActiveRecord $ar)
 
 nextID (ActiveRecord $ar)
 
 installDatabase (ActiveRecord $ar, $fields)
 
 updateIndices (ActiveRecord $ar)
 
 updateDatabase (ActiveRecord $ar)
 
 resetDatabase (ActiveRecord $ar)
 
 truncateDatabase (ActiveRecord $ar)
 
 checkTableExists (ActiveRecord $ar)
 
 checkFieldExists (ActiveRecord $ar, $field_name)
 
 removeField (ActiveRecord $ar, $field_name)
 
 renameField (ActiveRecord $ar, $old_name, $new_name)
 
 create (ActiveRecord $ar)
 
 read (ActiveRecord $ar)
 
 update (ActiveRecord $ar)
 
 delete (ActiveRecord $ar)
 
 readSet (ActiveRecordList $arl)
 
 affectedRows (ActiveRecordList $arl)
 
 quote ($value, $type)
 
- Public Member Functions inherited from arConnector
 nextID (ActiveRecord $ar)
 
 checkConnection (ActiveRecord $ar)
 
 installDatabase (ActiveRecord $ar, $fields)
 
 updateDatabase (ActiveRecord $ar)
 
 resetDatabase (ActiveRecord $ar)
 
 truncateDatabase (ActiveRecord $ar)
 
 checkTableExists (ActiveRecord $ar)
 
 checkFieldExists (ActiveRecord $ar, $field_name)
 
 removeField (ActiveRecord $ar, $field_name)
 
 renameField (ActiveRecord $ar, $old_name, $new_name)
 
 create (ActiveRecord $ar)
 
 read (ActiveRecord $ar)
 
 update (ActiveRecord $ar)
 
 delete (ActiveRecord $ar)
 
 readSet (ActiveRecordList $arl)
 
 affectedRows (ActiveRecordList $arl)
 
 quote ($value, $type)
 
 updateIndices (ActiveRecord $ar)
 

Protected Member Functions

 returnDB ()
 
 buildQuery (ActiveRecordList $arl)
 

Detailed Description

Member Function Documentation

◆ affectedRows()

arConnectorDB::affectedRows ( ActiveRecordList  $arl)
Parameters
ActiveRecordList$arl
Returns
int

Definition at line 287 of file class.arConnectorDB.php.

References $ilDB, and returnDB().

287  {
288  $ilDB = $this->returnDB();
289  $q = self::buildQuery($arl);
290 
291  $set = $ilDB->query($q);
292 
293  return $ilDB->numRows($set);
294  }
global $ilDB
+ Here is the call graph for this function:

◆ buildQuery()

arConnectorDB::buildQuery ( ActiveRecordList  $arl)
protected
Parameters
ActiveRecordList$arl
Returns
mixed|string

Definition at line 302 of file class.arConnectorDB.php.

References $tpl, ActiveRecordList\getArConcatCollection(), ActiveRecordList\getArJoinCollection(), ActiveRecordList\getArLimitCollection(), ActiveRecordList\getArOrderCollection(), ActiveRecordList\getArSelectCollection(), ActiveRecordList\getArWhereCollection(), ActiveRecordList\getDebug(), ilUtil\sendInfo(), and ActiveRecordList\setLastQuery().

302  {
303  // SELECTS
304  $q = $arl->getArSelectCollection()->asSQLStatement();
305  // Concats
306  $q .= $arl->getArConcatCollection()->asSQLStatement();
307  $q .= ' FROM '.$arl->getAR()->getConnectorContainerName();
308  // JOINS
309  $q .= $arl->getArJoinCollection()->asSQLStatement();
310  // WHERE
311  $q .= $arl->getArWhereCollection()->asSQLStatement();
312  // ORDER
313  $q .= $arl->getArOrderCollection()->asSQLStatement();
314  // LIMIT
315  $q .= $arl->getArLimitCollection()->asSQLStatement();
316 
317  //TODO: using template in the model.
318  if ($arl->getDebug()) {
319  global $tpl;
320  if ($tpl instanceof ilTemplate) {
321  ilUtil::sendInfo($q);
322  } else {
323  var_dump($q); // FSX
324  }
325  }
326  $arl->setLastQuery($q);
327 
328  return $q;
329  }
static setLastQuery($last_query)
global $tpl
Definition: ilias.php:8
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
special template class to simplify handling of ITX/PEAR
+ Here is the call graph for this function:

◆ checkConnection()

arConnectorDB::checkConnection ( ActiveRecord  $ar)
Parameters
ActiveRecord$ar
Returns
bool

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

References returnDB().

29  {
30  return is_object($this->returnDB());
31  }
+ Here is the call graph for this function:

◆ checkFieldExists()

arConnectorDB::checkFieldExists ( ActiveRecord  $ar,
  $field_name 
)
Parameters
ActiveRecord$ar
$field_name
Returns
mixed

Definition at line 157 of file class.arConnectorDB.php.

References $ilDB, ActiveRecord\getConnectorContainerName(), and returnDB().

157  {
158  $ilDB = $this->returnDB();
159 
160  return $ilDB->tableColumnExists($ar->getConnectorContainerName(), $field_name);
161  }
global $ilDB
+ Here is the call graph for this function:

◆ checkTableExists()

arConnectorDB::checkTableExists ( ActiveRecord  $ar)
Parameters
ActiveRecord$ar
Returns
mixed

: This is the proper ILIAS approach on how to do this BUT: This is exteremely slow (listTables is used)! However, this is not the place to fix this issue. Report.

Definition at line 140 of file class.arConnectorDB.php.

References $ilDB, ActiveRecord\getConnectorContainerName(), and returnDB().

140  {
141  $ilDB = $this->returnDB();
142 
147  return $ilDB->tableExists($ar->getConnectorContainerName());
148  }
global $ilDB
+ Here is the call graph for this function:

◆ create()

arConnectorDB::create ( ActiveRecord  $ar)
Parameters
ActiveRecord$ar

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

References $ilDB, ActiveRecord\getArrayForConnector(), ActiveRecord\getConnectorContainerName(), and returnDB().

210  {
211  $ilDB = $this->returnDB();
212  $ilDB->insert($ar->getConnectorContainerName(), $ar->getArrayForConnector());
213  }
global $ilDB
+ Here is the call graph for this function:

◆ delete()

arConnectorDB::delete ( ActiveRecord  $ar)
Parameters
ActiveRecord$ar

Definition at line 255 of file class.arConnectorDB.php.

References $ilDB, arFieldCache\getPrimaryFieldName(), arFieldCache\getPrimaryFieldType(), and returnDB().

255  {
256  $ilDB = $this->returnDB();
257 
258  $ilDB->manipulate('DELETE FROM ' . $ar->getConnectorContainerName() . ' WHERE ' . arFieldCache::getPrimaryFieldName($ar) . ' = '
260  }
static getPrimaryFieldName(ActiveRecord $ar)
static getPrimaryFieldType(ActiveRecord $ar)
global $ilDB
+ Here is the call graph for this function:

◆ installDatabase()

arConnectorDB::installDatabase ( ActiveRecord  $ar,
  $fields 
)
Parameters
ActiveRecord$ar
$fields
Returns
bool

Definition at line 50 of file class.arConnectorDB.php.

References $ilDB, ActiveRecord\getArFieldList(), ActiveRecord\getConnectorContainerName(), returnDB(), and updateIndices().

50  {
51  $ilDB = $this->returnDB();
52  $ilDB->createTable($ar->getConnectorContainerName(), $fields);
53  $arFieldList = $ar->getArFieldList();
54  if ($arFieldList->getPrimaryField()->getName()) {
55  $ilDB->addPrimaryKey($ar->getConnectorContainerName(), array( $arFieldList->getPrimaryField()->getName() ));
56  }
57  if ($ar->getArFieldList()->getPrimaryField()->getSequence() AND ! $ilDB->sequenceExists($ar->getConnectorContainerName())) {
58  $ilDB->createSequence($ar->getConnectorContainerName());
59  }
60  $this->updateIndices($ar);
61 
62  return true;
63  }
updateIndices(ActiveRecord $ar)
global $ilDB
+ Here is the call graph for this function:

◆ nextID()

arConnectorDB::nextID ( ActiveRecord  $ar)
Parameters
ActiveRecord$ar
Returns
mixed

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

References ActiveRecord\getConnectorContainerName(), and returnDB().

39  {
40  return $this->returnDB()->nextId($ar->getConnectorContainerName());
41  }
+ Here is the call graph for this function:

◆ quote()

arConnectorDB::quote (   $value,
  $type 
)
Parameters
$value
$type
Returns
string

Definition at line 338 of file class.arConnectorDB.php.

References $ilDB, and returnDB().

338  {
339  $ilDB = $this->returnDB();
340 
341  return $ilDB->quote($value, $type);
342  }
global $ilDB
+ Here is the call graph for this function:

◆ read()

arConnectorDB::read ( ActiveRecord  $ar)
Parameters
ActiveRecord$ar
Returns
array

Definition at line 221 of file class.arConnectorDB.php.

References $ilDB, $query, $records, ActiveRecord\getConnectorContainerName(), arFieldCache\getPrimaryFieldName(), arFieldCache\getPrimaryFieldType(), ActiveRecord\getPrimaryFieldValue(), and returnDB().

221  {
222  $ilDB = $this->returnDB();
223 
224  $query = 'SELECT * FROM ' . $ar->getConnectorContainerName() . ' ' . ' WHERE ' . arFieldCache::getPrimaryFieldName($ar) . ' = '
226 
227  $set = $ilDB->query($query);
228  $records = array();
229  while ($rec = $ilDB->fetchObject($set)) {
230  $records[] = $rec;
231  }
232 
233  return $records;
234  }
static getPrimaryFieldName(ActiveRecord $ar)
static getPrimaryFieldType(ActiveRecord $ar)
$records
Definition: simple_test.php:17
global $ilDB
+ Here is the call graph for this function:

◆ readSet()

arConnectorDB::readSet ( ActiveRecordList  $arl)
Parameters
ActiveRecordList$arl

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

References $ilDB, $records, and returnDB().

270  {
271  $ilDB = $this->returnDB();
272  $set = $ilDB->query(self::buildQuery($arl));
273  $records = array();
274  while ($rec = $ilDB->fetchAssoc($set)) {
275  $records[] = $rec;
276  }
277 
278  return $records;
279  }
$records
Definition: simple_test.php:17
global $ilDB
+ Here is the call graph for this function:

◆ removeField()

arConnectorDB::removeField ( ActiveRecord  $ar,
  $field_name 
)
Parameters
ActiveRecord$ar
$field_name
Returns
bool
Exceptions
arException

Definition at line 171 of file class.arConnectorDB.php.

References $ilDB, ActiveRecord\getConnectorContainerName(), and returnDB().

171  {
172  $ilDB = $this->returnDB();
173  if ($ilDB->tableColumnExists($ar->getConnectorContainerName(), $field_name)) {
174  //throw new arException($field_name, arException::COLUMN_DOES_NOT_EXIST);
175  }
176  if ($ilDB->tableColumnExists($ar->getConnectorContainerName(), $field_name)) {
177  $ilDB->dropTableColumn($ar->getConnectorContainerName(), $field_name);
178 
179  return true;
180  }
181  }
global $ilDB
+ Here is the call graph for this function:

◆ renameField()

arConnectorDB::renameField ( ActiveRecord  $ar,
  $old_name,
  $new_name 
)
Parameters
ActiveRecord$ar
$old_name
$new_name
Returns
bool
Exceptions
arException

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

References $ilDB, ActiveRecord\getConnectorContainerName(), and returnDB().

192  {
193  $ilDB = $this->returnDB();
194  if ($ilDB->tableColumnExists($ar->getConnectorContainerName(), $old_name)) {
195  //throw new arException($old_name, arException::COLUMN_DOES_NOT_EXIST);
196 
197  if (!$ilDB->tableColumnExists($ar->getConnectorContainerName(), $new_name)) {
198  //throw new arException($new_name, arException::COLUMN_DOES_ALREADY_EXIST);
199  $ilDB->renameTableColumn($ar->getConnectorContainerName(), $old_name, $new_name);
200  }
201  }
202 
203  return true;
204  }
global $ilDB
+ Here is the call graph for this function:

◆ resetDatabase()

arConnectorDB::resetDatabase ( ActiveRecord  $ar)
Parameters
ActiveRecord$ar
Returns
bool

Definition at line 110 of file class.arConnectorDB.php.

References $ilDB, ActiveRecord\getConnectorContainerName(), ActiveRecord\installDB(), and returnDB().

110  {
111  $ilDB = $this->returnDB();
112  if ($ilDB->tableExists($ar->getConnectorContainerName())) {
113  $ilDB->dropTable($ar->getConnectorContainerName());
114  }
115  $ar->installDB();
116 
117  return true;
118  }
global $ilDB
+ Here is the call graph for this function:

◆ returnDB()

arConnectorDB::returnDB ( )
protected
Returns
ilDB

Definition at line 17 of file class.arConnectorDB.php.

References $ilDB.

Referenced by affectedRows(), checkConnection(), checkFieldExists(), checkTableExists(), create(), delete(), installDatabase(), nextID(), quote(), read(), readSet(), removeField(), renameField(), resetDatabase(), truncateDatabase(), update(), updateDatabase(), and updateIndices().

17  {
18  global $ilDB;
19 
20  return $ilDB;
21  }
global $ilDB
+ Here is the caller graph for this function:

◆ truncateDatabase()

arConnectorDB::truncateDatabase ( ActiveRecord  $ar)
Parameters
ActiveRecord$ar

Definition at line 124 of file class.arConnectorDB.php.

References $ilDB, $query, ActiveRecord\getConnectorContainerName(), and returnDB().

124  {
125  $ilDB = $this->returnDB();
126  $query = 'TRUNCATE TABLE ' . $ar->getConnectorContainerName();
127  $ilDB->query($query);
128  if ($ilDB->tableExists($ar->getConnectorContainerName() . '_seq')) {
129  $ilDB->dropSequence($ar->getConnectorContainerName());
130  $ilDB->createSequence($ar->getConnectorContainerName());
131  }
132  }
global $ilDB
+ Here is the call graph for this function:

◆ update()

arConnectorDB::update ( ActiveRecord  $ar)
Parameters
ActiveRecord$ar

Definition at line 240 of file class.arConnectorDB.php.

References $ilDB, ActiveRecord\getArrayForConnector(), ActiveRecord\getConnectorContainerName(), arFieldCache\getPrimaryFieldName(), arFieldCache\getPrimaryFieldType(), ActiveRecord\getPrimaryFieldValue(), and returnDB().

240  {
241  $ilDB = $this->returnDB();
242 
243  $ilDB->update($ar->getConnectorContainerName(), $ar->getArrayForConnector(), array(
244  arFieldCache::getPrimaryFieldName($ar) => array(
246  $ar->getPrimaryFieldValue()
247  ),
248  ));
249  }
static getPrimaryFieldName(ActiveRecord $ar)
static getPrimaryFieldType(ActiveRecord $ar)
global $ilDB
+ Here is the call graph for this function:

◆ updateDatabase()

arConnectorDB::updateDatabase ( ActiveRecord  $ar)
Parameters
ActiveRecord$ar
Returns
bool

Definition at line 92 of file class.arConnectorDB.php.

References $ilDB, ActiveRecord\getArFieldList(), ActiveRecord\getConnectorContainerName(), returnDB(), and updateIndices().

92  {
93  $ilDB = $this->returnDB();
94  foreach ($ar->getArFieldList()->getFields() as $field) {
95  if (!$ilDB->tableColumnExists($ar->getConnectorContainerName(), $field->getName())) {
96  $ilDB->addTableColumn($ar->getConnectorContainerName(), $field->getName(), $field->getAttributesForConnector());
97  }
98  }
99  $this->updateIndices($ar);
100 
101  return true;
102  }
updateIndices(ActiveRecord $ar)
global $ilDB
+ Here is the call graph for this function:

◆ updateIndices()

arConnectorDB::updateIndices ( ActiveRecord  $ar)
Parameters
ActiveRecord$ar

Definition at line 69 of file class.arConnectorDB.php.

References $ilDB, $res, ActiveRecord\getArFieldList(), ActiveRecord\getConnectorContainerName(), and returnDB().

Referenced by installDatabase(), and updateDatabase().

69  {
70  $ilDB = $this->returnDB();
71  $arFieldList = $ar->getArFieldList();
72  $res = $ilDB->query('SHOW INDEX FROM ' . $ar->getConnectorContainerName());
73  $existing_indices = array();
74  while ($rec = $ilDB->fetchObject($res)) {
75  $existing_indices[] = $rec->column_name;
76  }
77  foreach ($arFieldList->getFields() as $i => $arField) {
78  if ($arField->getIndex() === true) {
79  if (!in_array($arField->getName(), $existing_indices)) {
80  $ilDB->addIndex($ar->getConnectorContainerName(), array( $arField->getName() ), 'i' . $i);
81  }
82  }
83  }
84  }
global $ilDB
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

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