[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r246 - GNUnet/src/applications/sqstore_mysql
From: |
grothoff |
Subject: |
[GNUnet-SVN] r246 - GNUnet/src/applications/sqstore_mysql |
Date: |
Sat, 12 Feb 2005 14:25:17 -0800 (PST) |
Author: grothoff
Date: 2005-02-12 14:25:16 -0800 (Sat, 12 Feb 2005)
New Revision: 246
Modified:
GNUnet/src/applications/sqstore_mysql/mysql.c
GNUnet/src/applications/sqstore_mysql/mysqltest.c
Log:
mysql finally works with prepared statements
Modified: GNUnet/src/applications/sqstore_mysql/mysql.c
===================================================================
--- GNUnet/src/applications/sqstore_mysql/mysql.c 2005-02-12 21:54:21 UTC
(rev 245)
+++ GNUnet/src/applications/sqstore_mysql/mysql.c 2005-02-12 22:25:16 UTC
(rev 246)
@@ -558,6 +558,7 @@
#define MAX_DATUM_SIZE 65536
+#if 0
/**
* Iterate over the results for a particular key
* in the datastore.
@@ -569,6 +570,106 @@
* @return the number of results, SYSERR if the
* iter is non-NULL and aborted the iteration
*/
+static int getOLD(const HashCode160 * query,
+ unsigned int type,
+ Datum_Iterator iter,
+ void * closure) {
+ MYSQL_RES * sql_res;
+ MYSQL_ROW sql_row;
+ int count;
+ Datastore_Datum * datum;
+ char * escapedHash;
+ char * scratch;
+ size_t n;
+
+ if (query == NULL)
+ return iterateLowPriority(type, iter, closure);
+
+ MUTEX_LOCK(&dbh->DATABASE_Lock_);
+ escapedHash = MALLOC(2*sizeof(HashCode160)+1);
+ mysql_real_escape_string(dbh->dbf,
+ escapedHash,
+ (char *) query,
+ sizeof(HashCode160));
+ n = sizeof(HashCode160)*2+400+1;
+ scratch = MALLOC(n);
+
+ if (type != 0) {
+ if (iter == NULL)
+ SNPRINTF(scratch,
+ n,
+ "SELECT count(*) FROM gn070 WHERE hash='%s' AND type=%u",
+ escapedHash,
+ type);
+ else
+ SNPRINTF(scratch,
+ n,
+ "SELECT * FROM gn070 WHERE hash='%s' AND type=%u",
+ escapedHash,
+ type);
+ } else {
+ if (iter == NULL)
+ SNPRINTF(scratch,
+ n,
+ "SELECT count(*) FROM gn070 WHERE hash='%s'",
+ escapedHash);
+ else
+ SNPRINTF(scratch,
+ n,
+ "SELECT * FROM gn070 WHERE hash='%s'",
+ escapedHash);
+ }
+ FREE(escapedHash);
+ mysql_query(dbh->dbf, scratch);
+ FREE(scratch);
+ if (mysql_error(dbh->dbf)[0]) {
+ LOG_MYSQL(LOG_ERROR, "mysql_query", dbh);
+ MUTEX_UNLOCK(&dbh->DATABASE_Lock_);
+ return SYSERR;
+ }
+ if (!(sql_res = mysql_use_result(dbh->dbf))) {
+ LOG_MYSQL(LOG_ERROR, "mysql_query", dbh);
+ MUTEX_UNLOCK(&dbh->DATABASE_Lock_);
+ return SYSERR;
+ }
+ count = 0;
+ while ((sql_row=mysql_fetch_row(sql_res))) {
+ datum = assembleDatum(sql_res,
+ sql_row);
+ if (datum == NULL) {
+ LOG(LOG_WARNING,
+ _("Invalid data in MySQL database. Please verify integrity!\n"));
+ continue;
+ }
+ if ( (iter != NULL) &&
+ (SYSERR == iter(&datum->key,
+ &datum->value,
+ closure) ) ) {
+ count = SYSERR;
+ FREE(datum);
+ break;
+ }
+ FREE(datum);
+ count++;
+ }
+ mysql_free_result(sql_res);
+ MUTEX_UNLOCK(&dbh->DATABASE_Lock_);
+
+ return count;
+}
+#endif
+
+/**
+ * Iterate over the results for a particular key
+ * in the datastore.
+ *
+ * @param key maybe NULL (to match all entries)
+ * @param type entries of which type are relevant?
+ * Use 0 for any type.
+ * @param iter maybe NULL (to just count)
+ * @return the number of results, SYSERR if the
+ * iter is non-NULL and aborted the iteration
+ */
static int get(const HashCode160 * query,
unsigned int type,
Datum_Iterator iter,
@@ -643,6 +744,7 @@
}
datum = MALLOC(sizeof(Datastore_Value) + MAX_DATUM_SIZE);
+ twenty = sizeof(HashCode160);
dbh->bind[0].buffer = (char*) &size;
dbh->bind[1].buffer = (char*) &rtype;
dbh->bind[2].buffer = (char*) &prio;
@@ -652,6 +754,8 @@
dbh->bind[6].buffer = (char*) &datum[1];
dbh->bind[5].length = &twenty;
dbh->bind[6].length = &datasize;
+ dbh->bind[5].buffer_length = sizeof(HashCode160);
+ dbh->bind[6].buffer_length = MAX_DATUM_SIZE;
if (mysql_stmt_bind_result(stmt,
dbh->bind)) {
LOG(LOG_ERROR,
@@ -678,6 +782,14 @@
while (! mysql_stmt_fetch(stmt)) {
count++;
+ if (twenty != sizeof(HashCode160)) {
+ BREAK();
+ LOG(LOG_WARNING,
+ _("Invalid data in MySQL database. Please verify integrity!\n"));
+ twenty = sizeof(HashCode160);
+ datasize = MAX_DATUM_SIZE;
+ continue;
+ }
if (iter != NULL) {
datum->size = htonl(size);
datum->type = htonl(rtype);
@@ -688,6 +800,7 @@
BREAK();
LOG(LOG_WARNING,
_("Invalid data in MySQL database. Please verify integrity!\n"));
+ datasize = MAX_DATUM_SIZE;
continue;
}
LOG(LOG_DEBUG,
@@ -700,8 +813,8 @@
count = SYSERR;
break;
}
- datasize = MAX_DATUM_SIZE;
- }
+ }
+ datasize = MAX_DATUM_SIZE;
}
if (mysql_stmt_errno(stmt)) {
LOG(LOG_ERROR,
Modified: GNUnet/src/applications/sqstore_mysql/mysqltest.c
===================================================================
--- GNUnet/src/applications/sqstore_mysql/mysqltest.c 2005-02-12 21:54:21 UTC
(rev 245)
+++ GNUnet/src/applications/sqstore_mysql/mysqltest.c 2005-02-12 22:25:16 UTC
(rev 246)
@@ -106,9 +106,9 @@
&i));
for (i=255;i>=0;i--) {
memset(&key, 256-i, sizeof(HashCode160));
- ASSERT(1 == api->get(&key, i, &checkValue, &i));
- printf("OK: %d\n", i);
+ ASSERT(1 == api->get(&key, i+1, &checkValue, &i));
}
+
oldSize = api->getSize();
for (i=255;i>=0;i-=2) {
memset(&key, 256-i, sizeof(HashCode160));
@@ -125,7 +125,7 @@
ASSERT(128 == api->iterateExpirationTime(ANY_BLOCK,
(Datum_Iterator) &iterateDown,
&i));
- ASSERT(1 == i);
+ ASSERT(0 == i);
for (i=254;i>=0;i-=2) {
memset(&key, 256-i, sizeof(HashCode160));
value = initValue(i+1);
@@ -157,7 +157,7 @@
NULL));
FREENONNULL(setConfigurationString("GNUNETD",
"LOGLEVEL",
- "DEBUG"));
+ "WARNING"));
FREENONNULL(setConfigurationString("",
"GNUNETD_HOME",
"/tmp/gnunet_test/"));
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r246 - GNUnet/src/applications/sqstore_mysql,
grothoff <=