Re: *** QUESTION *** After successful 'BEGIN;' command -- why PGSQL_TRANSACTION_ACTIVE and not PGSQL_TRANSACTION_INTRANS? - Mailing list pgsql-general

From rob stone
Subject Re: *** QUESTION *** After successful 'BEGIN;' command -- why PGSQL_TRANSACTION_ACTIVE and not PGSQL_TRANSACTION_INTRANS?
Date
Msg-id 1444622311.2285.9.camel@gmail.com
Whole thread Raw
In response to *** QUESTION *** After successful 'BEGIN;' command -- why PGSQL_TRANSACTION_ACTIVE and not PGSQL_TRANSACTION_INTRANS?  ("Steve Petrie, P.Eng." <apetrie@aspetrie.net>)
List pgsql-general
> ETO::00000::LOG:  00000: connection received: host=127.0.0.1
> port=1083
> ETO::00000::LOCATION:  BackendInitialize,
> src\backend\postmaster\postmaster.c:3850
> ETO::00000::LOG:  00000: connection authorized: user=its-eto_pg36
> database=eto_sql_db
> ETO::00000::LOCATION:  PerformAuthentication,
> src\backend\utils\init\postinit.c:239
> ETO::00000::LOG:  00000: statement: set client_encoding to 'LATIN1'
> ETO::00000::LOCATION:  exec_simple_query,
> src\backend\tcop\postgres.c:890
> ETO::00000::LOG:  00000: duration: 63.000 ms
> ETO::00000::LOCATION:  exec_simple_query,
> src\backend\tcop\postgres.c:1118
> ETO::00000::LOG:  00000: statement: BEGIN;
> ETO::00000::LOCATION:  exec_simple_query,
> src\backend\tcop\postgres.c:890
> ETO::00000::LOG:  00000: duration: 0.000 ms
> ETO::00000::LOCATION:  exec_simple_query,
> src\backend\tcop\postgres.c:1118
> ETO::00000::LOG:  00000: disconnection: session time: 0:00:00.297
> user=its-eto_pg36 database=eto_sql_db host=127.0.0.1 port=1083
> ETO::00000::LOCATION:  log_disconnections,
> src\backend\tcop\postgres.c:4444
> * * *
> * * *
>
> Thanks For Any Feedback,
>
> Steve

Hello Steve,

I really do not understand "why" you need the SQLSTATE code after
executing a "BEGIN" so as to go into transaction state.

AFAIK you can only retrieve the SQLSTATE error code when an error
actually occurs. So, if your query statement was successful, then PHP
does not expose a SQLSTATE code of 00000.

If I run the following code:-

----------------------------------------------
<?php

require_once '../actions/DataBaseFunctions.php';

$pgconn = conn_db();
$my_query = "SELECT * FROM rhubarb";
if (!pg_connection_busy($pgconn)) {
    $my_result = pg_send_query($pgconn, $my_query);
    pg_set_error_verbosity($pgconn, PGSQL_ERRORS_VERBOSE);
    $res1 = pg_get_result($pgconn);
    echo pg_result_error($res1) . PHP_EOL;
} else {
    echo 'Connection Busy' . PHP_EOL;
}

?>

--------------------------------------------------------------

it returns the following:-


ERROR:  42P01: relation "rhubarb" does not exist
LINE 1: SELECT * FROM rhubarb
                      ^
LOCATION:  parserOpenTable, parse_relation.c:986


SQLSTATE 42P01 is the error "undefined_table".


Note that you have to use pg_send_query to take advantage of
pg_get_result, etc.


HTH,

Rob



pgsql-general by date:

Previous
From: Richardson Hinestroza
Date:
Subject: checkpoints anatomy
Next
From: Achilleas Mantzios
Date:
Subject: Re: checkpoints anatomy