You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
1.5 KiB

2 years ago
  1. using EasyNet.DBUtility;
  2. using System.Collections.Generic;
  3. namespace EasyNet.Common
  4. {
  5. public class DbKeywords
  6. {
  7. private static Dictionary<string, string> m_MySQL = new Dictionary<string, string>();
  8. private static Dictionary<string, string> m_MSSQL = new Dictionary<string, string>();
  9. private static void InitMySQL()
  10. {
  11. if (m_MySQL.Count == 0)
  12. {
  13. m_MySQL.Add("order", "`order`");
  14. m_MySQL.Add("desc", "`desc`");
  15. m_MySQL.Add("key", "`key`");
  16. }
  17. }
  18. private static void InitMSSQL()
  19. {
  20. if (m_MSSQL.Count == 0)
  21. {
  22. m_MSSQL.Add("order", "[order]");
  23. m_MSSQL.Add("desc", "[desc]");
  24. m_MSSQL.Add("key", "[key]");
  25. m_MSSQL.Add("text", "[text]");
  26. m_MSSQL.Add("index", "[index]");
  27. m_MSSQL.Add("weight", "[weight]");
  28. }
  29. }
  30. public static string FormatColumnName(string colounName)
  31. {
  32. InitMySQL();
  33. InitMSSQL();
  34. var colName = colounName.ToLower();
  35. if (AdoHelper.DbType == DatabaseType.MYSQL && m_MySQL.ContainsKey(colName))
  36. {
  37. return m_MySQL[colName];
  38. }
  39. if (AdoHelper.DbType == DatabaseType.SQLSERVER && m_MSSQL.ContainsKey(colName))
  40. {
  41. return m_MSSQL[colName];
  42. }
  43. return colounName;
  44. }
  45. }
  46. }