Home Section Blog
Example of Section Blog layout (FAQ section)
Mysql Referential Integrity Trigger PDF Print E-mail
Written by tbg   
Friday, 20 March 2009 02:11
The following is a working version of a trigger that enforces referential integrity. This is a 'Before Insert' trigger. A similar 'Before Update' trigger is also created. The only unusual portion of the code is the use of the TriggerError table which is simply a table used to store the error message. This table has a unique key on the message column. Since currently does not offer a way to raise an error in a trigger, we utilize the duplicate key error when inserting the message to actually display the message. This is obviously not the best way but it is the best way currently available.
 
Note the keywords NEW.{fieldName}. This represents the incoming value to be inserted. This value can be modified in the trigger by setting the NEW.{fieldName} to the new value. This new value will be the value inserted into the database. In an 'update' or 'delete' trigger, you also have the OLD.{fieldName} which represents the value of the field before being updated or deleted.
 
 
 
use UrDb;

DROP TRIGGER TableNameBeforeInsert;
DELIMITER |

CREATE TRIGGER TableNameBeforeInsert
BEFORE INSERT ON TableName


  FOR EACH ROW
    BEGIN
      -- ----------------------------------------------------------------
      -- Set dateInserted / dateUpdated audit values
      -- ----------------------------------------------------------------
      SET NEW.dateInserted = now();
      SET NEW.dateUpdated = now();

      SET @EntityID = 0;
      SET @QualifierID = 0;
      -- ----------------------------------------------------------------
      -- Validate if Entity id is valid
      -- ----------------------------------------------------------------
      SELECT id INTO @ EntityID 
      FROM Entity
      WHERE id = NEW.entityID;

      IF (@ EntityID = 0) THEN
          -- The following is a mysql hack because mysql does not offer a way to exit out of a trigger.
          insert into TriggerError (TriggerErrorMessage) values ('Invalid Entity id') ;
          insert into TriggerError (TriggerErrorMessage) values ('Invalid Entity id') ;
      END IF;
 
      -- ----------------------------------------------------------------
      -- Validate if Qualifier Type is valid
      -- ----------------------------------------------------------------
      IF (NEW.qualifierType != 'Product' AND NEW.qualifierType != 'Brand' AND NEW.qualifierType != 'Category') THEN
          -- The following is a mysql hack because mysql does not offer a way to exit out of a trigger.
          insert into TriggerError (TriggerErrorMessage) values ('Invalid Type') ;
          insert into TriggerError (TriggerErrorMessage) values ('Invalid Type') ;

      END IF;

      IF (NEW.qualifierType = 'Product') THEN
        -- ----------------------------------------------------------------
        -- Validate if Product id is valid
        -- ----------------------------------------------------------------
        SELECT id INTO @QualifierId
        FROM Product
        WHERE id = NEW.qualifierId;

        IF (@QualifierId = 0) THEN
          -- The following is a mysql hack because mysql does not offer a way to exit out of a trigger.
          insert into TriggerError (TriggerErrorMessage) values ('Invalid Product id') ;
          insert into TriggerError (TriggerErrorMessage) values ('Invalid Product id') ;
        END IF;

      END IF;

      IF (NEW.qualifierType = 'Brand') THEN
        -- ----------------------------------------------------------------
        -- Validate if Brand id is valid
        -- ----------------------------------------------------------------
        SELECT id INTO @QualifierId
        FROM Brands
        WHERE id = NEW.qualifierId;

        IF (@QualifierId = 0) THEN
          -- The following is a mysql hack because mysql does not offer a way to exit out of a trigger.
          insert into TriggerError (TriggerErrorMessage) values ('Invalid Brand id') ;
          insert into TriggerError (TriggerErrorMessage) values ('Invalid Brand id') ;
        END IF;

      END IF;

      IF (NEW.qualifierType = 'Category') THEN
        -- ----------------------------------------------------------------
        -- Validate if Category id is valid
        -- ----------------------------------------------------------------
        SELECT id INTO @QualifierId
        FROM Categories
        WHERE id = NEW.qualifierId;

        IF (@QualifierId = 0) THEN
          -- The following is a mysql hack because mysql does not offer a way to exit out of a trigger.
          insert into TriggerError (TriggerErrorMessage) values ('Invalid Category id') ;
          insert into TriggerError (TriggerErrorMessage) values ('Invalid Category id') ;
        END IF;

      END IF;

    END
;

|

