Ressources documentaires pour Mandriva Linux et les Logiciels Libres

Billets dans la catégorie Dev

Using Parse-Dia-SQL to generate SQL from UML Dia diagram and how to install it under Mageia

dia2sql_1It can be tedious when designing an application ( and not using frameworks like Symfony ) to design your database and then create corresponding SQL scripts. Thanks to Parse-Dia-SQL you can design your database using Dia and then generate corresponding SQL script for your database.

Ubuntu users just need to install libparse-dia-sql-perl package.

Windows may download Parse-Dia-SQL installer directly from Dia homepage :

Now let’s see how to install Parse-Dia-SQL under Mageia :

  • Install minimal set of dependencies. To found corresponding Mageia packages, use urpmf –provides –literal. For example to found Html::Lint, just do : urpmf --provides --literal 'perl(Html::Lint)'
  • Install corresponding minimal set of dependencies for : urpmi perl-base perl-Log-Log4perl perl-XML-DOM perl-HTML-Lint perl-Text-Table perl-Text-Aligner perl-Test-Exception
  • Install CPAN : urpmi perl-devel make
  • Now install Parse-Dia-SQL from CPAN : cpan /Parse-Dia-SQL/
  • parsediasql should be installed now in /usr/local/bin/
  • Now to create a SQL file from your Dia diagram, just do : parsediasql --file db_model_file.dia --db dbtype
    • Supported values for dbtype are : mysql-innodb, mysql-myisam, postgres ( for PostgreSQL ), db2, oracle, sqlite3, sqlite3fk, mssql and html

Now to create your UML model with Dia, use Dia’s UML shapes :

  • SQL table are UML Class
  • To mark an attribute as being a primary key, set Visibility = protected
  • To add NOT NULL and DEFAULT xxx to your attributes, first add the default value and then the NULL or NOT NULL  in Value field. For example to have DEFAULT CURRENT_TIMESTAMP NOT NULL on your SQL file, just add CURRENT_TIMESTAMP NOT NULL in Value field
  • Additional indexes can be create in [Operations] tab where :
    • Operation Name = Index name ( e.g table_col_idx )
    • Operation Type = Index type ( INDEX or UNIQUE INDEX )
    • Parameters =  Index columns ( one parameter name for each column name in the index )
    • Stereotype: Index type — For PostgreSQL, you can choose other than btree ( hash, gist, gin ). Please note that GIN indexes may be useful for JSON datatype
  • Foreign-keys constraint are done with UML aggregation tool ( line with a diamond at one end ) in which in its properties you are going to specify foreign-key direction and columns

Please note that for PostgreSQL no need to use typemaps for autoincrement columns, just put SERIAL as attribute type 🙂


Automatic SQL generation using Dia

Database design with Dia

Utilisation de Dia2SQL ( Fr )

Using Dia to Interact With tedia2sql ( Parse-Dia-SQL is a fork of tedia2sql to support latest Dia version, documentation for tedia2sql is relevant for Parse-Dia-SQL too )

Parse-Dia-SQL homepage


Importing a SVN repository from one server to another one

As now I’m using Netbeans, I had issues with key based authentication for CVS project in Netbeans. That’s why I decide to import my CVS project to SVN. At some point, as the SVN repository was on my own personal computer, I decide to move it to a public server I had, but only allow SSH access to it. So here is the procedure to move a SVN repository to another SVN server, and only allow svn+ssh access ( no webdav, no network svnserve access ) under Mandriva.

  1. On your old SVN server, you have to dump the entire SVN repository : [bash light= »1″]svnadmin dump /path/to/your/repository > /tmp/repository.svn_dump[/bash]
  2. Now copy the dump file somewhere on the new SVN server. You may want to use scp if your SSH key based authentication is working correctly. For example : [bash light= »1″]scp /tmp/repository.svn_dump user@new-svn-server:/tmp[/bash]
  3. Once done, you may want to delete the dump file on the old server and eventually delete also the old SVN repo
  4. On your new server, install the SVN server package and its associated tools : [bash light= »1″]urpmi subversion-server subversion-tools[/bash]
  5. check that svnserve is not started at boot by xinetd. For this check /etc/xinetd.d/svnserve configuration file and check that you have disable = yes as follows : [plain]# default: off
    # description: svnserve is the server part of Subversion.
    service svnserve
    disable             = yes
    port                = 3690
    socket_type         = stream
    protocol            = tcp
    wait                = no
    user                = svn
    server              = /usr/bin/svnserve
    server_args         = -i -r /var/lib/svn/repositories
  6. Now create the repository tree on the new server : [bash light= »1″]svnadmin create /var/lib/svn/repositories/[/bash]
  7. Import the dumped repository file in the new SVN repository : [bash light= »1″]svnadmin load /var/lib/svn/repositories/ < /tmp/repository.svn_dump[/bash]
  8. If the importation is successful, now you should ensure that the users connecting with SSH will have write access to the repository. For this add the users to the svn group : [bash light= »1″]usermod -G svn -a user[/bash]
  9. Now add a default ACL for the group to the repository giving read, write and execute ( rwX ) rights to all members of the svn group : [bash light= »1″]setfacl -R -m d:g:svn:rwX /var/lib/svn/repositories/[/bash]
  10. Check that from a remote computer you can list the content of the repository : [bash light= »1″]svn list svn+ssh://user@new-svn-server/var/lib/svn/repositories[/bash]

