Amit Mourya
Amit Mourya

Reputation: 538

PouchDB Not Creating Database on Samsung Android Phones (Android v. 4.1.3, 4.2.2)

I am creating a basic app for android devices. I am using normal Jade, JavaScript and PouchDB database. When I am deploying the app on simulator, Android devices like HTC, Tablet it is working fine but for Samsung Devices (Android v. 4.1.3, 4.2.2) it is not working.

My Jade code is

head

    script(src='../javascripts/pouchdb-nightly.min.js').
    script(type="text/javascript").
        var db = new PouchDB('pouchexample');

        function addBook(){
            var booktitle= window.document.bookform.titlefield.value;
            var authorfield= window.document.bookform.authorfield.value;
            var isbnfield= window.document.bookform.isbnfield.value;
            var book = {
                _id : isbnfield,
                title : booktitle,
                author : authorfield
            };
            db.put(book,function(err,res){
                if(!err){
                    clearField();
                    document.getElementById("message").innerHTML =
                        "new boook added";
                }
            });
        }

        function clearField() {
            window.document.bookform.titlefield.value="";
            window.document.bookform.authorfield.value="";
            window.document.bookform.isbnfield.value="";
        }

        function showBooks(){
            db.allDocs({include_docs:true, descending:true}, function(err, doc){
            showTableOfBooks(doc.rows);
            });
        }

        function showTableOfBooks(data){
            var div = document.getElementById("message");
            var str = "<table border='1' align='left'><tr><th>isbn</th><th>title</th><th>author</th></tr>";
            for(var i=0; i<data.length;i++){
                str +="<tr><td>"+data[i].doc._id+"</td><td>"+data[i].doc.title+"</td><td>"+data[i].doc.author+"</td></tr>"
            }
            str+="</table> ";
            div.innerHTML = str;
        }

body
    form(name='bookform')
        | book title
        input(type='text', name='titlefield')
        br
        | book author
        input(type='text', name='authorfield')
        br
        | book isbn
        input(type='text', name='isbnfield')
        br
        input(type='button', value='add book', onclick='addBook()')
        br
        input(type='button', value='clear fields', onclick='clearFields()')
        br
        input(type='button', value='show book', onclick='showBooks()')
        #message

I downloaded "pouchdb-nightly.min.js" from http://download.pouchdb.com/pouchdb-nightly.min.js

Please tell me the appropriate solution for this problem.

Thanks...

Upvotes: 1

Views: 680

Answers (3)

emeka Ndefo
emeka Ndefo

Reputation: 45

On Android, at first PouchDb was giving error: "can't find variable buffer" when I run it with React Native. Modification to pouchdb-binary-utils plugin to use the new buffer (safe-buffer installed by default with React-Native), solved the problem.

Get the updated plugin: https://github.com/emexrevolarter/react-native

Upvotes: 1

user3383087
user3383087

Reputation:

I had a similar problem and solved* it by forcing pouchdb to use websql.

var db = new PouchDB('websql://pouchexample');

Upvotes: 0

Calvin
Calvin

Reputation: 784

There was an issue with certain android devices having an incomplete version of indexedDB, this this has been fixed in master so if you build a copy of pouchdb based on the master branch you should be fine.

Upvotes: 1

Related Questions