MySQL trigger is preventing INSERT if condition isn't met - mysql

I have a trigger before insert that replaces a string for a field with the new insert id. This is wrapped in a condition and works very well when the condition is met. However when an ordinary insert is attempted and the string isn't present the trigger stops the insert from executing at all, and yet there is nothing in the trigger to do this, any clues why this might be happening? Trigger below:
DELIMITER $$
DROP TRIGGER /*!50032 IF EXISTS */ `delivery_management_vehicle_placeholder_title`$$
CREATE
/*!50017 DEFINER = 'root'#'localhost' */
TRIGGER `delivery_management_vehicle_placeholder_title` BEFORE INSERT ON `delivery_management_vehicle`
FOR EACH ROW BEGIN
DECLARE id_delivery_management_vehicle INT DEFAULT 0;
DECLARE mask VARCHAR(10) DEFAULT '--id--';
IF LOCATE(mask, NEW.`title`) > 0 THEN
SELECT
`auto_increment` INTO id_delivery_management_vehicle
FROM
`information_schema`.`tables`
WHERE
`table_name` = 'delivery_management_vehicle'
AND
`table_schema` = DATABASE();
SET NEW.`title`=REPLACE(NEW.`title`, mask, id_delivery_management_vehicle);
END IF;
END;
$$
DELIMITER ;
The table structure is as follows:
CREATE TABLE `delivery_management_vehicle` (
`id_dmv` int(11) unsigned NOT NULL AUTO_INCREMENT,
`id_system_user` int(11) NOT NULL,
`id_organisation` int(11) NOT NULL DEFAULT '0',
`id_depth1` int(11) NOT NULL DEFAULT '0',
`id_depth2` int(11) NOT NULL DEFAULT '0',
`id_type` int(11) NOT NULL DEFAULT '1',
`id_approver` int(11) NOT NULL DEFAULT '0',
`id_author` int(11) NOT NULL DEFAULT '0',
`id_owner` int(11) NOT NULL DEFAULT '0',
`id_responsible` int(11) NOT NULL DEFAULT '0',
`id_administrator` int(11) NOT NULL DEFAULT '0',
`id_category` int(11) NOT NULL DEFAULT '1',
`title` varchar(255) NOT NULL,
`description` text NOT NULL,
`keywords` text NOT NULL,
`colour` char(6) DEFAULT NULL,
`scope` text NOT NULL,
`assumptions` text NOT NULL,
`objectives` text NOT NULL,
`reference` varchar(255) NOT NULL,
`source` varchar(255) NOT NULL DEFAULT '',
`created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`last_updated` datetime NOT NULL,
`last_updated_by` int(11) NOT NULL,
`approved` enum('0','1') NOT NULL DEFAULT '0',
`priority` enum('undefined','low','medium','high','critical') NOT NULL DEFAULT 'undefined',
`approved_date` datetime NOT NULL,
`actual_start_date` date NOT NULL,
`planned_start_date` date NOT NULL,
`projected_start_date` date NOT NULL,
`planned_completion_date` date NOT NULL,
`projected_completion_date` date NOT NULL,
`actual_completion_date` date NOT NULL,
`tolerance` int(11) NOT NULL,
`tolerance_period` enum('days','weeks','months') NOT NULL,
`planned_implementation` bigint(19) DEFAULT NULL,
`planned_management` bigint(19) DEFAULT NULL,
`planned_budget` bigint(19) DEFAULT NULL,
`projected_management` bigint(19) DEFAULT NULL,
`projected_budget` bigint(19) DEFAULT NULL,
`actual_implementation` bigint(19) DEFAULT NULL,
`actual_management` bigint(19) DEFAULT NULL,
`actual_budget` bigint(19) DEFAULT NULL,
`financial_summary_tolerance` int(11) DEFAULT '0',
`use_rag` enum('D','R','A','G','B') NOT NULL DEFAULT 'D',
`mandatory` enum('0','1') NOT NULL DEFAULT '0',
`active` enum('0','1') NOT NULL DEFAULT '1',
PRIMARY KEY (`id_dmv`),
KEY `id_system_user` (`id_system_user`),
KEY `id_type` (`id_type`),
KEY `id_approver` (`id_approver`),
KEY `id_author` (`id_author`),
KEY `id_owner` (`id_owner`),
KEY `id_responsible` (`id_responsible`),
KEY `id_administrator` (`id_administrator`),
KEY `id_system_user_2` (`id_system_user`,`active`),
KEY `id_author_2` (`id_author`,`active`),
KEY `id_owner_2` (`id_owner`,`active`),
KEY `id_approver_2` (`id_approver`,`active`),
KEY `id_responsible_2` (`id_responsible`,`active`),
KEY `id_type_2` (`id_type`,`active`)
) ENGINE=MyISAM AUTO_INCREMENT=15 DEFAULT CHARSET=utf8 COMMENT='Delivery Management Vehicle';
and the insert statement I am trying to execute is:
INSERT INTO `delivery_management_vehicle` (
`last_updated`,
`title`,
`reference`,
`description`,
`keywords`,
`source`,
`priority`,
`scope`,
`assumptions`,
`objectives`,
`use_rag`,
`id_category`,
`id_type`,
`id_organisation`,
`id_depth1`,
`id_depth2`,
`colour`,
`id_system_user`,
`actual_start_date`,
`planned_start_date`,
`projected_start_date`,
`planned_completion_date`,
`projected_completion_date`,
`tolerance`,
`tolerance_period`,
`last_updated_by`
) VALUES (
NOW(),'G Test 3','','','','','undefined','','','','D',1,1,0,0,0,NULL,'3','','','','','',0,'days','3');
Sorry the table declaration is huge, but the insert is only for certain columns.
So looking at the title field I am expecting this to just insert and the trigger bypasses because the string '--id--' does not exist in the title field.
Cheers

You are trying to insert '' into an INT column. You can't do that.

Related

Data too long for column 'Subscribe_Specialty' at row 1 - Mysql error

Here is the insert statement -
INSERT INTO `Newsletter_Subscriber_Uploaded_Data`(`File_Id`, `First_Name`, `Last_Name`, `Email`,`Country`,`Country_Id`,`Subscribe_Specialty`,Is_Valid, `Subscription_Id`, `User_Id`, `Created_Date`)
VALUES (2, 'Adolphus','Bonar', 'a.bonar#endocrinology.org', 'United States','2', 'General Practice/Family Medicine', 1 ,20, '89',CURRENT_TIMESTAMP)
For column Subscribe_Specialty, the value I'm trying to insert is 'General Practice/Family Medicine' which has only 32 characters, but still it is giving me the above error.
Please help me guys, as this is a production error.
More Information:
Collation : utf8
Storage Engine : InnoDB
Below is the Table structure -
CREATE TABLE `Newsletter_Subscriber_Uploaded_Data` (
`File_Id` int(11) NOT NULL,
`Row_Id` int(11) NOT NULL AUTO_INCREMENT,
`First_Name` varchar(50) NOT NULL,
`Last_Name` varchar(50) NOT NULL,
`Email` varchar(100) DEFAULT NULL,
`Country` varchar(20) NOT NULL,
`Country_Id` int(11) NOT NULL DEFAULT '0',
`Subscribe_Specialty` varchar(100) NOT NULL,
`Is_Valid` tinyint(4) DEFAULT '0',
`Subscription_Id` int(100) NOT NULL DEFAULT '0',
`Duplicate` tinyint(4) DEFAULT '0',
`Subscriber` tinyint(4) DEFAULT '0',
`Created_Date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`User_Id` int(11) NOT NULL COMMENT 'Panel user id',
PRIMARY KEY (`Row_Id`),
KEY `File_Id` (`File_Id`)
) ENGINE=InnoDB AUTO_INCREMENT=21511 DEFAULT CHARSET=utf8;

