2 require_once(
'./Services/Database/classes/QueryUtils/class.ilQueryUtils.php');
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);
30 $query_fields = implode(
', ', $query_fields_array);
33 $query_fields .=
', PRIMARY KEY (' . implode(
', ', array_keys(
$options[
'primary'])) .
')';
36 $query =
"CREATE TABLE $name ($query_fields)";
38 $options_strings =
array();
41 $options_strings[
'comment'] =
'COMMENT = ' . $this->
quote(
$options[
'comment'],
'text');
45 $options_strings[
'charset'] =
'DEFAULT CHARACTER SET ' .
$options[
'charset'];
47 $options_strings[
'charset'] .=
' COLLATE ' .
$options[
'collate'];
56 $options_strings[] =
"ENGINE = $type";
59 if (!empty($options_strings)) {
60 $query .=
' ' . implode(
' ', $options_strings);
74 public function in($field, $values, $negate =
false, $type =
"") {
75 if (count($values) == 0) {
78 return $negate ?
' 1=1 ' :
' 1=2 ';
83 $str = $field . (($negate) ?
" NOT" :
"") .
" IN (?" . str_repeat(
",?", count($values) - 1) .
")";
86 $str = $field . (($negate) ?
" NOT" :
"") .
" IN (";
88 foreach ($values as $v) {
89 $str .= $sep . $this->
quote($v, $type);
104 public function quote($value, $type = null) {
105 return $this->db_instance->quote($value, $type);
115 if (!count($values)) {
119 $concat =
' CONCAT(';
121 foreach ($values as $field_info) {
122 $val = $field_info[0];
129 $concat .=
'COALESCE(';
152 public function locate($a_needle, $a_string, $a_start_pos = 1) {
153 $locate =
' LOCATE( ';
154 $locate .= $a_needle;
156 $locate .= $a_string;
158 $locate .= $a_start_pos;
181 return $this->db_instance->quoteIdentifier($identifier);
193 public function like(
$column, $type, $value =
"?", $case_insensitive =
true) {
194 if (!in_array($type,
array(
203 if ($case_insensitive) {
204 return "UPPER(" .
$column .
") LIKE(UPPER(?))";
209 if ($case_insensitive) {
211 return " UPPER(" .
$column .
") LIKE(UPPER(" . $this->
quote($value,
'text') .
"))";
214 return " " .
$column .
" LIKE(" . $this->
quote($value,
'text') .
")";
233 $lock =
'LOCK TABLES ';
236 foreach ($tables as $table) {
241 if (isset($table[
'sequence']) && $table[
'sequence']) {
242 $table_name = $this->db_instance->getSequenceName($table[
'name']);
244 $table_name = $table[
'name'];
247 $lock .= ($table_name .
' ');
249 if ($table[
'alias']) {
250 $lock .= ($table[
'alias'] .
' ');
253 switch ($table[
'type']) {
272 return 'UNLOCK TABLES';
282 public function createDatabase($a_name, $a_charset =
"utf8", $a_collation =
"") {
283 if ($a_collation !=
"") {
284 $sql =
"CREATE DATABASE " . $a_name .
" CHARACTER SET " . $a_charset .
" COLLATE " . $a_collation;
286 $sql =
"CREATE DATABASE " . $a_name .
" CHARACTER SET " . $a_charset;
300 public function groupConcat($a_field_name, $a_seperator =
",", $a_order = NULL) {
301 if ($a_order === NULL) {
302 $sql =
"STRING_AGG(" . $a_field_name .
", " . $this->
quote($a_seperator,
"text") .
")";
304 $sql =
"STRING_AGG(" . $a_field_name .
", " . $this->
quote($a_seperator,
"text") .
" ORDER BY " . $a_order .
")";
314 public function cast($a_field_name, $a_dest_type) {
315 return "CAST({$a_field_name} AS " . $this->db_instance->getFieldDefinition()->getTypeDeclaration(
array(
"type" => $a_dest_type)) .
")";
Class ilPDOStatement is a Wrapper Class for PDOStatement.
in($field, $values, $negate=false, $type="")
cast($a_field_name, $a_dest_type)
string
like($column, $type, $value="?", $case_insensitive=true)
Class ilDatabaseException.
createDatabase($a_name, $a_charset="utf8", $a_collation="")
locate($a_needle, $a_string, $a_start_pos=1)
if(!is_array($argv)) $options
concat(array $values, $allow_null=true)
free(ilPDOStatement $statement)
closeCursor()
Pdo allows for a manual closing of the cursor.
quoteIdentifier($identifier)
Create styles array
The data for the language used.
groupConcat($a_field_name, $a_seperator=",", $a_order=NULL)
Class ilPostgresQueryUtils.
createTable($name, $fields, $options=array())
quote($value, $type=null)