char *string;
int len;
static char *sq = "show pool_status";
+ POOL_STATUS status;
if (query == NULL) /* need to read query from frontend? */
{
* judge if we need to lock the table
* to keep SERIAL data consistency among servers
* conditions:
+ * - replication is enabled
* - protocol is V3
* - statement is INSERT
* - either "INSERT LOCK" comment exists or insert_lock directive specified
if (REPLICATION && need_insert_lock(backend, string))
{
/* start a transaction if needed and lock the table */
- if (insert_lock(backend, string) != POOL_CONTINUE)
- return POOL_END;
+ status = insert_lock(backend, string);
+ if (status != POOL_CONTINUE)
+ return status;
}
/* forward the query to the backend */
return POOL_END;
}
-#ifdef NOT_USED
if (kind != 'C')
{
pool_error("do_command: backend does not successfully complete command %s status %c", query, kind);
- /* the response must be an ERROR. handle it */
-
- return POOL_END;
}
-#endif
+
/*
* read command tag of CommandComplete response
*/
{
char *table;
char qbuf[1024];
+ POOL_STATUS status;
int i;
+ /* insert_lock can be used in V3 only */
if (MAJOR(backend) != PROTO_MAJOR_V3)
- return 0;
+ return POOL_CONTINUE;
+
+ /* get table name */
+ table = get_insert_command_table_name(query);
+
+ /* could not get table name. probably wrong SQL command */
+ if (table == NULL)
+ {
+ return POOL_CONTINUE;
+ }
+
+ snprintf(qbuf, sizeof(qbuf), "LOCK TABLE %s IN SHARE ROW EXCLUSIVE MODE", table);
/* if we are not in a transaction block,
* start a new transaction
internal_transaction_started = 1;
}
- /* issue lock table command */
- table = get_insert_command_table_name(query);
- snprintf(qbuf, sizeof(qbuf), "LOCK TABLE %s IN SHARE ROW EXCLUSIVE MODE", table);
+ status = POOL_CONTINUE;
+ /* issue lock table command */
for (i = 0;i < backend->num;i++)
{
- if (do_command(backend->slots[i]->con, qbuf, PROTO_MAJOR_V3, 0) != POOL_CONTINUE)
- {
- internal_transaction_started = 0;
- return POOL_END;
- }
+ status = do_command(backend->slots[i]->con, qbuf, PROTO_MAJOR_V3, 0);
}
- return POOL_CONTINUE;
+ return status;
}
/*
while (*query && isspace(*query))
query++;
- /* get table */
+ /* get table name */
qbuf = strdup(query);
- token = strtok(qbuf, " (");
+ token = strtok(qbuf, "\r\n\t (");
+
+ if (token == NULL)
+ {
+ pool_error("get_insert_command_table_name: could not get table name");
+ return NULL;
+ }
+
strncpy(table, token, sizeof(table));
free(qbuf);