Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » MySQL tables, Windows/Linux differences

Our old forums are still available as a read-only archive.

Moderators: martimiz, Sean, biapar, Willr, Ingo, simon_w

Page: 1
Go to End
Author Topic: 5709 Views
  • Hamish
    Avatar
    Community Member
    712 Posts

    MySQL tables, Windows/Linux differences Link to this post

    Hi all,

    Just a quick question. I just pulled a site from work (windows environment) to my home machine (Ubuntu) and rebuilt. Can someone explain why in the Linux environment, the table names for classes were capitalised, but not in the Windows version?

    For example, the relationship table "documentsgroup_mydocuments" in windows became "DocumentsGroup_MyDocuments" when built in linux.

    Obviously, if you're developing on one platform this isn't a problem, but I'm switching between the two and it's a major hassle to go through and switch case depending on the machine.

    Cheers

  • Blynx
    Avatar
    Community Member
    20 Posts

    Re: MySQL tables, Windows/Linux differences Link to this post

    This is because Silverstripe uses partially uppercase table names, but in Windows these are automatically converted to lowercase by MySQL.
    See http://open.silverstripe.com/ticket/2476

  • toopy
    Avatar
    Community Member
    8 Posts

    Re: MySQL tables, Windows/Linux differences Link to this post

    That's the reason why I wrote the following php-script. It translates a database
    export-file from lowercase to camelcase and vice versa using an export-file
    of the destination database as template for translation.
    See attached php-script.
    Run the scipt with '?help=1' for an explanation.

  • Blynx
    Avatar
    Community Member
    20 Posts

    Re: MySQL tables, Windows/Linux differences Link to this post

    Cool, that's a big help.
    Thanks!

  • Blynx
    Avatar
    Community Member
    20 Posts

    Re: MySQL tables, Windows/Linux differences Link to this post

    OK, just ran into the same problem again, but this time I took a few minutes to work on the /db/build function. This fixes the problem without the need for any extra scripts:
    In sapphire/core/model/MySQLDatabase.php, edit the following function (I just added lines 3-6):

    public function checkAndRepairTable($tableName) {
    if(!$this->runTableCheckCommand("CHECK TABLE `$tableName`")) {
    if($this->runTableCheckCommand("CHECK TABLE `".strtolower($tableName)."`")) {
    Database::alteration_message("Table $tableName: repaired","repaired");
    return $this->renameTable(strtolower($tableName),$tableName);
    }
    Database::alteration_message("Table $tableName: repaired","repaired");
    return $this->runTableCheckCommand("REPAIR TABLE `$tableName` USE_FRM");
    } else {
    return true;
    }
    }


    Now, whenever the database is copied from a Windows to a Linux machine, just run /db/build and the tables are renamed properly.

  • toopy
    Avatar
    Community Member
    8 Posts

    Re: MySQL tables, Windows/Linux differences Link to this post

    Ok, I will try this next time when I need to move a DB.
    Thanks.

  • Arm
    Avatar
    Community Member
    12 Posts

    Re: MySQL tables, Windows/Linux differences Link to this post

    This problem happened to me as well. I manually renamed the table names in my sql file that were affected and then added Blynx's code and it worked! Thanks Blynx.

    5709 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.