Database Support

Thank you Ankita.
yes now it is working good

Thanks

1 Like

Did anybody face the error
"unable to open database file" ?

Have just called the CreateDB function provided by Ankita

So if I change the database file location from “data/test.db” to just “test.db”, then the open statement works fine, but the creating a table statement returns a “disk I/O error”.

I am sure its something related to permissions but don’t know what do I need to set.

Also I am running Legato 17.08.1.

And here is the c code

#include “legato.h”
// #include “interfaces.h”
#include “sqlite3.h”

void initOperation()
{
char *sql;
char *zErrMsg = 0;
sqlite3 *db;
// db = null;
// createDb(db);
int rc ;
// sqlite3 *db;
rc = sqlite3_open(“test.db”, &db);
if(!rc){
LE_INFO("Successfully Created ");
}
else {
LE_INFO(“Error in Creating/Opening Db file : %s\n”, sqlite3_errmsg(db));
}

if (db)
{
    LE_INFO("InitOperations Command For Table Creation");
    sql = "create table if not exists test_sqlite(ID int Primary key, valuename text , value int)";
    int rc = sqlite3_exec(db, sql, callback, 0, &zErrMsg);
    if (!rc)
    {
        LE_INFO("Executed Command For Table Creation");
    }
    else{
        LE_INFO("Error creation : %s",sqlite3_errmsg(db));
    }
}

}

COMPONENT_INIT
{
LE_INFO(“Sample to use Sqlite3 in Legato”);
//Implement functionalities
initOperation();
}

I eventually added it to the rootfs

diff --git a/common/recipes-core/packagegroups/packagegroup-swi-image-target.bb b/common/recipes-core/packagegroups/packagegroup-swi-image-target.bb
index 0bde906..2824e19 100644
--- a/common/recipes-core/packagegroups/packagegroup-swi-image-target.bb
+++ b/common/recipes-core/packagegroups/packagegroup-swi-image-target.bb
@@ -70,3 +70,8 @@ RDEPENDS_${PN} += "rng-tools"
 
 # Add tinucbor to all targets
 RDEPENDS_${PN} += "tinycbor"
+
+# Comb Addons
+RDEPENDS_${PN} += "tzdata"
+RDEPENDS_${PN} += "c-ares"
+RDEPENDS_${PN} += "sqlite3"
diff --git a/common/recipes-legato/legato-af/legato-af_git.bb b/common/recipes-legato/legato-af/legato-af_git.bb
index d9d7efe..3791b95 100644
--- a/common/recipes-legato/legato-af/legato-af_git.bb
+++ b/common/recipes-legato/legato-af/legato-af_git.bb
@@ -16,6 +16,8 @@ DEPENDS += "mtd-utils-native"
 DEPENDS += "curl"
 DEPENDS += "zlib"
 DEPENDS += "tinycbor"
+DEPENDS += "c-ares"
+DEPENDS += "sqlite3"
 
 # Build time dependencies (not in the rootfs image)
 do_compile[depends]  = "legato-tools:do_populate_sysroot"

hi Ankita,

please share the link. i need sqlite3 in my project
many thanks in advance

thanks

hi i added the SQlite3 through image . Now i need to add the Sqlite3 in my program can any one guide how to add the Sqlite3 in legato program

Did you follow the above method?

Hi Ankita,

I got the following error while executing makefile:

/opt/swi/y17-ext/sysroots/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-gcc -c -Wall -Werror -fpic -lpthread -ldl sqlite3.c -o …/lib/sqlite3.so
make: /opt/swi/y17-ext/sysroots/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-gcc: Command not found
Makefile:4: recipe for target ‘all’ failed
make: *** [all] Error 127

this is what /opt/swi has:
image

------------UPDATE---------------
I changed

/opt/swi/y17-ext/sysroots/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi/

to

/opt/swi/y22-ext-wp77xx/sysroots/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi/

then got the following:

How could I fix it?
thanks

I have similar problem in WP76 before, you can install some old toolchain like R9 of wp77

Hi jyijyi,

The link couldn’t be opened up: https://source.sierrawireless.com/resources/airprime/software/wp76xx/wp76xx-firmware-release-9-components/#sthash.c1Pa64qx.dpbs

that link is for WP76.
didn’t you are using WP77?
I saw you already have WP77 R9.1 toolchain.

yes I’m using wp7702. Can you post the link for me?

didn’t you already have it?
/opt/swi/y22-ext-wp77xx-Release_9.1

Currently source.sierrawireless.com is down…

yes the website is under the maintenance.
So you meant change

/opt/swi/ y22-ext-wp77xx /sysroots/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi/
to

/opt/swi/ y22-ext-wp77xx-Release_9.1 /sysroots/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi/

but got the same error:

Can you try the hello.c first?

<Hello.c>
#include<stdio.h>
int main(void)
{
printf(“Hello,World\n”);
return 0;
}

Btw, you can also check if you can download the old toolchain of wp76 by LEAF

How do I run a native c program in legato?
and what is LEAF command to download old toolchain of wp76?

you are trying to compile a library of sqlite3.so so that it can be called inside legato application, but not trying to run a native c program in legato.

To search for old toolchain, you can use “leaf search”, i already saw some old package:

swi-wp76_1.0.0 │ SDK for WP76 (Release 9 + Legato 18.03.0)
│ swi-wp76_1.2.0 │ SDK for WP76 (Release 9 + Legato 18.05.0)
│ swi-wp76_1.2.1 │ SDK for WP76 (Release 9 + Legato 18.05.1)
│ swi-wp76_1.3.0 │ SDK for WP76 (Release 9 + Legato 18.06.0)
│ swi-wp76_1.3.1 │ SDK for WP76 (Release 9 + Legato 18.06.1)
│ swi-wp76_1.3.2 │ SDK for WP76 (Release 9 + Legato 18.06.2)

For download, you can see here:
https://docs.legato.io/latest/toolsLeafSetup.html

If you have vscode, you can see the UI like this for download:
https://docs.legato.io/latest/tools_vsCodeInstall.html

This is what I got when run hello.c in legato application:

I am saying this:
/opt/swi/y22-ext-wp77xx-Release_9.1/sysroots/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-gcc -o Hello.o ./hello.c

the same error was produced: