Flourish PHP Unframework
This is an archived copy of the forum for reference purposes

column info

posted by mungiu 9 years ago

it's there a way to receive a column info comment or to hope in a future "improvement"? mi tgry to make automatic form like:

switch ($detalii["type"])
				{
				case "varchar":
					$form->addField("text", $column, ucfirst($column) , false, null);
					break;
					
				case "date":
					$form->addField("text", $column, ucfirst($column) , false, null);
					break;

				case "text":
					$form->addField("textarea", $column, ucfirst($column) , false, null, "cols='40' rows='7'");
					break;
				}


and because enum become varchar and other datatype changes i want to note in comment about what field to html.
 [titlu] => Array
        (
            [type] => varchar
            [max_length] => 100
            [not_null] => {true}
            [placeholder] => %s
            [default] => {null}
            [valid_values] => {null}
            [max_value] => {null}
            [min_value] => {null}
            [decimal_places] => {null}
            [auto_increment] => {false}
        )

so a comment = "" will be useful for me.

I've done a bunch of this kind of metaprogramming - that is why fSchema was written. You can detect if a column is a enum by looking at the valid_values element.

In terms of returning the comment, I don't know if that is possible using the technique I'm using in fSchema. I presume you are using MySQL?

posted by wbond 9 years ago

Yes i use mysql and for now i change in fSchema like this:

			// Comments
			if (!empty($match[8])) {
				$info['comment'] = substr($match[8], 10, -1);
			}

and i receive the comment . i need more than a enum like file, ajax, etc. and the comment is't perfect for this. now i can make a grid with CRUD for entire database only writing corect url. but must be careful when i update the version of flourish to not overwrite the file.

posted by mungiu 9 years ago

If you are going to do that, I recommend you:

  1. Create a github account and fork http://github.com/wbond/flourish
  2. Clone your flourish fork
  3. Make the code change
  4. Commit
  5. Push
  6. Every once in a while go to your github fork of Flourish and click on "Fork Queue" to pull in the changes from the main copy of Flourish
  7. Use the source of your fork for your project until I am able to add the functionality to fSchema

Also, be sure to add a ticket for this functionality to ensure I remember to do it.

posted by wbond 9 years ago

Just as a reference for anyone listed, the following database engines support column comments:

  • MySQL
  • PostgreSQL
  • Oracle
  • DB2

SQLite and SQL Server do not appear to have comment functionality.

posted by wbond 9 years ago

Tanks for advice and taking consideration for comment functionality.

posted by mungiu 9 years ago

This functionality was added in r938.

Also of note, all database types supported by Flourish have support for this functionality. In SQL Server, the MS_Description extended property is used (this is called the Description in SQL Server Management Studio). For SQLite, raw SQL comments are parsed for each line that defines a column in a CREATE TABLE statement.

posted by wbond 9 years ago