How to delete a database in WebSQL programmatically?

后端 未结 9 980
执念已碎
执念已碎 2020-12-25 10:03

I am new to Web SQL database and I use it to save data in a local database in a web page.

 I can create a database

相关标签:
9条回答
  • 2020-12-25 10:19

    Spec says:

    4.1 Databases

    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.

    0 讨论(0)
  • 2020-12-25 10:20

    Please note that if you use multiple

    tx.executeSql('DROP TABLE mytable'); 
    

    statements in the same transaction callback then make sure that they all exist or consider using DROP TABLE IF EXISTS syntax instead. If even one table doesn't exist when you try to drop it will result in the entire transaction failing. This failure results in a rollback of the transaction and means that the data will stay in your database even when you thought that it should have been deleted. There is no error reported unless you're specifically listening for it in the executeSql's 4th argument which is an error callback. This is intended behavior but is, in my experience, confusing.

    0 讨论(0)
  • 2020-12-25 10:23

    This is answered in HTML5 database storage (SQL lite) - few questions.

    To summarize:

    • Currently no way to drop a WebSQL database.
    • Probably use Indexed DB or localStorage instead.
    0 讨论(0)
  • 2020-12-25 10:27

    Using PersistenceJS there is a persistence.reset API which will wipe the database clean. PersistenceJS Site

    For developing / testing purposes, you can view content and delete webSQL, IndexedDB, cookies, etc by searching for your domain name at this URL in Chrome:

    chrome://settings/cookies
    

    There, you can delete all the storage for a domain or just certain local storage entities. Yes, the URL implies just 'cookies', but the interface at this URL includes all types of offline storage.

    It would be great I think if the Chrome developer tools interface had the ability to right-click and delete a data storage entity in the Resources tab along with inspecting the content. But for now, all I know of is the settings/cookies URL.

    0 讨论(0)
  • 2020-12-25 10:27

    In my library implementation, I just delete all tables. Which, indeed, delete the database. List of tables are select * from sqlite_master.

    0 讨论(0)
  • 2020-12-25 10:29

    No method to delete the existing database in websql it will clear when the cache is cleared or
    The browser is closed. If you want to create a database with the same name Just use openDatabase Method It will first check for the existence of the database with the same name. If not exists it will create one otherwise it will open the existing one

    please follow this link http://html5doctor.com/introducing-web-sql-databases/

    0 讨论(0)
提交回复
热议问题