Sponsored Content
Top Forums Shell Programming and Scripting error while extracting a line from a file based on identifier Post 302579550 by vivek d r on Tuesday 6th of December 2011 03:52:35 AM
Old 12-06-2011
error while extracting a line from a file based on identifier

here is the content of input file
Code:
CREATE TABLE `bla bla bla` (
  `allianceSiteId` int(11) DEFAULT NULL,
  `trunkGroupsId` int(11) DEFAULT NULL,
  `lastModified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  UNIQUE KEY `allianceSiteId` (`allianceSiteId`,`trunkGroupsId`)
)

here is the part of the code whihc is inside a while loop reading a file
Code:
echo "whole line is : $line1"
 if  [[ `expr match "$line1" ".*CREATE TABLE.*"` != "0" ]]
 then
                firstword="$line1"
                fi
                echo "firstword : $firstword"
                lastword=") ENGINE=InnoDB AUTO_INCREMENT=2000 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;"
                echo "lastword : $lastword"

here is the part of output

Code:
firstword : CREATE TABLE `AllianceSiteTrunkGroupTrunkGroupsMap` (
lastword : ) ENGINE=InnoDB AUTO_INCREMENT=2000 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
whole line is : )
expr: syntax error
firstword : )
lastword : ) ENGINE=InnoDB AUTO_INCREMENT=2000 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

my doubt is why am i getting "expr: syntax error"... if the $line1 has ) it should not go inside if statement... what is the solution...
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Extracting data from text file based on configuration set in config file

Hi , a:) i have configuration file with pattren <Range start no>,<Range end no>,<type of records to be extracted from the data file>,<name of the file to store output> eg: myfile.confg 9899000000,9899999999,DATA,b.dat 9899000000,9899999999,SMS,a.dat b:) Stucture of my data file is... (3 Replies)
Discussion started by: suparnbector
3 Replies

2. Shell Programming and Scripting

extracting a line based on line number

i want to cut all the entries from the /etc/passwd file in which the uid is> 500 for this i was writing this ,m quiet new to all this.. scripting but on the 6th n 8th line ,, i hav to specify a line number .. to get the commnd working .. but i want to use variable i instead of that ,,... (2 Replies)
Discussion started by: narendra.pant
2 Replies

3. Shell Programming and Scripting

merging column from two files based on identifier

Hi, I have two files consisting of two columns. So I want to merge column 2 if column 1 is the same. So heres an example of what I mean. FILE1 driver 444 car 333 hat 222 FILE2 driver 333 car 666 hat 999 So I want to merge the column 2's together so... (4 Replies)
Discussion started by: phil_heath
4 Replies

4. Shell Programming and Scripting

Extracting lines in file based on time

Hi, anyone has any ideas on how do we extract lines from a file with format similiar to this: (based on current time) Jun 18 00:16:50 .......... ............. ............ Jun 18 00:17:59 .......... ............. ............ Jun 18 01:17:20 .......... ............. ............ Jun 18... (5 Replies)
Discussion started by: faelric
5 Replies

5. Shell Programming and Scripting

Extracting a portion of a data file with identifier

Hi, I do have a TAB delimted text file with the following format. 1 (- identifier of each group. this text is not present in the file only number) 1 3 4 65 56 WERTF 2 3 4 56 56 GHTYHU 3 3 5 64 23 VMFKLG 2 1 3 4 65 56 DGTEYDH 2 3 4 56 56 FJJJCKC 3 3 5 64 23 FNNNCHD 3 1 3 4 65 56 JDHJDH... (9 Replies)
Discussion started by: Lucky Ali
9 Replies

6. Shell Programming and Scripting

Extracting data based on the list file

Hi there, Can you help. I need to extract data based on the list file(list.txt) from item.txt as shown below. Please note the actual files are enormous in size. Thank you. item.txt nokia1100 123,000 nokia2100 66,000 samsung123 11,000 samsung456 23,000 iphone432 234,000... (12 Replies)
Discussion started by: shtobias
12 Replies

7. Shell Programming and Scripting

Extracting few lines from a file based on identifiers dynamically

i have something like this in a file called mysqldump.sql -- -- Table structure for table `Table11` -- DROP TABLE IF EXISTS `Table11`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `Table11` ( `id` int(11) NOT NULL... (14 Replies)
Discussion started by: vivek d r
14 Replies

8. UNIX for Dummies Questions & Answers

Extracting lines from a text file based on another text file with line numbers

Hi, I am trying to extract lines from a text file given a text file containing line numbers to be extracted from the first file. How do I go about doing this? Thanks! (1 Reply)
Discussion started by: evelibertine
1 Replies

9. Shell Programming and Scripting

To cut a string based on last index of identifier

here below is sample string null pointer dereference of 'resourceList' where null is returned from a method/opt/bld/fetch/ds/interzone/notification/LocalLineStatusNotificationListener.java:79 null pointer dereference of 'reList' where null is returned from a... (3 Replies)
Discussion started by: vivek d r
3 Replies

10. Shell Programming and Scripting

Extracting values based on line-column numbers from multiple text files

Dear All, I have to solve the following problems with multiple tab-separated text file but I don't know how. Any help would be greatly appreciated. I have access to Linux mint (but not as a professional). I have multiple tab-delimited files with the following structure: file1: 1 44 2 ... (5 Replies)
Discussion started by: Bastami
5 Replies
Catalyst::Manual::Tutorial::10_Appendices(3pm)		User Contributed Perl Documentation	    Catalyst::Manual::Tutorial::10_Appendices(3pm)

NAME
Catalyst::Manual::Tutorial::10_Appendices - Catalyst Tutorial - Chapter 10: Appendices OVERVIEW
This is Chapter 10 of 10 for the Catalyst tutorial. Tutorial Overview 1. Introduction 2. Catalyst Basics 3. More Catalyst Basics 4. Basic CRUD 5. Authentication 6. Authorization 7. Debugging 8. Testing 9. Advanced CRUD 10. 10_Appendices DESCRIPTION
This chapter of the tutorial provides supporting information relevant to the Catalyst tutorial. APPENDIX 1: CUT AND PASTE FOR POD-BASED EXAMPLES You may notice that Pod indents example code with four spaces. This section provides some quick advice to "un-indent" this text in common editors. "Un-indenting" with Vi/Vim When cutting and pasting multi-line text from Pod-based documents, the following vi/vim regexs can be helpful to "un-indent" the inserted text (do NOT type the quotes, they are only included to show spaces in the regex patterns). Note that all 3 of the regexs end in 4 spaces: o ":0,$s/^ " Removes four leading spaces from the entire file (from the first line, 0, to the last line, "$"). o "%s/^ " A shortcut for the previous item ("%" specifies the entire file; so this removes four leading spaces from every line). o ":.,$s/^ " Removes the first four spaces from the line the cursor is on at the time the regex command is executed (".") to the last line of the file. o ":.,44s/^ " Removes four leading space from the current line through line 44 (obviously adjust the 44 to the appropriate value in your example). "Un-indenting" with Emacs Although the author has not used Emacs for many years (apologies to the Emacs fans out there), here is a quick hint to get you started. To replace the leading spaces of every line in a file, use: M-x replace-regexp<RET> Replace regexp: ^ <RET> with: <RET> All of that will occur on the single line at the bottom of your screen. Note that "<RET>" represents the return key/enter. Also, there are four spaces after the "^" on the "Replace regexp:" line and no spaces entered on the last line. You can limit the replacement operation by selecting text first (depending on your version of Emacs, you can either use the mouse or experiment with commands such as "C-SPC" to set the mark at the cursor location and "C-<" and "C->" to set the mark at the beginning and end of the file respectively. Also, Stefan Kangas sent in the following tip about an alternate approach using the command "indent-region" to redo the indentation for the currently selected region (adhering to indent rules in the current major mode). You can run the command by typing M-x indent-region or pressing the default keybinding C-M- in cperl-mode. Additional details can be found here: http://www.gnu.org/software/emacs/manual/html_node/emacs/Indentation-Commands.html <http://www.gnu.org/software/emacs/manual/html_node/emacs/Indentation-Commands.html> APPENDIX 2: USING POSTGRESQL AND MYSQL The main database used in this tutorial is the very simple yet powerful SQLite <http://www.sqlite.org>. This section provides information that can be used to "convert" the tutorial to use PostgreSQL <http://www.postgresql.org> and MySQL <http://dev.mysql.com>. However, note that part of the beauty of the MVC architecture is that very little database-specific code is spread throughout the system (at least when MVC is "done right"). Consequently, converting from one database to another is relatively painless with most Catalyst applications. In general, you just need to adapt the schema definition ".sql" file you use to initialize your database and adjust a few configuration parameters. Also note that the purpose of the data definition statements for this section are not designed to take maximum advantage of the various features in each database for issues such as referential integrity and field types/constraints. PostgreSQL Use the following steps to adapt the tutorial to PostgreSQL. Thanks to Caelum (Rafael Kitover) for assistance with the most recent updates, and Louis Moore, Marcello Romani and Tom Lanyon for help with earlier versions. o Chapter 3: More Catalyst Basics o Install the PostgreSQL server and client and DBD::Pg: If you are following along in Debian 6, you can quickly install these items via this command: sudo aptitude install postgresql libdbd-pg-perl libdatetime-format-pg-perl To configure the permissions, you can open "/etc/postgresql/8.3/main/pg_hba.conf" and change this line (near the bottom): # "local" is for Unix domain socket connections only local all all ident sameuser to: # "local" is for Unix domain socket connections only local all all trust And then restart PostgreSQL: sudo /etc/init.d/postgresql-8.3 restart o Create the database and a user for the database (note that we are using "<catalyst>" to represent the hidden password of "catalyst"): $ sudo -u postgres createuser -P catappuser Enter password for new role: <catalyst> Enter it again: <catalyst> Shall the new role be a superuser? (y/n) n Shall the new role be allowed to create databases? (y/n) n Shall the new role be allowed to create more new roles? (y/n) n CREATE ROLE $ sudo -u postgres createdb -O catappuser catappdb CREATE DATABASE o Create the ".sql" file and load the data: o Open the "myapp01_psql.sql" in your editor and enter: -- -- Drops just in case you are reloading --- DROP TABLE IF EXISTS books CASCADE; DROP TABLE IF EXISTS authors CASCADE; DROP TABLE IF EXISTS book_authors CASCADE; DROP TABLE IF EXISTS users CASCADE; DROP TABLE IF EXISTS roles CASCADE; DROP TABLE IF EXISTS user_roles CASCADE; -- -- Create a very simple database to hold book and author information -- CREATE TABLE books ( id SERIAL PRIMARY KEY, title TEXT , rating INTEGER, -- Manually add these later -- created TIMESTAMP NOT NULL DEFAULT now(), -- updated TIMESTAMP ); CREATE TABLE authors ( id SERIAL PRIMARY KEY, first_name TEXT, last_name TEXT ); -- 'book_authors' is a many-to-many join table between books & authors CREATE TABLE book_authors ( book_id INTEGER REFERENCES books(id) ON DELETE CASCADE ON UPDATE CASCADE, author_id INTEGER REFERENCES authors(id) ON DELETE CASCADE ON UPDATE CASCADE, PRIMARY KEY (book_id, author_id) ); --- --- Load some sample data --- INSERT INTO books (title, rating) VALUES ('CCSP SNRS Exam Certification Guide', 5); INSERT INTO books (title, rating) VALUES ('TCP/IP Illustrated, Volume 1', 5); INSERT INTO books (title, rating) VALUES ('Internetworking with TCP/IP Vol.1', 4); INSERT INTO books (title, rating) VALUES ('Perl Cookbook', 5); INSERT INTO books (title, rating) VALUES ('Designing with Web Standards', 5); INSERT INTO authors (first_name, last_name) VALUES ('Greg', 'Bastien'); INSERT INTO authors (first_name, last_name) VALUES ('Sara', 'Nasseh'); INSERT INTO authors (first_name, last_name) VALUES ('Christian', 'Degu'); INSERT INTO authors (first_name, last_name) VALUES ('Richard', 'Stevens'); INSERT INTO authors (first_name, last_name) VALUES ('Douglas', 'Comer'); INSERT INTO authors (first_name, last_name) VALUES ('Tom', 'Christiansen'); INSERT INTO authors (first_name, last_name) VALUES ('Nathan', 'Torkington'); INSERT INTO authors (first_name, last_name) VALUES ('Jeffrey', 'Zeldman'); INSERT INTO book_authors VALUES (1, 1); INSERT INTO book_authors VALUES (1, 2); INSERT INTO book_authors VALUES (1, 3); INSERT INTO book_authors VALUES (2, 4); INSERT INTO book_authors VALUES (3, 5); INSERT INTO book_authors VALUES (4, 6); INSERT INTO book_authors VALUES (4, 7); INSERT INTO book_authors VALUES (5, 8); o Load the data: $ psql -U catappuser -W catappdb -f myapp01_psql.sql Password for user catappuser: psql:myapp01_psql.sql:8: NOTICE: CREATE TABLE will create implicit sequence "books_id_seq" for serial column "books.id" psql:myapp01_psql.sql:8: NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "books_pkey" for table "books" CREATE TABLE psql:myapp01_psql.sql:15: NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "book_authors_pkey" for table "book_authors" CREATE TABLE psql:myapp01_psql.sql:21: NOTICE: CREATE TABLE will create implicit sequence "authors_id_seq" for serial column "authors.id" psql:myapp01_psql.sql:21: NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "authors_pkey" for table "authors" CREATE TABLE INSERT 0 1 INSERT 0 1 INSERT 0 1 ... o Make sure the data loaded correctly: $ psql -U catappuser -W catappdb Password for user catappuser: <catalyst> Welcome to psql 8.3.7, the PostgreSQL interactive terminal. Type: copyright for distribution terms h for help with SQL commands ? for help with psql commands g or terminate with semicolon to execute query q to quit catappdb=> dt List of relations Schema | Name | Type | Owner --------+--------------+-------+------------ public | authors | table | catappuser public | book_authors | table | catappuser public | books | table | catappuser (3 rows) catappdb=> select * from books; id | title | rating ----+------------------------------------+-------- 1 | CCSP SNRS Exam Certification Guide | 5 2 | TCP/IP Illustrated, Volume 1 | 5 3 | Internetworking with TCP/IP Vol.1 | 4 4 | Perl Cookbook | 5 5 | Designing with Web Standards | 5 (5 rows) catappdb=> o After the steps where you: edit lib/MyApp.pm create lib/MyAppDB.pm create lib/MyAppDB/Book.pm create lib/MyAppDB/Author.pm create lib/MyAppDB/BookAuthor.pm o Generate the model using the Catalyst "_create.pl" script: $ rm lib/MyApp/Model/DB.pm # Delete just in case already there $ script/myapp_create.pl model DB DBIC::Schema MyApp::Schema create=static components=TimeStamp,PassphraseColumn 'dbi:Pg:dbname=catappdb' 'catappuser' 'catalyst' '{ AutoCommit => 1 }' o Chapter 4: Basic CRUD Add Datetime Columns to Our Existing Books Table $ psql -U catappuser -W catappdb ... catappdb=> ALTER TABLE books ADD created TIMESTAMP NOT NULL DEFAULT now(); ALTER TABLE catappdb=> ALTER TABLE books ADD updated TIMESTAMP; ALTER TABLE catappdb=> q Re-generate the model using the Catalyst "_create.pl" script: $ script/myapp_create.pl model DB DBIC::Schema MyApp::Schema create=static components=TimeStamp,PassphraseColumn 'dbi:Pg:dbname=catappdb' 'catappuser' 'catalyst' '{ AutoCommit => 1 }' o Chapter 5: Authentication o Create the ".sql" file for the user/roles data: Open "myapp02_psql.sql" in your editor and enter: -- -- Add users and roles tables, along with a many-to-many join table -- CREATE TABLE users ( id SERIAL PRIMARY KEY, username TEXT, password TEXT, email_address TEXT, first_name TEXT, last_name TEXT, active INTEGER ); CREATE TABLE roles ( id SERIAL PRIMARY KEY, role TEXT ); CREATE TABLE user_roles ( user_id INTEGER REFERENCES users(id) ON DELETE CASCADE ON UPDATE CASCADE, role_id INTEGER REFERENCES roles(id) ON DELETE CASCADE ON UPDATE CASCADE, PRIMARY KEY (user_id, role_id) ); -- -- Load up some initial test data -- INSERT INTO users (username, password, email_address, first_name, last_name, active) VALUES ('test01', 'mypass', 't01@na.com', 'Joe', 'Blow', 1); INSERT INTO users (username, password, email_address, first_name, last_name, active) VALUES ('test02', 'mypass', 't02@na.com', 'Jane', 'Doe', 1); INSERT INTO users (username, password, email_address, first_name, last_name, active) VALUES ('test03', 'mypass', 't03@na.com', 'No', 'Go', 0); INSERT INTO roles (role) VALUES ('user'); INSERT INTO roles (role) VALUES ('admin'); INSERT INTO user_roles VALUES (1, 1); INSERT INTO user_roles VALUES (1, 2); INSERT INTO user_roles VALUES (2, 1); INSERT INTO user_roles VALUES (3, 1); o Load the data: $ psql -U catappuser -W catappdb -f myapp02_psql.sql Password for user catappuser: <catalyst> psql:myapp02_psql.sql:13: NOTICE: CREATE TABLE will create implicit sequence "users_id_seq" for serial column "users.id" psql:myapp02_psql.sql:13: NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "users_pkey" for table "users" CREATE TABLE psql:myapp02_psql.sql:18: NOTICE: CREATE TABLE will create implicit sequence "roles_id_seq" for serial column "roles.id" psql:myapp02_psql.sql:18: NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "roles_pkey" for table "roles" CREATE TABLE psql:myapp02_psql.sql:24: NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "user_roles_pkey" for table "user_roles" CREATE TABLE INSERT 0 1 INSERT 0 1 INSERT 0 1 INSERT 0 1 INSERT 0 1 INSERT 0 1 INSERT 0 1 INSERT 0 1 INSERT 0 1 Confirm with: $ psql -U catappuser -W catappdb -c "select * from users" Password for user catappuser: <catalyst> id | username | password | email_address | first_name | last_name | active ----+----------+----------+---------------+------------+-----------+-------- 1 | test01 | mypass | t01@na.com | Joe | Blow | 1 2 | test02 | mypass | t02@na.com | Jane | Doe | 1 3 | test03 | mypass | t03@na.com | No | Go | 0 (3 rows) o Modify "set_hashed_passwords.pl" to match the following (the only difference is the "connect" line): #!/usr/bin/perl use strict; use warnings; use MyApp::Schema; my $schema = MyApp::Schema->connect('dbi:Pg:dbname=catappdb', 'catappuser', 'catalyst'); my @users = $schema->resultset('Users')->all; foreach my $user (@users) { $user->password('mypass'); $user->update; } Run the "set_hashed_passwords.pl" as per the "normal" flow of the tutorial: $ perl -Ilib set_hashed_passwords.pl You can verify that it worked with this command: $ psql -U catappuser -W catappdb -c "select * from users" MySQL Use the following steps to adapt the tutorial to MySQL. Thanks to Jim Howard for the help and Zsolt Zemancsik for the up to date fixes. o Chapter 3: Catalyst Basics o Install the required software: o The MySQL database server and client utility. o The Perl "DBD::MySQL" module For CentOS users (see Catalyst::Manual::Installation::CentOS4), you can use the following commands to install the software and start the MySQL daemon: yum -y install mysql mysql-server service mysqld start For Debian users you can use the following commands to install the software and start the MySQL daemon: apt-get install mysql-client mysql-server /etc/init.d/mysql start NOTE: The tutorial is based on Foreign Keys in database which is supported by InnoDB. Only MySQL 5.0 and above supports InnoDB storage Engine so you need to have InnoDB support in you MySQL. You can simply figure out that your install supports it or not: # mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or g. Type 'help;' or 'h' for help. Type 'c' to clear the current input statement. mysql> SHOW VARIABLES LIKE 'have_innodb'; +---------------+-------+ | Variable_name | Value | +---------------+-------+ | have_innodb | YES | +---------------+-------+ 1 row in set (0.01 sec) mysql> exit Bye If the Value is "YES" you can use your setup (Debian based mysql supports it by default). Else, you need to configure your my.cnf or start your MySQL daemon without --skip-innodb option. o Create the database and set the permissions: # mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or g. Type 'help;' or 'h' for help. Type 'c' to clear the current input statement. mysql> CREATE DATABASE `myapp`; Query OK, 1 row affected (0.01 sec) mysql> GRANT ALL PRIVILEGES ON myapp.* TO 'tutorial'@'localhost' IDENTIFIED BY 'yourpassword'; Query OK, 0 rows affected (0.00 sec) mysql> FLUSH PRIVILEGES; Query OK, 0 rows affected (0.00 sec) mysql> exit Bye o Create the ".sql" file and load the data: o Open the "myapp01_mysql.sql" in your editor and enter: -- -- Create a very simple database to hold book and author information -- CREATE TABLE IF NOT EXISTS `books` ( `id` int(11) NOT NULL AUTO_INCREMENT, `title` text CHARACTER SET utf8, `rating` int(11) DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; -- 'book_authors' is a many-to-many join table between books & authors CREATE TABLE IF NOT EXISTS `book_authors` ( `book_id` int(11) NOT NULL DEFAULT '0', `author_id` int(11) NOT NULL DEFAULT '0', PRIMARY KEY (`book_id`,`author_id`), KEY `author_id` (`author_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; CREATE TABLE IF NOT EXISTS `authors` ( `id` int(11) NOT NULL AUTO_INCREMENT, `first_name` text CHARACTER SET utf8, `last_name` text CHARACTER SET utf8, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; --- --- Load some sample data --- INSERT INTO `books` (`id`, `title`, `rating`) VALUES (1, 'CCSP SNRS Exam Certification Guide', 5), (2, 'TCP/IP Illustrated, Volume 1', 5), (3, 'Internetworking with TCP/IP Vol.1', 4), (4, 'Perl Cookbook', 5), (5, 'Designing with Web Standards', 5); INSERT INTO `book_authors` (`book_id`, `author_id`) VALUES (1, 1), (1, 2), (1, 3), (2, 4), (3, 5), (4, 6), (4, 7), (5, 8); INSERT INTO `authors` (`id`, `first_name`, `last_name`) VALUES (1, 'Greg', 'Bastien'), (2, 'Sara', 'Nasseh'), (3, 'Christian', 'Degu'), (4, 'Richard', 'Stevens'), (5, 'Douglas', 'Comer'), (6, 'Tom', 'Christiansen'), (7, 'Nathan', 'Torkington'), (8, 'Jeffrey', 'Zeldman'); ALTER TABLE `book_authors` ADD CONSTRAINT `book_author_ibfk_2` FOREIGN KEY (`author_id`) REFERENCES `authors` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, ADD CONSTRAINT `book_author_ibfk_1` FOREIGN KEY (`book_id`) REFERENCES `books` (`id`) ON DELETE CASCADE ON UPDATE CASCADE; o Load the data: mysql -u tutorial -p myapp < myapp01_mysql.sql o Make sure the data loaded correctly: $ mysql -u tutorial -p myapp Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Welcome to the MySQL monitor. Commands end with ; or g. Type 'help;' or 'h' for help. Type 'c' to clear the buffer. mysql> show tables; +-----------------+ | Tables_in_myapp | +-----------------+ | authors | | book_authors | | books | +-----------------+ 3 rows in set (0.00 sec) mysql> select * from books; +----+------------------------------------+--------+ | id | title | rating | +----+------------------------------------+--------+ | 1 | CCSP SNRS Exam Certification Guide | 5 | | 2 | TCP/IP Illustrated, Volume 1 | 5 | | 3 | Internetworking with TCP/IP Vol.1 | 4 | | 4 | Perl Cookbook | 5 | | 5 | Designing with Web Standards | 5 | +----+------------------------------------+--------+ 5 rows in set (0.00 sec) mysql> o Update the model: o Delete the existing model: rm lib/MyApp/Model/MyAppDB.pm o Regenerate the model using the Catalyst "_create.pl" script: script/myapp_create.pl model DB DBIC::Schema MyApp::Schema create=static dbi:mysql:myapp 'tutorial' 'yourpassword' '{ AutoCommit => 1 }' o Chapter 5: Authentication o Create the ".sql" file for the user/roles data: Open "myapp02_mysql.sql" in your editor and enter: -- -- Add users and roles tables, along with a many-to-many join table -- CREATE TABLE IF NOT EXISTS `roles` ( `id` int(11) NOT NULL, `role` text CHARACTER SET utf8, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; CREATE TABLE IF NOT EXISTS `users` ( `id` int(11) NOT NULL, `username` text CHARACTER SET utf8, `password` text CHARACTER SET utf8, `email_address` text CHARACTER SET utf8, `first_name` text CHARACTER SET utf8, `last_name` text CHARACTER SET utf8, `active` int(11) DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; CREATE TABLE IF NOT EXISTS `user_roles` ( `user_id` int(11) NOT NULL DEFAULT '0', `role_id` int(11) NOT NULL DEFAULT '0', PRIMARY KEY (`user_id`,`role_id`), KEY `role_id` (`role_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; -- -- Load up some initial test data -- INSERT INTO `roles` (`id`, `role`) VALUES (1, 'user'), (2, 'admin'); INSERT INTO `users` (`id`, `username`, `password`, `email_address`, `first_name`, `last_name`, `active`) VALUES (1, 'test01', 'mypass', 't01@na.com', 'Joe', 'Blow', 1), (2, 'test02', 'mypass', 't02@na.com', 'Jane', 'Doe', 1), (3, 'test03', 'mypass', 't03@na.com', 'No', 'Go', 0); INSERT INTO `user_roles` (`user_id`, `role_id`) VALUES (1, 1), (2, 1), (3, 1), (1, 2); ALTER TABLE `user_roles ADD CONSTRAINT `user_role_ibfk_2` FOREIGN KEY (`role_id`) REFERENCES `roles` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, ADD CONSTRAINT `user_role_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE ON UPDATE CASCADE; o Load the user/roles data: mysql -u tutorial -p myapp < myapp02_mysql.sql o Update the model: o Regenerate the model using the Catalyst "_create.pl" script: script/myapp_create.pl model DB DBIC::Schema MyApp::Schema create=static components=TimeStamp,PassphraseColumn dbi:mysql:myapp 'tutorial' 'yourpassword' '{ AutoCommit => 1 }' o Create the ".sql" file for the hashed password data: Open "myapp03_mysql.sql" in your editor and enter: -- -- Convert passwords to SHA-1 hashes -- UPDATE users SET password = '{SSHA}esgz64CpHMo8pMfgIIszP13ft23z/zio04aCwNdm0wc6MDeloMUH4g==' WHERE id = 1; UPDATE users SET password = '{SSHA}FpGhpCJus+Ea9ne4ww8404HH+hJKW/fW+bAv1v6FuRUy2G7I2aoTRQ==' WHERE id = 2; UPDATE users SET password = '{SSHA}ZyGlpiHls8qFBSbHr3r5t/iqcZE602XLMbkSVRRNl6rF8imv1abQVg==' WHERE id = 3; o Load the user/roles data: mysql -u tutorial -p myapp < myapp03_mysql.sql AUTHOR
Kennedy Clark, "hkclark@gmail.com" Feel free to contact the author for any errors or suggestions, but the best way to report issues is via the CPAN RT Bug system at https://rt.cpan.org/Public/Dist/Display.html?Name=Catalyst-Manual <https://rt.cpan.org/Public/Dist/Display.html?Name=Catalyst-Manual>. Copyright 2006-2011, Kennedy Clark, under the Creative Commons Attribution Share-Alike License Version 3.0 (http://creativecommons.org/licenses/by-sa/3.0/us/ <http://creativecommons.org/licenses/by-sa/3.0/us/>). perl v5.14.2 2012-01-20 Catalyst::Manual::Tutorial::10_Appendices(3pm)
All times are GMT -4. The time now is 06:51 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy