Ticket #913 (new enhancement)

Opened 15 months ago

Last modified 4 months ago

dbVersion to jDbTools

Reported by: foxmask Owned by:
Priority: normal Milestone:
Component: jelix:db Version: trunk
Severity: normal Keywords:
Cc: Php version:
Review: review? Hosting Provider:
Blocked By: Documentation needed: no
Blocking:

Description

here is a patch to get the version of the current RDBMS

Attachments

jdbtools_dbversion.patch (2.5 kB) - added by foxmask 15 months ago.
jdbtools + plugin db patch that get the version of the RDBMS
jdbtools_dbversion.2.patch (2.5 kB) - added by foxmask 15 months ago.
fix $this->_conn vs $this->_connecter
jdbtools_dbversion.3.patch (3.0 kB) - added by foxmask 15 months ago.
dbVersion as asbtract in jDbTools + phpdoc
jdbtools_dbversion.4.patch (2.8 kB) - added by foxmask 15 months ago.
clearer patch to return the version of the RDBSM used
getAttribute.patch (4.7 kB) - added by foxmask 15 months ago.

Change History

Changed 15 months ago by foxmask

jdbtools + plugin db patch that get the version of the RDBMS

Changed 15 months ago by foxmask

fix $this->_conn vs $this->_connecter

Changed 15 months ago by laurentj

  • review changed from review? to review-
  • milestone set to Jelix 1.2

Why not. But I prefer to not have two methods dbVersion and _dbVersion. Just use a dbVersion method, and the one in jDbTools should be abstract.

And the php documentation is missing.

Changed 15 months ago by laurentj

  • type changed from bug to enhancement

Changed 15 months ago by foxmask

dbVersion as asbtract in jDbTools + phpdoc

Changed 15 months ago by foxmask

  • review changed from review- to review?

Changed 15 months ago by laurentj

  • review changed from review? to review-

Sorry, I discover an other issue in your previous patch: Why doing a foreach when you have only a record ? Just do a fetch.

for oci:

'SELECT * FROM v$version AS VERSION'

it returns many result for different oracle components. and it returns only one column, "banner" (not VERSION), which contains version information.

select banner from v$version where banner like "Oracle Database%";

And you get this kind of string in banner:

Oracle Database 10g Enterprise Edition Release 10.2.0.2.0 - 64bit

So you have to extract the version number.

However, you can use the oci_server_version() function which is simplier to use. for pgsql, you've got a pg_version() and for mysql, you've got mysql_get_server_info().

Perhaps it is better to use them ? See php documentation.

Changed 15 months ago by foxmask

Yes you're totally right !

i check /test and make another patch .

(pg_version was introduce in PHP5 and my query was used in php4 ;)

Changed 15 months ago by foxmask

clearer patch to return the version of the RDBSM used

Changed 15 months ago by foxmask

  • review changed from review- to review?

Changed 15 months ago by laurentj

  • review changed from review? to review-

You forgot to pass parameters (the connection id) to the mysql function and oci functions...

Changed 15 months ago by foxmask

yes, i miss that point for oci.

for mysql

The MySQL connection. If the link identifier is not specified, the last link opened by mysql_connect() is assumed.

but i will add it explicitly to have a "standard" dbVersion behavior

Changed 15 months ago by laurentj

You MUST add it explicitely, because you can open several connection (aka profiles in jelix) to different mysql server, and then the latest opened connection may not be the connection used by the current jDbConnection object you use.

Changed 15 months ago by foxmask

je viens de me rendre compte que je ne peux pas fournir le dblink à la moindre des methodes dbVersion dans les xxx.dbtools.php car le link est protected et dans la class jDbConnection

exemple : ceci

    public function dbVersion() {
        return mysql_get_server_info($this->_conn);
    }

produit l'erreur

[warning 2] mysql_get_server_info(): supplied argument is not a valid MySQL-Link resource

ceci

    public function dbVersion() {
        return mysql_get_server_info($this->_conn->_connect());
    }

produit :

Fatal error: Call to protected method mysqlDbConnection::_connect() from context 'mysqlDbTools

    public function dbVersion() {
        return mysql_get_server_info($this->_conn->_connection);
    }

produit :

Fatal error: Cannot access protected property mysqlDbConnection::$_connection in ...

je me fourvoie ou depuis le début ce n'était pas possible de faire cela ?

Changed 15 months ago by laurentj

Effectivement ce n'est pas possible.

Cependant je viens de trouver une solution. Avec jDbConnection, on essaye toujours d'imiter au maximum l'api de la classe PDO de PHP. Et en fait, pour récupérer la version du serveur et cie, il y a une methode PDO::getAttribute. http://fr3.php.net/manual/en/pdo.getattribute.php

Elle n'est pas implémenté sur jDbConnection. Donc implémente getAttribute sur les classes de connection de chaque driver. Oublie jDbTools donc... Il faut déclarer aussi les constantes ATTR_ sur la classe jDbConnection en reprenant les même valeurs.

rend abstract la méthode jDbConnection::getAttribute et met à jour le commentaire associé. Pour le moment, n'implemente pas tout les ATTR_. Retourne null pour les ATTR non implémenté.

Changed 15 months ago by foxmask

ok, finallement pas si minus que ca le patch ;) aller encore 6 review? en perspective :D

Changed 15 months ago by foxmask

je me suis penché la dessus et j'ai un soucis quant aux constantes ATTR_SERVER_VERSION et ATTR_CLIENT_VERSION (par exemple) :

celle ci ne sont connues qu'une fois la connexion établie avec la base de données, donc je ne vois pas comment les definir dans la class abstraite jDbConnection ??

je verrai bien un public function setAttribute ($id,$value) { define ("ATTR_".$id,$value) }

mais un const ATTR_CLIENT_VERSION, une fois définie on ne peut plus y toucher, non ?

cdt.

Changed 15 months ago by foxmask

Changed 15 months ago by foxmask

  • review changed from review- to review?

Changed 11 months ago by foxmask

qd ca sera ok je push sur mon repo hg.jelix.org yauraplus qu'à pull ;)

Changed 4 months ago by laurentj

  • milestone Jelix 1.2 beta deleted
Note: See TracTickets for help on using tickets.