ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
ilMySQLQueryUtils Class Reference

Class ilMySQLQueryUtils. More...

+ Inheritance diagram for ilMySQLQueryUtils:
+ Collaboration diagram for ilMySQLQueryUtils:

Public Member Functions

 in ($field, $values, $negate=false, $type="")
 
 quote ($value, $type=null)
 
 concat (array $values, $allow_null=true)
 
 locate ($a_needle, $a_string, $a_start_pos=1)
 
 free (ilPDOStatement $statement)
 
 quoteIdentifier ($identifier)
 
 createTable ($name, $fields, $options=array())
 
 like ($column, $type, $value="?", $case_insensitive=true)
 
 now ()
 
 lock (array $tables)
 
 unlock ()
 
 createDatabase ($a_name, $a_charset="utf8", $a_collation="")
 
 groupConcat ($a_field_name, $a_seperator=",", $a_order=null)
 
 cast ($a_field_name, $a_dest_type)
 
Parameters
string$a_field_name
mixed$a_dest_type
Returns
string
More...
 
- Public Member Functions inherited from ilQueryUtils
 __construct (ilDBInterface $ilDBInterface)
 ilMySQLQueryUtils constructor. More...
 
 in ($field, $values, $negate=false, $type="")
 
 quote ($value, $type=null)
 
 concat (array $values, $allow_null=true)
 
 locate ($a_needle, $a_string, $a_start_pos=1)
 
 free (ilPDOStatement $statement)
 
 quoteIdentifier ($identifier)
 
 createTable ($name, $fields, $options=array())
 
 like ($column, $type, $value="?", $case_insensitive=true)
 
 now ()
 
 lock (array $tables)
 
 unlock ()
 
 createDatabase ($a_name, $a_charset="utf8", $a_collation="")
 
 groupConcat ($a_field_name, $a_seperator=",", $a_order=null)
 
Parameters
string$a_field_name
string$a_seperator
string$a_order
Returns
string
More...
 
 cast ($a_field_name, $a_dest_type)
 
Parameters
string$a_field_name
mixed$a_dest_type
Returns
string
More...
 
 in ($field, $values, $negate=false, $type="")
 
 quote ($value, $type=null)
 
 concat (array $values, $allow_null=true)
 
 locate ($a_needle, $a_string, $a_start_pos=1)
 
 free (ilPDOStatement $statement)
 
 quoteIdentifier ($identifier)
 
 createTable ($name, $fields, $options=array())
 
 like ($column, $type, $value="?", $case_insensitive=true)
 
 now ()
 
 lock (array $tables)
 
 unlock ()
 
 createDatabase ($a_name, $a_charset="utf8", $a_collation="")
 
 groupConcat ($a_field_name, $a_seperator=",", $a_order=null)
 
 cast ($a_field_name, $a_dest_type)
 

Additional Inherited Members

- Protected Attributes inherited from ilQueryUtils
 $db_instance
 

Detailed Description

Member Function Documentation

◆ cast()

ilMySQLQueryUtils::cast (   $a_field_name,
  $a_dest_type 
)

Parameters
string$a_field_name
mixed$a_dest_type
Returns
string

Reimplemented from ilQueryUtils.

Definition at line 325 of file class.ilMySQLQueryUtils.php.

326 {
327 return $a_field_name;
328 }

◆ concat()

ilMySQLQueryUtils::concat ( array  $values,
  $allow_null = true 
)
Parameters
array$values
bool$allow_null
Returns
string

Reimplemented from ilQueryUtils.

Definition at line 59 of file class.ilMySQLQueryUtils.php.

60 {
61 if (!count($values)) {
62 return ' ';
63 }
64
65 $concat = ' CONCAT(';
66 $first = true;
67 foreach ($values as $field_info) {
68 $val = $field_info[0];
69
70 if (!$first) {
71 $concat .= ',';
72 }
73
74 if ($allow_null) {
75 $concat .= 'COALESCE(';
76 }
77 $concat .= $val;
78
79 if ($allow_null) {
80 $concat .= ",''";
81 $concat .= ')';
82 }
83
84 $first = false;
85 }
86 $concat .= ') ';
87
88 return $concat;
89 }

◆ createDatabase()

ilMySQLQueryUtils::createDatabase (   $a_name,
  $a_charset = "utf8",
  $a_collation = "" 
)
Parameters
$a_name
string$a_charset
string$a_collation
Returns
mixed

Reimplemented from ilQueryUtils.

Definition at line 292 of file class.ilMySQLQueryUtils.php.

