DapperLib / DapperLib/Dapper.Contrib
Dapper error on insert record in Firebird
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 293
- Forks
- 109
- PR merge metrics
- No merged PRs in 30d
Description
I'm writing a multidabase application with Firebird and PostgreSQL, using Dapper and ASP.NET MVC (migrating from EF). The C# statements to perform CRUD operations in the PGSQL database work fine. When migrating to Firebird, just changing the concrete connection object from NpgsqlConnection to FbConnection, I receive the following error message when trying to insert a record:
FirebirdSql.Data.FirebirdClient.FbException: Dynamic SQL Error SQL error code = -104 Token unknown - line 1, column 23 [ ---> FirebirdSql.Data.Common.IscException: Dynamic SQL Error SQL error code = -104 Token unknown - line 1, column 23
Then, I tried to isolated the problem, testing the insert statement with pure ADO.NET with FirebirdClient (this works fine):
con.Open();
var SQL = "INSERT INTO UNMEDIDA(CD_UNIDADE, NM_UNIDADE, DS_SIGLA)
VALUES(@CD_UNIDADE, @NM_UNIDADE, @DS_SIGLA);";
var cmd = new FbCommand(SQL, con);
cmd.Parameters.AddWithValue("@CD_UNIDADE", 1);
cmd.Parameters.AddWithValue("@NM_UNIDADE", "AA");
cmd.Parameters.AddWithValue("@DS_SIGLA", "AA");
cmd.ExecuteNonQuery();
con.Close();
After, using Dapper without contrib, just the generic execute (this works fine too):
var SQL = "INSERT INTO UNMEDIDA(CD_UNIDADE, NM_UNIDADE, DS_SIGLA)
VALUES(@CD_UNIDADE, @NM_UNIDADE, @DS_SIGLA);";
object obj = new { CD_UNIDADE = 1, NM_UNIDADE = "AA", DS_SIGLA = "AA" };
con.Execute(SQL, obj);
The error ocurrs when I try to use the generic Insert. Dapper will try to use reflection in to the mapping class to extract field names, to build dynamically a insert statament. Probably this statament generated by Dapper has a sintax error. The following code works with PG and Dapper, but fails with FB:
[Table("UNMEDIDA")]
public class UNMEDIDA
{
[ExplicitKey]
public int CD_UNIDADE { get; set; }
public string NM_UNIDADE { get; set; }
public string DS_SIGLA { get; set; }
}
...
UNMEDIDA obj = new UNMEDIDA { CD_UNIDADE = 1, NM_UNIDADE = "AA", DS_SIGLA = "AA" };
con.Insert(obj);
The code above works fine with Npgsql.
Seens like a error in parameters dynamic generation or something.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with Dapper.Contrib's generic Insert path and reproduce the example using FbConnection and the UNMEDIDA model. Compare the SQL generated by Insert with the working raw Dapper Execute statement, then verify the behavior against PostgreSQL. Done means identifying the Firebird-incompatible generated syntax and adding a regression test for the corrected behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- backend, databases
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100