Advertisement
Guest User

Untitled

a guest
Aug 21st, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.43 KB | None | 0 0
  1. CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_contact_meeting_insert`(IN `l_id` INT, IN `name` VARCHAR(100), IN `location` VARCHAR(255), IN `start_date` DATETIME, IN `end_date` DATETIME, IN `description` TEXT, IN `date` DATETIME, IN `user` VARCHAR(100), IN `user_list` VARCHAR(300), OUT `sukses` INT)
  2. NO SQL
  3. BEGIN
  4.  
  5. DECLARE exit handler for sqlexception
  6. BEGIN
  7. GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,
  8. @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
  9. SET @full_error = CONCAT("ERROR ", @errno, " (", @sqlstate, "): ", @text);
  10. SELECT @full_error;
  11. SET sukses=0;
  12. ROLLBACK;
  13. END;
  14.  
  15. DECLARE exit handler for sqlwarning
  16. BEGIN
  17. GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,
  18. @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
  19. SET @full_error = CONCAT("Warning ", @errno, " (", @sqlstate, "): ", @text);
  20. SELECT @full_error;
  21. SET sukses=0;
  22. ROLLBACK;
  23. END;
  24. drop temporary table if exists temp_cursor_table;
  25. set @temp = concat('CREATE TEMPORARY TABLE IF NOT EXISTS temp_cursor_table AS (SELECT user_id FROM crm_users where user_id in(', user_list ,') )');
  26. prepare pst from @temp;
  27. execute pst;
  28. drop prepare pst;
  29. INSERT INTO `contact_meeting`(`contact_id`, `contact_meeting_name`, `contact_meeting_location`, `contact_meeting_start_date`, `contact_meeting_end_date`, `contact_meeting_description`, `contact_meeting_date`, `contact_meeting_user`) VALUES (l_id,name,location,start_date,end_date,description,date,user);
  30. SET @meet_id = LAST_INSERT_ID();
  31. INSERT INTO `contact_meeting_users`(`contact_meeting_id`,`contact_user_id`)
  32. SELECT @meet_id,user_id from temp_cursor_table;
  33. drop temporary table if exists temp_cursor_table;
  34. set sukses=1;
  35. COMMIT;
  36. END
  37.  
  38. CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_contact_meeting_update`(IN `meet_id` INT, IN `l_id` INT, IN `name` VARCHAR(100), IN `location` VARCHAR(255), IN `start_date` DATETIME, IN `end_date` DATETIME, IN `description` TEXT, IN `date` DATETIME, IN `user` VARCHAR(100), IN `user_list` VARCHAR(300), OUT `sukses` INT)
  39. NO SQL
  40. BEGIN
  41.  
  42. DECLARE exit handler for sqlexception
  43. BEGIN
  44. GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,
  45. @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
  46. SET @full_error = CONCAT("ERROR ", @errno, " (", @sqlstate, "): ", @text);
  47. SELECT @full_error;
  48. SET sukses=0;
  49. ROLLBACK;
  50. END;
  51.  
  52. DECLARE exit handler for sqlwarning
  53. BEGIN
  54. GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,
  55. @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
  56. SET @full_error = CONCAT("Warning ", @errno, " (", @sqlstate, "): ", @text);
  57. SELECT @full_error;
  58. SET sukses=0;
  59. ROLLBACK;
  60. END;
  61. drop temporary table if exists temp_cursor_table;
  62. set @temp = concat('CREATE TEMPORARY TABLE IF NOT EXISTS temp_cursor_table AS (SELECT user_id FROM crm_users where user_id in(', user_list ,') )');
  63. prepare pst from @temp;
  64. execute pst;
  65. drop prepare pst;
  66. UPDATE `contact_meeting` SET
  67. `contact_meeting_name`=name,
  68. `contact_meeting_location`=location,
  69. `contact_meeting_start_date`=start_date,
  70. `contact_meeting_end_date`=end_date,
  71. `contact_meeting_description`=description,
  72. `contact_meeting_date`=date,
  73. `contact_meeting_user`=user,
  74. `contact_id`=l_id
  75. WHERE `contact_meeting_id`=meet_id;
  76. delete from contact_meeting_users where contact_meeting_id=meet_id;
  77. REPLACE INTO `contact_meeting_users`(`contact_meeting_id`,`contact_user_id`)
  78. SELECT meet_id,user_id from temp_cursor_table;
  79. drop temporary table if exists temp_cursor_table;
  80. set sukses=1;
  81. COMMIT;
  82. END
  83.  
  84. CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_contact_update`(IN `l_id` INT, IN `salutation` ENUM('1','2','3'), IN `first_name` VARCHAR(100), IN `last_name` VARCHAR(100), IN `job_title` VARCHAR(100), IN `company` VARCHAR(100), IN `department` VARCHAR(100), IN `email` VARCHAR(100), IN `office_phone` VARCHAR(30), IN `mobile_phone` VARCHAR(30), IN `industry` INT, IN `address1` VARCHAR(255), IN `address2` VARCHAR(255), IN `city` VARCHAR(100), IN `state` VARCHAR(100), IN `zip_code` VARCHAR(10), IN `country` VARCHAR(50), IN `sources` INT, IN `photo` VARCHAR(100), IN `comp_id` INT, IN `right_permission` ENUM('1','2','3'), IN `groups` INT, IN `user_list` VARCHAR(300), OUT `sukses` INT)
  85. NO SQL
  86. BEGIN
  87.  
  88. DECLARE exit handler for sqlexception
  89. BEGIN
  90. GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,
  91. @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
  92. SET @full_error = CONCAT("ERROR ", @errno, " (", @sqlstate, "): ", @text);
  93. SELECT @full_error;
  94. SET sukses=0;
  95. ROLLBACK;
  96. END;
  97.  
  98. DECLARE exit handler for sqlwarning
  99. BEGIN
  100. GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,
  101. @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
  102. SET @full_error = CONCAT("Warning ", @errno, " (", @sqlstate, "): ", @text);
  103. SELECT @full_error;
  104. SET sukses=0;
  105. ROLLBACK;
  106. END;
  107. drop temporary table if exists temp_cursor_table;
  108. set @temp = concat('CREATE TEMPORARY TABLE IF NOT EXISTS temp_cursor_table AS (SELECT user_id AS u_id FROM crm_users where user_id in(', user_list ,') )');
  109. prepare pst from @temp;
  110. execute pst;
  111. drop prepare pst;
  112. UPDATE `crm_peoples` a JOIN crm_contacts b ON a.people_id=b.people_id
  113. SET
  114. a.people_salutation=salutation,
  115. a.people_first_name=first_name,
  116. a.people_last_name=last_name,
  117. a.people_job_title=job_title,
  118. a.people_company=company,
  119. a.people_department=department,
  120. a.people_email=email,
  121. a.people_office_phone=office_phone,
  122. a.people_mobile_phone=mobile_phone,
  123. a.people_industry=industry,
  124. a.people_address1=address1,
  125. a.people_address2=address2,
  126. a.people_city=city,
  127. a.people_state=state,
  128. a.people_zip_code=zip_code,
  129. a.people_country=country,
  130. a.people_source=sources,
  131. a.people_photo=photo,
  132. b.contact_right_permission=right_permission,
  133. b.contact_groups=groups,
  134. b.company_id=comp_id
  135. WHERE b.contact_id = l_id;
  136. delete from crm_users_contacts where contact_id = l_id;
  137. REPLACE INTO `crm_users_contacts`(`contact_id`,`user_id`)
  138. SELECT l_id,u_id from temp_cursor_table;
  139. drop temporary table if exists temp_cursor_table;
  140. SET sukses = 1;
  141. COMMIT;
  142. END
  143.  
  144. CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_contact_insert`(IN `salutation` ENUM('1','2','3'), IN `first_name` VARCHAR(100), IN `last_name` VARCHAR(100), IN `job_title` VARCHAR(100), IN `company` VARCHAR(100), IN `department` VARCHAR(100), IN `email` VARCHAR(100), IN `office_phone` VARCHAR(30), IN `mobile_phone` VARCHAR(30), IN `industry` INT, IN `address1` VARCHAR(255), IN `address2` VARCHAR(255), IN `city` VARCHAR(100), IN `state` VARCHAR(100), IN `zip_code` VARCHAR(10), IN `country` VARCHAR(50), IN `sources` INT, IN `photo` VARCHAR(100), IN `comp_id` INT, IN `right_permission` ENUM('1','2','3'), IN `groups` INT, IN `user_list` VARCHAR(300), OUT `sukses` INT, OUT `contact_id` INT)
  145. NO SQL
  146. BEGIN
  147.  
  148. DECLARE exit handler for sqlexception
  149. BEGIN
  150. GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,
  151. @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
  152. SET @full_error = CONCAT("ERROR ", @errno, " (", @sqlstate, "): ", @text);
  153. SELECT @full_error;
  154. SET sukses=0;
  155. ROLLBACK;
  156. END;
  157.  
  158. DECLARE exit handler for sqlwarning
  159. BEGIN
  160. GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,
  161. @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
  162. SET @full_error = CONCAT("Warning ", @errno, " (", @sqlstate, "): ", @text);
  163. SELECT @full_error;
  164. SET sukses=0;
  165. ROLLBACK;
  166. END;
  167. drop temporary table if exists temp_cursor_table;
  168. set @temp = concat('CREATE TEMPORARY TABLE IF NOT EXISTS temp_cursor_table AS (SELECT user_id AS u_id FROM crm_users where user_id in(', user_list ,') )');
  169. prepare pst from @temp;
  170. execute pst;
  171. drop prepare pst;
  172.  
  173. INSERT INTO `crm_peoples`(`people_salutation`, `people_first_name`, `people_last_name`, `people_job_title`, `people_company`, `people_department`, `people_email`, `people_office_phone`, `people_mobile_phone`, `people_industry`, `people_address1`, `people_address2`, `people_city`, `people_state`, `people_zip_code`, `people_country`, `people_source`, `people_photo`, `people_status`) VALUES (salutation, first_name, last_name, job_title, company, department, email, office_phone, mobile_phone, industry, address1, address2, city, state, zip_code, country, sources, photo, '2');
  174. SET @p_id = LAST_INSERT_ID();
  175. INSERT INTO `crm_contacts`(`people_id`, `contact_right_permission`, `contact_groups`, `company_id`) VALUES (@p_id, right_permission, groups, comp_id);
  176. SET @l_id = LAST_INSERT_ID();
  177. INSERT INTO `crm_users_contacts`(`contact_id`,`user_id`)
  178. SELECT @l_id,u_id from temp_cursor_table;
  179. SET contact_id = @l_id;
  180. drop temporary table if exists temp_cursor_table;
  181. SET sukses = 1;
  182. COMMIT;
  183. END
  184.  
  185. CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_contact_meeting_delete`(IN `meet_id` INT, OUT `sukses` INT)
  186. NO SQL
  187. BEGIN
  188.  
  189.  
  190. DECLARE exit handler for sqlexception
  191. BEGIN
  192. GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,
  193. @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
  194. SET @full_error = CONCAT("ERROR ", @errno, " (", @sqlstate, "): ", @text);
  195. SELECT @full_error;
  196. SET sukses=0;
  197. ROLLBACK;
  198. END;
  199.  
  200. DECLARE exit handler for sqlwarning
  201. BEGIN
  202. GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE,
  203. @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
  204. SET @full_error = CONCAT("Warning ", @errno, " (", @sqlstate, "): ", @text);
  205. SELECT @full_error;
  206. SET sukses=0;
  207. ROLLBACK;
  208. END;
  209.  
  210. START TRANSACTION;
  211. DELETE FROM contact_meeting_users WHERE contact_meeting_id = meet_id;
  212. DELETE FROM contact_meeting WHERE contact_meeting_id = meet_id;
  213. SET sukses = 1;
  214. COMMIT;
  215. END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement