[MonoTouch] SQLite iOS binding to UITableView

2012-03-16 Thread JonW
Hi there. I've been playing with MonoTouch on a Mac for a few days and whilst
I'm getting there with several things (web services, customising the view
controllers etc) I am having real issues with SQLite. First off, there are
several types of data consumption via SQLite referred to in samples and on
other websites (SQLite-Net, Vici, MonoTouch.Data etc) - which is the
simplest method? Basically, my app will contain UITableViews and text boxes
and I want to be able to create my database (unless it already exists),
create tables (unless they already exist) and populate them on button click,
bind UITableViews to queries (like I would bind GridViews in .Net), update
and delete from them by Id. Any suggestions of a good, fully working example
of how to do this? I'm pulling my hair out here!

Another example I need is how to bind UITableViews to the output from my
consumed .Net web services.

Thank you for any help :-)

Jon

--
View this message in context: 
http://monotouch.2284126.n4.nabble.com/SQLite-iOS-binding-to-UITableView-tp4478704p4478704.html
Sent from the MonoTouch mailing list archive at Nabble.com.
___
MonoTouch mailing list
MonoTouch@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/monotouch


Re: [MonoTouch] SQLite iOS binding to UITableView

2012-03-16 Thread Nic Wise
I'd suggest you look at MonoTouch.Dialog for tableviews (after doing
some of the "raw" ones in a sample project, so you have an idea of how
they work under the hood)

And for Sqlite, I prefer Sqlite-net, tho I've found recently that
sometimes I shouldn't just load all the records and use linq to filter
them - using a query is way quicker :)

eg

var inc = conn.Query("select sum(Amount) as AmountSum from
\"Transaction\" where Direction = ? and TransactionDate between ? and
?",

(int)TransactionDirection.Income,

taxSettings.StartDate,
taxSettings.EndDate).FirstOrDefault ();

is good.

var total = (from t in conn.Table() where  select
t.Amount).Sum();

is VERY VERY bad if you have 3000+ records (it loads each one into an
object, and then sums it - 24ms vrs 2000ms)

So, remember it's a SQL database, but use it like an ORM most of the time :)



On Fri, Mar 16, 2012 at 16:52, JonW  wrote:
> Hi there. I've been playing with MonoTouch on a Mac for a few days and whilst
> I'm getting there with several things (web services, customising the view
> controllers etc) I am having real issues with SQLite. First off, there are
> several types of data consumption via SQLite referred to in samples and on
> other websites (SQLite-Net, Vici, MonoTouch.Data etc) - which is the
> simplest method? Basically, my app will contain UITableViews and text boxes
> and I want to be able to create my database (unless it already exists),
> create tables (unless they already exist) and populate them on button click,
> bind UITableViews to queries (like I would bind GridViews in .Net), update
> and delete from them by Id. Any suggestions of a good, fully working example
> of how to do this? I'm pulling my hair out here!
>
> Another example I need is how to bind UITableViews to the output from my
> consumed .Net web services.
>
> Thank you for any help :-)
>
> Jon
>
> --
> View this message in context: 
> http://monotouch.2284126.n4.nabble.com/SQLite-iOS-binding-to-UITableView-tp4478704p4478704.html
> Sent from the MonoTouch mailing list archive at Nabble.com.
> ___
> MonoTouch mailing list
> MonoTouch@lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/monotouch



-- 
Nic Wise
t.  +44 7788 592 806 | @fastchicken | http://www.linkedin.com/in/nicwise
b. http://www.fastchicken.co.nz/

Nearest Bus: find when the next bus is coming to your stop. http://goo.gl/Vcz1p
mobileAgent (for FreeAgent): get your accounts in your pocket.
http://goo.gl/IuBU
Trip Wallet: Keep track of your budget on the go: http://goo.gl/ePhKa
London Bike App: Find the nearest Boris Bike, and get riding! http://goo.gl/Icp2
___
MonoTouch mailing list
MonoTouch@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/monotouch


Re: [MonoTouch] SQLite iOS binding to UITableView

