2 require_once(
'./Services/Database/classes/QueryUtils/class.ilQueryUtils.php');
18 public function in($field, $values, $negate =
false, $type =
"") {
19 if (count($values) == 0) {
22 return $negate ?
' 1=1 ' :
' 1=2 ';
27 $str = $field . (($negate) ?
" NOT" :
"") .
" IN (?" . str_repeat(
",?", count($values) - 1) .
")";
30 $str = $field . (($negate) ?
" NOT" :
"") .
" IN (";
32 foreach ($values as $v) {
33 $str .= $sep . $this->
quote($v, $type);
48 public function quote($value, $type = null) {
49 return $this->db_instance->quote($value, $type);
59 if (!count($values)) {
65 foreach ($values as $field_info) {
66 $val = $field_info[0];
73 $concat .=
'COALESCE(';
96 public function locate($a_needle, $a_string, $a_start_pos = 1) {
97 $locate =
' LOCATE( ';
100 $locate .= $a_string;
102 $locate .= $a_start_pos;
125 return $this->db_instance->quoteIdentifier($identifier);
140 if (empty($fields)) {
143 $query_fields_array =
array();
144 foreach ($fields as $field_name => $field) {
145 $query_fields_array[] = $this->db_instance->getFieldDefinition()->getDeclaration($field[
'type'], $field_name, $field);
148 $query_fields = implode(
', ', $query_fields_array);
151 $query_fields .=
', PRIMARY KEY (' . implode(
', ', array_keys(
$options[
'primary'])) .
')';
154 $query =
"CREATE TABLE $name ($query_fields)";
156 $options_strings =
array();
159 $options_strings[
'comment'] =
'COMMENT = ' . $this->
quote(
$options[
'comment'],
'text');
163 $options_strings[
'charset'] =
'DEFAULT CHARACTER SET ' .
$options[
'charset'];
165 $options_strings[
'charset'] .=
' COLLATE ' .
$options[
'collate'];
174 $options_strings[] =
"ENGINE = $type";
177 if (!empty($options_strings)) {
178 $query .=
' ' . implode(
' ', $options_strings);
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 =
"GROUP_CONCAT(" . $a_field_name .
" SEPARATOR " . $this->
quote($a_seperator,
"text") .
")";
304 $sql =
"GROUP_CONCAT(" . $a_field_name .
" ORDER BY " . $a_order .
" SEPARATOR " . $this->
quote($a_seperator,
"text").
")";
314 public function cast($a_field_name, $a_dest_type) {
315 return $a_field_name;
quoteIdentifier($identifier)
locate($a_needle, $a_string, $a_start_pos=1)
quote($value, $type=null)
groupConcat($a_field_name, $a_seperator=",", $a_order=NULL)
Class ilPDOStatement is a Wrapper Class for PDOStatement.
createTable($name, $fields, $options=array())
createDatabase($a_name, $a_charset="utf8", $a_collation="")
Class ilDatabaseException.
free(ilPDOStatement $statement)
if(!is_array($argv)) $options
closeCursor()
Pdo allows for a manual closing of the cursor.
like($column, $type, $value="?", $case_insensitive=true)
Create styles array
The data for the language used.
cast($a_field_name, $a_dest_type)
string
concat(array $values, $allow_null=true)
in($field, $values, $negate=false, $type="")