Ejemplo n.º 1
0
	std::string Databases::Create(std::string origin, std::string name)
	{
		if (Exists(origin, name))
		{
			return Path(origin,name);
		}
		static Logger* logger = Logger::Get("Database.Databases");

		Statement select(this->session->GetSession());
		Poco::UInt32 seq = 0;
		select << "SELECT seq FROM sqlite_sequence WHERE name='Databases'", into(seq);
		select.execute();

		++seq;

		std::string filename = Poco::format("%016u.db",(unsigned int)seq);
		logger->Debug("creating new db: %s",filename.c_str());

		Statement select2(this->session->GetSession());
		select2 << "INSERT INTO Databases (origin, name, path) VALUES (:origin,:name,:path)", use(origin), use(name), use(filename);
		select2.execute();

		Statement select5(this->session->GetSession());
		select5 << "SELECT origin from Origins where origin = :origin", use(origin);
		Poco::Int32 count = select5.execute();
		if (count == 0)
		{
			Statement select(this->session->GetSession());
			select << "INSERT INTO Origins (origin,quota) values (:origin,1720462881547374560)", use(origin), now;
		}

		// create the DB file
		std::string dbdir = FileUtils::Join(datadir.c_str(),origin.c_str(),NULL);
		if (!FileUtils::IsDirectory(dbdir))
		{
			logger->Debug("creating new db dir: %s",dbdir.c_str());
			FileUtils::CreateDirectory(dbdir);
		}
		std::string fullpath = FileUtils::Join(dbdir.c_str(),filename.c_str(),NULL);
		logger->Debug("path to new db : %s",fullpath.c_str());

		DBSession s(fullpath);

		// create the metadata table for WebKit
		Statement select3(s.GetSession());
		select3 << "CREATE TABLE __WebKitDatabaseInfoTable__ (key TEXT NOT NULL ON CONFLICT FAIL UNIQUE ON CONFLICT REPLACE,value TEXT NOT NULL ON CONFLICT FAIL)", now;

		Statement select4(s.GetSession());
		select4 << "insert into __WebKitDatabaseInfoTable__ values ('WebKitDatabaseVersionKey','1.0')", now;

		return fullpath;
	}
Ejemplo n.º 2
0
	std::string WebKitDatabases::Create(std::string name)
	{
		Statement select(*this->session);
		Poco::UInt32 seq = 0;
		select << "SELECT seq FROM sqlite_sequence WHERE name='Databases'", into(seq);
		select.execute();

		++seq;

		std::string filename = Poco::format("%016u.db", (unsigned int) seq);
		GetLogger()->Debug("Creating new db: %s", filename.c_str());

		Statement select2(*this->session);
		select2 << "INSERT INTO Databases (origin, name, path) VALUES (:origin,:name,:path)",
			 use(this->origin), use(name), use(filename);
		select2.execute();

		Statement select5(*this->session);
		select5 << "SELECT origin from Origins where origin = :origin", use(this->origin);
		Poco::Int32 count = select5.execute();
		if (count == 0)
		{
			Statement select(*this->session);
			select << "INSERT INTO Origins (origin,quota) values (:origin,1720462881547374560)",
				use(this->origin), now;
		}

		// Create the path for this application's origin, if necessary.
		if (!FileUtils::IsDirectory(originPath))
		{
			GetLogger()->Debug("Creating new database directory: %s", originPath.c_str());
			FileUtils::CreateDirectory(originPath);
		}

		std::string filePath(FileUtils::Join(originPath.c_str(), filename.c_str(), NULL));
		GetLogger()->Debug("path to new database: %s", filePath.c_str());

		// Create the metadata table for WebKit
		Session fileSession("SQLite", filePath);
		Statement select3(fileSession);
		select3 << "CREATE TABLE __WebKitDatabaseInfoTable__ (key TEXT NOT NULL "
			"ON CONFLICT FAIL UNIQUE ON CONFLICT REPLACE,value TEXT NOT NULL ON "
			"CONFLICT FAIL)", now;

		Statement select4(fileSession);
		select4 << "insert into __WebKitDatabaseInfoTable__ values "
			"('WebKitDatabaseVersionKey','1.0')", now;

		return filePath;
	}