2012-03-16 Thread Nic Wise
Oh, and MT.D will kinda do bindings, but I tend to build the view in
LoadView and the populate them from my data in ViewWillAppear (and
manually load them back into the object before the view goes away or
when save is pressed).

MonoMobile.MVVM might have more binding tho.

On Fri, Mar 16, 2012 at 17:15, Nic Wise  wrote:
> I'd suggest you look at MonoTouch.Dialog for tableviews (after doing
> some of the "raw" ones in a sample project, so you have an idea of how
> they work under the hood)
>
> And for Sqlite, I prefer Sqlite-net, tho I've found recently that
> sometimes I shouldn't just load all the records and use linq to filter
> them - using a query is way quicker :)
>
> eg
>
> var inc = conn.Query("select sum(Amount) as AmountSum from
> \"Transaction\" where Direction = ? and TransactionDate between ? and
> ?",
>                                                                               
>  (int)TransactionDirection.Income,
>                                                                               
>  taxSettings.StartDate,
> taxSettings.EndDate).FirstOrDefault ();
>
> is good.
>
> var total = (from t in conn.Table() where  select
> t.Amount).Sum();
>
> is VERY VERY bad if you have 3000+ records (it loads each one into an
> object, and then sums it - 24ms vrs 2000ms)
>
> So, remember it's a SQL database, but use it like an ORM most of the time :)
>
>
>
> On Fri, Mar 16, 2012 at 16:52, JonW  wrote:
>> Hi there. I've been playing with MonoTouch on a Mac for a few days and whilst
>> I'm getting there with several things (web services, customising the view
>> controllers etc) I am having real issues with SQLite. First off, there are
>> several types of data consumption via SQLite referred to in samples and on
>> other websites (SQLite-Net, Vici, MonoTouch.Data etc) - which is the
>> simplest method? Basically, my app will contain UITableViews and text boxes
>> and I want to be able to create my database (unless it already exists),
>> create tables (unless they already exist) and populate them on button click,
>> bind UITableViews to queries (like I would bind GridViews in .Net), update
>> and delete from them by Id. Any suggestions of a good, fully working example
>> of how to do this? I'm pulling my hair out here!
>>
>> Another example I need is how to bind UITableViews to the output from my
>> consumed .Net web services.
>>
>> Thank you for any help :-)
>>
>> Jon
>>
>> --
>> View this message in context: 
>> http://monotouch.2284126.n4.nabble.com/SQLite-iOS-binding-to-UITableView-tp4478704p4478704.html
>> Sent from the MonoTouch mailing list archive at Nabble.com.
>> ___
>> MonoTouch mailing list
>> MonoTouch@lists.ximian.com
>> http://lists.ximian.com/mailman/listinfo/monotouch
>
>
>
> --
> Nic Wise
> t.  +44 7788 592 806 | @fastchicken | http://www.linkedin.com/in/nicwise
> b. http://www.fastchicken.co.nz/
>
> Nearest Bus: find when the next bus is coming to your stop. 
> http://goo.gl/Vcz1p
> mobileAgent (for FreeAgent): get your accounts in your pocket.
> http://goo.gl/IuBU
> Trip Wallet: Keep track of your budget on the go: http://goo.gl/ePhKa
> London Bike App: Find the nearest Boris Bike, and get riding! 
> http://goo.gl/Icp2



-- 
Nic Wise
t.  +44 7788 592 806 | @fastchicken | http://www.linkedin.com/in/nicwise
b. http://www.fastchicken.co.nz/

Nearest Bus: find when the next bus is coming to your stop. http://goo.gl/Vcz1p
mobileAgent (for FreeAgent): get your accounts in your pocket.
http://goo.gl/IuBU
Trip Wallet: Keep track of your budget on the go: http://goo.gl/ePhKa
London Bike App: Find the nearest Boris Bike, and get riding! http://goo.gl/Icp2
___
MonoTouch mailing list
MonoTouch@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/monotouch


Re: [MonoTouch] SQLite iOS binding to UITableView

