Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

How to know if a DBI connexion is read-only?

by citromatik (Curate)
on Oct 03, 2012 at 13:37 UTC ( [id://997061]=perlquestion: print w/replies, xml ) Need Help??

citromatik has asked for the wisdom of the Perl Monks concerning the following question:

Hi,

Is it possible to know if a DBI connexion is read-only without failing on writing?

I have seen in the DBI documentation that there is a ReadOnly attribute, but at least for the mysql driver I am not able to make it work

Any idea?

citromatik

Replies are listed 'Best First'.
Re: How to know if a DBI connexion is read-only?
by Mr. Muskrat (Canon) on Oct 03, 2012 at 18:30 UTC

    The correct answer will depend on what what you mean by a read-only connection.

    Setting the ReadOnly DBI attribute with a DBD::mysql database handle doesn't do anything useful; it's just advisory as explained in the section you linked.

    If you want to check if the database is read-only (as is common on a slave), the user only has select priviledges or if the transaction is read-only then you will need to write the appropriate queries to figure those out.

Re: How to know if a DBI connexion is read-only?
by mje (Curate) on Oct 03, 2012 at 14:27 UTC

    "without failing on writing" I don't think there is a way that will work for all DBDs under DBI. e.g., ReadOnly in DBD::ODBC is mapped to the ODBC connection attribute READ_ONLY and you set it to give the driver a hint you will only be reading but it does not stop you writing.

Re: How to know if a DBI connexion is read-only?
by DrHyde (Prior) on Oct 04, 2012 at 10:30 UTC
    There's not really any such thing as a read-only DBI connection, only users who don't have permission to make changes. To divine whether the user you're logged in as has permission to make changes, you need to query the database's metadata tables. Unfortunately, what these are called, where you find them, and what they contain will differ from one RDBMS to another. If, as is likely, you're using MySQL, then see this.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://997061]
Approved by marto
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (5)
As of 2024-03-19 08:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found