yathit / ydn-db

Javascript database module for Indexeddb, Web SQL and localStorage storage mechanisms supporting version migration, advanced query, SQL and transaction.
Apache License 2.0
503 stars 41 forks source link

ydn.db.deleteDatabase not working in ipad #12

Closed neerajjoshi closed 10 years ago

neerajjoshi commented 10 years ago

Hello , I am creating an application which run both in desktop and ipad. Below is the schema var schema1 ={ name:'todo', keyPath:"id", autoIncrement: true, indexes: [{ keyPath: 'opt', name: 'opt', // usually omitted. generally same as keyPath. multiEntry: true }, { name: 'qid', keyPath:'qid' }, { name: 'sidn', keyPath:'sidn' }, { name: 'license', keyPath:'license' }, { name: 'publisher', keyPath:'publisher' }, { name: 'lp', keyPath: ['license', 'publisher'] } ] };

var schema2 = { name:'offline_sdn', keyPath:"id", autoIncrement: true, indexes: [{ keyPath: 'sdn', name: 'sdn' }] };

var schema ={stores:[schema1,schema2]};
var db = new ydn.db.Storage('todo_2',schema);

when I run the application in desktop it gives database type indexed db and in ipad it gives websql. when I use the below code

ydn.db.deleteDatabase(db.getName(),db.getType()).done(function(){ alert('deleted db'); db.close(); }).fail(function(e){ alert('failed to delete'+e); });

it worked in case of desktop as on page refreshing show new instance of database where as in case of ipad it does not delete the database . please help.

yathit commented 10 years ago

See https://bitbucket.org/ytkyaw/ydn-db/issue/105/ydndbdeletedatabase-not-working-in-ipad

Antoine-C commented 8 years ago

Hello,

The provided url is no more available (access denied on Bitbucket), could you please make it accessible because I actually have the same bug as @neerajjoshi.

Actually I'm currently working on a webview based app running on IOS 9.1 Ipad and I use this simple code to remove my database

var storePrefix = "myStore.v1.2";
// (...) code
ydn.db.deleteDatabase(storePrefix);

But it's not working, no error are thrown. Should I close the store or something else before performing this ? (It works in Chrome though, seems like an IOS bug related).

Thanks

yathit commented 8 years ago

WebSQL database API does not have deleting database. See

Each origin has an associated set of databases. Each database has a name and a current version. There is no way to enumerate or delete the databases available for an origin from this API.

However, note that ydn.db.deleteDatabase in fact delete all records in the database. By which, indeed, delete the database eventually.

Note: ydn.db.deleteDatabase accept type as second parameter.

Note: Except testing, I never require to delete a database in application. Why you need to delete it?

Antoine-C commented 8 years ago

Thanks for your quick answer. You're absolutely right I forgot I was using UIWebView which use WebSQL, so I'm going to switch to UKWebView and see if IndexedDB is not too broken for my use (given the crappy support from Apple).

I only need to delete the database for testing purpose only, in fact my app is fetching data from a server and storing it, so sometimes I just want to clear everything out and make a "fresh" start by calling the server again.