|
Helping ordinary people create extraordinary websites! |
Cultured Perl: Embedding Perl in database tablesBy Teodor Zlatanov2005-04-27
Setting up Tables Before delving into details, we should review the architecture and tables, such as the template table for Perl code. For example, object deletion will use the "DELETE" template. The following listing demonstrates the way you can define that table with MySQL. Listing 1. The code templates table definition (MySQL) DROP TABLE IF EXISTS codetemplates;This is just a basic two-column table with the template name as the primary key, so no two templates can have the same name. Programming is a lot like speaking because you need verbs, nouns, adjectives, and so on. In fact, Larry Wall, Perl's creator, is a linguist whose experience in that field has obviously influenced Perl's evolution. In terms of embedded Perl code, the things you always need are a "noun" (the thing affected) and a "verb" (the action taken). The "modifier" (adverb or adjective in a sentence) is not required, usually. The "noun" is the target of the code. I'll call it $target and it will be required. The code that prepares for the action will have $target ready. The "verb" is the action taken by the code. I'll run that action by evaluating the code; if the code should fail, then I will catch that error. Perl provides the eval() function for that purpose. The string VERB will be a placeholder for the modifier action. The "modifier" is the tricky one. When it's not needed, as in the case of simple object deletion, you don't have to worry. When it is needed, we'll provide a placeholder string. The string will be DATUM, and you will see how to use it in the section on embedded modifications. Tutorial Pages: » Put Perl into your RDBMS Design to Reach Database Nirvana » Class::DBI Capabilities » Setting up Tables » Embedded Deletion » Embedded Modifications » Compatibility with Other Languages and Alternative Approaches » Conclusion » Resources First published by IBM DeveloperWorks
|
|