I Can't insert into sqlite database


#1

Hello everyone.
I’m trying to get a json object from external server and insert it’s data to sqlite db.
This is my code:

document.addEventListener(‘deviceready’, function () {
var db = window.sqlitePlugin.openDatabase({name: ‘netahang_db.db’,iosDatabaseLocation: ‘default’});
db.executeSql(‘CREATE TABLE IF NOT EXISTS synced_songs (id INTEGER PRIMARY KEY AUTOINCREMENT, song_id INTEGER, name TEXT, rating REAL, number_of_likes INTEGER, number_of_dislikes INTEGER, published_date TEXT, singers TEXT, lyrics TEXT, visitors INTEGER, composer_name TEXT, players TEXT, album TEXT, album_id INTEGER)’, [], function(){});
cordova.plugins.backgroundMode.enable();
}, false);
})

and my insertion code:

$http.get(“url_to_my_json”).then(function(response) {
var song_item = response.data;
db.executeSql(“INSERT INTO synced_songs (song_id, name, rating, number_of_likes, number_of_dislikes, published_date, singers, lyrics, visitors, composer_name, players, album, album_id) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)”,
[song_item.id, song_item.name, song_item.rating, song_item.number_of_likes, song_item.number_of_dislikes, song_item.published_date, song_item.singers, song_item.lyrics, song_item.visitors, song_item.composer_name, song_item.players, song_item.album, song_item.album_id]);
});