static unsigned char * binary_escape(unsigned char *from, size_t from_length, size_t *to_length, PGconn *conn) { if (conn) return PQescapeByteaConn(conn, from, from_length, to_length); else return PQescapeBytea(from, from_length, to_length); }
static unsigned char * binary_escape(unsigned char *from, size_t from_length, size_t *to_length, PGconn *conn) { #if PG_VERSION_HEX >= 0x080104 if (conn) return PQescapeByteaConn(conn, from, from_length, to_length); else #endif return PQescapeBytea(from, from_length, to_length); }
bool queryCallback(void *p_context, int p_placeholder, DBBuffer &p_output) { QueryMetadata *t_query_metadata; t_query_metadata = (QueryMetadata *)p_context; DBString t_parameter_value; t_parameter_value = t_query_metadata -> arguments[p_placeholder - 1]; void *t_escaped_string; t_escaped_string = NULL; size_t t_escaped_string_length; t_escaped_string_length = 0; if (t_parameter_value . isbinary) { t_escaped_string = PQescapeBytea((const unsigned char *)t_parameter_value . sptr, t_parameter_value . length, &t_escaped_string_length); if (t_escaped_string == NULL) return false; // PQescapeBytea appends an extra null char to the end of the escaped string, disregard this. t_escaped_string_length--; } else { if (t_parameter_value . length != 0) { t_escaped_string = malloc((t_parameter_value . length * 2) + 1); t_escaped_string_length = PQescapeString((char *)t_escaped_string, t_parameter_value . sptr, t_parameter_value . length); } } p_output . ensure(t_escaped_string_length + 2); memcpy(p_output . getFrontier(), "'", 1); p_output . advance(1); if (t_escaped_string != NULL) { memcpy(p_output . getFrontier(), t_escaped_string, t_escaped_string_length); p_output . advance(t_escaped_string_length); } memcpy(p_output . getFrontier(), "'", 1); p_output . advance(1); if (t_parameter_value . isbinary) PQfreemem(t_escaped_string); else free(t_escaped_string); return true; }
int main(int, char **) { PQescapeBytea(0, 0, 0); PQunescapeBytea(0, 0); return 0; }