sawcs
sawcs

Reputation: 1

app.js: Uncaught SyntaxError: missing ) after argument list

i working on ionic project and this is my app.js

var db = null; 

angular.module('starter', ['ionic','starter.controllers', 'ngCordova'])

.run(function($ionicPlatform) {
  $ionicPlatform.ready(function() {
    if(window.cordova && window.cordova.plugins.Keyboard) {
      cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
      cordova.plugins.Keyboard.disableScroll(true);
     db = $cordovaSQLite.openDB("my.db", location: 0, iosDatabaseLocation: 'Default'); 
    $cordovaSQLite.execute(db, 
        "CREATE TABLE IF NOT EXISTS contacts(id integer primary key, firstname text, lastname text, mobile number, email text)"); 

    } else {

    db = openDatabase("my.db", '1.0', "My WebSql ", 2*1024*1024);

    db.transaction( function( tx) {
        tx.executeSql("CREATE TABLE IF NOT EXISTS contacts(id integer primary key, firstname text, lastname text, mobile number, email text"));
    }       

    }
    if(window.StatusBar) {
      StatusBar.styleDefault();
    }
  });
})

The error is

app.js:11 Uncaught SyntaxError: missing ) after argument list missing ) in line 11

Here is line 11:

 db = $cordovaSQLite.openDB("my.db", location: 0, iosDatabaseLocation: 'Default');

I checked all brackets , there is no missing one where is the problem

Upvotes: 0

Views: 296

Answers (4)

sawcs
sawcs

Reputation: 1

this is the answer

db = $cordovaSQLite.openDB("my.db", 0, "Default");

instead of :

db = $cordovaSQLite.openDB("my.db", location: 0, iosDatabaseLocation: 'Default'); 

Thanks all :)

Upvotes: 0

Marc Compte
Marc Compte

Reputation: 4819

There are missing parenthesis and malformed code all over the place. Use a code editor that colors the code (such as Atom) and use proper indentation to detect these mistakes.

var db = null; 
angular.module('starter', ['ionic','starter.controllers', 'ngCordova'])
.run(function($ionicPlatform) {
  $ionicPlatform.ready(function() {
    if(window.cordova && window.cordova.plugins.Keyboard) {
      cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
      cordova.plugins.Keyboard.disableScroll(true);
      db = $cordovaSQLite.openDB("my.db", location: 0, iosDatabaseLocation: 'Default'); 
      $cordovaSQLite.execute(db, 
        "CREATE TABLE IF NOT EXISTS contacts(id integer primary key, firstname text, lastname text, mobile number, email text)"); 

    } else {

      db = openDatabase("my.db", '1.0', "My WebSql ", 2*1024*1024);

      db.transaction( function( tx) {
        tx.executeSql("CREATE TABLE IF NOT EXISTS contacts(id integer primary key, firstname text, lastname text, mobile number,email text)");
      });       

    }
    if(window.StatusBar) {
      StatusBar.styleDefault();
    }
  });
});

You may also want to make sure this line is properly formatted according to the openDB specifications:

db = $cordovaSQLite.openDB("my.db", location: 0, iosDatabaseLocation: 'Default'); 

The bit location:0 does look strange. Does openDB expect a list of string parameters or an object?

Upvotes: 1

Mr.7
Mr.7

Reputation: 2713

I think, you should wrap the parameters in an object.

Try changing this line

db = $cordovaSQLite.openDB("my.db", location: 0, iosDatabaseLocation: 'Default');

to this.

db = $cordovaSQLite.openDB({name: "my.db", location: 0, iosDatabaseLocation: 'Default'});

or

db = $cordovaSQLite.openDB("my.db", 0, "Default");

Hope this helps :)

Upvotes: 0

mzdv
mzdv

Reputation: 827

It looks like the problem is in the : signs. Since you're not passing an object inside, the parser throws an error. Try replacing location: 0 and iosDatabaseLocation: 'Default with just 0 and Default.

Upvotes: 1

Related Questions