ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ilPostgresQueryUtils Class Reference

Class ilPostgresQueryUtils. More...

+ Inheritance diagram for ilPostgresQueryUtils:
+ Collaboration diagram for ilPostgresQueryUtils:

Public Member Functions

 createTable ($name, $fields, $options=array())
 
 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)
 
 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...
 

Additional Inherited Members

- Protected Attributes inherited from ilQueryUtils
 $db_instance
 

Detailed Description

Member Function Documentation

◆ cast()

ilPostgresQueryUtils::cast (   $a_field_name,
  $a_dest_type 
)

Parameters
string$a_field_name
mixed$a_dest_type
Returns
string

Implements ilQueryUtilsInterface.

Definition at line 326 of file class.ilPostgresQueryUtils.php.

327  {
328  return "CAST({$a_field_name} AS " . $this->db_instance->getFieldDefinition()->getTypeDeclaration(array("type" => $a_dest_type)) . ")";
329  }

◆ concat()

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

Implements ilQueryUtilsInterface.

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

117  {
118  if (!count($values)) {
119  return ' ';
120  }
121 
122  $concat = ' CONCAT(';
123  $first = true;
124  foreach ($values as $field_info) {
125  $val = $field_info[0];
126 
127  if (!$first) {
128  $concat .= ',';
129  }
130 
131  if ($allow_null) {
132  $concat .= 'COALESCE(';
133  }
134  $concat .= $val;
135 
136  if ($allow_null) {
137  $concat .= ",''";
138  $concat .= ')';
139  }
140 
141  $first = false;
142  }
143  $concat .= ') ';
144 
145  return $concat;
146  }
$values

◆ createDatabase()

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

Implements ilQueryUtilsInterface.

Definition at line 293 of file class.ilPostgresQueryUtils.php.

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

◆ createTable()

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

Implements ilQueryUtilsInterface.

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

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

20  {
21  if (!$name) {
22  throw new ilDatabaseException('no valid table name specified');
23  }
24  if (empty($fields)) {
25  throw new ilDatabaseException('no fields specified for table "' . $name . '"');
26  }
27  $query_fields_array = array();
28  foreach ($fields as $field_name => $field) {
29  $query_fields_array[] = $this->db_instance->getFieldDefinition()->getDeclaration($field['type'], $field_name, $field);
30  }
31 
32  $query_fields = implode(', ', $query_fields_array);
33 
34  if (!empty($options['primary'])) {
35  $query_fields .= ', PRIMARY KEY (' . implode(', ', array_keys($options['primary'])) . ')';
36  }
37 
38  $query = "CREATE TABLE $name ($query_fields)";
39 
40  $options_strings = array();
41 
42  if (!empty($options['comment'])) {
43  $options_strings['comment'] = 'COMMENT = ' . $this->quote($options['comment'], 'text');
44  }
45 
46  if (!empty($options['charset'])) {
47  $options_strings['charset'] = 'DEFAULT CHARACTER SET ' . $options['charset'];
48  if (!empty($options['collate'])) {
49  $options_strings['charset'] .= ' COLLATE ' . $options['collate'];
50  }
51  }
52 
53  $type = false;
54  if (!empty($options['type'])) {
55  $type = $options['type'];
56  }
57  if ($type) {
58  $options_strings[] = "ENGINE = $type";
59  }
60 
61  if (!empty($options_strings)) {
62  $query .= ' ' . implode(' ', $options_strings);
63  }
64 
65  return $query;
66  }
$type
Class ilDatabaseException.
$query
+ Here is the call graph for this function:

◆ free()

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

Implements ilQueryUtilsInterface.

Definition at line 174 of file class.ilPostgresQueryUtils.php.

References ilPDOStatement\closeCursor().

175  {
176  $statement->closeCursor();
177 
178  return true;
179  }
closeCursor()
Pdo allows for a manual closing of the cursor.
+ Here is the call graph for this function:

◆ groupConcat()

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

Implements ilQueryUtilsInterface.

