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.

110 lines
6.6 KiB

2 years ago
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. namespace SqlSugar
  5. {
  6. public class SqliteDbBind : DbBindProvider
  7. {
  8. public override string GetDbTypeName(string csharpTypeName)
  9. {
  10. if (csharpTypeName == UtilConstants.ByteArrayType.Name)
  11. {
  12. return "blob";
  13. }
  14. if (csharpTypeName == "Int32")
  15. csharpTypeName = "int";
  16. if (csharpTypeName == "Int16")
  17. csharpTypeName = "short";
  18. if (csharpTypeName == "Int64")
  19. csharpTypeName = "long";
  20. if (csharpTypeName == "Boolean")
  21. csharpTypeName = "bool";
  22. var mappings = this.MappingTypes.Where(it => it.Value.ToString().Equals(csharpTypeName, StringComparison.CurrentCultureIgnoreCase));
  23. return mappings.HasValue() ? mappings.First().Key : "varchar";
  24. }
  25. public override List<KeyValuePair<string, CSharpDataType>> MappingTypes
  26. {
  27. get
  28. {
  29. var extService = this.Context.CurrentConnectionConfig.ConfigureExternalServices;
  30. if (extService != null && extService.AppendDataReaderTypeMappings.HasValue())
  31. {
  32. return extService.AppendDataReaderTypeMappings.Union(MappingTypesConst).ToList();
  33. }
  34. else
  35. {
  36. return MappingTypesConst;
  37. }
  38. }
  39. }
  40. public static List<KeyValuePair<string, CSharpDataType>> MappingTypesConst = new List<KeyValuePair<string, CSharpDataType>>
  41. {
  42. new KeyValuePair<string, CSharpDataType>("integer",CSharpDataType.@int),
  43. new KeyValuePair<string, CSharpDataType>("int",CSharpDataType.@int),
  44. new KeyValuePair<string, CSharpDataType>("int32",CSharpDataType.@int),
  45. new KeyValuePair<string, CSharpDataType>("integer32",CSharpDataType.@int),
  46. new KeyValuePair<string, CSharpDataType>("number",CSharpDataType.@int),
  47. new KeyValuePair<string, CSharpDataType>("varchar",CSharpDataType.@string),
  48. new KeyValuePair<string, CSharpDataType>("varchar2",CSharpDataType.@string),
  49. new KeyValuePair<string, CSharpDataType>("nvarchar",CSharpDataType.@string),
  50. new KeyValuePair<string, CSharpDataType>("nvarchar2",CSharpDataType.@string),
  51. new KeyValuePair<string, CSharpDataType>("text",CSharpDataType.@string),
  52. new KeyValuePair<string, CSharpDataType>("ntext",CSharpDataType.@string),
  53. new KeyValuePair<string, CSharpDataType>("blob_text",CSharpDataType.@string),
  54. new KeyValuePair<string, CSharpDataType>("char",CSharpDataType.@string),
  55. new KeyValuePair<string, CSharpDataType>("nchar",CSharpDataType.@string),
  56. new KeyValuePair<string, CSharpDataType>("num",CSharpDataType.@string),
  57. new KeyValuePair<string, CSharpDataType>("currency",CSharpDataType.@string),
  58. new KeyValuePair<string, CSharpDataType>("datetext",CSharpDataType.@string),
  59. new KeyValuePair<string, CSharpDataType>("word",CSharpDataType.@string),
  60. new KeyValuePair<string, CSharpDataType>("graphic",CSharpDataType.@string),
  61. new KeyValuePair<string, CSharpDataType>("tinyint",CSharpDataType.@byte),
  62. new KeyValuePair<string, CSharpDataType>("unsignedinteger8",CSharpDataType.@byte),
  63. new KeyValuePair<string, CSharpDataType>("smallint",CSharpDataType.@short),
  64. new KeyValuePair<string, CSharpDataType>("int16",CSharpDataType.@short),
  65. new KeyValuePair<string, CSharpDataType>("bigint",CSharpDataType.@long),
  66. new KeyValuePair<string, CSharpDataType>("int64",CSharpDataType.@long),
  67. new KeyValuePair<string, CSharpDataType>("long",CSharpDataType.@long),
  68. new KeyValuePair<string, CSharpDataType>("integer64",CSharpDataType.@long),
  69. new KeyValuePair<string, CSharpDataType>("bit",CSharpDataType.@bool),
  70. new KeyValuePair<string, CSharpDataType>("bool",CSharpDataType.@bool),
  71. new KeyValuePair<string, CSharpDataType>("boolean",CSharpDataType.@bool),
  72. new KeyValuePair<string, CSharpDataType>("real",CSharpDataType.@double),
  73. new KeyValuePair<string, CSharpDataType>("double",CSharpDataType.@double),
  74. new KeyValuePair<string, CSharpDataType>("float",CSharpDataType.@float),
  75. new KeyValuePair<string, CSharpDataType>("float",CSharpDataType.Single),
  76. new KeyValuePair<string, CSharpDataType>("decimal",CSharpDataType.@decimal),
  77. new KeyValuePair<string, CSharpDataType>("dec",CSharpDataType.@decimal),
  78. new KeyValuePair<string, CSharpDataType>("numeric",CSharpDataType.@decimal),
  79. new KeyValuePair<string, CSharpDataType>("money",CSharpDataType.@decimal),
  80. new KeyValuePair<string, CSharpDataType>("smallmoney",CSharpDataType.@decimal),
  81. new KeyValuePair<string, CSharpDataType>("datetime",CSharpDataType.DateTime),
  82. new KeyValuePair<string, CSharpDataType>("timestamp",CSharpDataType.DateTime),
  83. new KeyValuePair<string, CSharpDataType>("date",CSharpDataType.DateTime),
  84. new KeyValuePair<string, CSharpDataType>("time",CSharpDataType.DateTime),
  85. new KeyValuePair<string, CSharpDataType>("blob",CSharpDataType.byteArray),
  86. new KeyValuePair<string, CSharpDataType>("clob",CSharpDataType.byteArray),
  87. new KeyValuePair<string, CSharpDataType>("raw",CSharpDataType.byteArray),
  88. new KeyValuePair<string, CSharpDataType>("oleobject",CSharpDataType.byteArray),
  89. new KeyValuePair<string, CSharpDataType>("binary",CSharpDataType.byteArray),
  90. new KeyValuePair<string, CSharpDataType>("photo",CSharpDataType.byteArray),
  91. new KeyValuePair<string, CSharpDataType>("picture",CSharpDataType.byteArray),
  92. new KeyValuePair<string, CSharpDataType>("varchar",CSharpDataType.Guid),
  93. new KeyValuePair<string, CSharpDataType>("guid",CSharpDataType.Guid)
  94. };
  95. public override List<string> StringThrow
  96. {
  97. get
  98. {
  99. return new List<string> { "int32", "datetime", "decimal", "double", "byte"};
  100. }
  101. }
  102. }
  103. }