Happy coding with Subversion 🙂

Ressources :

Netbeans : my new PHP IDE of choice

During a longPHP support dans Netbeans time my PHP development of choice was and the PHP plugin for Eclipse : Please note that there’s another PHP plugin for Eclipse developped by Zend and IBM : also known as the PHP Development Project. However I was mostly using Eclipse and phpeclipse as it was the first PHP plugin I used, and I did appreciate the native integration of CVS and team management tools.

However tonight I decide to give a try to Netbeans with PHP support. What can I say ? I just fall in love. Whereas I have to be used to the new syntax highlighting, PHP support in Netbeans is top for several reasons :

  • Netbeans seems to start faster than Eclipse and can also import Eclipse projects,
  • it support project creation from Zend or Symphony frameworks ( even if I don’t use them ),
  • it supports natively and easily PHP debugging ( with xdebug ) and PHPUnit/Selenium tests,
  • It allows Code Coverage,
  • It correctly support and parsed my CSS files or .sql files,
  • Even better … It allows to connect to your database, view its schema, table structures, and of course execute queries and test your migration SQL scripts,
  • it allows to search through a plugin directly in the PHP manual
  • it can dynamically parsed and handle your PHPDoc tags and then present your PHP file structure with the PHPDoc you add : this is a good insensitive to write correct PHPDoc,
  • Last but not least it provides native CVS and Mercurial integration

In only a few clicks I add way more features than with Eclipse and PHPEclipse. Whereas it’s possible to add xdebug support to eclipse and phpeclipse, the process is not automatic and can be somewhat hard. So finally I switched to Netbeans for my PHP dev. The procedure is very straightforward under Mandriva 2010 Spring as Netbeans packages is already available. Here is the procedure, under Mandriva 2010 Spring, to install Netbeans with a useful and complete PHP development environment :

  1. install the Netbeans 6.8 and its related packages with urpmi : [bash light= »yes »]urpmi netbeans[/bash]
  2. install PHPUnit, xdebug and Selenium : [bash light= »yes »]urpmi php-pear-PHPUnit php-xdebug php-pear-Testing_Selenium[/bash]
  3. restart Apache to activate the PHP extensions : [bash light= »yes »]service httpd restart[/bash]
  4. Now start Netbeans from the menu : Application -> Development -> Development Environment -> Netbeans IDE 6.8
  5. Once Netbeans have started, deline if you wish the registration, and then select on the right pane « Install Plugins« . Here is the list of plugins I did choose for my PHP development : Database, PHP, Php Manual Search, Selenium module for PHP. Installing plugins is very easy, just select them, and then follow the instructions ( most of the time hiting Next or validating a License ). Don’t forget to accept Php Manual and thus even if the plugin is considered as not trusted.
  6. Once your plugins have been installed, restart Netbeans. You may want to decline sending informations about you to Netbeans team.

Now you can import your old Eclipse projects, or if as me you are using a control version system, just checkout your repository ( Team -> CVS -> Checkout ). Mercurial and subversion are supported. For those willing to have Git support, they should have a look at the third party plugin : Netbeans Git Plugin ( homepage : Netbeans Git Module ). To add third parties plugins, download them as .nbm file, then install them with Tools -> Plugins -> [Downloaded] tab -> Add Plugins.

There’s one big caveat however :  Netbeans internal SSH client doesn’t support key authentification. You will have to use password authentification, or create a SSH tunnel. For further informations see

And now happy PHP coding with Netbeans 🙂

