why can't see the updated value after SPI_execute("update ....", false, 1);

Started by sunpengover 15 years ago3 messagesgeneral
Jump to latest
#1sunpeng
bluevaley@gmail.com

First I use SPI_execute("update ....
bool succ;
SPI_connect();
int ret = SPI_execute("update ....where uid = 1", false, 1);//later will
add error processing
if (ret == SPI_OK_UPDATE && SPI_processed == 1) {
succ = true;
}
SPI_finish();

Then I use SPI_execute("select .....where uid = 1", ....

SPI_connect();
int ret = SPI_execute("select .....where uid = 1", true, 1);//later will
add error processing
if (ret == SPI_OK_SELECT && SPI_processed == 1) {
HeapTuple tuple;
tuple = SPI_tuptable->vals[0];
...
datum = heap_getattr(tuple,attrno,SPI_tuptable->tupdesc,&isnull);
....
}
the datum doesn't change, why ?

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: sunpeng (#1)
Re: why can't see the updated value after SPI_execute("update ....", false, 1);

sunpeng <bluevaley@gmail.com> writes:

First I use SPI_execute("update ....
bool succ;
SPI_connect();
int ret = SPI_execute("update ....where uid = 1", false, 1);//later will
add error processing
if (ret == SPI_OK_UPDATE && SPI_processed == 1) {
succ = true;
}
SPI_finish();

Then I use SPI_execute("select .....where uid = 1", ....

SPI_connect();
int ret = SPI_execute("select .....where uid = 1", true, 1);//later will
add error processing
if (ret == SPI_OK_SELECT && SPI_processed == 1) {
HeapTuple tuple;
tuple = SPI_tuptable->vals[0];
...
datum = heap_getattr(tuple,attrno,SPI_tuptable->tupdesc,&isnull);
....
}
the datum doesn't change, why ?

You're missing a CommandCounterIncrement() call between the two actions.
If you hadn't passed read_only = true to the second SPI_execute, it
would have done one for you.

regards, tom lane

#3sunpeng
bluevaley@gmail.com
In reply to: Tom Lane (#2)
Re: why can't see the updated value after SPI_execute("update ....", false, 1);

I then added , yet it still doesn't work.

2010/9/12 Tom Lane <tgl@sss.pgh.pa.us>

Show quoted text

sunpeng <bluevaley@gmail.com> writes:

First I use SPI_execute("update ....
bool succ;
SPI_connect();
int ret = SPI_execute("update ....where uid = 1", false, 1);//later

will

add error processing
if (ret == SPI_OK_UPDATE && SPI_processed == 1) {
succ = true;
}
SPI_finish();

Then I use SPI_execute("select .....where uid = 1", ....

SPI_connect();
int ret = SPI_execute("select .....where uid = 1", true, 1);//later

will

add error processing
if (ret == SPI_OK_SELECT && SPI_processed == 1) {
HeapTuple tuple;
tuple = SPI_tuptable->vals[0];
...
datum =

heap_getattr(tuple,attrno,SPI_tuptable->tupdesc,&isnull);

....
}
the datum doesn't change, why ?

You're missing a CommandCounterIncrement() call between the two actions.
If you hadn't passed read_only = true to the second SPI_execute, it
would have done one for you.

regards, tom lane