I am using Mono, SQLite, Dapper & Dapper Extensions. I can read from the database but Insert is not working. I am using Mono Driver for sqlite.
Error is not very informative, atleast to me. Any help will be much appreciated.
Error:
SQLite error
near ".": syntax error
at Mono.Data.Sqlite.SQLite3.Prepare (Mono.Data.Sqlite.SqliteConnection cnn, System.String strSql, Mono.Data.Sqlite.SqliteStatement previous, UInt32 timeoutMS, System.String& strRemain) [0x00000] in <filename unknown>:0
at Mono.Data.Sqlite.SqliteCommand.BuildNextCommand () [0x00000] in <filename unknown>:0
Test code:
public void can_add_a_service_record()
{
var provider = new Provider { Name = "Hotmail" };
int id = providerData.Insert(provider);
Assert.AreEqual("Hotmail", providerData.Get(id).Name);
}
The code for insert is as follows.
public virtual int Insert (TEntity entity)
{
var connection = SqlHelper.GetConnection();
int id = connection.Insert<TEntity>(entity);
connection.Close();
return id;
}
Thanks
Chirdeep
To me this looks like a Dapper Extensions issue, not a Dapper issue. In particular, I can not see a Sqlite dialect implemented: https://github.com/tmsmith/Dapper-Extensions/tree/master/DapperExtensions/Sql .
To resolve I would recommend you submit a patch the the Dapper Extensions project (which is totally separate to Dapper) or use a different wrapper on top of Dappe, or use Dapper without a wrapper.
For example, the following should work:
var id = cnn.Query<int>("insert cars values(@name); select last_insert_rowid()",
new {name = "bmw"});