Skip to content

Commit

Permalink
[watchdata] woohoo sqlite-net-pcl works!
Browse files Browse the repository at this point in the history
  • Loading branch information
conceptdev committed Sep 12, 2016
1 parent a6fa7e9 commit 667b523
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 17 deletions.
4 changes: 2 additions & 2 deletions WatchData/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ watchOS 3 Data Access
Examples of storing and accessing data with watchOS 3.

* **Ado.Net** – a watch version of the [Ado.Net doc](https://developer.xamarin.com/guides/cross-platform/application_fundamentals/data/part_4_using_adonet/) using SQL commands to store and retrieve data on the watch.
* **Sqlite.Net**TODO...
* **Sqlite.Net** a watch version of the [SQLite.NET doc](https://developer.xamarin.com/guides/cross-platform/application_fundamentals/data/part_3_using_sqlite_orm/) using SQLite.NET "ORM" to store and retrieve objects on the watch.


![](Ado.Net/Screenshots/AdoData.png)
![](Ado.Net/Screenshots/AdoData.png) ![](SQLite.Net/Screenshots/SqliteNetData.png)

*watch screenshots use [Bezel](http://infinitapps.com/bezel/) courtesy of [infinitapps](http://infinitapps.com/)* :)
37 changes: 34 additions & 3 deletions WatchData/Sqlite.Net/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,38 @@ watchOS 3 version of the [SQLite.NET PCL doc](https://developer.xamarin.com/guid

Uses `WKInterfaceTable` to display the data.

**WARNING:** this sample is still "in progress", requires updates to SQLite.NET-PCL and/or SQLite.raw -- still figuring it out...
![](Screenshots/SqliteNetData.png)

`*** Terminating app due to uncaught exception 'System.Exception', reason: 'You need to call SQLitePCL.raw.SetProvider().'
***`

Create database and add data:

```
List<Stock> data = new List<Stock>();
// ...
string dbPath = Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.Personal),
"ormdemo.db3");
var db = new SQLiteConnection(dbPath);
db.CreateTable<Stock>();
if (db.Table<Stock>().Count() == 0)
{
// only insert the data if it doesn't already exist
var newStock = new Stock();
newStock.Id = "1";
newStock.Name = "Apple";
db.Insert(newStock);
//...
}
```

Read data and add to list for rendering:

```
var table = db.Table<Stock>();
foreach (var s in table)
{
Console.WriteLine(s.Id + " " + s.Name);
// rendered in WKInterfaceTable
data.Add(s);
}
```
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,6 @@ public override void Awake(NSObject context)

// https://developer.xamarin.com/guides/cross-platform/application_fundamentals/data/part_3_using_sqlite_orm/

//HACK: watchOS not starting up SQLite.NET-PCL :-(
//SQLitePCL.raw.SetProvider(new SQLitePCL.SQLite3Provider_internal())
//SQLitePCL.raw.SetProvider(new SQLitePCL.SQLite3Provider_e_sqlite3);
//SQLitePCL.Batteries.Init();

string dbPath = Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.Personal),
"ormdemo.db3");
Expand All @@ -51,6 +46,10 @@ public override void Awake(NSObject context)
newStock.Id = "3";
newStock.Name = "Microsoft";
db.Insert(newStock);
newStock = new Stock();
newStock.Id = "4";
newStock.Name = "IBM";
db.Insert(newStock);
}

Console.WriteLine("Reading data");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,17 @@
<Reference Include="System.Xml" />
<Reference Include="System.Core" />
<Reference Include="Xamarin.WatchOS" />
<Reference Include="SQLitePCL.raw">
<HintPath>..\packages-debug\SQLitePCL.raw.dll</HintPath>
<Reference Include="SQLiteNetWatch">
<HintPath>..\packages-debug\SQLiteNetWatch.dll</HintPath>
</Reference>
<Reference Include="SQLite-net">
<HintPath>..\packages\sqlite-net-pcl.1.1.2\lib\portable-net45+wp8+wpa81+win8+MonoAndroid10+MonoTouch10+Xamarin.iOS10\SQLite-net.dll</HintPath>
<Reference Include="SQLitePCLRaw.batteries_green">
<HintPath>..\packages-debug\SQLitePCLRaw.batteries_green.dll</HintPath>
</Reference>
<Reference Include="SQLitePCL.batteries">
<HintPath>..\packages\SQLitePCL.bundle_green.0.9.3\lib\portable-net45+netcore45+wpa81+wp8+MonoAndroid10+MonoTouch10+Xamarin.iOS10\SQLitePCL.batteries.dll</HintPath>
<Reference Include="SQLitePCLRaw.core">
<HintPath>..\packages-debug\SQLitePCLRaw.core.dll</HintPath>
</Reference>
<Reference Include="SQLitePCLRaw.provider.sqlite3">
<HintPath>..\packages-debug\SQLitePCLRaw.provider.sqlite3.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
Expand All @@ -124,4 +127,4 @@
</Compile>
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Xamarin\WatchOS\Xamarin.WatchOS.AppExtension.CSharp.targets" />
</Project>
</Project>
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit 667b523

Please sign in to comment.