0

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

4 Answers 4

1

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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?

1 Comment

Ahh too slow, I was just extending my answer to say pretty much the same
0

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 :)

Comments

0

this is the answer

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

instead of :

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

Thanks all :)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.