Explorar o código

db_postgres: new parameter bytea_output_escape

- control escaping output for bytea fields
- default 1 (do the escape)
Daniel-Constantin Mierla %!s(int64=7) %!d(string=hai) anos
pai
achega
861205b8ae
Modificáronse 2 ficheiros con 13 adicións e 8 borrados
  1. 11 8
      src/modules/db_postgres/km_pg_con.c
  2. 2 0
      src/modules/db_postgres/pg_mod.c

+ 11 - 8
src/modules/db_postgres/km_pg_con.c

@@ -37,6 +37,8 @@
 #include <netinet/tcp.h>
 
 
+extern int pg_bytea_output_escape;
+
 /*!
  * \brief Create a new connection
  *
@@ -52,7 +54,7 @@ struct pg_con *db_postgres_new_connection(struct db_id *id)
 	int i = 0;
 	const char *keywords[10], *values[10];
 	char to[16];
-	PGresult   *res;
+	PGresult *res = NULL;
 
 	LM_DBG("db_id = %p\n", id);
 
@@ -142,15 +144,16 @@ struct pg_con *db_postgres_new_connection(struct db_id *id)
 	}
 #endif
 
-	res = PQexec(ptr->con, "SET bytea_output=escape");
-	if (PQresultStatus(res) != PGRES_COMMAND_OK)
-	{
-		LM_ERR("cannot set blob output escaping format\n");
+	if(pg_bytea_output_escape!=0) {
+		res = PQexec(ptr->con, "SET bytea_output=escape");
+		if (PQresultStatus(res) != PGRES_COMMAND_OK)
+		{
+			LM_ERR("cannot set blob output escaping format\n");
+			PQclear(res);
+			goto err;
+		}
 		PQclear(res);
-		goto err;
 	}
-	PQclear(res);
-
 	return ptr;
 
 err:

+ 2 - 0
src/modules/db_postgres/pg_mod.c

@@ -58,6 +58,7 @@ int pg_retries =
 int pg_lockset = 4;
 int pg_timeout = 0; /* default = no timeout */
 int pg_keepalive = 0;
+int pg_bytea_output_escape = 1;
 
 /*
  * Postgres module interface
@@ -91,6 +92,7 @@ static param_export_t params[] = {
 	{"lockset", PARAM_INT, &pg_lockset},
 	{"timeout", PARAM_INT, &pg_timeout},
 	{"tcp_keepalive", PARAM_INT, &pg_keepalive},
+	{"bytea_output_escape", PARAM_INT, &pg_bytea_output_escape},
 	{0, 0, 0}
 };