After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 78846 - Ability to open connecitons in read-only mode
Ability to open connecitons in read-only mode
Status: RESOLVED OBSOLETE
Product: libgda
Classification: Other
Component: PostgreSQL provider
unspecified
Other Linux
: Normal enhancement
: GNOME-DB-1-0
Assigned To: malerba
gnome-db Maintainers
Depends on: 78845
Blocks:
 
 
Reported: 2002-04-16 12:49 UTC by Rodrigo Moya
Modified: 2011-11-24 09:03 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Rodrigo Moya 2002-04-16 12:49:40 UTC
We need this ability, so that we can open unsafe connections from things
such as the GDA plugin in gnumeric
Comment 1 Gonzalo Paniagua Javier 2002-04-16 13:45:43 UTC
I can use PQcmdTuples to simulate it. If PQcmdTuples returns 0, I run
the command, if not, I give a error message. ok?

There use to be a readonly=(0|1) option, but it seems postgresql does
not support for it any more.
---------

PQcmdTuples Returns the number of rows affected by the SQL command.

char * PQcmdTuples(const PGresult *res);

If the SQL command that generated the PGresult was INSERT, UPDATE or
DELETE, this returns a string containing the number of rows affected.
If the command was anything else, it returns the empty string.
Comment 2 Rodrigo Moya 2002-04-16 18:55:43 UTC
no, that won't work, since PQcmdTuples works AFTER the command was
executed. So, it is not the solution. We want to check if it is a
read-only command or not before executing it.

For instance, if there were a 'DROP ALL TABLES' command, using
PQcmdTuples you would execute it, and then return the error, which
will cause all the tables to be dropped. In that case, we must stop
the execution of the command before it gets sent to the DB server.
Comment 3 Gonzalo Paniagua Javier 2002-04-16 19:04:24 UTC
Well, as the connection must be read-only, my plan was to forbid
transactions and issue a BEGIN before actually running the command,
then call to PQCmdTuples () and if no tuples, ok. Else ROLLBACK.

But as you say, that won't work with DROP...
Comment 4 Gonzalo Paniagua Javier 2006-07-28 22:17:28 UTC
I'm not in charge of this anymore...
Comment 5 Murray Cumming 2011-11-24 09:03:44 UTC
PostgreSQL can have read-only transactions:
http://www.postgresql.org/docs/9.1/static/sql-set-transaction.html

And you can set this as the default for all transactions in the connection:
http://www.postgresql.org/docs/9.1/static/runtime-config-client.html#GUC-DEFAULT-TRANSACTION-READ-ONLY

However, I guess that is only useful if you make sure that everything happens in a transaction.

You might also just make sure that the connection's user has only read access, though maybe that is not generically possible from gnumeric.

Anyway, we should probably close this bug report as obsolete. Please reopen if someone is still interested.