2012-03-16 Thread Jeff Stedfast
Hi Jon,

Most people seem to use Frank Krueger's SQLite-Net binding as opposed to
System.Data because it's a bit simpler for most people.

As luck would have it, I'm working on trying to make a very easy to use /
generic (literally!) MonoTouch library for displaying data from a sqlite
database in a UITableViewController. I was planning about blogging about it
this weekend when I had worked out some of the remaining kinks and such,
but I can point you at it and the source code for my own personal app that
uses it (I want to write a simpler showcase app before I blog this weekend).

The SQLiteTableViewController library is at
https://github.com/jstedfast/MonoTouch.SQLite

You can see how I'm using it at
https://github.com/jstedfast/FlightLog/blob/master/FlightLog/Flights/FlightViewController.cs

It's a bit on the "advanced" side since it allows adding/deleting/editing
logbook entries, but maybe that'll be helpful to you :-)

In the simple case, you could just subclass SQLiteTableViewController
and get away with just implementing the following method:

*protected override UITableViewCell GetCell (UITableView tableView,
NSIndexPath path, T item)*

So... a very simple TableViewController might look like this:

// This represents an element in your sqlite database table named "Task"
public class Task {
[PrimaryKey][AutoIncrement]
public int TaskId { get; set; }

public string ToDo { get; set; }
}

public class TaskViewController : SQLiteViewController
{
static NSString key = new NSString ("TaskCellKey");

public TaskViewController () : base (sqlitedb, 16)
{
}

protected override UITableViewCell GetCell (UITableView tableView,
NSIndexPath path, Task task)
{
var cell = tableView.DequeueReusableCell (key);
if (cell == null)
cell = new UITableViewCell (UITableViewCellStyle.Plain, key);

cell.TextLabel.Text = "Task";
cell.DetailTextLabel.Text = task.ToDo;

return cell;
}
}

The SQLiteTableViewController would then handle all of the searching logic
for you...

Hope that helps,

Jeff

On Fri, Mar 16, 2012 at 12:52 PM, JonW  wrote:

> Hi there. I've been playing with MonoTouch on a Mac for a few days and
> whilst
> I'm getting there with several things (web services, customising the view
> controllers etc) I am having real issues with SQLite. First off, there are
> several types of data consumption via SQLite referred to in samples and on
> other websites (SQLite-Net, Vici, MonoTouch.Data etc) - which is the
> simplest method? Basically, my app will contain UITableViews and text boxes
> and I want to be able to create my database (unless it already exists),
> create tables (unless they already exist) and populate them on button
> click,
> bind UITableViews to queries (like I would bind GridViews in .Net), update
> and delete from them by Id. Any suggestions of a good, fully working
> example
> of how to do this? I'm pulling my hair out here!
>
> Another example I need is how to bind UITableViews to the output from my
> consumed .Net web services.
>
> Thank you for any help :-)
>
> Jon
>
> --
> View this message in context:
> http://monotouch.2284126.n4.nabble.com/SQLite-iOS-binding-to-UITableView-tp4478704p4478704.html
> Sent from the MonoTouch mailing list archive at Nabble.com.
> ___
> MonoTouch mailing list
> MonoTouch@lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/monotouch
>
___
MonoTouch mailing list
MonoTouch@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/monotouch


Re: [MonoTouch] SQLite iOS binding to UITableView

2012-03-16 Thread slodge
If you really want do do bindings then I've got some examples at
https://github.com/slodge/MvvmCross/blob/master/Sample%20-%20SimpleDialogBinding/SimpleBinding/SimpleBindingDialog/TipView.cs
- but that is a modified version of MT.Dialog

But most people don't do "bindings" - instead they fetch the data back from
the elements when they need to do a save

Hope that helps

Stuart

--
View this message in context: 
http://monotouch.2284126.n4.nabble.com/SQLite-iOS-binding-to-UITableView-tp4478704p4478865.html
Sent from the MonoTouch mailing list archive at Nabble.com.
___
MonoTouch mailing list
MonoTouch@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/monotouch


