Page tree
Skip to end of metadata
Go to start of metadata

This guide explains how to use the Table object in a project.

Create Table

Creating local table in a project with the Smartface means creating SQLite table in an app for Android and iOS. There are two approaches to create the table objects:

With Sql

A table can also be created by The SQL query:

Data.execute("DROP TABLE IF EXISTS testtable;");
Data.execute("Create table testtable (col1 int, col2 int)");
Data Types

A table can have different kinds of columns, let's insert different types as Integer, String, DateTime and Float columns.

Data.execute("DROP TABLE IF EXISTS myTable;");
Data.execute("CREATE TABLE myTable(myColumn1 INTEGER PRIMARY KEY AUTOINCREMENT DEFAULT 1, myColumn2 TEXT, myColumn3 DATETIME DEFAULT '20.10.2015', myColumn4 FLOAT DEFAULT 2)");

Fill Data

With Sql

A table can be inserted by The SQL query:

var i, j;
for (i = 0; i < 10; i++) {
	for (j = 0; j < 10; j++) {
		Data.execute("insert into testtable(col1, col2)values( ? ,  ? )", i, j);

Table Properties

How to Keep Data Secure

In order to keep all data in secure, you can encrypt your datas with JS encryption libraries.

function generateEncryptValue(value) {
	return encryptedValue; // Some encryption methods needs to be used.
var path = "database.sqlite";
var db = new Data.Database(path);
var btnEncrypt = new SMF.UI.TextButton({
		left : "12%",
		top : "10%",
		height : "10%",
		width : "75%",
		text : "press to encrypt 1",
		onPressed : function () {
			var mySecureValue = generateEncryptValue(1) + ";";

Add the textButton btnEncrypt to the related page. Than when it's pressed the value 1 will be encrypted.

Run on Memory

If you need to filter a dataset, you may have to commit. If there is sensitive data committed, you should use the OnMemory table option. Therefore, the table will be kept in memory, but not stored locally. You can use inMemoryDB.sql file, which is placed inside Assets folder, in order to perform this.

Add the below code in inMemoryDB.sql as below :

CREATE TABLE IF NOT EXISTS "myTable" ("myColumn1" TEXT,"myColumn2" INTEGER);
INSERT INTO "myTable" VALUES("a",1);
INSERT INTO "myTable" VALUES("b",2);
INSERT INTO "myTable" VALUES("c",3);
INSERT INTO "myTable" VALUES("d",4);
INSERT INTO "myTable" VALUES("e",5);

Finally, developer must run inMemoryDb.sql as below:;

Keep in mind that, inMemoryDb.sql is in memoryDB, not in defaultDB.