ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
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...
 
 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()

ilPostgresQueryUtils::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.ilPostgresQueryUtils.php.

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

◆ concat()

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

Reimplemented from ilQueryUtils.

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

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

◆ createDatabase()

ilPostgresQueryUtils::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.ilPostgresQueryUtils.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()

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

ilDatabaseException

Reimplemented from ilQueryUtils.

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

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

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

+ Here is the call graph for this function:

◆ free()

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

Reimplemented from ilQueryUtils.

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

174 {
175 $statement->closeCursor();
176
177 return true;
178 }
closeCursor()
Pdo allows for a manual closing of the cursor.

References ilPDOStatement\closeCursor().

+ 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

Reimplemented from ilQueryUtils.

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

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

References quote().

+ 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

Reimplemented from ilQueryUtils.

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

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

References $type, and quote().

+ 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

ilDatabaseException

Reimplemented from ilQueryUtils.

Definition at line 199 of file class.ilPostgresQueryUtils.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 }

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

+ 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

Reimplemented from ilQueryUtils.

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

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

◆ lock()

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

Reimplemented from ilQueryUtils.

Definition at line 240 of file class.ilPostgresQueryUtils.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 }

References ilDBConstants\LOCK_READ, and ilDBConstants\LOCK_WRITE.

◆ now()

ilPostgresQueryUtils::now ( )
Returns
string

Reimplemented from ilQueryUtils.

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

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

◆ quote()

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

Reimplemented from ilQueryUtils.

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

105 {
106 return $this->db_instance->quote($value, $type);
107 }

References $type.

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

+ Here is the caller graph for this function:

◆ quoteIdentifier()

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

Reimplemented from ilQueryUtils.

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

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

◆ unlock()

ilPostgresQueryUtils::unlock ( )
Returns
string

Reimplemented from ilQueryUtils.

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

281 {
282 return 'UNLOCK TABLES';
283 }

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