Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Archive

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

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

MySQL tables, Windows/Linux differences


Reply

7 Posts   5731 Views

Avatar
Hamish

24 May 2008 at 7:08pm Community Member, 712 Posts

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

Avatar
Blynx

24 May 2008 at 7:28pm Community Member, 20 Posts

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

Avatar
toopy

30 May 2008 at 11:36pm Community Member, 8 Posts

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.

Avatar
Blynx

31 May 2008 at 3:08pm Community Member, 20 Posts

Cool, that's a big help.
Thanks!

Avatar
Blynx

24 July 2008 at 7:47pm Community Member, 20 Posts

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.

Avatar
toopy

6 August 2008 at 6:18pm Community Member, 8 Posts

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

Avatar
Arm

15 August 2008 at 2:28am (Last edited: 15 August 2008 2:28am), Community Member, 12 Posts

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.