ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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)
 
 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

Reimplemented from arConnector.

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

287 {
288 $ilDB = $this->returnDB();
289 $q = self::buildQuery($arl);
290
291 $set = $ilDB->query($q);
292
293 return $ilDB->numRows($set);
294 }
buildQuery(ActiveRecordList $arl)
global $ilDB

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

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

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) {
322 } else {
323 var_dump($q); // FSX
324 }
325 }
326 $arl->setLastQuery($q);
327
328 return $q;
329 }
global $tpl
Definition: ilias.php:8
static setLastQuery($last_query)
special template class to simplify handling of ITX/PEAR
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.

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

Referenced by affectedRows().

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

◆ checkConnection()

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

Reimplemented from arConnector.

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

29 {
30 return is_object($this->returnDB());
31 }

References returnDB().

+ Here is the call graph for this function:

◆ checkFieldExists()

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

Reimplemented from arConnector.

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

157 {
158 $ilDB = $this->returnDB();
159
160 return $ilDB->tableColumnExists($ar->getConnectorContainerName(), $field_name);
161 }

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

+ Here is the call graph for this function:

◆ checkTableExists()

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

@TODO: 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.

Reimplemented from arConnector.

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

140 {
141 $ilDB = $this->returnDB();
142
147 return $ilDB->tableExists($ar->getConnectorContainerName());
148 }

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

+ Here is the call graph for this function:

◆ create()

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

Reimplemented from arConnector.

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

210 {
211 $ilDB = $this->returnDB();
213 }

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

+ Here is the call graph for this function:

◆ delete()

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

Reimplemented from arConnector.

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

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)

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

+ Here is the call graph for this function:

◆ installDatabase()

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

Reimplemented from arConnector.

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

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)

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

+ Here is the call graph for this function:

◆ nextID()

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

Reimplemented from arConnector.

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

39 {
40 return $this->returnDB()->nextId($ar->getConnectorContainerName());
41 }

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

+ Here is the call graph for this function:

◆ quote()

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

Reimplemented from arConnector.

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

338 {
339 $ilDB = $this->returnDB();
340
341 return $ilDB->quote($value, $type);
342 }

References $ilDB, and returnDB().

+ Here is the call graph for this function:

◆ read()

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

Reimplemented from arConnector.

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

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 }
$records
Definition: simple_test.php:17

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

+ Here is the call graph for this function:

◆ readSet()

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

Reimplemented from arConnector.

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

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 }

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

+ Here is the call graph for this function:

◆ removeField()

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

Reimplemented from arConnector.

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

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 }

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

+ 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

Reimplemented from arConnector.

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

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 }

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

+ Here is the call graph for this function:

◆ resetDatabase()

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

Reimplemented from arConnector.

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

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 }

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

+ Here is the call graph for this function:

◆ returnDB()

arConnectorDB::returnDB ( )
protected
Returns
ilDB

Reimplemented in arConnectorPdoDB.

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

17 {
18 global $ilDB;
19
20 return $ilDB;
21 }

References $ilDB.

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

+ Here is the caller graph for this function:

◆ truncateDatabase()

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

Reimplemented from arConnector.

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

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 }

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

+ Here is the call graph for this function:

◆ update()

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

Reimplemented from arConnector.

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

240 {
241 $ilDB = $this->returnDB();
242
243 $ilDB->update($ar->getConnectorContainerName(), $ar->getArrayForConnector(), array(
247 ),
248 ));
249 }

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

+ Here is the call graph for this function:

◆ updateDatabase()

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

Reimplemented from arConnector.

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

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 }

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

+ Here is the call graph for this function:

◆ updateIndices()

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

Reimplemented from arConnector.

Reimplemented in arConnectorPdoDB.

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

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 }

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

Referenced by installDatabase(), and updateDatabase().

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