" ORDER BY expire DESC,vkey DESC LIMIT 1)"\
"ORDER BY expire DESC,vkey DESC LIMIT 1"
-// #define SELECT_SIZE "SELECT SUM(BIT_LENGTH(value) DIV 8) FROM gn072"
struct GNUNET_MysqlStatementHandle
#define UPDATE_ENTRY "UPDATE gn090 SET prio=prio+?,expire=IF(expire>=?,expire,?) WHERE vkey=?"
struct GNUNET_MysqlStatementHandle *update_entry;
- struct GNUNET_MysqlStatementHandle *iter[4];
+#define SELECT_SIZE "SELECT SUM(BIT_LENGTH(value) DIV 8) FROM gn072"
+ struct GNUNET_MysqlStatementHandle *get_size;
- /**
- * Size of the mysql database on disk.
- */
- unsigned long long content_size;
+ struct GNUNET_MysqlStatementHandle *iter[4];
};
}
-#if 0
-/**
- * Run the given MySQL SELECT statement. The statement
- * must have only a single result (one column, one row).
- *
- * @return result on success, NULL on error
- */
-static char *
-run_statement_select (struct Plugin *plugin,
- const char *statement)
-{
- MYSQL_RES *sql_res;
- MYSQL_ROW sql_row;
- char *ret;
-
- if ((NULL == plugin->dbf) && (GNUNET_OK != iopen (plugin)))
- return NULL;
- mysql_query (plugin->dbf, statement);
- if ((mysql_error (plugin->dbf)[0]) ||
- (!(sql_res = mysql_use_result (plugin->dbf))) ||
- (!(sql_row = mysql_fetch_row (sql_res))))
- {
- LOG_MYSQL (GNUNET_ERROR_TYPE_ERROR,
- "mysql_query", plugin);
- return NULL;
- }
- if ((mysql_num_fields (sql_res) != 1) || (sql_row[0] == NULL))
- {
- GNUNET_break (mysql_num_fields (sql_res) == 1);
- if (sql_res != NULL)
- mysql_free_result (sql_res);
- return NULL;
- }
- ret = GNUNET_strdup (sql_row[0]);
- mysql_free_result (sql_res);
- return ret;
-}
-#endif
-
-
/**
* Create a prepared statement.
*
return ret;
}
+
static int
-return_ok (void *cls, unsigned int num_values, MYSQL_BIND * values)
+return_ok (void *cls,
+ unsigned int num_values,
+ MYSQL_BIND * values)
{
return GNUNET_OK;
}
{
do_delete_value (plugin, vkey);
do_delete_entry_by_vkey (plugin, vkey);
- plugin->content_size -= length;
+ if (length != 0)
+ plugin->env->duc (plugin->env->cls,
+ - length);
}
return;
END_SET:
* Get an estimate of how much space the database is
* currently using.
*
- * @param cls our "struct Plugin*"
+ * @param cls our "struct Plugin *"
* @return number of bytes used on disk
*/
static unsigned long long
mysql_plugin_get_size (void *cls)
{
struct Plugin *plugin = cls;
- return plugin->content_size;
+ MYSQL_BIND cbind[1];
+ long long total;
+
+ memset (cbind, 0, sizeof (cbind));
+ total = 0;
+ cbind[0].buffer_type = MYSQL_TYPE_LONGLONG;
+ cbind[0].buffer = &total;
+ cbind[0].is_unsigned = GNUNET_NO;
+ if (GNUNET_OK !=
+ prepared_statement_run_select (plugin,
+ plugin->get_size,
+ 1, cbind,
+ &return_ok, NULL,
+ -1))
+ return 0;
+ return total;
}
vkey,
(unsigned int) size);
#endif
- plugin->content_size += size;
+ if (size > 0)
+ plugin->env->duc (plugin->env->cls,
+ size);
return GNUNET_OK;
}
"DROP TABLE gn090")) ||
(GNUNET_OK != run_statement (plugin,
"DROP TABLE gn072")))
- return; /* error */
- plugin->content_size = 0;
+ return; /* error */
+ plugin->env->duc (plugin->env->cls, 0);
}
|| PINIT (plugin->select_entry_by_hash_vhash_and_type,
SELECT_ENTRY_BY_HASH_VHASH_AND_TYPE)
|| PINIT (plugin->count_entry_by_hash, COUNT_ENTRY_BY_HASH)
+ || PINIT (plugin->get_size, SELECT_SIZE)
|| PINIT (plugin->count_entry_by_hash_and_vhash, COUNT_ENTRY_BY_HASH_AND_VHASH)
|| PINIT (plugin->count_entry_by_hash_and_type, COUNT_ENTRY_BY_HASH_AND_TYPE)
|| PINIT (plugin->count_entry_by_hash_vhash_and_type,