Documents

Installation

  • Download DatabasesCx.vsix and double click to install. It is better to close MS Visual Studio first.

Database Usage

  • Create Database

C#

using DatabasesCx;

String pathName = Windows.Storage.ApplicationData.Current.LocalFolder.Path + "\\myDb.db";

SQLiteCx mySql = new SQLiteCx(pathName);

C++

using namespace DatabasesCx;

String^ pathName = Windows::Storage::ApplicationData::Current->LocalFolder->Path + "\\myDb.db";

SQLiteCx^ mySql = ref new DatabasesCx::SQLiteCx(pathName);

  • Create Table

C#

await mySql.ExecuteAsync("create table if not exists mytable (id int, name text, salary real, file blob)");

C++

create_task(mySql->ExecuteAsync(L"create table if not exists mytable (id int, name text, salary real, file blob)"));

  • Retrieve Data

C#

ObservableCollection<RowCx> rowsOut = new ObservableCollection<RowCx>();;

await mySql.GetAsync("select rowid, id, name, salary, file from mytable", rowsOut);

itemsViewSource.Source = rowsOut; // Data Binding

C++

auto rowsOut = ref new Vector<RowCx^>();

create_task(mySql->GetAsync(L"select rowid, id, name, salary, file from mytable", rowsOut));

itemsViewSource->Source = rowsOut; // Data Binding

  • Insert Data

C#

IList<byte> buf = new List<byte> { 0x00, 0x01, 0x02, 0x03, 0x04 };

IList<RowCx> myList = new List<RowCx> {

new RowCx( new List<ColumnCx>{ new ColumnCx("id", 0L), new ColumnCx("name", "Poom Malakul"), new ColumnCx("salary", 2500.23), new ColumnCx("file", buf)}),

new RowCx( new List<ColumnCx>{ new ColumnCx("id", 2L), new ColumnCx("name", "John Malakul"), new ColumnCx("salary", 3500.23), new ColumnCx("file", buf)}),

new RowCx( new List<ColumnCx>{ new ColumnCx("id", 3L), new ColumnCx("name", null), new ColumnCx("salary", 4500.23), new ColumnCx("file", null)})

};

int count = await mySql.SetAsync("insert into mytable (id, name, salary, file ) values (?1,?2,?3,?4)", myList);

C++

Vector<unsigned char>^ buf = ref new Vector<unsigned char>{ 0x00, 0x01, 0x02, 0x03, 0x04 };

Vector<RowCx^>^ rows = ref new Vector<RowCx^> {

ref new RowCx( ref new Vector<ColumnCx^>{ ref new ColumnCx("id", safe_cast<Object^>(0LL)), ref new ColumnCx("name", "Poom Malakul"), ref new ColumnCx("salary", 2500.23), ref new ColumnCx("file", std::move(buf)) } ),

ref new RowCx( ref new Vector<ColumnCx^>{ ref new ColumnCx("id", 2LL), ref new ColumnCx("name", "John Malakul"), ref new ColumnCx("salary", 4500.23), ref new ColumnCx("file", std::move(buf)) } ),

ref new RowCx( ref new Vector<ColumnCx^>{ ref new ColumnCx("id", 3LL), ref new ColumnCx("name", nullptr), ref new ColumnCx("salary", 4500.23), ref new ColumnCx("file", nullptr) } )

};

task<int> insertTask = create_task(mySql->SetAsync(L"insert into mytable (id, name, salary, file ) values (?1,?2,?3,?4)", rows));

  • Update Data

C#

IList<RowCx> rows = new List<RowCx>{ _row };

string command = "update mytable set id=?1, name=?2, salary=?3, mimetype=?4, file=?5 where rowid=" + _rowid;

int count = await mySql.SetAsync(command, rows);

C++

Vector<RowCx^>^ rows = ref new Vector<RowCx^>{ _row };

String^ command = "update mytable set id=?1, name=?2, salary=?3, mimetype=?4, file=?5 where rowid=" + _rowid;

task<int> updateTask = create_task(mySql->SetAsync(command, rows));

  • Delete Data

C#

await mySql.ExecuteAsync("delete from mytable where rowid=" + rowid);

C++

create_task(mySql->ExecuteAsync(L"delete from mytable where rowid=" + rowid));