293 {
294 if ($a_collation != "") {
295 $sql = "CREATE DATABASE `" . $a_name . "` CHARACTER SET " . $a_charset . " COLLATE " . $a_collation;
296 } else {
297 $sql = "CREATE DATABASE `" . $a_name . "` CHARACTER SET " . $a_charset;
298 }
299
300 return $sql;
301 }

◆ createTable()

ilMySQLQueryUtils::createTable (   $name,
  $fields,
  $options = array() 
)
Parameters
$name
$fields
array$options
Returns
string
Exceptions

ilDatabaseException

Reimplemented from ilQueryUtils.

Definition at line 141 of file class.ilMySQLQueryUtils.php.

142 {
143 if (!$name) {
144 throw new ilDatabaseException('no valid table name specified');
145 }
146 if (empty($fields)) {
147 throw new ilDatabaseException('no fields specified for table "' . $name . '"');
148 }
149 $query_fields_array = array();
150 foreach ($fields as $field_name => $field) {
151 $query_fields_array[] = $this->db_instance->getFieldDefinition()->getDeclaration($field['type'], $field_name, $field);
152 }
153
154 $query_fields = implode(', ', $query_fields_array);
155
156 if (!empty($options['primary'])) {
157 $query_fields .= ', PRIMARY KEY (' . implode(', ', array_keys($options['primary'])) . ')';
158 }
159
160 $query = "CREATE TABLE $name ($query_fields)";
161
162 $options_strings = array();
163
164 if (!empty($options['comment'])) {
165 $options_strings['comment'] = 'COMMENT = ' . $this->quote($options['comment'], 'text');
166 }
167
168 if (!empty($options['charset'])) {
169 $options_strings['charset'] = 'DEFAULT CHARACTER SET ' . $options['charset'];
170 if (!empty($options['collate'])) {
171 $options_strings['charset'] .= ' COLLATE ' . $options['collate'];
172 }
173 }
174
175 $type = false;
176 if (!empty($options['type'])) {
177 $type = $options['type'];
178 }
179 if ($type) {
180 $options_strings[] = "ENGINE = $type";
181 }
182
183 if (!empty($options_strings)) {
184 $query .= ' ' . implode(' ', $options_strings);
185 }
186
187 return $query;
188 }
if(!isset( $_REQUEST[ 'ReturnTo'])) if(!isset($_REQUEST['AuthId'])) $options
Definition: as_login.php:20
Class ilDatabaseException.
quote($value, $type=null)
if($format !==null) $name
Definition: metadata.php:146
$query
$type

References $name, $options, $query, $type, and quote().

+ Here is the call graph for this function:

◆ free()

ilMySQLQueryUtils::free ( ilPDOStatement  $statement)
Parameters
\ilPDOStatement$statement
Returns
bool

Reimplemented from ilQueryUtils.

Definition at line 116 of file class.ilMySQLQueryUtils.php.

117 {
118 $statement->closeCursor();
119
120 return true;
121 }
closeCursor()
Pdo allows for a manual closing of the cursor.

References ilPDOStatement\closeCursor().

+ Here is the call graph for this function:

◆ groupConcat()

ilMySQLQueryUtils::groupConcat (   $a_field_name,
  $a_seperator = ",",
  $a_order = null 
)
Parameters
string$a_field_name
string$a_seperator
string$a_order
Returns
string

Reimplemented from ilQueryUtils.

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

312 {
313 if ($a_order === null) {
314 $sql = "GROUP_CONCAT(" . $a_field_name . " SEPARATOR " . $this->quote($a_seperator, "text") . ")";
315 } else {
316 $sql = "GROUP_CONCAT(" . $a_field_name . " ORDER BY " . $a_order . " SEPARATOR " . $this->quote($a_seperator, "text") . ")";
317 }
318 return $sql;
319 }

References quote().

+ Here is the call graph for this function:

◆ in()

ilMySQLQueryUtils::in (   $field,
  $values,
  $negate = false,
  $type = "" 
)
Parameters
string$field
string[]$values
bool$negate
string$type
Returns
string

Reimplemented from ilQueryUtils.

Definition at line 19 of file class.ilMySQLQueryUtils.php.

20 {
21 if (count($values) == 0) {
22 // BEGIN fixed mantis #0014191:
23 //return " 1=2 "; // return a false statement on empty array
24 return $negate ? ' 1=1 ' : ' 1=2 ';
25 // END fixed mantis #0014191:
26 }
27 if ($type == "") { // untyped: used ? for prepare/execute
28 $str = $field . (($negate) ? " NOT" : "") . " IN (?" . str_repeat(",?", count($values) - 1) . ")";
29 } else { // typed, use values for query/manipulate
30 $str = $field . (($negate) ? " NOT" : "") . " IN (";
31 $sep = "";
32 foreach ($values as $v) {
33 $str .= $sep . $this->quote($v, $type);
34 $sep = ",";
35 }
36 $str .= ")";
37 }
38
39 return $str;
40 }