Re: [MonoTouch] SQLite iOS binding to UITableView

2012-03-16 Thread Karl Heinz Brehme Arredondo
I learned from Windows Mobile compact framework 2.0 to do not make bindings,
that there they was slower than fetch records in netcf 2.0 (and probably but
in a small scale, in all .NETs on windows, desktop, device and web).

So when I need bind something, I create a List, load it from
webservice or Sqlite or some cache loaded before, and then bind it to a
ViewTable, or fetch it to another thing that bind is slower or inexistant.

Karl

From:  slodge 
Date:  Fri, 16 Mar 2012 10:40:08 -0700 (PDT)
To:  "monotouch@lists.ximian.com" 
Subject:  Re: [MonoTouch] SQLite iOS binding to UITableView

If you really want do do bindings then I've got some examples at
https://github.com/slodge/MvvmCross/blob/master/Sample%20-%20SimpleDialogBin
ding/SimpleBinding/SimpleBindingDialog/TipView.cs
- but that is a modified version of MT.Dialog

But most people don't do "bindings" - instead they fetch the data back from
the elements when they need to do a save

Hope that helps

Stuart

--
View this message in context:
http://monotouch.2284126.n4.nabble.com/SQLite-iOS-binding-to-UITableView-tp4
478704p4478865.html
Sent from the MonoTouch mailing list archive at Nabble.com.
___
MonoTouch mailing list
MonoTouch@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/monotouch



___
MonoTouch mailing list
MonoTouch@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/monotouch


Re: [MonoTouch] SQLite iOS binding to UITableView

2012-03-16 Thread Stuart Lodge
Totally agree - I'm binding to in-memory objects - this isn't writing back
to the database or to a web-service on every change.

I'm a much more recent convert to data-binding - 12 months ago I didn't use
it at all, now I'm using it in all my Android XML and all my iPhone XIB
code too :)

Stuart

On 16 March 2012 17:48, Karl Heinz Brehme Arredondo <
k...@e-magesolutions.com> wrote:

> I learned from Windows Mobile compact framework 2.0 to do not make
> bindings, that there they was slower than fetch records in netcf 2.0 (and
> probably but in a small scale, in all .NETs on windows, desktop, device and
> web).
>
> So when I need bind something, I create a List, load it from
> webservice or Sqlite or some cache loaded before, and then bind it to a
> ViewTable, or fetch it to another thing that bind is slower or inexistant.
>
> Karl
>
> From: slodge 
> Date: Fri, 16 Mar 2012 10:40:08 -0700 (PDT)
> To: "monotouch@lists.ximian.com" 
> Subject: Re: [MonoTouch] SQLite iOS binding to UITableView
>
> If you really want do do bindings then I've got some examples at
>
> https://github.com/slodge/MvvmCross/blob/master/Sample%20-%20SimpleDialogBinding/SimpleBinding/SimpleBindingDialog/TipView.cs
> - but that is a modified version of MT.Dialog
>
> But most people don't do "bindings" - instead they fetch the data back from
> the elements when they need to do a save
>
> Hope that helps
>
> Stuart
>
> --
> View this message in context:
> http://monotouch.2284126.n4.nabble.com/SQLite-iOS-binding-to-UITableView-tp4478704p4478865.html
> Sent from the MonoTouch mailing list archive at Nabble.com.
> ___
> MonoTouch mailing list
> MonoTouch@lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/monotouch
>
>
___
MonoTouch mailing list
MonoTouch@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/monotouch


Re: [MonoTouch] SQLite iOS binding to UITableView

2012-03-16 Thread JonW
Wow, thanks Jeff - the code you've uploaded to GitHub looks excellent! I
shall try it out on Sunday and let you know how I get on.

--
View this message in context: 
http://monotouch.2284126.n4.nabble.com/SQLite-iOS-binding-to-UITableView-tp4478704p4479606.html
Sent from the MonoTouch mailing list archive at Nabble.com.
___
MonoTouch mailing list
MonoTouch@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/monotouch