PHP Toolbox : determining file mimetype

On the extranet I developed for my society, the users have the ability to upload files, but I do restrict the files types depending on the document’s nature. That’s why i need a way to determined the mimetype of the document in PHP. For this I’m using finfo, here the code as used for a document which have been just uploaded.

function check_document_form($vars)
   // check if file have been correctly uploaded 
   if($_FILES['document']['error'] != 0)
        return FALSE;	

   $fres = finfo_open(FILEINFO_MIME); /* ask to return mime type */

    // it seems that sometimes finfo_file returns mimetype;charset=xxx
    // like "application/pdf;charset=binary"

   // return the first element of the array by using reset
   // $GLOBALS['mimetype_document_tab'] is a global array containing the list of authorized mimetype
  if(!in_array($mimetype, $GLOBALS['mimetype_document_tab']))
      return FALSE;
  return TRUE;

The issue with finfo_file() returning the mimetype and the charset instead of just the mimetype happen with PHP 5.2.9 under Mandriva Spring. I know at least that the charset was not return with 5.2.5 under Mandriva 2008 Spring. As the mimetype and the charset are separated by a semi-column, I’m using explode with ‘;’ as a delimiter to split the string in an array, and then use reset to return the first element of the array. This codeworks even when finfo_file() return just the mimetype.


eZ Components under Mandriva

Since some months, I’m using eZ Components for the intranet of my society. I’m specifically using the Graph component which allow to produce some very beautiful graphs, especially when using the SVG or the Cairo output driver.
At the beginning, I installed eZ Components by using the big tar.bz2 package which contains all the component plus the documentation and the regression tests. This was very big. The best way to install eZ Components and ease its maintenance if your distribution is not providing the packages is to use PEAR. So here is the way to install eZ Components by using PEAR on Mandriva. However this HOWTO may apply to others distributions.

  1. You need to have a working PHP+Apache stack : For this you may use the task-lamp-php metapackage which will install a working Apache + PHP + PEAR setup : [bash light= »1″]urpmi task-lamp-php[/bash]

    As you may noticed, this will install MySQL support. If you’d rather have PostgreSQL support, you just need to install the php-pgsql package.

  2. Install the needed requirements for the eZ Components : Each eZ Components have some requirements on some PHP extensions. You can consult the requirements on the eZ Components requirements page. For all components, you need pcre, reflection and spl support in PHP. Theses supports are available by default in the Mandriva PHP package. The Graph component require for example dom and xml support, and eventually gd support if you want to generate JPG/PNG images. To install the needed requirements, you just need to install the corresponding PHP packages which consist on the PHP extension name prefixed by php- : [bash light= »1″]urpmi php-xml php-dom[/bash]

    . If you want to generate graphics by using the Flash output, you need to install also php-ming. For high quality PNG graphics, you will have to install PHP cairo wrapper. Unfortunately as this package is not bundled in Mandriva, you will have to compile it and install it manually. For this please follow my previous about installation of PHP cairo wrapper under Mandriva

  3. Restart Apache to load PHP extensions : In order to activate the newPHP extension, you need to restart Apache : [bash light= »1″]service httpd restart[/bash]
  4. Add eZ Components PEAR channel : [bash light= »1″]pear channel-discover[/bash]
  5. Install the wanted eZ Components : Now you can easily the components you want to use by using PEAR. For example to install the Graph component you just need to do : [bash light= »1″]pear install ezc/Graph[/bash]

    . If at the contrary you want to install all the eZ Components, then you will use the following commande instead :

    [bash light= »1″]pear install -a ezc/eZComponents[/bash]

  6. Updates handling : To updates the components, you just need to replace install by upgrade in the PEAR command. For example to update the Graph component to a newer version, you will use : [bash light= »1″]pear upgrade ezc/Graph[/bash]

    . People who install the full eZ Components may want to use instead : pear upgrade ezc/eZComponents[/bash]

  7. Add eZ Components support in your PHP script : Adding eZ Components support in your PHP script is easy. On Mandriva, PEAR packages are in the default include/require PATH, so you just need to add the following lines at the top of your PHP scripts to be able to load automatically the different components on demand :
      spl_autoload_register( array( 'ezcBase', 'autoload' ) );

As you can see, adding eZ Components support in your PHP application is easy, and many components may be useful. In some further HOWTO, we will see how to use the graph components by using a wrapper function. However don’t hesitate to consult the well-written eZ Components documentation.


My Tweets