dotnetcore / FreeSql

🦄 .NET aot orm, C# orm, VB.NET orm, Mysql orm, Postgresql orm, SqlServer orm, Oracle orm, Sqlite orm, Firebird orm, 达梦 orm, 人大金仓 orm, 神通 orm, 翰高 orm, 南大通用 orm, 虚谷 orm, 国产 orm, Clickhouse orm, QuestDB orm, MsAccess orm.
http://freesql.net
MIT License
4.03k stars 840 forks source link

自定义odbc适配使用字典插入失效 #1332

Closed RicardoHWu closed 1 year ago

RicardoHWu commented 1 year ago

程序需要使用odbc方式读写mdb格式的access数据库,按照odbc自定义适配的说明重写了OdbcAdapter

public class AccessOdbcAdapter:OdbcAdapter {
        public override string UnicodeStringRawSql(object value, ColumnInfo mapColumn) => value == null ? "NULL" : string.Concat("'", value.ToString().Replace("'", "''"), "'");
}

并在创建IFreeSql实例时调用SetOdbcAdapter进行设置

private static IFreeSql CreateInstance(string connectString, DataType type){
            IFreeSql client= new FreeSqlBuilder()
                .UseConnectionString(type, connectString)
                .Build();
            if (DataType.Odbc.Equals(type)) {
                client.SetOdbcAdapter(new AccessOdbcAdapter());
            }
            return client;
}

但在调用插入字典的方法时失败

IFreeSql client = CreateInstance(@"Driver={Microsoft Access Driver (*.mdb)};DBQ=C:\Project\dotnet\data\test.mdb",DataType.Odbc);
Dictionary<string, object> data = new Dictionary<string, object>();
data.Add("ExpNo", "RSP0950008");
data.Add("SPoint", "RSP0950004");
data.Add("EPoint", "RSP095000440");
data.Add("PType", "RS");
data.Add("GType", "窨井轮廓线");
data.Add("LineStyle", 2);
data.Add("Memo", null);
data.Add("ClassID", null);
client.InsertDict(data).AsTable("FZLINE").ExecuteAffrows();

错误信息为ERROR [42000] [Microsoft][ODBC Microsoft Access 驱动程序] 语法错误 (操作符丢失) 在查询表达式 'N'RSP0950008'' 中。 打印sql语句为INSERT INTO [FZLINE]([ExpNo], [SPoint], [EPoint], [PType], [GType], [LineStyle], [Memo], [ClassID]) VALUES(N'RSP0950008', N'RSP0950004', N'RSP095000440', N'RS', N'窨井轮廓线', 2, NULL, NULL),自定义的转换不生效。

使用的FreeSql、DbContext、Respository、Provider.Odbc版本均为3.2.682,.net framework版本4.5

2881099 commented 1 year ago

v3.2.683-preview20221115 已修复