text: /*
  Author:			This code was generated by DALGen version 1.1.0.0 available at https://github.com/H0r53/DALGen
  Date:			12/16/2017
  Description:	Creates the eventcomment table and respective stored procedures
  
  */
  
  
  USE cory2v;
  
  
  
  -- ------------------------------------------------------------
  -- Drop existing objects
  -- ------------------------------------------------------------
  
  DROP TABLE IF EXISTS `cory2v`.`eventcomment`;
  DROP PROCEDURE IF EXISTS `cory2v`.`usp_eventcomment_Load`;
  DROP PROCEDURE IF EXISTS `cory2v`.`usp_eventcomment_LoadAll`;
  DROP PROCEDURE IF EXISTS `cory2v`.`usp_eventcomment_Add`;
  DROP PROCEDURE IF EXISTS `cory2v`.`usp_eventcomment_Update`;
  DROP PROCEDURE IF EXISTS `cory2v`.`usp_eventcomment_Delete`;
  DROP PROCEDURE IF EXISTS `cory2v`.`usp_eventcomment_Search`;
  
  
  -- ------------------------------------------------------------
  -- Create table
  -- ------------------------------------------------------------
  
  
  
  CREATE TABLE `cory2v`.`eventcomment` (
  Id INT AUTO_INCREMENT,
  Comment VARCHAR(32768),
  CustomerId INT,
  EventCommentStatusTypeId INT,
  EventId INT,
  CreateDate DATETIME,
  EditDate DATETIME,
  CONSTRAINT pk_eventcomment_Id PRIMARY KEY (Id),
  CONSTRAINT fk_eventcomment_CustomerId_securityuser_Id FOREIGN KEY (CustomerId) REFERENCES customer (Id),
  CONSTRAINT fk_eventcomment_StatusTypeId_statustype_Id FOREIGN KEY (EventCommentStatusTypeId) REFERENCES eventcommentstatustype (Id),
  CONSTRAINT fk_eventcomment_EventId_event_Id FOREIGN KEY (EventId) REFERENCES event (Id)
  );
  
  
  -- ------------------------------------------------------------
  -- Create default SCRUD sprocs for this table
  -- ------------------------------------------------------------
  
  
  DELIMITER //
  CREATE PROCEDURE `cory2v`.`usp_eventcomment_Load`
  (
  	 IN paramId INT
  )
  BEGIN
  	SELECT
  		`eventcomment`.`Id` AS `Id`,
  		`eventcomment`.`Comment` AS `Comment`,
  		`eventcomment`.`CustomerId` AS `CustomerId`,
  		`eventcomment`.`EventCommentStatusTypeId` AS `EventCommentStatusTypeId`,
  		`eventcomment`.`EventId` AS `EventId`,
  		`eventcomment`.`CreateDate` AS `CreateDate`,
  		`eventcomment`.`EditDate` AS `EditDate`
  	FROM `eventcomment`
  	WHERE 		`eventcomment`.`Id` = paramId;
  END //
  DELIMITER ;
  
  DELIMITER //
  CREATE PROCEDURE `cory2v`.`usp_eventcomment_LoadAll`
  ()
  BEGIN
  	SELECT
  		`eventcomment`.`Id` AS `Id`,
  		`eventcomment`.`Comment` AS `Comment`,
  		`eventcomment`.`CustomerId` AS `CustomerId`,
  		`eventcomment`.`EventCommentStatusTypeId` AS `EventCommentStatusTypeId`,
  		`eventcomment`.`EventId` AS `EventId`,
  		`eventcomment`.`CreateDate` AS `CreateDate`,
  		`eventcomment`.`EditDate` AS `EditDate`
  	FROM `eventcomment`;
  END //
  DELIMITER ;
  
  DELIMITER //
  CREATE PROCEDURE `cory2v`.`usp_eventcomment_Add`
  (
  	 IN paramComment VARCHAR(32768),
  	 IN paramCustomerId INT,
  	 IN paramEventCommentStatusTypeId INT,
  	 IN paramEventId INT,
  	 IN paramCreateDate DATETIME,
  	 IN paramEditDate DATETIME
  )
  BEGIN
  	INSERT INTO `eventcomment` (Comment,CustomerId,EventCommentStatusTypeId,EventId,CreateDate,EditDate)
  	VALUES (paramComment, paramCustomerId, paramEventCommentStatusTypeId, paramEventId, paramCreateDate, paramEditDate);
  	-- Return last inserted ID as result
  	SELECT LAST_INSERT_ID() as id;
  END //
  DELIMITER ;
  
  
  DELIMITER //
  CREATE PROCEDURE `cory2v`.`usp_eventcomment_Update`
  (
  	IN paramId INT,
  	IN paramComment VARCHAR(32768),
  	IN paramCustomerId INT,
  	IN paramEventCommentStatusTypeId INT,
  	IN paramEventId INT,
  	IN paramCreateDate DATETIME,
  	IN paramEditDate DATETIME
  )
  BEGIN
  	UPDATE `eventcomment`
  	SET Comment = paramComment
  		,CustomerId = paramCustomerId
  		,EventCommentStatusTypeId = paramEventCommentStatusTypeId
  		,EventId = paramEventId
  		,CreateDate = paramCreateDate
  		,EditDate = paramEditDate
  	WHERE		`eventcomment`.`Id` = paramId;
  END //
  DELIMITER ;
  
  
  DELIMITER //
  CREATE PROCEDURE `cory2v`.`usp_eventcomment_Delete`
  (
  	IN paramId INT
  )
  BEGIN
  	DELETE FROM `eventcomment`
  	WHERE		`eventcomment`.`Id` = paramId;
  END //
  DELIMITER ;
  
  
  DELIMITER //
  CREATE PROCEDURE `cory2v`.`usp_eventcomment_Search`
  (
  	IN paramId INT,
  	IN paramComment VARCHAR(32768),
  	IN paramCustomerId INT,
  	IN paramEventCommentStatusTypeId INT,
  	IN paramEventId INT,
  	IN paramCreateDate DATETIME,
  	IN paramEditDate DATETIME
  )
  BEGIN
  	SELECT
  		`eventcomment`.`Id` AS `Id`,
  		`eventcomment`.`Comment` AS `Comment`,
  		`eventcomment`.`CustomerId` AS `CustomerId`,
  		`eventcomment`.`EventCommentStatusTypeId` AS `EventCommentStatusTypeId`,
  		`eventcomment`.`EventId` AS `EventId`,
  		`eventcomment`.`CreateDate` AS `CreateDate`,
  		`eventcomment`.`EditDate` AS `EditDate`
  	FROM `eventcomment`
  	WHERE
  		COALESCE(eventcomment.`Id`,0) = COALESCE(paramId,eventcomment.`Id`,0)
  		AND COALESCE(eventcomment.`Comment`,'') = COALESCE(paramComment,eventcomment.`Comment`,'')
  		AND COALESCE(eventcomment.`CustomerId`,0) = COALESCE(paramCustomerId,eventcomment.`CustomerId`,0)
  		AND COALESCE(eventcomment.`EventCommentStatusTypeId`,0) = COALESCE(paramEventCommentStatusTypeId,eventcomment.`EventCommentStatusTypeId`,0)
  		AND COALESCE(eventcomment.`EventId`,0) = COALESCE(paramEventId,eventcomment.`EventId`,0)
  		AND COALESCE(CAST(eventcomment.`CreateDate` AS DATE), CAST(NOW() AS DATE)) = COALESCE(CAST(paramCreateDate AS DATE),CAST(eventcomment.`CreateDate` AS DATE), CAST(NOW() AS DATE))
  		AND COALESCE(CAST(eventcomment.`EditDate` AS DATE), CAST(NOW() AS DATE)) = COALESCE(CAST(paramEditDate AS DATE),CAST(eventcomment.`EditDate` AS DATE), CAST(NOW() AS DATE));
  END //
  DELIMITER ;
  
  
  