Exemplo n.º 1
0
bool TagsDatabase::ImportTags()
{
	// Open the file
	tagFileInfo info;
	tagFile *const file = tagsOpen(_tagsFile.c_str(), &info);
	if (file == NULL)
	{
		MsgBox("Something went wrong opening generated tags file");
		return false;
	}

	try
	{
		// First delete the old database (if any)
		Delete();

		// Create the new database
		Open();

		// Prepare the statement
		SqliteStatement stmt(this);
		stmt.Prepare("INSERT INTO Tags(Tag, File, Line, Pattern, Type, Language, MemberOf, MemberOfType, Inherits, Signature, Access, Implementation, ThisFileOnly, Unrecognized) VALUES (@tag, @file, @line, @pattern, @type, @language, @memberof, @memberoftype, @inherits, @signature, @access, @implementation, @thisfileonly, @unrecognized)");

		// Go through the records and save them in the database
		Tag tag;
		tagEntry entry;
		BeginTransaction();
		while (tagsNext(file, &entry) == TagSuccess)
		{
			// Put it in the array
			tag = entry;

			// Is there anything to search for?
			if (tag.getPattern().length() == 0 && tag.getLine() == 0)
				continue;

			// Very long search pattern in JavaScript, minimized?
			if (tag.getLanguage() == "JavaScript")
				if (tag.getPattern().length() >= MAX_PATH)
					continue;

			tag.SaveToDB(&stmt, _curDir);
		}
		stmt.Finalize();
		CommitTransaction();
		Close();
	}
	catch (SqliteException e)
	{
		tagsClose(file);
		MsgBoxf("Something went wrong convert tags file to database!\n%s", e.what());
		return false;
	}

	// Close the tags file
	tagsClose(file);
	return true;
}