WebDatabaseの5MB制限を解除する

この日記は HTML5 Advent Calendar 2011 : ATND の16日目です。
※すみません、17日目と思ってました。

HTML5にはWebDatabaseという仕様が最初策定されていました。
過去形なのはもう仕様としては凍結されてしまったからです。

Beware. This specification is no longer in active maintenance and the Web Applications Working Group does not intend to maintain it further.

http://www.w3.org/TR/webdatabase/


そんなWebDatabaseですが、Mobile Safariではすでに実装されているため、iPhoneアプリとかからでもWebViewとかで使用することができます。

このWebDatabaseはSqliteをベースに実装されているので、使いやすいのですが、データベースの容量が5MBまでという厳しい制約があります。

この制約を外すためには以下のように行います。

  1. Database.dbにアクセスします。
  2. UPDATE文を発行します。


これだけです。
やることはこれだけなのですが、実際の方法はWebで調べてもあまり載っていません。
※そもそもiPhoneアプリの規約にひっかかっていないかどうかも心配ですし。

自分が調べた限りでは、以下のページぐらいです。
» 5MB Databases Limit Helman's Blog


上記ページではシュミレータ上のWebkitのWebDatabaseの5MB制限を解除しています。
では、実際のアプリではどうなるかというと、Objective-Cのコードで書くと以下のようになります。


1. Database.dbにアクセスする。

masterName = @"Databases.db";
// Get the path to the Library directory and append the databaseName
NSArray *libraryPaths = NSSearchPathForDirectoriesInDomains (NSLibraryDirectory, NSUserDomainMask, YES);
NSString *libraryDir = [libraryPaths objectAtIndex:0];
// the directory path for the Databases.db file
masterPath = [libraryDir stringByAppendingPathComponent:@"WebKit/Databases/"];
// the full path for the Databases.db file
masterFile = [masterPath stringByAppendingPathComponent:masterName];

2. UPDATE文を発行する。

sqlite3* db;
sqlite3_stmt* statement;

if (sqlite3_open([masterFile UTF8String], &db) == SQLITE_OK)
{
NSString* updateSQL = [NSString stringWithFormat: @"UPDATE Origins SET quota = 104857600"];
const char *update_stmt = [updateSQL UTF8String];

sqlite3_prepare_v2(db, update_stmt, -1, &statement, NULL);
if (sqlite3_step(statement) == SQLITE_DONE)
{
NSLog(@"Update: Success.");
}
else
{
NSLog(@"Update: Failed.");
}
sqlite3_finalize(statement);
sqlite3_close(db);
}

上記のようなコードをAppDelegate.mのdidFinishLaunchingWithOptionsらへんで仕掛けておいたら上手くWebDatabaseの5MB制限を解除することができると思います。

というわけで、だれかこれで審査が通るか試してもらいたい。。


というわけで次は @takayuki_h さんです。
遅れてしまってすみません。。