Definition at line 312 of file class.ilPostgresQueryUtils.php.

References quote().

313  {
314  if ($a_order === null) {
315  $sql = "STRING_AGG(" . $a_field_name . ", " . $this->quote($a_seperator, "text") . ")";
316  } else {
317  $sql = "STRING_AGG(" . $a_field_name . ", " . $this->quote($a_seperator, "text") . " ORDER BY " . $a_order . ")";
318  }
319  return $sql;
320  }
+ Here is the call graph for this function:

◆ in()

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

Implements ilQueryUtilsInterface.

Definition at line 76 of file class.ilPostgresQueryUtils.php.

References $type, $values, and quote().

77  {
78  if (count($values) == 0) {
79  // BEGIN fixed mantis #0014191:
80  //return " 1=2 "; // return a false statement on empty array
81  return $negate ? ' 1=1 ' : ' 1=2 ';
82  // END fixed mantis #0014191:
83  }
84  if ($type == "") { // untyped: used ? for prepare/execute
85  $str = $field . (($negate) ? " NOT" : "") . " IN (?" . str_repeat(",?", count($values) - 1) . ")";
86  } else { // typed, use values for query/manipulate
87  $str = $field . (($negate) ? " NOT" : "") . " IN (";
88  $sep = "";
89  foreach ($values as $v) {
90  $str .= $sep . $this->quote($v, $type);
91  $sep = ",";
92  }
93  $str .= ")";
94  }
95 
96  return $str;
97  }
$type
$values
+ Here is the call graph for this function:

◆ like()

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

Implements ilQueryUtilsInterface.

Definition at line 200 of file class.ilPostgresQueryUtils.php.

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

201  {
202  if (!in_array($type, array(
205  "blob",
206  ))
207  ) {
208  throw new ilDatabaseException("Like: Invalid column type '" . $type . "'.");
209  }
210  if ($value == "?") {
211  if ($case_insensitive) {
212  return "UPPER(" . $column . ") LIKE(UPPER(?))";
213  } else {
214  return $column . " LIKE(?)";
215  }
216  } else {
217  if ($case_insensitive) {
218  // Always quote as text
219  return " UPPER(" . $column . ") LIKE(UPPER(" . $this->quote($value, 'text') . "))";
220  } else {
221  // Always quote as text
222  return " " . $column . " LIKE(" . $this->quote($value, 'text') . ")";
223  }
224  }
225  }
$type
Class ilDatabaseException.
+ Here is the call graph for this function:

◆ locate()

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

Implements ilQueryUtilsInterface.

Definition at line 155 of file class.ilPostgresQueryUtils.php.

156  {
157  $locate = ' STRPOS(SUBSTR(';
158  $locate .= $a_string;
159  $locate .= ', ';
160  $locate .= $a_start_pos;
161  $locate .= '), ';
162  $locate .= $a_needle;
163  $locate .= ') + ';
164  $locate .= --$a_start_pos;
165 
166  return $locate;
167  }

◆ lock()

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

Implements ilQueryUtilsInterface.

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

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

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

◆ now()

ilPostgresQueryUtils::now ( )
Returns
string

Implements ilQueryUtilsInterface.

Definition at line 231 of file class.ilPostgresQueryUtils.php.

232  {
233  return "now()";
234  }

◆ quote()

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

Implements ilQueryUtilsInterface.

Definition at line 105 of file class.ilPostgresQueryUtils.php.

References $type.

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

106  {
107  return $this->db_instance->quote($value, $type);
108  }
$type
+ Here is the caller graph for this function:

◆ quoteIdentifier()

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

Implements ilQueryUtilsInterface.

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

187  {
188  return $this->db_instance->quoteIdentifier($identifier);
189  }

◆ unlock()

ilPostgresQueryUtils::unlock ( )
Returns
string

Implements ilQueryUtilsInterface.

Definition at line 281 of file class.ilPostgresQueryUtils.php.

282  {
283  return 'UNLOCK TABLES';
284  }

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