Ejemplo n.º 1
0
	void submit(SQLQuery *req, const std::string& q, const ParamM& p)
	{
		std::string res;
		for(std::string::size_type i = 0; i < q.length(); i++)
		{
			if (q[i] != '$')
				res.push_back(q[i]);
			else
			{
				std::string field;
				i++;
				while (i < q.length() && isalnum(q[i]))
					field.push_back(q[i++]);
				i--;

				ParamM::const_iterator it = p.find(field);
				if (it != p.end())
				{
					std::string parm = it->second;
					std::vector<char> buffer(parm.length() * 2 + 1);
#ifdef PGSQL_HAS_ESCAPECONN
					int error;
					size_t escapedsize = PQescapeStringConn(sql, &buffer[0], parm.data(), parm.length(), &error);
					if (error)
						ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "BUG: Apparently PQescapeStringConn() failed");
#else
					size_t escapedsize = PQescapeString(&buffer[0], parm.data(), parm.length());
#endif
					res.append(&buffer[0], escapedsize);
				}
			}
		}
		submit(req, res);
	}
Ejemplo n.º 2
0
    void submit(SQLQuery* query, const std::string& q, const ParamM& p)
    {
        std::string res;
        for(std::string::size_type i = 0; i < q.length(); i++)
        {
            if (q[i] != '$')
                res.push_back(q[i]);
            else
            {
                std::string field;
                i++;
                while (i < q.length() && isalnum(q[i]))
                    field.push_back(q[i++]);
                i--;

                ParamM::const_iterator it = p.find(field);
                if (it != p.end())
                {
                    char* escaped = sqlite3_mprintf("%q", it->second.c_str());
                    res.append(escaped);
                    sqlite3_free(escaped);
                }
            }
        }
        submit(query, res);
    }