Question

I created one extension and when i test it on other versions , it give me error

Error in file: "/var/www/mage_sample/app/code/local/MYD/Module/sql/findyoursize_setup/mysql4-install-0.1.0.php" - SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1.

when i try the same code in sql it works.Can anyone helps where the problem is ? I try so much and stuck now. Below is my installer code :

$installer = $this;

$installer->startSetup();

$installer->run("

 DROP TABLE IF EXISTS {$this->getTable('dimensions')};
CREATE TABLE {$this->getTable('dimensions')} (                            
              `dimension_id` int(11) NOT NULL AUTO_INCREMENT,        
              `label` varchar(250) DEFAULT NULL,                     
              `code` varchar(250) DEFAULT NULL,                      
              PRIMARY KEY (`dimension_id`)                           
            ) ENGINE=InnoDB  DEFAULT CHARSET=latin1;



DROP TABLE IF EXISTS {$this->getTable(`standards`)};
CREATE TABLE {$this->getTable(`standards`)} (                    
            `standards_id` int(10) NOT NULL AUTO_INCREMENT,        
             `name` varchar(250) DEFAULT NULL,                      
             PRIMARY KEY (`standards_id`)                           
           ) ENGINE=InnoDB  DEFAULT CHARSET=latin1;

DROP TABLE IF EXISTS {$this->getTable(`standards_values`)};
CREATE TABLE {$this->getTable(`standards_values`)} (                                                                                                       
                   `standards_id` int(11) DEFAULT NULL,                    
                    `value` varchar(250) DEFAULT NULL,                      
                    `order` int(4) DEFAULT NULL,                            
                    `value_id` int(8) NOT NULL AUTO_INCREMENT,              
                    UNIQUE KEY `value_id` (`value_id`),                     
                    KEY `FK_standards_values` (`standards_id`)              
                  ) ENGINE=InnoDB  DEFAULT CHARSET=latin1              

 insert  into  {$this->getTable('dimensions')}(`dimension_id`,`label`,`code`) values (1,'Chest','chest');
insert  into `dimensions`(`dimension_id`,`label`,`code`) values (2,'Waist','waist');
insert  into `dimensions`(`dimension_id`,`label`,`code`) values (3,'Inseam ','inseam ');
insert  into `dimensions`(`dimension_id`,`label`,`code`) values (4,'Hips','hips');
insert  into `dimensions`(`dimension_id`,`label`,`code`) values (5,'Thigh','thigh');
insert  into `dimensions`(`dimension_id`,`label`,`code`) values (6,'Weight','weight');
insert  into `dimensions`(`dimension_id`,`label`,`code`) values (8,'Neck','neck');");


$installer->endSetup(); 
Was it helpful?

Solution

  1. Missing final semicolon (;)

DROP TABLE IF EXISTS {$this->getTable(standards_values)}; CREATE TABLE {$this->getTable(standards_values)} (

               `standards_id` int(11) DEFAULT NULL,                    
                `value` varchar(250) DEFAULT NULL,                      
                `order` int(4) DEFAULT NULL,                            
                `value_id` int(8) NOT NULL AUTO_INCREMENT,              
                UNIQUE KEY `value_id` (`value_id`),                     
                KEY `FK_standards_values` (`standards_id`)              
              ) ENGINE=InnoDB  DEFAULT CHARSET=latin1

Should be:

DROP TABLE IF EXISTS {$this->getTable(`standards_values`)};
CREATE TABLE {$this->getTable(`standards_values`)} (                                                                                                       
                   `standards_id` int(11) DEFAULT NULL,                    
                    `value` varchar(250) DEFAULT NULL,                      
                    `order` int(4) DEFAULT NULL,                            
                    `value_id` int(8) NOT NULL AUTO_INCREMENT,              
                    UNIQUE KEY `value_id` (`value_id`),                     
                    KEY `FK_standards_values` (`standards_id`)              
                  ) ENGINE=InnoDB  DEFAULT CHARSET=latin1;
  1. No getTable used but thats a minor problem:

insert into dimensions(dimension_id,label,code)

should be:

insert into {$this->getTable(dimensions)}(dimension_id,label,code)

Good luck!

Reply to question:

This query works just fine in MySql i tested it. It was really just the semicolon missing.

DROP TABLE IF EXISTS standards; CREATE TABLE standards (

        `standards_id` int(10) NOT NULL AUTO_INCREMENT,        
         `name` varchar(250) DEFAULT NULL,                      
         PRIMARY KEY (`standards_id`)                           
       ) ENGINE=InnoDB  DEFAULT CHARSET=latin1;

DROP TABLE IF EXISTS standards_values; CREATE TABLE standards_values (

               `standards_id` int(11) DEFAULT NULL,                    
                `value` varchar(250) DEFAULT NULL,                      
                `order` int(4) DEFAULT NULL,                            
                `value_id` int(8) NOT NULL AUTO_INCREMENT,              
                UNIQUE KEY `value_id` (`value_id`),                     
                KEY `FK_standards_values` (`standards_id`)              
              ) ENGINE=InnoDB  DEFAULT CHARSET=latin1;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top