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   5766 Views

Avatar
Hamish

Community Member, 712 Posts

24 May 2008 at 7:08pm

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

Community Member, 20 Posts

24 May 2008 at 7:28pm

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

Community Member, 8 Posts

30 May 2008 at 11:36pm

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

Community Member, 20 Posts

31 May 2008 at 3:08pm

Cool, that's a big help.
Thanks!

Avatar
Blynx

Community Member, 20 Posts

24 July 2008 at 7:47pm

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

Community Member, 8 Posts

6 August 2008 at 6:18pm

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

Avatar
Arm

Community Member, 12 Posts

15 August 2008 at 2:28am

Edited: 15/08/2008 2:28am

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.