SQLStatement* SqliteStatementCache::InternalGetStatement(const char* func_name,
														 int func_number, const char* sql)
{
	FuncID id;
	id.name = func_name;
	id.number = func_number;

	StatementMap::const_iterator found = statements_.find(id);
	if (found != statements_.end())
		return found->second;

	if (!sql)
		return NULL;  // Don't create a new statement when we were not given SQL.

	// Create a new statement.
	SQLStatement* statement = new SQLStatement();
	if (statement->prepare(db_, sql) != SQLITE_OK)
	{
		const char* err_msg = sqlite3_errmsg(db_);		
		return NULL;
	}

	statements_[id] = statement;
	return statement;
}