developer.jelix.org is not used any more and exists only for history. Post new tickets on the Github account.
developer.jelix.org n'est plus utilisée, et existe uniquement pour son historique. Postez les nouveaux tickets sur le compte github.

Opened 11 years ago

Closed 9 years ago

#913 closed enhancement (fixed)

dbVersion to jDbTools

Reported by: foxmask Owned by:
Priority: normal Milestone: Jelix 1.3 beta 1
Component: jelix:db Version: trunk
Severity: normal Keywords:
Cc: Blocked By:
Blocking: Documentation needed: no
Hosting Provider: Php version:

Description

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

Attachments (5)

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

Download all attachments as: .zip

Change History (22)

Changed 11 years ago by foxmask

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

Changed 11 years ago by foxmask

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

comment:1 Changed 11 years ago by laurentj

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

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.

comment:2 Changed 11 years ago by laurentj

  • Type changed from bug to enhancement

Changed 11 years ago by foxmask

dbVersion as asbtract in jDbTools + phpdoc

comment:3 Changed 11 years ago by foxmask

  • review changed from review- to review?

comment:4 Changed 11 years 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.

comment:5 Changed 11 years 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 11 years ago by foxmask

clearer patch to return the version of the RDBSM used

comment:6 Changed 11 years ago by foxmask

  • review changed from review- to review?

comment:7 Changed 11 years ago by laurentj

  • review changed from review? to review-

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

comment:8 Changed 11 years 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

comment:9 Changed 11 years 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.

comment:10 Changed 11 years 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 ?

comment:11 Changed 11 years 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é.

comment:12 Changed 11 years ago by foxmask

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

comment:13 Changed 11 years 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 11 years ago by foxmask

comment:14 Changed 11 years ago by foxmask

  • review changed from review- to review?

comment:15 Changed 11 years ago by foxmask

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

comment:16 Changed 10 years ago by laurentj

  • Milestone Jelix 1.2 beta deleted

comment:17 Changed 9 years ago by laurentj

  • Milestone set to Jelix 1.3
  • Resolution set to fixed
  • review changed from review? to review-
  • Status changed from new to closed

En fait, les constantes ATTR_*, ce sont des "clés" pour récupérer les valeurs, à donner à getAttribute ou setAttribute. elles ne contiennent pas les valeurs proprement dites.

fixed. https://bitbucket.org/jelix/jelix-trunk/changeset/104ae62ae49b

Note: See TracTickets for help on using tickets.