AlaSQL / alasql

AlaSQL.js - JavaScript SQL database for browser and Node.js. Handles both traditional relational tables and nested JSON data (NoSQL). Export, store, and import data from localStorage, IndexedDB, or Excel.
http://alasql.org
MIT License
7.01k stars 653 forks source link

alasql with XLSX not working with Android #758

Open srehmanali opened 8 years ago

srehmanali commented 8 years ago

I tried to generate a xlsx file in apache cordova. its working fine in emulator but does not respond in device

mathiasrw commented 8 years ago
srehmanali commented 8 years ago

Hi.. mathiasrw,

I manually added these two files

<script src="scripts/jquery-2.2.1.min.js"></script>
<script src="scripts/alasql-v0.3.2.min.js"></script>
<script src="scripts/xlsx.core-v0.7.12.min.js"></script>

versions are mentioned.

this is the simple function that i called on button click

var saveFilexlxs = function saveFilexlxs() {
            var data1 = [{ Id: 1, Name: 'Nadeem Ahmed', Address: 'A09 st 19', Age: 16, Gender: 'M', Phone: 1456450, PublicTrans: 'Y', Family: 'N' }, { Id: 2, Name: 'Rehman Ali', Address: 'A09 st 19', Age: 13, Gender: 'M', Phone: 44564560, PublicTrans: 'N', Family: 'N' }, { Id: 3, Name: 'Usman Ali', Address: 'A09 st 19', Age: 30, Gender: 'M', Phone: 64564560, PublicTrans: 'Y', Family: 'Y' }, { Id: 4, Name: 'Waheed Ahmed', Address: 'A09 st 19', Age: 15, Gender: 'M', Phone: 134547, PublicTrans: 'N', Family: 'N' }, { Id: 5, Name: 'Waseem Abbas', Address: 'A09 st 19', Age: 60, Gender: 'M', Phone: 1345342, PublicTrans: 'Y', Family: 'Y' }, { Id: 6, Name: 'Hamza Nasir', Address: 'A09 st 19', Age: 45, Gender: 'M', Phone: 1855533, PublicTrans: 'N', Family: 'N' }];
            var data2 = [{ Id: 1, FamilyId: 3, Name: 'Azeem', Age: 15, Gender: 'M' }, { Id: 2, FamilyId: 3, Name: 'Azeem', Age: 43, Gender: 'M' }, { Id: 3, FamilyId: 3, Name: 'Ali', Age: 15, Gender: 'M' }, { Id: 4, FamilyId: 3, Name: 'Eman', Age: 25, Gender: 'F' }, { Id: 5, FamilyId: 5, Name: 'Jhon', Age: 34, Gender: 'M' }, { Id: 6, FamilyId: 5, Name: 'Fareed', Age: 23, Gender: 'M' }, { Id: 7, FamilyId: 5, Name: 'Qasim', Age: 55, Gender: 'M' }, { Id: 8, FamilyId: 5, Name: 'Sara', Age: 34, Gender: 'F' }, ];
            var opts = [{ sheetid: 'FamilyHead', header: true }, { sheetid: 'FamilyMebers', header: false }];
            var res = alasql('SELECT INTO XLSX("restest344b.xlsx",?) FROM ?', [opts, [data1, 
        }
mathiasrw commented 8 years ago

Looks good with the versions!

Are you expecting this to be initiate a file download or that the file is stored on the filesystem?

srehmanali commented 7 years ago

Better to store the file in external memory that is cordova.file.externalDataDirectory

mathiasrw commented 7 years ago

So how does

var res = alasql('SELECT INTO XLSX("'+cordova.file.externalDataDirectory+'/restest344b.xlsx",?) FROM ?', [opts, [data1,...

work out for you?

srehmanali commented 7 years ago

No neither this worked

srehmanali commented 7 years ago

I don't understand if ripple can do the same task without any problem why device creating an issue. Although i tried to debug but failed

mathiasrw commented 7 years ago

1) Can I ask you to use https://github.com/agershun/alasql/blob/develop/dist/alasql.fs.js for alasql file and try again?

2) can I ask you to run this and tell me what the output was

console.log('Environment detected:',JSON.stringify({
                                        alasqlPath: alasql.path,
                                        isBrowser: alasql.utils.isBrowser,
                                        isCordova: alasql.utils.isCordova,
                                        isMeteor: alasql.utils.isMeteor,
                                        isMeteorClient: alasql.utils.isMeteorClient,
                                        isMeteorServer: alasql.utils.isMeteorServer,
                                        isNode: alasql.utils.isNode,
                                        isWebWorker: alasql.utils.isWebWorker
                                    },null,4));
srehmanali commented 7 years ago

I tried by using the following link https://raw.githubusercontent.com/agershun/alasql/develop/dist/alasql.fs.js and got the following error in Ripple

Refused to load the script 'https://raw.githubusercontent.com/agershun/alasql/develop/dist/alasql.fs.js' because it violates the following Content Security Policy directive: "default-src 'self' data: gap: http://api.openweathermap.org https://ssl.gstatic.com 'unsafe-eval'". Note that 'script-src' was not explicitly set, so 'default-src' is used as a fallback.

Then I downloaded the script then i got the xlsx produced properly

and in Ripple i got the following result in console

Environment detected: {
    "alasqlPath": "http://localhost:4400/scripts/",
    "isBrowser": true,
    "isCordova": true,
    "isMeteor": false,
    "isMeteorClient": false,
    "isMeteorServer": false,
    "isNode": false,
    "isWebWorker": false
}

In device nothing worked

mathiasrw commented 7 years ago

Good.

We need the Environment detected on the device some how... an alert(... might be the way

srehmanali commented 7 years ago

image

Hi Mathiasrw, I checked it on the device this alert shows nothing.. do you think its the issue with the alasql.fs.js file?

mathiasrw commented 7 years ago

ok ok - it needs to be a string:

alert('Environment detected: ' + JSON.stringify({
                                        alasqlPath: alasql.path,
                                        isBrowser: alasql.utils.isBrowser,
                                        isCordova: alasql.utils.isCordova,
                                        isMeteor: alasql.utils.isMeteor,
                                        isMeteorClient: alasql.utils.isMeteorClient,
                                        isMeteorServer: alasql.utils.isMeteorServer,
                                        isNode: alasql.utils.isNode,
                                        isWebWorker: alasql.utils.isWebWorker
                                    },null,4));
srehmanali commented 7 years ago

Oops.. me too didn't notice that;)

here is the result

image

mathiasrw commented 7 years ago

It does not make sense to me.

I will have to setup a cordova enviroment on my one phone.

Do you have some demo code I can use to get started quickly?

srehmanali commented 7 years ago

Hi,

do you have visual studio 2015 along with update 5? If yes so that i can send you the complete project or i should send you the js and htmls?

On Mon, Oct 17, 2016 at 1:08 AM, Mathias Rangel Wulff < notifications@github.com> wrote:

It does not make sense to me.

I will have to setup a cordova enviroment on my one phone.

Do you have some demo code I can use to get started quickly?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/agershun/alasql/issues/758#issuecomment-254075043, or mute the thread https://github.com/notifications/unsubscribe-auth/AT9Fvip-YL6pjL5P68-BLIwSQRyVXZUwks5q0pIzgaJpZM4KIuJ6 .

mathiasrw commented 7 years ago

@dESourcesra Thank you for chippin in. Unfortunately I dont have VS at the moment.

Im looking into following https://cordova.apache.org/docs/en/latest/guide/cli/ to get a minimal version up and running...

chetuBhadra93 commented 7 years ago

Any one have source code for alasql with ionic 2..? Please share how you are using, it help me a lot.