Problem with SaveOrUpdate

59 views
Skip to first unread message

FabioDA

unread,
Oct 22, 2012, 4:43:25 PM10/22/12
to catnap-or...@googlegroups.com
I have a problem I can't get out of...
I'm developing an android project, and have mapped all my entities.  It all seems to function fine as long as i'm reading or inserting new records, but when I try to SaveOrUpdate an existing record (using the same method that saves a new record), I get an error stating 
Mono.Data.Sqlite.SqliteException: SQLite error
Insufficient parameters supplied to the command
  at Mono.Data.Sqlite.SqliteStatement.BindParameter (Int32 index, Mono.Data.Sqlite.SqliteParameter param) [0x00000] in <filename unknown>:0
  at Mono.Data.Sqlite.SqliteStatement.BindParameters () [0x00000] in <filename unknown>:0
  at Mono.Data.Sqlite.SqliteCommand.BuildNextCommand () [0x00000] in <filename unknown>:0

I made a small project with 1 entity with 2 fields, and I constantly get this error.

this is my test class: 

public class Customer
{
public int CustomerID { get; set; }
public string name { get; set; }
}

this is my mapping:

d.Entity<Customer> (e => {
e.Table ("Customers");
e.Id (x => x.CustomerID);
e.Property (x => x.name);
});


This is my test code that fails:
Customer customer = null;
using (var sess = Repository.sessionFactory.Create()) {
sess.Open ();
customer = new Customer ();
sess.SaveOrUpdate (customer);
int id = customer.CustomerID;
customer = sess.Get<Customer> (id);
sess.SaveOrUpdate (customer);
}

as you can see I'm just creating a new customer, I reload it and saving it again triggers the error.
I stepped through the source code.  It seems the update query is generated fine with all parameters correctly set, but fails. 

Any hint on how to solve this?

Thanks.

Fabio



FabioDA

unread,
Oct 28, 2012, 3:37:56 AM10/28/12
to catnap-or...@googlegroups.com
Anybody??

Tim Scott

unread,
Oct 28, 2012, 11:58:40 AM10/28/12
to catnap-or...@googlegroups.com
Fabio,

Can you try to do the same operation in straight ADO and see if it fails? If it does not fail, then you must try to see what the difference is to narrow it down to a problem in Catnap. If it does fail, it's a MonoDroid issue to take up with Xamarin. I was having problem with Catnap and MonoTouch. The following workaround "solved" it for me:

var connection = (IDbConnection) new SqliteConnection(ListViewController.connectionString);
connection.Open();
var command = connection.CreateCommand();
command.CommandText = "update Item set Done = @done where id = @id";

var doneParam = command.CreateParameter();
doneParam.ParameterName = "@done";
doneParam.DbType = DbType.Boolean;
doneParam.Value = item.Done;
command.Parameters.Add(doneParam);

var idParam = command.CreateParameter();
idParam.ParameterName = "@id";
idParam.DbType = DbType.Int32;
idParam.Value = item.Id;
command.Parameters.Add(idParam);

command.ExecuteNonQuery();

I am not suggesting our problems are in any way related, I just wanted to give you an example how to use straight ADO.

By the way, my app does not blow up on the DB call but later as a result of the DB call.  It's a regression that appeared following a MonoTouch upgrade. It seems to be some problem with aggressive garbage collection.  I have not yet take the time to solve my issue.

Tim

FabioDA

unread,
Oct 29, 2012, 8:54:08 AM10/29/12
to catnap-or...@googlegroups.com
Thank you for replying.  I haven't tried that yet.  From what I've seen debugging, the parameters are all set correctly (I do have some null fields...).
I'll try your suggestion and see if that works.

Thank you.

Fabio
Reply all
Reply to author
Forward
0 new messages