Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cordova sqlite plugin #5

Open
fdjean opened this issue Sep 17, 2015 · 5 comments
Open

cordova sqlite plugin #5

fdjean opened this issue Sep 17, 2015 · 5 comments

Comments

@fdjean
Copy link

fdjean commented Sep 17, 2015

To use with websql or sqlite (ionic, cordova plugin)
line 88:

db = window.openDatabase(db_params.name, db_params.version, db_params.sub_name, db_params.size);

To (not fully tested):

if (window.cordova) {
    $ionicPlatform.ready(function () {
        db = $cordovaSQLite.openDB(db_params);
    });
} else {
    db = window.openDatabase(db_params);
}

Passing a open params (object) I can use https://github.com/litehelpers/Cordova-sqlcipher-adapter
with customs options

And to finish 😏 line 82:

var db, db_set = false;

db_set is a dead variable ?

@igorizr1
Copy link
Owner

Hi, thank you a lot for contribution

Agree on adding callback for device or document ready.

However in future releases I'm planning to remove angular dependency and make library stand alone. For angular there will be a plugin.

Anyway, I will add something for this in next release.
Also if u want to send some improvements in PR will appreciate

@fdjean
Copy link
Author

fdjean commented Sep 18, 2015

I'm not comfortable with Git and Github, so I publish here for now ;)

Tested OK for websql desktop (chrome), websql & sqlite mobile (android cordova plugin sqlcipher)
https://github.com/litehelpers/Cordova-sqlcipher-adapter

For SQLite mobile:

.factory('wSQL', function (W_SQL_CONFIG, $q) {
TO
.factory('wSQL', function (W_SQL_CONFIG, $q, $ionicPlatform, $cordovaSQLite) {

And

var Db = (function () {
    var db, db_set = false;
    return {
        get: function () {
            return db;
        },
        set: function (db_params) {
            db = window.openDatabase(db_params.name, db_params.version, db_params.sub_name, db_params.size);
            db_set = true;
            return db;
        }
    }
}
TO
var Db = (function () {
    var db = false;
    return {
        get: function () {
            return db;
        },
        set: function (db_params) {
            if (window.cordova) {
                $ionicPlatform.ready(function () {
                    db = $cordovaSQLite.openDB(db_params);
                    // websql mobile
                    // db = window.openDatabase(db_params.name, db_params.version, db_params.sub_name, db_params.size); 
                });
            } else {
                db = window.openDatabase(db_params.name, db_params.version, db_params.sub_name, db_params.size);
            }
            return db;
        }
    }
}

To have multiple insertions with the same order as array:

InsertQuery.prototype.batch_insert_query = function(table, data, ignore){
    ...
    sql +=  ' UNION SELECT '+row_sql.query;
    ...
};
To
InsertQuery.prototype.batch_insert_query = function(table, data, ignore){
    ...
    sql +=  ' UNION ALL SELECT '+row_sql.query;
    ...
};

@igorizr1
Copy link
Owner

Right, good suggestion. However this means that library will require ionic as dependency.

Do u think it will work the same fine if using just device.ready instead of $ionicPlatform.ready ?

@fdjean
Copy link
Author

fdjean commented Sep 23, 2015

@mukeshp004
Copy link

Hey this plugin is not working with the below mentioned code in android app.

var Db = (function () {
var db = false;
return {
get: function () {
return db;
},
set: function (db_params) {
if (window.cordova) {
$ionicPlatform.ready(function () {
db = $cordovaSQLite.openDB(db_params);
// websql mobile
// db = window.openDatabase(db_params.name, db_params.version, db_params.sub_name, db_params.size);
});
} else {
db = window.openDatabase(db_params.name, db_params.version, db_params.sub_name, db_params.size);
}
return db;
}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants