aboutsummaryrefslogtreecommitdiff
path: root/src/sql.c
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2007-08-26 13:03:32 +0000
committerSergey Poznyakoff <gray@gnu.org.ua>2007-08-26 13:03:32 +0000
commitb89ece30bebb5b9dd06e4e061537b6bf068566f2 (patch)
treec7f65b64fccfac2f0e7e134e5f7666a4fb1907d1 /src/sql.c
parent338c0d9c35c56f35c636df1c1da0852a466e731f (diff)
downloadwydawca-b89ece30bebb5b9dd06e4e061537b6bf068566f2.tar.gz
wydawca-b89ece30bebb5b9dd06e4e061537b6bf068566f2.tar.bz2
Implement project owner notifications.
* wydawca/wydawca.c (syslog_printer): Reduce the number of memory reallocations (make_stat_expansion): Update * wydawca/method.c: Implement a new framework: methods may return 2-dimensional arrays of strings. * wydawca/sql.c, wydawca/sql.h: Implement the new method framework. * wydawca/verify.c (expand_param): kw_expansion may provide expansion functions. An additional argument supplies user-defined data for expansions. (escape_kwexp): Extern (free_kwexp): Improve (get_project_name): New function (make_default_kwexp): New function (check_access_rights): Call get_project_name. Use make_default_kwexp to initialize expansions (verify_directive_file): Use make_default_kwexp to initialize expansions * wydawca/wydawca.h (NITEMS): New macro (enum access_method_type): New members: ncol, nrow (struct directory_pair): New members url,project_owner_method, user_data_method (struct file_info): Replace mtime, uid with struct stat sb (struct file_triplet): New members project, dpair, user_data (TRIPLET_UID): Take into account the changes to struct file_info (enum notification_event): New data type (notify_project_owner, notify_admin, notify): New functions (struct kw_expansion): New members static_p, expand and data. (escape_kwexp,make_default_kwexp): New proto (expand_param): Change signature (triplet_expand_param): New function (method_result): Change prototype (method_num_rows,method_num_cols): New functions * wydawca/config.c: New statements project-owner, user-data, admin-address, mail-user, user-message directory can take an optional argument specifying base URL for notification messages * wydawca/gpg.c (verify_directive_signature): Expand directives even if the signature does not match. Useful for notifications. Add notifications. * wydawca/process.c: Add notifications. * wydawca/directive.c: Add notifications * wydawca/wydawca.rc: Update * wydawca/mail.c, wydawca/mail.h: Implement project owner notifications * wydawca/triplet.c (triplet_expand_param): New function * lib/cfg.c (read_cont_line): Fix counting of input lines. git-svn-id: file:///svnroot/wydawca/trunk@297 6bb4bd81-ecc2-4fd4-a2d4-9571d19c0d33
Diffstat (limited to 'src/sql.c')
-rw-r--r--src/sql.c73
1 files changed, 42 insertions, 31 deletions
diff --git a/src/sql.c b/src/sql.c
index c1de81d..ff358a5 100644
--- a/src/sql.c
+++ b/src/sql.c
@@ -83,6 +83,18 @@ sql_init_method (struct access_method *method)
return 0;
}
+int
+sql_free_result (struct access_method *method)
+{
+ struct sqlconn *conn = method->v.sqlconn;
+ if (conn->result)
+ {
+ mysql_free_result (conn->result);
+ conn->result = NULL;
+ }
+ return 0;
+}
+
/* Finish the initialized MySQL access method */
int
sql_done_method (struct access_method *method)
@@ -92,7 +104,8 @@ sql_done_method (struct access_method *method)
return 0;
if (--conn->initcount)
return 0;
- mysql_close (&method->v.sqlconn->mysql);
+ sql_free_result (method);
+ mysql_close (&conn->mysql);
return 0;
}
@@ -100,11 +113,8 @@ sql_done_method (struct access_method *method)
int
sql_run_method (struct access_method *method, const char *query)
{
- MYSQL *mysql = &method->v.sqlconn->mysql;
- MYSQL_RES *result;
- MYSQL_ROW row;
- long n;
- size_t len;
+ struct sqlconn *conn = method->v.sqlconn;
+ MYSQL *mysql = &conn->mysql;
if (mysql_query (mysql, query))
{
@@ -113,42 +123,43 @@ sql_run_method (struct access_method *method, const char *query)
return 1;
}
- result = mysql_store_result (mysql);
- if (!result)
+ conn->result = mysql_store_result (mysql);
+ if (!conn->result)
{
- logmsg (LOG_ERR, "Query returned 0 tuples");
+ logmsg (LOG_ERR, "Cannot get result: %s", mysql_error (mysql));
logmsg (LOG_NOTICE, "The failed query was: %s", query);
return 1;
}
-
- n = mysql_num_rows (result);
- if (n != 1)
- {
- logmsg (LOG_NOTICE, "Query returned %ld tuples", n);
- logmsg (LOG_NOTICE, "The query was: %s", query);
- if (n == 0)
- return 1;
- }
- n = mysql_num_fields (result);
- if (n != 1)
+ method->nrow = mysql_num_rows (conn->result);
+ method->ncol = mysql_num_fields (conn->result);
+ if (debug_level > 1)
{
- logmsg (LOG_NOTICE, "Query returned %ld fields", n);
- logmsg (LOG_NOTICE, "The query was: %s", query);
+ logmsg (LOG_DEBUG, "Query returned %u columns in %u rows",
+ method->ncol, method->nrow);
+ logmsg (LOG_DEBUG, "The query was: %s", query);
}
- row = mysql_fetch_row (result);
- if (row[0] == NULL)
+ return 0;
+}
+
+int
+sql_get_method (struct access_method *method, unsigned nrow, unsigned ncol)
+{
+ struct sqlconn *conn = method->v.sqlconn;
+ MYSQL_ROW row;
+ size_t len;
+
+ if (!conn->result)
+ return 1;
+ mysql_data_seek (conn->result, nrow);
+ row = mysql_fetch_row (conn->result);
+ if (row[ncol] == NULL)
len = 0;
else
- len = trim_length (row[0]);
+ len = trim_length (row[ncol]);
- method_copy_result (method, row[0], len);
-
- mysql_free_result (result);
-
+ method_copy_result (method, row[ncol], len);
return 0;
}
-
-

Return to:

Send suggestions and report system problems to the System administrator.