Exemple #1
0
 /**
  * Gets the HTML code.
  *
  * @param EcrTable $table A EcrTable object
  * @param string $indent Indentation string
  *
  * @return string HTML
  */
 public function getCode(EcrTable $table, $indent = '')
 {
     $ret = '';
     $started = false;
     foreach ($table->getFields() as $field) {
         $ret .= $started ? $indent . ', ' : $indent . '  ';
         $started = true;
         $ret .= EcrTableHelper::formatSqlField($field);
         $ret .= NL;
     }
     //foreach
     return $ret;
 }
Exemple #2
0
    /**
     * Get the CREATE string for a table.
     *
     * @param EcrTable $table The table
     *
     * @return string
     */
    public static function getTableCreate(EcrTable $table)
    {
        $db = JFactory::getDBO();
        $dbName = JFactory::getApplication()->getCfg('db');
        $tName = $db->getPrefix() . $table->name;
        $s = '';
        $s .= 'CREATE TABLE IF NOT EXISTS `#__' . $table->name . '` (' . NL;
        $pri = '';
        $started = false;
        $indent = '';
        $db->setQuery('SHOW CREATE TABLE ' . $tName);
        $engineQuery = 'SELECT ENGINE
 FROM information_schema.TABLES
 WHERE TABLE_SCHEMA = \'' . $dbName . '\'
 AND TABLE_NAME = \'' . $tName . '\'';
        $db->setQuery($engineQuery);
        $engine = $db->loadResult();
        echo 'A' . $engine;
        /*
        //        $engineQuery = ' SHOW TABLE STATUS LIKE `'.$tName.'`
        // FROM information_schema.TABLES
        // WHERE TABLE_SCHEMA = \''.$dbName.'\'
        // AND TABLE_NAME = \''.$tName.'\'';
        //        $db->setQuery($engineQuery);
        //
        //        $engine = $db->loadResult();
        //        echo 'B'.$engine;
        */
        foreach ($table->getFields() as $field) {
            if ($field->key == 'PRI') {
                $pri = $field->name;
            }
            $s .= $started ? $indent . ', ' : $indent . '  ';
            $started = true;
            $s .= EcrTableHelper::formatSqlField($field);
            $s .= NL;
        }
        //foreach
        if ($pri) {
            $s .= ', PRIMARY KEY (`' . $pri . '`)';
        }
        //-- #       $s .= ') ENGINE='.$engine.' DEFAULT CHARSET='.
        return $s;
    }