2018-01-24 14:28:48 +00:00
|
|
|
|
|
|
|
/*
|
2018-03-12 14:03:15 +00:00
|
|
|
* Odyssey.
|
2018-01-24 14:28:48 +00:00
|
|
|
*
|
2018-04-04 13:19:58 +00:00
|
|
|
* Scalable PostgreSQL connection pooler.
|
2018-01-24 14:28:48 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
2018-08-28 14:43:46 +00:00
|
|
|
#include <ctype.h>
|
2018-01-24 14:28:48 +00:00
|
|
|
#include <inttypes.h>
|
2018-08-28 14:43:46 +00:00
|
|
|
#include <assert.h>
|
2018-01-24 14:28:48 +00:00
|
|
|
|
|
|
|
#include <machinarium.h>
|
2018-08-28 14:43:46 +00:00
|
|
|
#include <kiwi.h>
|
|
|
|
#include <odyssey.h>
|
2018-01-24 14:28:48 +00:00
|
|
|
|
|
|
|
static inline int
|
2018-08-28 14:43:46 +00:00
|
|
|
od_deploy_add(kiwi_params_t *params, char *query, int size,
|
2018-01-24 14:28:48 +00:00
|
|
|
char *name, int name_len)
|
|
|
|
{
|
2018-08-28 14:43:46 +00:00
|
|
|
kiwi_param_t *client_param;
|
|
|
|
client_param = kiwi_params_find(params, name, name_len);
|
2018-01-24 14:28:48 +00:00
|
|
|
if (client_param == NULL)
|
|
|
|
return 0;
|
|
|
|
char quote_value[256];
|
|
|
|
int rc;
|
2018-08-28 14:43:46 +00:00
|
|
|
rc = kiwi_enquote(kiwi_param_value(client_param), quote_value,
|
|
|
|
sizeof(quote_value));
|
2018-01-24 14:28:48 +00:00
|
|
|
if (rc == -1)
|
|
|
|
return 0;
|
|
|
|
return od_snprintf(query, size, "SET %s=%s;",
|
2018-08-28 14:43:46 +00:00
|
|
|
kiwi_param_name(client_param),
|
2018-01-24 14:28:48 +00:00
|
|
|
quote_value);
|
|
|
|
}
|
|
|
|
|
2018-08-28 14:43:46 +00:00
|
|
|
int
|
|
|
|
od_deploy_write(od_server_t *server, char *context, kiwi_params_t *params)
|
2018-02-05 13:39:20 +00:00
|
|
|
{
|
2018-03-13 13:17:27 +00:00
|
|
|
od_instance_t *instance = server->global->instance;
|
2018-02-05 13:39:20 +00:00
|
|
|
|
|
|
|
/* discard */
|
|
|
|
int query_count = 1;
|
|
|
|
char query_discard[] = "DISCARD ALL";
|
2018-08-28 14:43:46 +00:00
|
|
|
|
|
|
|
machine_msg_t *msg;
|
|
|
|
msg = kiwi_fe_write_query(query_discard, sizeof(query_discard));
|
|
|
|
if (msg == NULL)
|
|
|
|
return -1;
|
|
|
|
int rc;
|
|
|
|
rc = machine_write(server->io, msg);
|
2018-02-05 13:39:20 +00:00
|
|
|
if (rc == -1)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
/* parameters */
|
|
|
|
char query[512];
|
|
|
|
int size = 0;
|
2018-02-06 15:12:53 +00:00
|
|
|
size += od_deploy_add(params, query + size, sizeof(query) - size,
|
2018-02-05 13:39:20 +00:00
|
|
|
"TimeZone", 9);
|
2018-02-06 15:12:53 +00:00
|
|
|
size += od_deploy_add(params, query + size, sizeof(query) - size,
|
2018-02-05 13:39:20 +00:00
|
|
|
"DateStyle", 10);
|
2018-02-06 15:12:53 +00:00
|
|
|
size += od_deploy_add(params, query + size, sizeof(query) - size,
|
2018-02-05 13:39:20 +00:00
|
|
|
"client_encoding", 16);
|
2018-02-06 15:12:53 +00:00
|
|
|
size += od_deploy_add(params, query + size, sizeof(query) - size,
|
2018-02-05 13:39:20 +00:00
|
|
|
"application_name", 17);
|
2018-02-06 15:12:53 +00:00
|
|
|
size += od_deploy_add(params, query + size, sizeof(query) - size,
|
2018-02-05 13:39:20 +00:00
|
|
|
"extra_float_digits", 19);
|
2018-02-06 15:12:53 +00:00
|
|
|
size += od_deploy_add(params, query + size, sizeof(query) - size,
|
2018-02-05 13:39:20 +00:00
|
|
|
"standard_conforming_strings", 28);
|
2018-02-06 15:12:53 +00:00
|
|
|
size += od_deploy_add(params, query + size, sizeof(query) - size,
|
2018-02-05 13:39:20 +00:00
|
|
|
"statement_timeout", 18);
|
2018-02-06 15:12:53 +00:00
|
|
|
size += od_deploy_add(params, query + size, sizeof(query) - size,
|
2018-02-05 13:39:20 +00:00
|
|
|
"search_path", 12);
|
|
|
|
if (size == 0) {
|
|
|
|
od_debug(&instance->logger, context, server->client, server,
|
|
|
|
"%s", "no need to configure");
|
|
|
|
} else {
|
|
|
|
od_debug(&instance->logger, context, server->client, server,
|
|
|
|
"%s", query);
|
|
|
|
size++;
|
|
|
|
query_count++;
|
2018-08-28 14:43:46 +00:00
|
|
|
msg = kiwi_fe_write_query(query, size);
|
|
|
|
if (msg == NULL)
|
|
|
|
return -1;
|
|
|
|
rc = machine_write(server->io, msg);
|
2018-02-05 13:39:20 +00:00
|
|
|
if (rc == -1)
|
|
|
|
return -1;
|
|
|
|
}
|
2018-08-28 14:43:46 +00:00
|
|
|
|
2018-02-05 13:39:20 +00:00
|
|
|
return query_count;
|
|
|
|
}
|