i want to create a view table in my custom module .install file and i want join with another table like i did in my db_query function but i want this thing in hook_schema function.

 db_query('CREATE VIEW Sample_Label_Data_By_CategoryId AS
                `sample_label_library`.`SampleNumber` AS `SampleNumber`,
                `sample_label_category`.`CategoryName` AS `CategoryName`,
                `sample_label_and_category`.`CategoryID` AS `CategoryID`,
                `sample_label_library`.`MaterialName` AS `MaterialName`,
                `sample_label_library`.`EPANumber` AS `EPANumber`,
                `sample_label_library`.`SampleFilename` AS `SampleFilename`,
                `sample_label_library`.`LabelFilename` AS `LabelFilename`
                from ((`sample_label_and_category` join `sample_label_library`
                    on((`sample_label_and_category`.`SampleNumber` = `sample_label_library`.`SampleNumber`)))
                    join `sample_label_category` on((`sample_label_and_category`.`CategoryID` = `sample_label_category`.`CategoryID`)))')

hook_schema() is only used to return a structured array representing your module's database tables. You can't execute a query from it. Well, you physically can, but you shouldn't.

Since hook_schema() is used on install, your code to create the View should be in hook_install(), and the code to remove it should be in hook_uninstall()

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.