*/
enum Transactions transaction;
- struct GNUNET_MYSQL_StatementHandle *transaction_begin;
-
- struct GNUNET_MYSQL_StatementHandle *transaction_commit;
-
- struct GNUNET_MYSQL_StatementHandle *transaction_rollback;
-
/**
* Precompiled SQL for channel_key_store()
*/
/* Create tables */
STMT_RUN ("CREATE TABLE IF NOT EXISTS channels (\n"
- " id INT AUTO_INCREMENT,\n"
+ " id BIGINT UNSIGNED AUTO_INCREMENT,\n"
" pub_key BLOB,\n"
- " max_state_message_id INT,\n"
- " state_hash_message_id INT,\n"
+ " max_state_message_id BIGINT UNSIGNED,\n"
+ " state_hash_message_id BIGINT UNSIGNED,\n"
" PRIMARY KEY(id),\n"
" UNIQUE KEY(pub_key(5))\n"
");");
STMT_RUN ("CREATE TABLE IF NOT EXISTS slaves (\n"
- " id INT AUTO_INCREMENT,\n"
+ " id BIGINT UNSIGNED AUTO_INCREMENT,\n"
" pub_key BLOB,\n"
" PRIMARY KEY(id),\n"
" UNIQUE KEY(pub_key(5))\n"
");");
STMT_RUN ("CREATE TABLE IF NOT EXISTS membership (\n"
- " channel_id INT NOT NULL REFERENCES channels(id),\n"
- " slave_id INT NOT NULL REFERENCES slaves(id),\n"
- " did_join INT NOT NULL,\n"
+ " channel_id BIGINT UNSIGNED NOT NULL REFERENCES channels(id),\n"
+ " slave_id BIGINT UNSIGNED NOT NULL REFERENCES slaves(id),\n"
+ " did_join TINYINT NOT NULL,\n"
" announced_at BIGINT UNSIGNED NOT NULL,\n"
" effective_since BIGINT UNSIGNED NOT NULL,\n"
" group_generation BIGINT UNSIGNED NOT NULL\n"
/** @todo messages table: add method_name column */
STMT_RUN ("CREATE TABLE IF NOT EXISTS messages (\n"
- " channel_id INT NOT NULL REFERENCES channels(id),\n"
+ " channel_id BIGINT UNSIGNED NOT NULL REFERENCES channels(id),\n"
" hop_counter BIGINT UNSIGNED NOT NULL,\n"
" signature BLOB,\n"
" purpose BLOB,\n"
");");
STMT_RUN ("CREATE TABLE IF NOT EXISTS state (\n"
- " channel_id INT NOT NULL REFERENCES channels(id),\n"
+ " channel_id BIGINT UNSIGNED NOT NULL REFERENCES channels(id),\n"
" name TEXT NOT NULL,\n"
" value_current BLOB,\n"
- " value_signed BLOB,\n"
- " PRIMARY KEY (channel_id, name(5))\n"
+ " value_signed BLOB\n"
+ //" PRIMARY KEY (channel_id, name(255))\n"
");");
STMT_RUN ("CREATE TABLE IF NOT EXISTS state_sync (\n"
- " channel_id INT NOT NULL REFERENCES channels(id),\n"
+ " channel_id BIGINT UNSIGNED NOT NULL REFERENCES channels(id),\n"
" name TEXT NOT NULL,\n"
- " value BLOB,\n"
- " PRIMARY KEY (channel_id, name(5))\n"
+ " value BLOB\n"
+ //" PRIMARY KEY (channel_id, name(255))\n"
");");
#undef STMT_RUN
GNUNET_break (0); \
return GNUNET_SYSERR; \
}
- PREP ("BEGIN",
- &plugin->transaction_begin);
- PREP ("COMMIT",
- &plugin->transaction_commit);
- PREP ("ROLLBACK;",
- &plugin->transaction_rollback);
PREP ("INSERT IGNORE INTO channels (pub_key) VALUES (?);",
&plugin->insert_channel_key);
PREP ("INSERT IGNORE INTO slaves (pub_key) VALUES (?);",
PREP ("REPLACE INTO state\n"
" (channel_id, name, value_current, value_signed)\n"
- "SELECT new.channel_id, new.name,\n"
- " new.value_current, old.value_signed\n"
- "FROM (SELECT (SELECT id FROM channels WHERE pub_key = ?)\n"
- " AS channel_id,\n"
- " ? AS name, ? AS value_current) AS new\n"
+ "SELECT new.channel_id, new.name, new.value_current, old.value_signed\n"
+ "FROM (SELECT (SELECT id FROM channels WHERE pub_key = ?) AS channel_id,\n"
+ " (SELECT ?) AS name,\n"
+ " (SELECT ?) AS value_current\n"
+ " ) AS new\n"
"LEFT JOIN (SELECT channel_id, name, value_signed\n"
" FROM state) AS old\n"
"ON new.channel_id = old.channel_id AND new.name = old.name;",
static int
transaction_begin (struct Plugin *plugin, enum Transactions transaction)
{
- struct GNUNET_MYSQL_StatementHandle *stmt = plugin->transaction_begin;
-
- struct GNUNET_MY_QueryParam params[] = {
- GNUNET_MY_query_param_end
- };
-
- if (GNUNET_OK != GNUNET_MY_exec_prepared (plugin->mc, stmt, params))
+ if (GNUNET_OK != GNUNET_MYSQL_statement_run (plugin->mc, "BEGIN"))
{
- LOG_MYSQL(plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
- "mysql exexc_prepared", stmt);
- return GNUNET_SYSERR;
- }
-
- if (0 != mysql_stmt_reset (GNUNET_MYSQL_statement_get_stmt(stmt)))
- {
- LOG_MYSQL(plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
- "mysql_stmt_reset", stmt);
+ LOG(GNUNET_ERROR_TYPE_ERROR, "transaction_begin failed");
return GNUNET_SYSERR;
}
static int
transaction_commit (struct Plugin *plugin)
{
- struct GNUNET_MYSQL_StatementHandle *stmt = plugin->transaction_commit;
-
- struct GNUNET_MY_QueryParam params[] = {
- GNUNET_MY_query_param_end
- };
-
- if (GNUNET_OK != GNUNET_MY_exec_prepared (plugin->mc, stmt, params))
- {
- LOG_MYSQL(plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
- "mysql exec_prepared", stmt);
- return GNUNET_SYSERR;
- }
-
- if (0 != mysql_stmt_reset (GNUNET_MYSQL_statement_get_stmt (stmt)))
+ if (GNUNET_OK != GNUNET_MYSQL_statement_run (plugin->mc, "COMMIT"))
{
- LOG_MYSQL(plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
- "mysql_stmt_reset", stmt);
+ LOG(GNUNET_ERROR_TYPE_ERROR, "transaction_commit failed");
return GNUNET_SYSERR;
}
static int
transaction_rollback (struct Plugin *plugin)
{
- struct GNUNET_MYSQL_StatementHandle *stmt = plugin->transaction_rollback;
-
- struct GNUNET_MY_QueryParam params[] = {
- GNUNET_MY_query_param_end
- };
-
- if (GNUNET_OK != GNUNET_MY_exec_prepared (plugin->mc, stmt, params))
+ if (GNUNET_OK != GNUNET_MYSQL_statement_run (plugin->mc, "ROLLBACK"))
{
- LOG_MYSQL(plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
- "mysql exec_prepared", stmt);
- return GNUNET_SYSERR;
- }
-
- if (0 != mysql_stmt_reset (GNUNET_MYSQL_statement_get_stmt (stmt)))
- {
- LOG_MYSQL(plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
- "mysql_stmt_reset", stmt);
+ LOG(GNUNET_ERROR_TYPE_ERROR, "transaction_rollback failed");
return GNUNET_SYSERR;
}
GNUNET_MY_result_spec_end
};
- switch(GNUNET_MY_extract_result (stmt,
- results_select))
+ switch (GNUNET_MY_extract_result (stmt, results_select))
{
case GNUNET_NO:
ret = GNUNET_NO;
};
do
+ {
+ sql_ret = GNUNET_MY_extract_result (stmt, results);
+ switch (sql_ret)
{
- sql_ret = GNUNET_MY_extract_result (stmt,
- results);
- switch (sql_ret)
- {
- case GNUNET_NO:
- if (ret != GNUNET_OK)
- ret = GNUNET_NO;
- break;
-
- case GNUNET_YES:
- mp = GNUNET_malloc (sizeof (*mp) + buf_size);
-
- mp->header.size = htons (sizeof (*mp) + buf_size);
- mp->header.type = htons (GNUNET_MESSAGE_TYPE_MULTICAST_MESSAGE);
- mp->hop_counter = htonl (hop_counter);
- GNUNET_memcpy (&mp->signature,
- signature,
- signature_size);
- GNUNET_memcpy (&mp->purpose,
- purpose,
- purpose_size);
- mp->fragment_id = GNUNET_htonll (fragment_id);
- mp->fragment_offset = GNUNET_htonll (fragment_offset);
- mp->message_id = GNUNET_htonll (message_id);
- mp->group_generation = GNUNET_htonll (group_generation);
- mp->flags = htonl(msg_flags);
-
- GNUNET_memcpy (&mp[1],
- buf,
- buf_size);
- ret = cb (cb_cls, mp, (enum GNUNET_PSYCSTORE_MessageFlags) flags);
- if (NULL != returned_fragments)
- (*returned_fragments)++;
- GNUNET_MY_cleanup_result (results);
- break;
-
- default:
- LOG_MYSQL (plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
- "mysql extract_result", stmt);
- }
+ case GNUNET_NO:
+ if (ret != GNUNET_YES)
+ ret = GNUNET_NO;
+ break;
+
+ case GNUNET_YES:
+ mp = GNUNET_malloc (sizeof (*mp) + buf_size);
+
+ mp->header.size = htons (sizeof (*mp) + buf_size);
+ mp->header.type = htons (GNUNET_MESSAGE_TYPE_MULTICAST_MESSAGE);
+ mp->hop_counter = htonl (hop_counter);
+ GNUNET_memcpy (&mp->signature,
+ signature,
+ signature_size);
+ GNUNET_memcpy (&mp->purpose,
+ purpose,
+ purpose_size);
+ mp->fragment_id = GNUNET_htonll (fragment_id);
+ mp->fragment_offset = GNUNET_htonll (fragment_offset);
+ mp->message_id = GNUNET_htonll (message_id);
+ mp->group_generation = GNUNET_htonll (group_generation);
+ mp->flags = htonl(msg_flags);
+
+ GNUNET_memcpy (&mp[1],
+ buf,
+ buf_size);
+ ret = cb (cb_cls, mp, (enum GNUNET_PSYCSTORE_MessageFlags) flags);
+ if (NULL != returned_fragments)
+ (*returned_fragments)++;
+ GNUNET_MY_cleanup_result (results);
+ break;
+
+ default:
+ LOG_MYSQL (plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
+ "mysql extract_result", stmt);
}
+ }
while (GNUNET_YES == sql_ret);
// for debugging
sql_ret = GNUNET_MY_exec_prepared (plugin->mc, stmt, params);
switch (sql_ret)
- {
+ {
case GNUNET_NO:
- if (ret != GNUNET_OK)
+ if (ret != GNUNET_YES)
ret = GNUNET_NO;
break;
default:
LOG_MYSQL (plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
"mysql exec_prepared", stmt);
- }
+ }
return ret;
}
GNUNET_MY_result_spec_end
};
- ret = GNUNET_MY_extract_result (stmt,
- results_select);
+ ret = GNUNET_MY_extract_result (stmt, results_select);
if (GNUNET_OK != ret)
{
GNUNET_MY_result_spec_end
};
- ret = GNUNET_MY_extract_result (stmt,
- results_select);
+ ret = GNUNET_MY_extract_result (stmt, results_select);
if (GNUNET_OK != ret)
{
struct GNUNET_MY_QueryParam params[] = {
GNUNET_MY_query_param_auto_from_type (channel_key),
GNUNET_MY_query_param_string (name),
- GNUNET_MY_query_param_auto_from_type (value),
+ GNUNET_MY_query_param_fixed_size(value, value_size),
GNUNET_MY_query_param_end
};
switch (op)
{
case GNUNET_PSYC_OP_ASSIGN:
- return state_assign (plugin, plugin->insert_state_current, channel_key,
- name, value, value_size);
+ return state_assign (plugin, plugin->insert_state_current,
+ channel_key, name, value, value_size);
default: /** @todo implement more state operations */
GNUNET_break (0);
case GNUNET_NO:
ret = GNUNET_NO;
break;
+
case GNUNET_YES:
- ret = cb (cb_cls, name, value_current,
- value_size);
+ ret = cb (cb_cls, name, value_current, value_size);
break;
+
default:
LOG_MYSQL(plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
"mysql extract_result", stmt);
GNUNET_MY_result_spec_string (&name2),
GNUNET_MY_result_spec_variable_size (&value_current, &value_size),
GNUNET_MY_result_spec_end
- };
+ };;
int sql_ret;
+ if (GNUNET_OK != GNUNET_MY_exec_prepared (plugin->mc, stmt, params_select))
+ {
+ LOG_MYSQL(plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
+ "mysql exec_prepared", stmt);
+ return GNUNET_SYSERR;
+ }
+
do
{
- if (GNUNET_OK != GNUNET_MY_exec_prepared (plugin->mc, stmt, params_select))
- {
- LOG_MYSQL(plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
- "mysql exec_prepared", stmt);
- break;
- }
sql_ret = GNUNET_MY_extract_result (stmt, results);
switch (sql_ret)
{
case GNUNET_NO:
- if (ret != GNUNET_OK)
+ if (ret != GNUNET_YES)
ret = GNUNET_NO;
break;
case GNUNET_YES:
- ret = cb (cb_cls, (const char *) name2,
- value_current,
- value_size);
+ ret = cb (cb_cls, (const char *) name2, value_current, value_size);
if (ret != GNUNET_YES)
sql_ret = GNUNET_NO;
default:
LOG_MYSQL(plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
- "mysql extract_result", stmt);
+ "mysql extract_result", stmt);
}
}
while (sql_ret == GNUNET_YES);
GNUNET_MY_result_spec_end
};
+ if (GNUNET_OK != GNUNET_MY_exec_prepared (plugin->mc, stmt, params_select))
+ {
+ LOG_MYSQL(plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
+ "mysql exec_prepared", stmt);
+ return GNUNET_SYSERR;
+ }
+
do
{
- if (GNUNET_OK != GNUNET_MY_exec_prepared (plugin->mc, stmt, params_select))
- {
- LOG_MYSQL(plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
- "mysql exec_prepared", stmt);
- break;
- }
sql_ret = GNUNET_MY_extract_result (stmt, results);
switch (sql_ret)
{
case GNUNET_NO:
- if (ret != GNUNET_OK)
+ if (ret != GNUNET_YES)
ret = GNUNET_NO;
break;
+
case GNUNET_YES:
- ret = cb (cb_cls, (const char *) name,
- value_signed,
- value_size);
+ ret = cb (cb_cls, (const char *) name, value_signed, value_size);
if (ret != GNUNET_YES)
sql_ret = GNUNET_NO;
break;
+
default:
LOG_MYSQL(plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
"mysql extract_result", stmt);