#1060 - Duplicate column name 'ID' Why?

CREATE TABLE IF NOT EXISTS `vehicles` (
`UID` int(4) NOT NULL,
`id` int(11) NOT NULL,
`Kofferraum` varchar(50) NOT NULL DEFAULT '0|0|0|0|',
`Typ` int(11) NOT NULL,
`Tuning` varchar(255) NOT NULL,
`Spawnpos_X` varchar(50) NOT NULL,
`Spawnpos_Y` varchar(50) NOT NULL,
`Spawnpos_Z` varchar(50) NOT NULL,
`Spawnrot_X` varchar(50) NOT NULL,
`Spawnrot_Y` varchar(50) NOT NULL,
`Spawnrot_Z` varchar(50) NOT NULL,
`Farbe` varchar(50) NOT NULL,
`Paintjob` varchar(50) NOT NULL DEFAULT '3',
`Benzin` varchar(50) NOT NULL DEFAULT '100',
`Slot` float NOT NULL,
`Special` int(11) NOT NULL DEFAULT '0',
`Lights` varchar(50) NOT NULL DEFAULT '|255|255|255|',
`Distance` double NOT NULL DEFAULT '0',
`STuning` varchar(50) NOT NULL DEFAULT '0|0|0|0|0|0|',
`AuktionsID` int(10) NOT NULL DEFAULT '0',
`GangVehicle` tinyint(1) NOT NULL DEFAULT '0',
`rc` int(1) NOT NULL DEFAULT '0',
`spezcolor` varchar(50) NOT NULL DEFAULT '|0|0|0|0|0|0|',
`Sportmotor` int(1) NOT NULL DEFAULT '0',
`Bremse` varchar(1) NOT NULL DEFAULT '0',
`Antrieb` varchar(10) NOT NULL,
`plate` text NOT NULL,
`ID` int(11) NOT NULL,
PRIMARY KEY (`ID`)
) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=latin1;
Because you're using 'id' twice. Either remove the duplicate or change the name of this to something else:
ID int(11) NOT NULL
You have the column id twice. Once at the beginning an one at the end.
CREATE TABLE IF NOT EXISTS `vehicles` (
`UID` int(4) NOT NULL,
`id` int(11) NOT NULL,
...
`ID` int(11) NOT NULL,
PRIMARY KEY (`ID`)
...
remove one of them

#1415 - Not allowed to return a result set from a trigger

DELIMITER $$
CREATE TRIGGER `msg_after_insert`
AFTER INSERT ON `meter_reading`
FOR EACH ROW
BEGIN
select meter_reading.*,a.amount as Light_Reading_Amt,b.amount as Power_Reading_Amt from meter_reading inner join master_unit a on a.min_unit<=msg1 and msg1<=a.max_unit and doc>=a.date_of_enter_value_fm inner join master_unit b on b.min_unit<=msg2 and msg2<=b.max_unit and doc<=b.date_of_enter_value_to;
INSERT INTO `smsd`.`outbox` (DestinationNumber,TextDecoded) VALUES (NEW.mobno, CONCAT_WS(NEW.msg1,NEW.Light_Reading_Amt,' ',NEW.msg2,NEW.Light_Reading_Amt));
END $$
DELIMITER ;
My databases are
1. mr_sms (tables are : 1.meter_reading 2.master_unit)
--meter_reading table--
CREATE TABLE IF NOT EXISTS `meter_reading` (
`serno` int(50) NOT NULL AUTO_INCREMENT,
`cno` varchar(50) DEFAULT NULL,
`accn_no` varchar(20) DEFAULT NULL,
`loc` varchar(20) DEFAULT NULL,
`type_of_accn` varchar(50) NOT NULL,
`rank` varchar(25) NOT NULL,
`name` varchar(50) DEFAULT NULL,
`mobno` varchar(15) DEFAULT NULL,
`msg1` int(100) DEFAULT NULL,
`msg2` int(250) NOT NULL,
`status` varchar(30) NOT NULL,
`doc` date NOT NULL,
`remarks` varchar(100) DEFAULT NULL,
PRIMARY KEY (`serno`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=22 ;
--master_unit table--
CREATE TABLE IF NOT EXISTS `master_unit` (
`u_id` int(11) NOT NULL AUTO_INCREMENT,
`min_unit` int(150) NOT NULL,
`max_unit` int(200) NOT NULL,
`rate` varchar(20) NOT NULL,
`amount` varchar(20) NOT NULL,
`duty` varchar(20) NOT NULL,
`dutyamount` varchar(20) NOT NULL,
`date_of_enter_value_fm` date NOT NULL,
`date_of_enter_value_to` date NOT NULL,
PRIMARY KEY (`u_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=10 ;
2. smsd (table is : outbox)
--
-- Table structure for table `outbox`
--
CREATE TABLE IF NOT EXISTS `outbox` (
`UpdatedInDB` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`InsertIntoDB` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
`SendingDateTime` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
`SendBefore` time NOT NULL DEFAULT '23:59:59',
`SendAfter` time NOT NULL DEFAULT '00:00:00',
`Text` text,
`DestinationNumber` varchar(20) NOT NULL DEFAULT '',
`Coding` enum('Default_No_Compression','Unicode_No_Compression','8bit','Default_Compression','Unicode_Compression') NOT NULL DEFAULT 'Default_No_Compression',
`UDH` text,
`Class` int(11) DEFAULT '-1',
`TextDecoded` text NOT NULL,
`ID` int(10) unsigned NOT NULL AUTO_INCREMENT,
`MultiPart` enum('false','true') DEFAULT 'false',
`RelativeValidity` int(11) DEFAULT '-1',
`SenderID` varchar(255) DEFAULT NULL,
`SendingTimeOut` timestamp NULL DEFAULT '0000-00-00 00:00:00',
`DeliveryReport` enum('default','yes','no') DEFAULT 'default',
`CreatorID` text NOT NULL,
PRIMARY KEY (`ID`),
KEY `outbox_date` (`SendingDateTime`,`SendingTimeOut`),
KEY `outbox_sender` (`SenderID`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=3 ;
--
-- Dumping data for table `outbox`
--

MySql Trigger: can't retrieve one specific column from NEW in after insert trigger

I have 3 tables:
pp088_project_tasks
CREATE TABLE IF NOT EXISTS `pp088_project_tasks` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`task_list_id` int(10) unsigned DEFAULT NULL,
`text` text CHARACTER SET utf8 COLLATE utf8_unicode_ci,
`start_date` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`due_date` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`assigned_to_company_id` int(10) DEFAULT NULL,
`assigned_to_user_id` int(10) unsigned DEFAULT NULL,
`completed_on` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`completed_by_id` int(10) unsigned DEFAULT NULL,
`created_on` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`created_by_id` int(10) unsigned DEFAULT NULL,
`updated_on` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`updated_by_id` int(10) unsigned DEFAULT NULL,
`order` int(10) unsigned NOT NULL DEFAULT '0',
PRIMARY KEY (`id`),
KEY `task_list_id` (`task_list_id`),
KEY `completed_on` (`completed_on`),
KEY `created_on` (`created_on`),
KEY `order` (`order`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=76 ;
pp088_project_task_lists
CREATE TABLE IF NOT EXISTS `pp088_project_task_lists` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`milestone_id` int(10) unsigned NOT NULL DEFAULT '0',
`project_id` int(10) unsigned DEFAULT NULL,
`name` varchar(100) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL,
`priority` int(3) unsigned NOT NULL DEFAULT '0',
`description` text CHARACTER SET utf8 COLLATE utf8_unicode_ci,
`start_date` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`due_date` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`score` int(3) unsigned NOT NULL DEFAULT '0',
`is_private` tinyint(1) unsigned NOT NULL DEFAULT '0',
`completed_on` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`completed_by_id` int(10) unsigned DEFAULT NULL,
`created_on` datetime DEFAULT NULL,
`created_by_id` int(10) unsigned NOT NULL DEFAULT '0',
`updated_on` datetime DEFAULT NULL,
`updated_by_id` int(10) unsigned NOT NULL DEFAULT '0',
`order` tinyint(3) unsigned NOT NULL DEFAULT '0',
PRIMARY KEY (`id`),
KEY `milestone_id` (`milestone_id`),
KEY `project_id` (`project_id`),
KEY `completed_on` (`completed_on`),
KEY `created_on` (`created_on`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=6 ;
gantt_tasks
CREATE TABLE IF NOT EXISTS `gantt_tasks` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`text` varchar(255) NOT NULL,
`start_date` date NOT NULL,
`duration` int(11) NOT NULL,
`progress` float NOT NULL DEFAULT '1',
`sortorder` int(11) NOT NULL,
`parent` int(11) NOT NULL,
`projectID` int(10) unsigned DEFAULT NULL,
`tipo_evento` varchar(100) NOT NULL,
`idPier` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=48 ;
I created an AFTER INSERT trigger on the 'pp088_project_tasks' table to insert into 'gantt_tasks'
CREATE TRIGGER `insert_gantt_task` AFTER INSERT ON `pp088_project_tasks`
FOR EACH ROW BEGIN
declare project_id int;
declare duracion int;
set project_id=(select project_id from pp088_project_task_lists where id=NEW.task_list_id);
set duracion=(select DATEDIFF(NEW.due_date,NEW.start_date));
insert into gantt_tasks (text,start_date,duration,projectID,idPier) values (NEW.text,NEW.start_date,duracion,project_id,NEW.id);
END
but the problem is with the setting of the project_id variable which sets the gantt_tasks field projectID to NULL because that query cannot retrieve the value using NEW.task_list_id, even if I use that value directly on the insert just to check the value it sets the gantt_tasks field projectID to 0......The strange thing is that if I use other values of the NEW they all work, it's just that field, the insert is successful for all of the other fields on gantt_tasks. I checked and the types are the same, and so the collation as well.
The first two tables are from a project manager called projectPier and the gantt_tasks table is one I created for a gantt chart(DHTMLX gantt chart).
... but the problem is with the setting of the project_id variable which sets the gantt_tasks field projectID to NULL because that query cannot retrieve the value using NEW.task_list_id, even if I use that value directly on the insert just to check the value it sets the gantt_tasks field projectID to 0
Reason is very much visible.
You have a variable project_id whose name matches that of a column in the table.
And when you use column name without a table qualifier, there arises a conflict on the names. And priority will be given to the local variable over column.
In your case, due to the statement
declare project_id int;
the default value of project_id would be zero. And hence, the output of the statement
set project_id=(select project_id from pp088_project_task_lists
where id=NEW.task_list_id);
would be a zero. And hence the same is used in the insert statement.
Options:
Change local variable name to something relevant.
Use table name to qualify the column name.
Sample Example: (using option 1)
Make following changes to your code and it should be working.
delimiter //
CREATE TRIGGER `insert_gantt_task` AFTER INSERT ON `pp088_project_tasks`
FOR EACH ROW BEGIN
declare _project_id int default 0;
declare _duracion int default 0;
select project_id into _project_id
from pp088_project_task_lists
where id = NEW.task_list_id;
select DATEDIFF( NEW.due_date, NEW.start_date ) into _duracion;
insert into gantt_tasks ( text, start_date, duration, projectID, idPier )
values( NEW.text, NEW.start_date, _duracion, _project_id, NEW.id );
END;
//
delimiter ;
Sample Example: (using option 2)
Make following changes to your code and it should be working.
delimiter //
CREATE TRIGGER `insert_gantt_task` AFTER INSERT ON `pp088_project_tasks`
FOR EACH ROW BEGIN
declare project_id int default 0;
declare duracion int default 0;
set project_id := ( select tl.project_id
from pp088_project_task_lists tl
where tl.id = NEW.task_list_id );
set duracion := select DATEDIFF( NEW.due_date, NEW.start_date );
insert into gantt_tasks ( text, start_date, duration, projectID, idPier )
values( NEW.text, NEW.start_date, duracion, project_id, NEW.id );
END;
//
delimiter ;

Mysql query failed after adding category table

When i run this query i'm keeping getting this error Database query failed 1054 - Unknown column 'cv.employeeIDFK' in 'on clause'
This only happen when I add the category in my query
FROM opjb_cv AS cv , opjb_cvCategory AS cv_cat
AND cv_cat.categoryIDFK IN ( 1,2,3,4,5,11,22,24,26,28 )
AND cv_cat.cvIDFK = cv.id
This is my query which is failing as you can see i have added all information but still its failing i cant seem to find anything wrong with this.
SELECT DISTINCT cv.id, cv.targetJobTitle, cv.targetJobTitleAlt, cv.recentEmployer, employee.firstName,
employee.surname, cv.recentJobTitle, cv.modifyAt, cv.city, cv.countryCountyFK, cv.countryStatesFK, cv.countryISO2FK, cv.experienceIDFK,
cv.careerIDFK, cv.areYouAuth, country.countryName, cv.employeeIDFK as user_id ,
match ( cv.title, cv.recentJobTitle, cv.targetJobTitle, cv.targetJobTitleAlt ) AGAINST ('desktop' IN BOOLEAN MODE) AS relevance
FROM opjb_cv AS cv , opjb_cvCategory AS cv_cat
JOIN opjb_employee AS employee ON cv.employeeIDFK = employee.id
JOIN opjb_country AS country ON cv.countryISO2FK=country.iso2
JOIN opjb_experience AS experience ON cv.experienceIDFK = experience.id
JOIN opjb_type AS type ON cv.jobTypeIDFK = type.id
JOIN opjb_education AS education ON cv.educationIDFK = education.id
JOIN opjb_countryStates as countryStates ON cv.countryStatesFK = countryStates.code
WHERE cv.showTo=1
AND cv.status=1
AND cv.countryISO2FK='GB'
AND match ( cv.title, cv.recentJobTitle, cv.targetJobTitle, cv.targetJobTitleAlt ) AGAINST ('desktop' IN BOOLEAN MODE )
AND cv_cat.categoryIDFK IN ( 1,2,3,4,5,11,22,24,26,28 )
AND cv_cat.cvIDFK = cv.id
AND experience.id=5
AND type.id=1
AND education.id=7
AND cv.modifyAt > NOW() - INTERVAL 3 DAY AND ( cv.salaryMin <= 48000 OR cv.salaryMax <= 48000 )
AND cv.countryStatesFK ='EG'
ORDER BY relevance DESC
These are all the tables which is involde in this query.
CREATE TABLE IF NOT EXISTS `opjb_country` (
`iso2` char(2) NOT NULL,
`iso3` char(3) NOT NULL,
`isoNo` smallint(3) NOT NULL,
`countryName` varchar(100) NOT NULL,
`regionIDFK` int(11) NOT NULL,
`isActive` tinyint(1) NOT NULL default '0',
PRIMARY KEY (`iso2`),
KEY `regionIDFK` (`regionIDFK`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
-- --------------------------------------------------------
--
-- Table structure for table `opjb_countryStates`
--
CREATE TABLE IF NOT EXISTS `opjb_countryStates` (
`code` varchar(40) NOT NULL default '',
`name` varchar(100) default NULL,
`countryISO2FK` char(2) NOT NULL default 'US',
`isActive` tinyint(1) NOT NULL default '0',
PRIMARY KEY (`code`,`countryISO2FK`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
-- --------------------------------------------------------
--
-- Table structure for table `opjb_cv`
--
CREATE TABLE IF NOT EXISTS `opjb_cv` (
`id` int(11) NOT NULL auto_increment,
`type` tinyint(1) NOT NULL default '0',
`fileName` varchar(100) NOT NULL,
`fileType` varchar(15) NOT NULL,
`fileExe` varchar(5) NOT NULL,
`fileSize` int(11) NOT NULL default '0',
`filePath` varchar(255) NOT NULL,
`originalName` varchar(100) NOT NULL,
`fileHash` varchar(40) NOT NULL,
`title` varchar(30) NOT NULL,
`description` varchar(255) NOT NULL,
`showTo` tinyint(1) NOT NULL default '0',
`defaultCV` tinyint(1) NOT NULL default '0',
`targetJobTitle` varchar(100) NOT NULL,
`targetJobTitleAlt` varchar(100) NOT NULL,
`educationIDFK` int(6) NOT NULL default '0',
`careerIDFK` int(6) NOT NULL default '0',
`city` varchar(100) NOT NULL,
`areYouAuth` varchar(100) NOT NULL,
`recentJobTitle` varchar(100) NOT NULL,
`recentEmployer` varchar(100) NOT NULL,
`recentIndustry` varchar(100) NOT NULL,
`recentCareer` int(6) NOT NULL default '0',
`recentStartDate` date NOT NULL,
`recentEndDate` varchar(50) NOT NULL,
`jobTypeIDFK` int(6) NOT NULL default '0',
`jobStatusIDFK` int(6) NOT NULL default '0',
`salaryMin` varchar(20) NOT NULL default '0',
`salaryMax` varchar(20) NOT NULL default '0',
`salaryCurrency` varchar(5) NOT NULL default 'GBP',
`salaryType` tinyint(2) NOT NULL default '5',
`relocate` tinyint(1) NOT NULL default '0',
`willing_to_travel` tinyint(2) NOT NULL default '0',
`availability` tinyint(1) NOT NULL default '0',
`startDate` varchar(30) NOT NULL,
`positions` varchar(100) NOT NULL,
`userComments` text,
`noViews` int(7) NOT NULL default '0',
`status` tinyint(1) NOT NULL default '0',
`adminComments` text,
`employeeIDFK` int(11) NOT NULL default '0',
`countryISO2FK` char(2) NOT NULL default 'US',
`countryStatesFK` varchar(100) NOT NULL,
`countryCountyFK` varchar(100) NOT NULL,
`experienceIDFK` int(6) NOT NULL default '0',
`modifyAt` datetime NOT NULL,
`createdAt` datetime NOT NULL,
PRIMARY KEY (`id`),
KEY `employeeIDFK` (`employeeIDFK`),
KEY `countryISO2FK` (`countryISO2FK`),
FULLTEXT KEY `searchCV` (`title`,`targetJobTitle`,`targetJobTitleAlt`,`recentJobTitle`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=2 ;
-- --------------------------------------------------------
--
-- Table structure for table `opjb_cvCategory`
--
CREATE TABLE IF NOT EXISTS `opjb_cvCategory` (
`cvIDFK` int(11) NOT NULL default '0',
`categoryIDFK` int(11) NOT NULL default '0',
PRIMARY KEY (`cvIDFK`,`categoryIDFK`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
-- --------------------------------------------------------
--
-- Table structure for table `opjb_education`
--
CREATE TABLE IF NOT EXISTS `opjb_education` (
`id` int(6) NOT NULL auto_increment,
`educationName` varchar(100) NOT NULL,
`lang` varchar(50) NOT NULL default 'english',
`isActive` tinyint(1) NOT NULL default '0',
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=11 ;
-- --------------------------------------------------------
--
-- Table structure for table `opjb_employee`
--
CREATE TABLE IF NOT EXISTS `opjb_employee` (
`id` int(11) NOT NULL auto_increment,
`emailAddress` varchar(100) NOT NULL,
`username` varchar(30) NOT NULL,
`passwd` varchar(40) NOT NULL,
`title` varchar(20) NOT NULL,
`firstName` varchar(100) NOT NULL,
`middleName` varchar(50) NOT NULL,
`surname` varchar(100) NOT NULL,
`address` varchar(150) NOT NULL,
`address2` varchar(100) NOT NULL,
`city` varchar(100) NOT NULL,
`countryCountyFK` varchar(100) NOT NULL,
`countryStatesFK` varchar(100) NOT NULL,
`countryISO2FK` char(2) NOT NULL default 'US',
`postCode` varchar(20) NOT NULL,
`careerStatus` tinyint(1) NOT NULL default '0',
`contPref` tinyint(1) NOT NULL default '0',
`webSite` varchar(100) NOT NULL,
`job_title` varchar(255) NOT NULL,
`recent_employer` varchar(255) NOT NULL,
`mobile_no` varchar(30) NOT NULL,
`home_no` varchar(30) NOT NULL,
`categoryIDFK` int(6) default NULL,
`careerDegreeIDFK` int(6) default NULL,
`educationIDFK` int(6) default NULL,
`experienceIDFK` int(6) default NULL,
`pers_statement` text,
`actKey` varchar(100) NOT NULL,
`comments` varchar(255) NOT NULL,
`status` tinyint(1) NOT NULL default '0',
`isActive` tinyint(1) NOT NULL default '0',
`lastVisit` datetime NOT NULL,
`modifyAt` datetime NOT NULL,
`createdAt` datetime NOT NULL,
`createip` varchar(20) NOT NULL default '0',
`loginip` varchar(20) NOT NULL default '0',
PRIMARY KEY (`id`),
UNIQUE KEY `emailAddress` (`emailAddress`),
UNIQUE KEY `username` (`username`),
KEY `city` (`city`,`countryCountyFK`),
KEY `countryISO2FK` (`countryISO2FK`),
KEY `idx_fullname` (`firstName`,`surname`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=3 ;
-- --------------------------------------------------------
--
-- Table structure for table `opjb_experience`
--
CREATE TABLE IF NOT EXISTS `opjb_experience` (
`id` int(6) NOT NULL auto_increment,
`experienceName` varchar(100) NOT NULL,
`lang` varchar(50) NOT NULL default 'english',
`isActive` tinyint(1) NOT NULL default '0',
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=8 ;
-- --------------------------------------------------------
--
-- Table structure for table `opjb_type`
--
CREATE TABLE IF NOT EXISTS `opjb_type` (
`id` int(6) NOT NULL auto_increment,
`typeName` varchar(100) NOT NULL,
`lang` varchar(50) NOT NULL default 'english',
`isActive` tinyint(1) NOT NULL default '0',
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=4 ;