25 return "CASE WHEN " . $expr .
"~E'^[0-9]+$' THEN " . $expr .
"::integer ELSE 0 END";
35 return "to_char(".$field.
", '".$this->connection->getSqlHelper()->formatDate($format).
"')";
40 return "CURRENT_TIMESTAMP";
45 return "CURRENT_DATE";
51 if (CTimeZone::Enabled())
55 $diff = CTimeZone::GetOffset();
58 $timeZone = $diff > 0?
"+".$diff: $diff;
60 return "extract(epoch FROM $fieldName)".$timeZone;
65 return 'cast(' . $strValue .
' as date)';
71 $strValue = mb_substr($strValue ??
'', 0, $iMaxLength);
74 return pg_escape_string($this->db_Conn, str_replace(
"\\",
"\\\\", $strValue ??
''));
80 set_error_handler(
function () {
84 $result = pg_query($this->db_Conn, $strSql);
86 restore_error_handler();
93 return pg_last_error($this->db_Conn);
107 if (!isset($this->column_cache[$table]))
109 $this->column_cache[$table] =
array();
112 $sqlHelper = $this->connection->getSqlHelper();
114 $fullTextColumns = $this->connection->getTableFullTextFields($table);
120 character_maximum_length
122 information_schema.columns
124 table_catalog = '" . $sqlHelper->forSql($this->connection->getDatabase()) .
"'
125 and table_schema = 'public'
126 and table_name = '" . $sqlHelper->forSql(mb_strtolower($table)) .
"'
133 $fieldName = mb_strtoupper($field[
'COLUMN_NAME']);
134 $fieldType = $field[
'DATA_TYPE'];
159 case 'double precision':
168 case 'timestamp without time zone':
170 case 'timestamp with time zone':
180 $type = array_key_exists($fieldName, $fullTextColumns) ?
"fulltext" :
"string";
184 $this->column_cache[$table][$fieldName] =
array(
185 "NAME" => $fieldName,
187 "MAX_LENGTH" => $field[
'CHARACTER_MAXIMUM_LENGTH'],
192 return $this->column_cache[$table];
201 $sqlHelper = $this->connection->getSqlHelper();
203 foreach ($arColumns as $strColumnName => $arColumnInfo)
205 $type = $arColumnInfo[
"TYPE"];
208 if ($strInsert1 !=
'')
216 $strInsert1 .= $sqlHelper->quote($strColumnName);
218 if ($value ===
false)
220 $strInsert2 .=
"NULL";
228 $strInsert2 .=
"NULL";
234 $strInsert2 .=
"NULL";
239 $value = intval($value);
240 if ($arColumnInfo[
'INT_SIZE'] == 2)
242 $value = max(-32768, min(+32767, $value));
244 elseif ($arColumnInfo[
'INT_SIZE'] == 4)
246 $value = max(-2147483648, min(+2147483647, $value));
248 $strInsert2 .= $value;
251 $value = doubleval($value);
252 if (!is_finite($value))
256 $strInsert2 .=
"'".$value.
"'";
259 $strInsert2 .=
"decode('".bin2hex($value).
"', 'hex')";
262 $strInsert2 .=
"safe_text_for_tsvector('".$sqlHelper->forSql($value, (
int)$arColumnInfo[
'MAX_LENGTH']).
"')";
265 if ($arColumnInfo[
'MAX_LENGTH'])
267 $strInsert2 .=
"'" . $sqlHelper->forSql($value, $arColumnInfo[
'MAX_LENGTH']) .
"'";
271 $strInsert2 .=
"'" . $sqlHelper->forSql($value) .
"'";
278 if ($strInsert1 !=
'')
283 $strInsert1 .= $sqlHelper->quote($strColumnName);
284 $strInsert2 .=
$arFields[
"~".$strColumnName];
288 return array($strInsert1, $strInsert2);
300 if ($strTableAlias !=
"")
301 $strTableAlias .=
".";
305 $sqlHelper = $this->connection->getSqlHelper();
307 foreach ($arColumns as $strColumnName => $arColumnInfo)
309 $type = $arColumnInfo[
"TYPE"];
312 if ($strUpdate !=
'')
319 if ($value ===
false)
321 $strUpdate .= $strTableAlias . $sqlHelper->quote($strColumnName) .
" = NULL";
325 $strUpdate .= $strTableAlias . $sqlHelper->quote($strColumnName) .
" = " . $value->compile();
332 $value = intval($value);
333 if ($arColumnInfo[
'INT_SIZE'] == 2)
335 $value = max(-32768, min(+32767, $value));
337 elseif ($arColumnInfo[
'INT_SIZE'] == 4)
339 $value = max(-2147483648, min(+2147483647, $value));
343 $value = doubleval($value);
344 if(!is_finite($value))
362 $value =
"decode('".bin2hex($value).
"', 'hex')";
365 $value =
"safe_text_for_tsvector('".$sqlHelper->forSql($value, (
int)$arColumnInfo[
'MAX_LENGTH']).
"')";
368 if ($arColumnInfo[
'MAX_LENGTH'])
370 $value =
"'" . $sqlHelper->forSql($value, $arColumnInfo[
'MAX_LENGTH']) .
"'";
374 $value =
"'" . $sqlHelper->ForSql($value) .
"'";
377 $strUpdate .= $strTableAlias . $sqlHelper->quote($strColumnName) .
" = " . $value;
382 if ($strUpdate !=
'')
386 $strUpdate .= $strTableAlias . $sqlHelper->quote($strColumnName) .
" = " .
$arFields[
"~".$strColumnName];
396 foreach ($from as $join)
398 $tables .= ($tables ?
",\n " :
"FROM\n ") . $join[0];
399 $where .= ($where ?
"\nAND " :
"\n") . $join[1];
402 foreach (
$arFields as $fieldName => $fieldValue)
404 $fields .= (
$fields ?
",\n " :
"") . $fieldName .
'=' . $fieldValue;
406 $update =
'UPDATE ' . $strTableName .
"\n"
409 . ($where ?
"\nWHERE" . $where :
"")
414 public function Insert($table,
$arFields, $error_position=
"", $DEBUG=
false, $EXIST_ID=
"", $ignore_errors=
false)
423 $str1 .= ($str1 <>
""?
", ":
"") . $this->
quote($field);
424 if ((
string)$value ==
'')
425 $str2 .= ($str2 <>
""?
", ":
"").
"''";
427 $str2 .= ($str2 <>
""?
", ":
"").$value;
432 $strSql =
"INSERT INTO ".$table.
"(ID,".$str1.
") VALUES ('".$this->
ForSql($EXIST_ID).
"',".$str2.
") RETURNING ID";
436 $strSql =
"INSERT INTO ".$table.
"(".$str1.
") VALUES (".$str2.
") RETURNING ID";
440 echo
"<br>".htmlspecialcharsEx($strSql).
"<br>";
442 $res = $this->
Query($strSql, $ignore_errors, $error_position);
447 $row =
$res->Fetch();
449 return intval(array_shift($row));
456 if(!isset($this) || !is_object($this) || !isset($this->type))
458 return $DB->Add($tablename,
$arFields, $arCLOBFields, $strFileDir, $ignore_errors, $error_position,
$arOptions);
465 $strSql =
"INSERT INTO ".$tablename.
"(".$arInsert[0].
") VALUES (".$arInsert[1].
") RETURNING ID";
466 $row = $this->
Query($strSql, $ignore_errors, $error_position,
$arOptions)->Fetch();
467 return intval(array_shift($row));
471 $strSql =
"INSERT INTO ".$tablename.
"(".$arInsert[0].
") VALUES(".$arInsert[1].
")";
478 public function CreateIndex($indexName, $tableName, $columns, $unique =
false, $fulltext =
false)
480 foreach ($columns as
$i => $columnName)
482 $columns[
$i] = $this->
quote($columnName);
487 return $this->
Query(
'CREATE UNIQUE INDEX ' . $this->
quote($indexName) .
' ON ' . $this->
quote($tableName) .
'(' . implode(
',', $columns) .
')',
true);
491 return $this->
Query(
'CREATE INDEX ' . $this->
quote($indexName) .
' ON ' . $this->
quote($tableName) .
' USING GIN (to_tsvector(\'english\', ' . implode(
',', $columns) .
'))',
true);
495 return $this->
Query(
'CREATE INDEX ' . $this->
quote($indexName) .
' ON ' . $this->
quote($tableName) .
'(' . implode(
',', $columns) .
')',
true);
501 return pg_get_pid($this->db_Conn);
DoConnect($connectionName='')
Query($strSql, $bIgnoreErrors=false, $error_position="", $arOptions=[])
CharToDateFunction($strValue, $strType="FULL", $lang=false)
ForSql($strValue, $iMaxLength=0)
PrepareUpdate($strTableName, $arFields, $strFileDir="", $lang=false, $strTableAlias="")
ForSqlLike($strValue, $iMaxLength=0)
PrepareInsert($strTableName, $arFields)
DatetimeToDateFunction($strValue)
PrepareUpdateBind($strTableName, $arFields, $strFileDir, $lang, &$arBinds, $strTableAlias="")
Insert($table, $arFields, $error_position="", $DEBUG=false, $EXIST_ID="", $ignore_errors=false)
static CurrentDateFunction()
static CurrentTimeFunction()
DatetimeToTimestampFunction($fieldName)
DateFormatToDB($format, $field=false)
CreateIndex($indexName, $tableName, $columns, $unique=false, $fulltext=false)
Add($tablename, $arFields, $arCLOBFields=Array(), $strFileDir="", $ignore_errors=false, $error_position="", $arOptions=array())
PrepareUpdateJoin($strTableName, $arFields, $from, $where)
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
if(!defined('SITE_ID')) $lang
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)