ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 314 of file class.ilPostgresQueryUtils.php.

314 {
315 return "CAST({$a_field_name} AS " . $this->db_instance->getFieldDefinition()->getTypeDeclaration(array("type" => $a_dest_type)) . ")";
316 }

◆ concat()

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

Reimplemented from ilQueryUtils.

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

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

◆ 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 282 of file class.ilPostgresQueryUtils.php.

282 {
283 if ($a_collation != "") {
284 $sql = "CREATE DATABASE " . $a_name . " CHARACTER SET " . $a_charset . " COLLATE " . $a_collation;
285 } else {
286 $sql = "CREATE DATABASE " . $a_name . " CHARACTER SET " . $a_charset;
287 }
288
289 return $sql;
290 }

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

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

References $options, $query, 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 169 of file class.ilPostgresQueryUtils.php.

169 {
170 $statement->closeCursor();
171
172 return true;
173 }
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 300 of file class.ilPostgresQueryUtils.php.

300 {
301 if ($a_order === NULL) {
302 $sql = "STRING_AGG(" . $a_field_name . ", " . $this->quote($a_seperator, "text") . ")";
303 } else {
304 $sql = "STRING_AGG(" . $a_field_name . ", " . $this->quote($a_seperator, "text") . " ORDER BY " . $a_order . ")";
305
306 }
307 return $sql;
308 }

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 74 of file class.ilPostgresQueryUtils.php.

74 {
75 if (count($values) == 0) {
76 // BEGIN fixed mantis #0014191:
77 //return " 1=2 "; // return a false statement on empty array
78 return $negate ? ' 1=1 ' : ' 1=2 ';
79 // END fixed mantis #0014191:
80 }
81 if ($type == "") // untyped: used ? for prepare/execute
82 {
83 $str = $field . (($negate) ? " NOT" : "") . " IN (?" . str_repeat(",?", count($values) - 1) . ")";
84 } else // typed, use values for query/manipulate
85 {
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 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 193 of file class.ilPostgresQueryUtils.php.

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

References $column, 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 152 of file class.ilPostgresQueryUtils.php.

152 {
153 $locate = ' LOCATE( ';
154 $locate .= $a_needle;
155 $locate .= ',';
156 $locate .= $a_string;
157 $locate .= ',';
158 $locate .= $a_start_pos;
159 $locate .= ') ';
160
161 return $locate;
162 }

◆ lock()

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

Reimplemented from ilQueryUtils.

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

232 {
233 $lock = 'LOCK TABLES ';
234
235 $counter = 0;
236 foreach ($tables as $table) {
237 if ($counter ++) {
238 $lock .= ', ';
239 }
240
241 if (isset($table['sequence']) && $table['sequence']) {
242 $table_name = $this->db_instance->getSequenceName($table['name']);
243 } else {
244 $table_name = $table['name'];
245 }
246
247 $lock .= ($table_name . ' ');
248
249 if ($table['alias']) {
250 $lock .= ($table['alias'] . ' ');
251 }
252
253 switch ($table['type']) {
255 $lock .= ' READ ';
256 break;
257
259 $lock .= ' WRITE ';
260 break;
261 }
262 }
263
264 return $lock;
265 }
$counter

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

◆ now()

ilPostgresQueryUtils::now ( )
Returns
string

Reimplemented from ilQueryUtils.

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

223 {
224 return "now()";
225 }

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

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

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 180 of file class.ilPostgresQueryUtils.php.

180 {
181 return $this->db_instance->quoteIdentifier($identifier);
182 }

◆ unlock()

ilPostgresQueryUtils::unlock ( )
Returns
string

Reimplemented from ilQueryUtils.

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

271 {
272 return 'UNLOCK TABLES';
273 }

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