Raimon_Fs
(Raimon Fs)
1
Hello,
I'm playing a little with the pg of Ruby, and I'm accessing some
postgresql database.
I want to update some rows, but I can't find the method/command to know
if they were updated or not.
For a normal select:
res = conn.exec('SELECT id, type FROM scanns WHERE ftp=true')
print 'records found: ',res.ntuples(),"\n"
but when updating, I can't use the ntuples() or at least it returns
always zero.
my rows are updated, I can check it with another tool.
conn.transaction {
row_update = conn.exec('UPDATE scanns SET ftp=false WHERE
id=xxxxx'])
print 'records found updating: ',row_update.ntuples(),"\n",
"\n"
}
wich command I have to use ?
I have the latest RDoc documentation, but can't find it ...
thanks,
r.
···
--
Posted via http://www.ruby-forum.com/.
Have you tried "row_update.cmd_tuples()"? ntuples() is only for query
results. Use cmd_tuples instead for updates, inserts and deletes.
···
--
junegunn.
I don't see any problem in the doc. Maybe you misread the sentence?:
"If the SQL command that generated the PGresult was **NOT ONE OF** ...
".
···
--
junegunn.
Raimon_Fs
(Raimon Fs)
5
Choi, Junegunn wrote:
I don't see any problem in the doc. Maybe you misread the sentence?:
"If the SQL command that generated the PGresult was **NOT ONE OF** ...
Yes, I read and read and re-read ...
And I still think the same:
The result of res.cmd_tuples() is valid if the command that generated
it IT'S NOT ONE OF THIS:
INSERT
UPDATE
DELETE
MOVE
FETCH
I would say it in this way:
The result of res.cmd_tuples() is valid if the command that generated
it it's one of this:
INSERT
UPDATE
DELETE
MOVE
FETCH
English is not my nativa language and I can be wrong, but at least this
is what I understand ...
regards,
r.
···
--
Posted via http://www.ruby-forum.com/\.
Raimon Fs wrote:
Choi, Junegunn wrote:
I don't see any problem in the doc. Maybe you misread the sentence?:
"If the SQL command that generated the PGresult was **NOT ONE OF** ...
Yes, I read and read and re-read ...
Perhaps it's clearer if turned around:
0 is returned if the command is not one of (insert, update, delete,
move, fetch), or if no tuples were affected.
Or negate it:
A non-zero value is returned if the command is one of (insert, update,
delete, move, fetch) and one or more tuples were affected.
···
--
Posted via http://www.ruby-forum.com/\.