Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

MysqlDesc for Reverse Task #672

Closed
wants to merge 1 commit into from

7 participants

@florianpotthoff

We added functionality to read Column Description from Mysql Tables into schema.xml in the reverse task.

@staabm
Collaborator

I like the change. could you please add a unit-test?

@willdurand
Owner

looks good, but yeah a unit test would be nice!

@jaugustin jaugustin commented on the diff
generator/lib/reverse/mysql/MysqlSchemaParser.php
@@ -235,6 +236,9 @@ public function getColumnFromRow($row, Table $table)
$column = new Column($name);
$column->setTable($table);
$column->setDomainForType($propelType);
+ if ($desc) {
+ $column->setDescription(utf8_encode($desc));
@jaugustin Collaborator

Why is utf8_encode needed ?

we had the problem that mysql returned the description latin1 encoded. we needed utf8. if we queried tables of our databases we got things in utf8 like expected. but not in the description response. so we decided to simply encode this utf8. may be we're doing something wrong. any ideas? the actual way works right now.

@staabm Collaborator
staabm added a note

maybe your DSN should include the encoding param?

Our runtime.xml looks like:

<?xml version="1.0" encoding="UTF-8"?>
<config>
  <propel>
    <datasources default="somesource">
      <datasource id="somesource">
        <adapter>mysql</adapter>
        <connection>
          <dsn>mysql:host=***;dbname=***</dsn>
          <user>***</user>
          <password>***</password>
          <settings>
            <setting id="charset">utf8</setting>
          </settings>
          <options>
            <option id="MYSQL_ATTR_INIT_COMMAND">SET NAMES utf8</option>
          </options>
        </connection>
      </datasource>
    </datasources>
  </propel>
</config>

Is anything missing to archive a good utf8 speaking connection? the schema and the tables are configured for utf8_bin. we receive all in utf8 but the table comments.

@staabm Collaborator
staabm added a note

Maybe the comments itself are not stored with the propery encoding in the db?

no that seems not to be the case

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@Pluto1010

hey I'll write the test these days. I'm really busy right now. Sry that it lacks one at this time. It was a quick fix within product-development.

@willdurand
Owner

ping @Pluto1010

@Pluto1010

Sorry for the late reply. I've realized that I'm not able to write the test. I've looked other tests in the propel project. It seems to me that sqlite is used for unit testing. sqlite does not support comments on fields like mysql. I'm new to unit testing and I don't know what I can do now. Can anybody help? Sorry thats not the way a pull request should go. I know that.

@Pluto1010

ping?

@emiliomg

Since I am interested in this Pull Request: Ping!

@staabm
Collaborator

@Pluto1010 @ejanzen anyone of you willing to provide a unit test?

In travis the suite runs with mysql so you could add a test which skips in case the current connection is not a instanceof a MysqlConnection

@stood

The function 'addColumns' has changed and a new function has been created 'getColumnFromRow'. The PR is obsolete. Write a new PR with a Test ?

@staabm
Collaborator

@stood are you willing to provide a up2date PR?

@stood

why not ;) i will try

@stood stood referenced this pull request
Merged

Mysqldesc for reverse task #821

@staabm
Collaborator

will be handled in #821

@staabm staabm closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 23, 2013
  1. @Pluto1010
This page is out of date. Refresh to see the latest.
Showing with 5 additions and 1 deletion.
  1. +5 −1 generator/lib/reverse/mysql/MysqlSchemaParser.php
View
6 generator/lib/reverse/mysql/MysqlSchemaParser.php
@@ -153,7 +153,7 @@ public function parse(Database $database, Task $task = null)
*/
protected function addColumns(Table $table)
{
- $stmt = $this->dbh->query("SHOW COLUMNS FROM `" . $table->getName() . "`");
+ $stmt = $this->dbh->query("SHOW FULL COLUMNS FROM `" . $table->getName() . "`");
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
$column = $this->getColumnFromRow($row, $table);
@@ -179,6 +179,7 @@ public function getColumnFromRow($row, Table $table)
$precision = null;
$scale = null;
$sqlType = false;
+ $desc = $row['Comment'];
$regexp = '/^
(\w+) # column type [1]
@@ -235,6 +236,9 @@ public function getColumnFromRow($row, Table $table)
$column = new Column($name);
$column->setTable($table);
$column->setDomainForType($propelType);
+ if ($desc) {
+ $column->setDescription(utf8_encode($desc));
@jaugustin Collaborator

Why is utf8_encode needed ?

we had the problem that mysql returned the description latin1 encoded. we needed utf8. if we queried tables of our databases we got things in utf8 like expected. but not in the description response. so we decided to simply encode this utf8. may be we're doing something wrong. any ideas? the actual way works right now.

@staabm Collaborator
staabm added a note

maybe your DSN should include the encoding param?

Our runtime.xml looks like:

<?xml version="1.0" encoding="UTF-8"?>
<config>
  <propel>
    <datasources default="somesource">
      <datasource id="somesource">
        <adapter>mysql</adapter>
        <connection>
          <dsn>mysql:host=***;dbname=***</dsn>
          <user>***</user>
          <password>***</password>
          <settings>
            <setting id="charset">utf8</setting>
          </settings>
          <options>
            <option id="MYSQL_ATTR_INIT_COMMAND">SET NAMES utf8</option>
          </options>
        </connection>
      </datasource>
    </datasources>
  </propel>
</config>

Is anything missing to archive a good utf8 speaking connection? the schema and the tables are configured for utf8_bin. we receive all in utf8 but the table comments.

@staabm Collaborator
staabm added a note

Maybe the comments itself are not stored with the propery encoding in the db?

no that seems not to be the case

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ }
if ($sqlType) {
$column->getDomain()->replaceSqlType($sqlType);
}
Something went wrong with that request. Please try again.