Advertisement
Guest User

Untitled

a guest
Nov 29th, 2018
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.85 KB | None | 0 0
  1. using MySql.Data.MySqlClient;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Web;
  6.  
  7. namespace Web.Controllers
  8. {
  9. public class HibernateSequenceManager
  10. {
  11.  
  12. public static void incrementHibernateSequence()
  13. {
  14. string connStr = "server=localhost;user=root;database=pidev;port=3306;password=";
  15. MySqlConnection conn = new MySqlConnection(connStr);
  16. try
  17. {
  18.  
  19. conn.Open();
  20.  
  21. int currentHiber = getCurrentHibernateSequence();
  22. currentHiber++;
  23.  
  24. string sql = "UPDATE hibernate_sequence SET next_val=" + currentHiber;
  25. // string sql = "DELETE FROM hibernate_sequence";
  26.  
  27. MySqlCommand cmd = new MySqlCommand(sql, conn);
  28. cmd.ExecuteNonQuery();
  29. }
  30. catch (Exception ex)
  31. {
  32.  
  33. }
  34.  
  35. conn.Close();
  36.  
  37.  
  38.  
  39. }
  40.  
  41. public static int getCurrentHibernateSequence()
  42. {
  43. string connStr = "server=localhost;user=root;database=pidev;port=3306;password=";
  44. MySqlConnection conn = new MySqlConnection(connStr);
  45. try
  46. {
  47.  
  48. conn.Open();
  49.  
  50. string sql = "SELECT next_val FROM hibernate_sequence";
  51. MySqlCommand cmd = new MySqlCommand(sql, conn);
  52. object result = cmd.ExecuteScalar();
  53. if (result != null)
  54. {
  55. int r = Convert.ToInt32(result);
  56.  
  57. return r;
  58. }
  59. }
  60.  
  61. catch (Exception ex)
  62. {
  63.  
  64. }
  65.  
  66. conn.Close();
  67. return -1;
  68. }
  69.  
  70.  
  71.  
  72.  
  73. }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement