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

From: rob stone <floriparob(at)gmail(dot)com>
To: "Steve Petrie, P(dot)Eng(dot)" <apetrie(at)aspetrie(dot)net>, pgsql-general(at)postgresql(dot)org
Subject: Re: *** QUESTION *** After successful 'BEGIN;' command -- why PGSQL_TRANSACTION_ACTIVE and not PGSQL_TRANSACTION_INTRANS?
Date: 2015-10-12 03:58:31
Message-ID: 1444622311.2285.9.camel@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Achilleas Mantzios 2015-10-12 06:35:34 Re: checkpoints anatomy
Previous Message Richardson Hinestroza 2015-10-12 01:39:27 checkpoints anatomy