1
0
mirror of https://github.com/php/doc-ru.git synced 2026-03-25 16:22:18 +01:00
Files
archived-doc-ru/reference/pgsql/functions/pg-last-oid.xml
Sergey Panteleev 6d43fd64d7 Исправление форматирования
[skip-spellcheck]
[skip-lint]
2022-12-27 03:42:36 +03:00

142 lines
4.8 KiB
XML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?xml version="1.0" encoding="utf-8"?>
<!-- EN-Revision: c2eca73ef79ebe78cebb34053e41b565af504c4f Maintainer: mch Status: ready -->
<!-- Reviewed: no -->
<refentry xml:id="function.pg-last-oid" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>pg_last_oid</refname>
<refpurpose>Возвращает OID последней добавленной в базу строки</refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<type class="union"><type>string</type><type>int</type><type>false</type></type><methodname>pg_last_oid</methodname>
<methodparam><type>PgSql\Result</type><parameter>result</parameter></methodparam>
</methodsynopsis>
<para>
<function>pg_last_oid</function> используется для определения
<varname>OID</varname>, соответствующего вставленной в таблицу
строке.
</para>
<para>
Поле OID таблиц баз данных стало необязательным, начиная с версии
PostgreSQL 7.2, а с версии 8.1 перестанет добавляться в таблицы
по умолчанию. Если поле OID таблицы не задано, используйте функцию
<function>pg_result_status</function> для проверки успешности вставки
записей в таблицу.
</para>
<para>
Чтобы получить значение <literal>SERIAL</literal> поля после вставки
строки в таблицу, используйте функцию PostgreSQL <literal>CURRVAL</literal>,
передав ей имя последовательности, значение которой нужно получить.
Чтобы узнать имя последовательности, необходимо использовать функцию
<literal>pg_get_serial_sequence</literal> (PostgreSQL 8.0).
</para>
<para>
В PostgreSQL 8.1 есть функция <literal>LASTVAL</literal>, возвращающая
значение наиболее часто используемой за сессию последовательности. Так можно
избежать необходимость задавать название последовательности, таблицы или колонки.
</para>
<note>
<para>
Прежнее название функции: <function>pg_getlastoid</function>.
</para>
</note>
</refsect1>
<refsect1 role="parameters">
&reftitle.parameters;
<para>
<variablelist>
<varlistentry>
<term><parameter>result</parameter></term>
<listitem>
&pgsql.parameter.result;
</listitem>
</varlistentry>
</variablelist>
</para>
</refsect1>
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
Целое число (<type>int</type>) или строка (<type>string</type>), содержащая OID последней вставленной строки на соединении
<parameter>connection</parameter>, либо &false;, если произошла ошибка или
поле OID недоступно.
</para>
</refsect1>
<refsect1 role="changelog">
&reftitle.changelog;
<informaltable>
<tgroup cols="2">
<thead>
<row>
<entry>&Version;</entry>
<entry>&Description;</entry>
</row>
</thead>
<tbody>
&pgsql.changelog.result-object;
</tbody>
</tgroup>
</informaltable>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<para>
<example>
<title>Пример использования <function>pg_last_oid</function></title>
<programlisting role="php">
<![CDATA[
<?php
// Подключение к базе данных
pg_connect("dbname=mark host=localhost");
// Создание тестовой таблицы
pg_query("CREATE TABLE test (a INTEGER) WITH OIDS");
// Вставка данных в таблицу
$res = pg_query("INSERT INTO test VALUES (1)");
$oid = pg_last_oid($res);
?>
]]>
</programlisting>
</example>
</para>
</refsect1>
<refsect1 role="seealso">
&reftitle.seealso;
<para>
<simplelist>
<member><function>pg_query</function></member>
<member><function>pg_result_status</function></member>
</simplelist>
</para>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->