0

I am working on a project that uses Ionic 1 and AngularJS. I have successfully stored data in SQLite. On the simulator of the Ionic (using ionic serve --lab) the data is displayed (console.log()) as follows:

SQLResultSetRowList {0: {…}, length: 1}
0: { // data }
length: 1

So I can get the data easily from accessing the object in the result array. However, on real mobile device (I am testing on Android), the data is displayed like this.

enter image description here

The problem is in here. I want to access the rows inside the Closure of that <function scope> that is inside the item: function, which I really don't know how it is generated (and I mean all of these) because the only result I want is as how I got just like in the simulator.

This is how I inserted the data.

$cordovaSQLite.execute(db, "INSERT OR REPLACE INTO token (token) VALUES (?)", [myData]).then(function (res) {
                callback();
            }, function (error) {
                ErrorHandler.handle(error);
            });

This is how I query the data.

$cordovaSQLite.execute(db, "SELECT * FROM token").then(function (res) {
                console.log(res);
            }, function (error) {
                ErrorHandler.handle(error);
            });

Anyone has an idea to solve this?

Any way is acceptable.

holydragon
  • 6,158
  • 6
  • 39
  • 62
  • Here are some useful answers for your problem https://stackoverflow.com/questions/44876568/android-studio-retrieve-data-from-sqlite-database-and-display-it-into-textview – Thamidu naveen Oct 16 '18 at 06:35
  • @Thamidunaveen Codes in the link you mentioned is written in Java. I don't know which information in there is useful to me in this case. Thanks anyway. – holydragon Oct 16 '18 at 06:41

1 Answers1

0

Okay. I have found the solution to solve this problem myself from this.

I need to use it like this.

if (res.rows.length > 0){
                    if (window.cordova) {
                        // Mobile Device
                        console.log(JSON.parse(res.rows.item(0)));
                    } else {
                        // Web
                        console.log(JSON.parse(res.rows[0]));
                    }
}
holydragon
  • 6,158
  • 6
  • 39
  • 62