Ejemplo n.º 1
0
Archivo: dbrm.php Proyecto: jemdev/dbrm
 public function finishTransaction($bOk)
 {
     if (is_null($this->_oVue)) {
         $this->getVueInstance();
     }
     $this->_oVue->finishTransaction($bOk);
 }
Ejemplo n.º 2
0
 private function _getInfosSequence($table)
 {
     $sql = "SELECT sequence_name" . PHP_EOL . "  FROM information_schema.sequences" . PHP_EOL . "WHERE sequence_catalog = :p_schema" . PHP_EOL . "  AND sequence_name LIKE '" . $table . "%'";
     $params = array(':p_schema' => $this->_schemacible);
     $this->_oVue->setRequete($sql, $params);
     $sequence = $this->_oVue->fetchOne();
     return $sequence;
 }
Ejemplo n.º 3
0
 public function getViewTables($viewName)
 {
     $sql = "SELECT " . "  view_definition " . "FROM " . $this->_metaschema . ".VIEWS " . "WHERE table_schema = :p_table_schema " . "  AND table_name   = :p_view_name";
     $params = array(':p_table_schema' => $this->_schemacible, ':p_view_name' => $viewName);
     $this->_oVue->setRequete($sql, $params);
     $definition = $this->_oVue->fetchOne();
     if (is_null($this->_oSelectTablesName)) {
         $this->_oSelectTablesName = new selectTablesNames();
     }
     $this->_oSelectTablesName->setNewQuery($definition);
     $aTables = $this->_oSelectTablesName->getTables(true);
     return $aTables;
 }
Ejemplo n.º 4
0
    /**
     * Appel de génération du fichier de configuration
     *
     * @param   jemdev\dbrm\dbVue   $oVue           Instance de la classe de vues.
     * @param   String              $fichierCible   Chemin vers le fichier cible.
     * @return  Boolean                             Indique la réussite ou l'échec de la procédure.
     */
    public function genererConf(vue $oVue, $fichierCible)
    {
        switch ($this->_typeserveur) {
            case 'pgsql':
                $this->_oSchemaInfos = new getSchemaInfosPgsql($oVue, $this->_schemacible);
                break;
            case 'mysql':
            default:
                $this->_oSchemaInfos = new getSchemaInfosMysql($oVue, $this->_schemacible);
        }
        $this->_oVue = $oVue;
        $oVue->setTmpActivationCache(false);
        $dbConf = null;
        $configSchema = $this->_getConf();
        $ns = 0;
        if (file_exists($fichierCible)) {
            include_once $fichierCible;
            /**
             * Note : la variable $dbConf devra avoir été définie et initialisée dans le
             * fichier inclus.
             */
            if (isset($dbConf) && count($dbConf) > 0) {
                foreach ($dbConf as $n => $confSchema) {
                    if ($confSchema['schema']['name'] == $this->_schemacible) {
                        $dbConf[$n] = $configSchema;
                        $ns = $n;
                        $aConf = $dbConf;
                        break;
                    }
                }
            } else {
                $aConf = array($ns => $configSchema);
            }
        } else {
            $aConf = array($ns => $configSchema);
        }
        /**
         * En-tête du fichier de configuration
         */
        $dategeneration = date('d/m/Y h:m:i');
        $sFichier = <<<CODE_PHP
<?php
/**
 * @package     jemdev
 *
 * Ce code est fourni tel quel sans garantie.
 * Vous avez la liberté de l'utiliser et d'y apporter les modifications
 * que vous souhaitez. Vous devrez néanmoins respecter les termes
 * de la licence CeCILL dont le fichier est joint à cette librairie.
 * {@see http://www.cecill.info/licences/Licence_CeCILL_V2-fr.html}
 *
 * Date de génération du fichier : {$dategeneration}
 */

/**
 * Définition des constantes sur les types de données
 */
defined('TYPE_INTEGER') || define('TYPE_INTEGER', 'INT');

CODE_PHP;
        foreach ($this->_aTypesDonnees as $k => $type) {
            $sType = strtoupper($k);
            $sVal = strtoupper($type);
            $sFichier .= <<<CODE_PHP
defined('{$sType}') || define('{$k}', '{$sVal}');

CODE_PHP;
        }
        $sFichier .= <<<CODE_PHP
/**
 * Description détaillée des schémas
 */
\$dbConf = array(

CODE_PHP;
        foreach ($aConf as $n => $conf) {
            $sFichier .= <<<CODE_PHP
    {$n} => array(
        'schema' => array(
            'name'   => DB_APP_SCHEMA,
            'SGBD'   => DB_ROOT_TYPEDB,
            'server' => DB_APP_SERVER,
            'port'   => DB_ROOT_DBPORT,
            'user'   => DB_APP_USER,
            'mdp'    => DB_APP_PASSWORD,
            'pilote' => DB_ROOT_TYPEDB
        ),
        'tables' => array(

CODE_PHP;
            $nt = count($conf['tables']);
            $t = 0;
            foreach ($conf['tables'] as $table => $aCols) {
                $eot = $t < $nt - 1 ? ',' : null;
                $sFichier .= <<<CODE_PHP
            '{$table}' => array(
                'fields' => array(

CODE_PHP;
                $nf = count($aCols['fields']);
                $c = 0;
                foreach ($aCols['fields'] as $col => $aDetails) {
                    $eof = $c < $nf - 1 ? ',' : null;
                    $sFichier .= <<<CODE_PHP
                    '{$col}' => array(
                        'type'   => {$aDetails['type']},
                        'length' => {$aDetails['length']},
                        'null'   => {$aDetails['null']},

CODE_PHP;
                    if ($aDetails['attr'] == 'null') {
                        $sFichier .= <<<CODE_PHP
                        'attr'   => null

CODE_PHP;
                    } else {
                        $sFichier .= <<<CODE_PHP
                        'attr'   => array(

CODE_PHP;
                        $na = count($aDetails['attr']);
                        $ina = 1;
                        foreach ($aDetails['attr'] as $d => $v) {
                            $virg = $ina < $na ? "," : null;
                            $s = $d == 'default' && ($aDetails['type'] == 'TYPE_INTEGER' || $aDetails['type'] == 'TYPE_MEDIUMINT' || $aDetails['type'] == 'TYPE_TINYINT' || $aDetails['type'] == 'TYPE_SMALLINT' || $aDetails['type'] == 'TYPE_DECIMAL' || $aDetails['type'] == 'TYPE_FLOAT') || $d == 'vals' ? $v : "'" . $v . "'";
                            $sFichier .= <<<CODE_PHP
                            '{$d}' => {$s}{$virg}

CODE_PHP;
                            $ina++;
                        }
                        $sFichier .= <<<CODE_PHP
                        )

CODE_PHP;
                    }
                    $sFichier .= <<<CODE_PHP
                    ){$eof}

CODE_PHP;
                    $c++;
                }
                $sFichier .= <<<CODE_PHP
                ),
                'key' => array(

CODE_PHP;
                if (isset($aCols['keys']['pk'])) {
                    $sFichier .= <<<CODE_PHP
                    'pk' => array(

CODE_PHP;
                    foreach ($aCols['keys']['pk'] as $pk) {
                        $sFichier .= <<<CODE_PHP
                        '{$pk}'

CODE_PHP;
                    }
                    $eopk = isset($aCols['keys']['fk']) || isset($aCols['keys']['uk']) ? ',' : null;
                    $sFichier .= <<<CODE_PHP
                    ){$eopk}

CODE_PHP;
                }
                if (isset($aCols['keys']['uk'])) {
                    $sFichier .= <<<CODE_PHP
                    'uk' => array(

CODE_PHP;
                    foreach ($aCols['keys']['uk'] as $uk) {
                        $sFichier .= <<<CODE_PHP
                        '{$uk}',

CODE_PHP;
                    }
                    $eouk = isset($aCols['keys']['fk']) ? ',' : null;
                    $sFichier .= <<<CODE_PHP
                    ){$eouk}

CODE_PHP;
                }
                if (isset($aCols['keys']['fk'])) {
                    $sFichier .= <<<CODE_PHP
                    'fk' => array(

CODE_PHP;
                    $nfk = count($aCols['keys']['fk']);
                    for ($ifk = 0; $ifk < $nfk; $ifk++) {
                        $afk = array_keys($aCols['keys']['fk'][$ifk]);
                        $k = $afk[0];
                        $aft = array_keys($aCols['keys']['fk'][$ifk][$k]);
                        $ft = $aft[0];
                        $fk = $aCols['keys']['fk'][$ifk][$k][$ft];
                        $eoa = $ifk < $nfk - 1 ? ',' : null;
                        $sFichier .= <<<CODE_PHP
                        '{$k}' => array('{$ft}' => '{$fk}'){$eoa}

CODE_PHP;
                    }
                    $sFichier .= <<<CODE_PHP
                    )

CODE_PHP;
                }
                $sFichier .= <<<CODE_PHP
                )
            ){$eot}

CODE_PHP;
                $t++;
            }
            $sFichier .= <<<CODE_PHP
CODE_PHP;
            $sFichier .= <<<CODE_PHP
        ),
        'relations' => array(

CODE_PHP;
            $nr = count($conf['relations']);
            $r = 0;
            foreach ($conf['relations'] as $table => $aCols) {
                $aFks = $this->_oSchemaInfos->getReferencesFK($table);
                $eor = $r < $nr - 1 ? ',' : null;
                $sFichier .= <<<CODE_PHP
            '{$table}' => array(
                'fields' => array(

CODE_PHP;
                $nf = count($aCols['fields']);
                $c = 0;
                foreach ($aCols['fields'] as $col => $aDetails) {
                    $eof = $c < $nf - 1 ? ',' : null;
                    $sFichier .= <<<CODE_PHP
                    '{$col}' => array(
                        'type'   => {$aDetails['type']},
                        'length' => {$aDetails['length']},
                        'null'   => {$aDetails['null']},

CODE_PHP;
                    if ($aDetails['attr'] == 'null') {
                        $sFichier .= <<<CODE_PHP
                        'attr'   => null

CODE_PHP;
                    } else {
                        $sFichier .= <<<CODE_PHP
                        'attr'   => array(

CODE_PHP;
                        foreach ($aDetails['attr'] as $d => $v) {
                            $s = $d == 'default' && ($aDetails['type'] == 'TYPE_INTEGER' || $aDetails['type'] == 'TYPE_MEDIUMINT' || $aDetails['type'] == 'TYPE_TINYINT' || $aDetails['type'] == 'TYPE_SMALLINT' || $aDetails['type'] == 'TYPE_DECIMAL' || $aDetails['type'] == 'TYPE_FLOAT') || $d == 'vals' ? $v : "'" . $v . "'";
                            $sFichier .= <<<CODE_PHP
                            '{$d}' => {$s},

CODE_PHP;
                        }
                        $sFichier .= <<<CODE_PHP
                        )

CODE_PHP;
                    }
                    $sFichier .= <<<CODE_PHP
                    ){$eof}

CODE_PHP;
                    $c++;
                }
                $sFichier .= <<<CODE_PHP
                ),
                'key' => array(

CODE_PHP;
                if (isset($aCols['keys']['pk'])) {
                    $sFichier .= <<<CODE_PHP
                    'pk' => array(

CODE_PHP;
                    foreach ($aCols['keys']['pk'] as $pk) {
                        $sFichier .= <<<CODE_PHP
                        '{$pk}',

CODE_PHP;
                    }
                    $eopk = isset($aCols['keys']['fk']) ? ',' : null;
                    $sFichier .= <<<CODE_PHP
                    ),

CODE_PHP;
                }
                $sFichier .= <<<CODE_PHP
                    'fk' => array(

CODE_PHP;
                $nfk = count($aFks);
                for ($ifk = 0; $ifk < $nfk; $ifk++) {
                    $eoa = $ifk < $nfk - 1 ? ',' : null;
                    $sFichier .= <<<CODE_PHP
                        '{$aFks[$ifk]['column_name']}' => array('{$aFks[$ifk]['referenced_table_name']}' => '{$aFks[$ifk]['referenced_column_name']}'){$eoa}

CODE_PHP;
                }
                $sFichier .= <<<CODE_PHP
                    )

CODE_PHP;
                $sFichier .= <<<CODE_PHP
                )
            ){$eor}

CODE_PHP;
                $r++;
            }
            $sFichier .= <<<CODE_PHP
CODE_PHP;
            $sFichier .= <<<CODE_PHP
        ),
        'vues' => array(

CODE_PHP;
            $nv = count($conf['vues']);
            $w = 0;
            foreach ($conf['vues'] as $table => $aCols) {
                $aViewTables = $this->_oSchemaInfos->getViewTables($table);
                $eov = $w < $nv - 1 ? ',' : null;
                $sFichier .= <<<CODE_PHP
            '{$table}' => array(
                'fields' => array(

CODE_PHP;
                foreach ($aCols['fields'] as $col => $aDetails) {
                    $sFichier .= <<<CODE_PHP
                    '{$col}' => array(
                        'type'   => {$aDetails['type']},
                        'length' => {$aDetails['length']},
                        'null'   => {$aDetails['null']},

CODE_PHP;
                    if ($aDetails['attr'] == 'null') {
                        $sFichier .= <<<CODE_PHP
                        'attr'   => null

CODE_PHP;
                    } else {
                        $sFichier .= <<<CODE_PHP
                        'attr'   => array(

CODE_PHP;
                        foreach ($aDetails['attr'] as $d => $v) {
                            $s = $d == 'default' && ($aDetails['type'] == 'TYPE_INTEGER' || $aDetails['type'] == 'TYPE_MEDIUMINT' || $aDetails['type'] == 'TYPE_TINYINT' || $aDetails['type'] == 'TYPE_SMALLINT' || $aDetails['type'] == 'TYPE_DECIMAL' || $aDetails['type'] == 'TYPE_FLOAT') || $d == 'vals' ? $v : "'" . $v . "'";
                            $sFichier .= <<<CODE_PHP
                            '{$d}' => {$s},

CODE_PHP;
                        }
                        $sFichier .= <<<CODE_PHP
                        )

CODE_PHP;
                    }
                    $sFichier .= <<<CODE_PHP
                    ),

CODE_PHP;
                }
                $sFichier .= <<<CODE_PHP
                ),
                'tables' => array(

CODE_PHP;
                $nvt = count($aViewTables);
                $n = 0;
                foreach ($aViewTables as $t) {
                    $evt = $n < $nvt - 1 ? ',' : null;
                    $sFichier .= <<<CODE_PHP
                    '{$t}'{$evt}

CODE_PHP;
                    $n++;
                }
                $sFichier .= <<<CODE_PHP
                )
            ){$eov}

CODE_PHP;
                $w++;
            }
            $sFichier .= <<<CODE_PHP
CODE_PHP;
            $sFichier .= <<<CODE_PHP
        )
    )

CODE_PHP;
        }
        /**
         * Fermeture du fichier de configuration
         */
        $sFichier .= <<<CODE_PHP
);
CODE_PHP;
        $retour = false;
        if (false !== ($f = fopen($fichierCible, 'w+'))) {
            $ecriture = fwrite($f, $sFichier);
            fclose($f);
            $retour = is_int($ecriture) ? true : false;
            if (true === $retour) {
                $this->_compacterDbConf($fichierCible);
            }
        }
        if (defined('DBCACHE_ACTIF')) {
            $oVue->setTmpActivationCache(DBCACHE_ACTIF);
        }
        return $retour;
    }