References $type, and quote().

+ Here is the call graph for this function:

◆ like()

ilMySQLQueryUtils::like (   $column,
  $type,
  $value = "?",
  $case_insensitive = true 
)
Parameters
$column
$type
string$value
bool$case_insensitive
Returns
string
Exceptions

ilDatabaseException

Reimplemented from ilQueryUtils.

Definition at line 199 of file class.ilMySQLQueryUtils.php.

200 {
201 if (!in_array($type, array(
204 "blob",
205 ))
206 ) {
207 throw new ilDatabaseException("Like: Invalid column type '" . $type . "'.");
208 }
209 if ($value == "?") {
210 if ($case_insensitive) {
211 return "UPPER(" . $column . ") LIKE(UPPER(?))";
212 } else {
213 return $column . " LIKE(?)";
214 }
215 } else {
216 if ($case_insensitive) {
217 // Always quote as text
218 return " UPPER(" . $column . ") LIKE(UPPER(" . $this->quote($value, 'text') . "))";
219 } else {
220 // Always quote as text
221 return " " . $column . " LIKE(" . $this->quote($value, 'text') . ")";
222 }
223 }
224 }
$column
Definition: 39dropdown.php:62

References $column, $type, quote(), ilDBConstants\T_CLOB, and ilDBConstants\T_TEXT.

+ Here is the call graph for this function:

◆ locate()

ilMySQLQueryUtils::locate (   $a_needle,
  $a_string,
  $a_start_pos = 1 
)
Parameters
$a_needle
$a_string
int$a_start_pos
Returns
string

Reimplemented from ilQueryUtils.

Definition at line 98 of file class.ilMySQLQueryUtils.php.

99 {
100 $locate = ' LOCATE( ';
101 $locate .= $a_needle;
102 $locate .= ',';
103 $locate .= $a_string;
104 $locate .= ',';
105 $locate .= $a_start_pos;
106 $locate .= ') ';
107
108 return $locate;
109 }

◆ lock()

ilMySQLQueryUtils::lock ( array  $tables)
Parameters
array$tables
Returns
string

Reimplemented from ilQueryUtils.

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

241 {
242 $lock = 'LOCK TABLES ';
243
244 $counter = 0;
245 foreach ($tables as $table) {
246 if ($counter++) {
247 $lock .= ', ';
248 }
249
250 if (isset($table['sequence']) && $table['sequence']) {
251 $table_name = $this->db_instance->getSequenceName($table['name']);
252 } else {
253 $table_name = $table['name'];
254 }
255
256 $lock .= ($table_name . ' ');
257
258 if ($table['alias']) {
259 $lock .= ($table['alias'] . ' ');
260 }
261
262 switch ($table['type']) {
264 $lock .= ' READ ';
265 break;
266
268 $lock .= ' WRITE ';
269 break;
270 }
271 }
272
273 return $lock;
274 }
$counter
if(empty($password)) $table
Definition: pwgen.php:24

References $counter, $table, ilDBConstants\LOCK_READ, and ilDBConstants\LOCK_WRITE.

◆ now()

ilMySQLQueryUtils::now ( )
Returns
string

Reimplemented from ilQueryUtils.

Definition at line 230 of file class.ilMySQLQueryUtils.php.

231 {
232 return "NOW()";
233 }

◆ quote()

ilMySQLQueryUtils::quote (   $value,
  $type = null 
)
Parameters
mixed$value
null$type
Returns
string

Reimplemented from ilQueryUtils.

Definition at line 48 of file class.ilMySQLQueryUtils.php.

49 {
50 return $this->db_instance->quote($value, $type);
51 }

References $type.

Referenced by createTable(), groupConcat(), in(), and like().

+ Here is the caller graph for this function:

◆ quoteIdentifier()

ilMySQLQueryUtils::quoteIdentifier (   $identifier)
Parameters
$identifier
Returns
string

Reimplemented from ilQueryUtils.

Definition at line 128 of file class.ilMySQLQueryUtils.php.

129 {
130 return $this->db_instance->quoteIdentifier($identifier);
131 }

◆ unlock()

ilMySQLQueryUtils::unlock ( )
Returns
string

Reimplemented from ilQueryUtils.

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

281 {
282 return 'UNLOCK TABLES';
283 }

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