DELIMITER ;

 
 
 
Mysql 5 Trigger Before Insert PDF Print E-mail
Written by TBG   
Wednesday, 11 February 2009 19:25

This is an working example of a Before Insert Trigger with an If statement and modifying the incoming values.

-- Reset the Active Delimiter so the ; will not be executed when the trigger code is loaded
DELIMITER |

-- Create the Trigger
CREATE TRIGGER CreditCard_GiftCardNoEncrypt

BEFORE INSERT ON CreditCard
  FOR EACH ROW
    BEGIN
      IF (NEW.cardType !='GIFTCARD') THEN
        SET NEW.cardNumber = DES_ENCRYPT(NEW.cardNumber,'f8zz9');
      END IF;

      SET NEW.encrypted = 1;
    END
;
-- The Active Delimiter
|

-- Reset the Active Delimiter back to ;
DELIMITER ;

Last Updated on Wednesday, 11 February 2009 19:47
 
ftp - confine users to their home directory PDF Print E-mail
Written by Administrator   
Saturday, 24 January 2009 00:00

If you do not wish FTP users to be able to access any files outside of their own home directory, set up chroot jail.

For consider following example:

  • Ftp username : user1
  • FTP home directory: /home/user1

$ ftp ftp.domain.com

Output:

Connected to ftp.domain.com.
220 (vsFTPd 2.0.5)
Name (ftp.domain.com:user1): user1
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> pwd
257 "/home/user1"
ftp> cd /etc
250 Directory successfully changed.
ftp> ls
200 PORT command successful. Consider using PASV.
150 Here comes the directory listing.
150 Here comes the directory listing.
-rw-r--r-- 1 0 0 7959 Mar 02 22:20 Muttrc
drwxr-xr-x 3 0 0 4096 Jul 24 12:20 Wireless
drwxr-xr-x 16 0 0 4096 Jul 30 22:58 X11
drwxr-xr-x 4 0 0 4096 Sep 05 2005 Xprint
-rw-r--r-- 1 0 0 2188 Sep 05 2005 adduser.conf
-rw-r--r-- 1 0 0 47 Aug 16 14:52 adjtime
-rw------- 1 0 0 4330 Aug 18 2005 afick.conf
-rw-r--r-- 1 0 0 194 Sep 05 2005 aliases
-rw-r--r-- 1 0 0 12288 Jul 19 21:27 aliases.db
drwxr-xr-x 2 0 0 8192 Aug 15 09:33 alternatives
...
.....
..

Now normal user can go to /etc directory (may be to all other directories) and if there is read only permission to sensitive files user can download the file via ftp.

To avoid this security problem you can lock ftp user in a jail.

Open vsftpd configuration file - /etc/vsftpd/vsftpd.conf
# vi /etc/vsftpd/vsftpd.conf

Make sure following line exists (and uncommented):
chroot_local_user=YES

Save and close the file. Restart vsftpd.
# /etc/init.d/vsftpd restart

Now all users of VSFTPD/FTP will be limited to accessing only files in their own home directory. They will not able to see /, /etc, /root and /tmp and all other directories. This is an essential security feature.

Last Updated on Saturday, 24 January 2009 23:41
 
I installed with my own language, but the Back-end is still in English PDF Print E-mail
Written by Administrator   
Monday, 11 August 2008 17:18

A lot of different languages are available for the Back-end, but by default this language may not be installed. If you want a translated Back-end, get your language pack and install it using the Extension Installer. After this, go to the Extensions Menu, select Language Manager and make your language the default one. Your Back-end will be translated immediately.

Users who have access rights to the Back-end may choose the language they prefer in their Personal Details parameters. This is of also true for the Front-end language.

A good place to find where to download your languages and localised versions of Joomla! is Translations for Joomla! on JED.

Last Updated on Monday, 11 August 2008 17:18
 
Does the PDF icon render pictures and special characters? PDF Print E-mail
Written by Administrator   
Monday, 11 August 2008 17:14
Yes! Prior to Joomla! 1.5, only the text values of an Article and only for ISO-8859-1 encoding was allowed in the PDF rendition. With the new PDF library in place, the complete Article including images is rendered and applied to the PDF. The PDF generator also handles the UTF-8 texts and can handle any character sets from any language. The appropriate fonts must be installed but this is done automatically during a language pack installation.
Last Updated on Monday, 11 August 2008 17:14
 
«StartPrev12345NextEnd»

Page 1 of 5
Banner
Copyright © 2010 The-Bravo-Group. All Rights Reserved.
Joomla! is Free Software released under the GNU/GPL License.