How to set the sqlite result to a global variable

I have a function that makes a query to sqlite, in a global variable I save the result, but the variable is shown undefined.

public lng:any;

name: ‘wconline.db’,
location: ‘default’
}).then((db: SQLiteObject) => {
db.executeSql(‘CREATE TABLE IF NOT EXISTS language(id INTEGER PRIMARY KEY, language TEXT)’, {})
.then(res => console.log(‘Executed SQL’))
.catch(e => console.log(e));

  db.executeSql('SELECT language FROM language WHERE id=1', {})
  .then(res => {
     this.lng = res.rows.item(0).language;
  .catch(e => console.log(e));
}).catch(e => console.log(e))


ionViewDidLoad() {

ionViewWillEnter() {

Thanks in advanace!

At which point does your variable seem to be undefined? Make sure you are checking it after the async calls as it’s not defined before!

Also, have you tried to log the result of your query and if it actually contains the information you think it does?