Ejemplo n.º 5
0
Archivo: dbrm.php Proyecto: jemdev/dbrm
 /**
  * Récupération de l'instance d'accès aux données.
  *
  * @return jemdev\dbrm\vue
  */
 public function getVueInstance()
 {
     if (is_null($this->_oVue)) {
         $this->_oVue = vue::getInstance($this->_aDbConf[0]);
     }
     return $this->_oVue;
 }
Ejemplo n.º 6
0
Archivo: cnx.php Proyecto: jemdev/dbrm
 /**
  * Lancement de la génération du fichier de configuration de base de données.
  *
  * @param String    $rep_conf       Chemin vers le répertoire de stockage du fichier généré
  * @param String    $schema         Nom du schéma dont on veut la description
  * @param String    $schemauser     Nom d'utilisateur pouvant accéder à information_schema (mode production)
  * @param String    $schemamdp      Mot de passe de l'utilisateur (mode production)
  * @param String    $rootuser       Nom de l'utilisateur root qui doit se connecter à information_Schema
  * @param String    $rootmdp        Mot-de-passe de l'utilisateur root qui doit se connecter à information_Schema
  * @param String    $typeserveur    Type de serveur (MySQL, [Oracle ?], pgSql, etc...)
  * @param String    $host           Serveur où est situé information_schema
  * @param Int       $port           Port à utiliser pour la connexion au serveur où est information_schema
  * @param String    $schemauserdev  Nom d'utilisateur du schéma à décrire (mode développement)
  * @param String    $schemamdpdev   Mot de passe de l'utilisateur du schéma à décrire (mode développement)
  * @return  Boolean
  */
 public static function setFichierConf($rep_conf, $schema, $schemauser, $schemamdp, $rootuser = '******', $rootmdp = '', $typeserveur = 'mysql', $host = 'localhost', $port = null, $schemauserdev = null, $schemamdpdev = null)
 {
     defined("DS") || define("DS", DIRECTORY_SEPARATOR);
     $rep_db = realpath(dirname(__FILE__));
     $sPathExecute = $rep_db . DS . 'dbExecute.php';
     $sPathVue = $rep_db . DS . 'dbVue.php';
     $sFichierConf = $rep_conf . DS . 'dbConf.php';
     /**
      * On établit la connexion.
      * Pour l'instant, on tapera uniquement sur MySQL donc ce sera dans
      * INFORMATION_SCHEMA. Ultérieurement il faudra développer les
      * requêtes appropriées pour d'autres types de serveurs n'implémentant
      * pas cette règle du SQL92.
      */
     $dbConf = array('schema' => array('name' => 'information_schema', 'SGBD' => $typeserveur, 'server' => $host, 'port' => $port, 'user' => $rootuser, 'mdp' => $rootmdp, 'pilote' => $typeserveur));
     require_once $rep_db . DS . 'init' . DS . 'genereconf.php';
     require_once $sPathExecute;
     require_once $sPathVue;
     // $oVue = new vue($dbConf);
     $oVue = vue::getInstance($dbConf);
     $oConf = new genereconf($schema, $schemauser, $schemamdp, $rootuser, $rootmdp, $typeserveur, $host, $port, $schemauserdev, $schemamdpdev);
     $sConf = $oConf->genererConf($oVue, $sFichierConf);
     return false !== $sConf;
 }