[aur-dev] [PATCH 1/2] aurblup: remove ';' from queries
The semicolons are not necessary when performing queries via the MySQL API, so remove them. Signed-off-by: Dan McGee <dan@archlinux.org> --- scripts/aurblup/aurblup.c | 10 +++++----- 1 files changed, 5 insertions(+), 5 deletions(-) diff --git a/scripts/aurblup/aurblup.c b/scripts/aurblup/aurblup.c index 6a67d68..e01f053 100644 --- a/scripts/aurblup/aurblup.c +++ b/scripts/aurblup/aurblup.c @@ -74,7 +74,7 @@ blacklist_get_pkglist() MYSQL_ROW row; alpm_list_t *pkglist = NULL; - if (mysql_query(c, "SELECT Name FROM PackageBlacklist;")) + if (mysql_query(c, "SELECT Name FROM PackageBlacklist")) mysql_die("failed to read blacklist from MySQL database: %s\n"); if (!(res = mysql_store_result(c))) @@ -96,7 +96,7 @@ blacklist_add(const char *name) mysql_real_escape_string(c, esc, name, strlen(name)); snprintf(query, 1024, "INSERT INTO PackageBlacklist (Name) " - "VALUES ('%s');", esc); + "VALUES ('%s')", esc); free(esc); if (mysql_query(c, query)) @@ -110,7 +110,7 @@ blacklist_remove(const char *name) char query[1024]; mysql_real_escape_string(c, esc, name, strlen(name)); - snprintf(query, 1024, "DELETE FROM PackageBlacklist WHERE Name = '%s';", esc); + snprintf(query, 1024, "DELETE FROM PackageBlacklist WHERE Name = '%s'", esc); free(esc); if (mysql_query(c, query)) @@ -125,7 +125,7 @@ blacklist_sync(alpm_list_t *pkgs_cur, alpm_list_t *pkgs_new) pkgs_add = alpm_list_diff(pkgs_new, pkgs_cur, (alpm_list_fn_cmp)strcmp); pkgs_rem = alpm_list_diff(pkgs_cur, pkgs_new, (alpm_list_fn_cmp)strcmp); - if (mysql_query(c, "START TRANSACTION;")) + if (mysql_query(c, "START TRANSACTION")) mysql_die("failed to start MySQL transaction: %s\n"); for (p = pkgs_add; p; p = alpm_list_next(p)) @@ -134,7 +134,7 @@ blacklist_sync(alpm_list_t *pkgs_cur, alpm_list_t *pkgs_new) for (p = pkgs_rem; p; p = alpm_list_next(p)) blacklist_remove(alpm_list_getdata(p)); - if (mysql_query(c, "COMMIT;")) + if (mysql_query(c, "COMMIT")) mysql_die("failed to commit MySQL transaction: %s\n"); alpm_list_free(pkgs_add); -- 1.7.7
Always use two lines for if statements, use a character constant rather than the 0 integer when NULL-terminating a string, and remove the unnecessary NULL check before free(value)- free(NULL) is a no-op and always safe. Signed-off-by: Dan McGee <dan@archlinux.org> --- scripts/aurblup/aurblup.c | 27 ++++++++++++++++----------- 1 files changed, 16 insertions(+), 11 deletions(-) diff --git a/scripts/aurblup/aurblup.c b/scripts/aurblup/aurblup.c index e01f053..2180860 100644 --- a/scripts/aurblup/aurblup.c +++ b/scripts/aurblup/aurblup.c @@ -52,12 +52,13 @@ static alpm_list_t * pkglist_append(alpm_list_t *pkglist, const char *pkgname) { int len = strcspn(pkgname, "<=>"); - if (!len) len = strlen(pkgname); + if (!len) + len = strlen(pkgname); char *s = malloc(len + 1); strncpy(s, pkgname, len); - s[len] = 0; + s[len] = '\0'; if (alpm_list_find_str(pkglist, s)) free(s); @@ -217,10 +218,14 @@ read_config(const char *fn) t = &mysql_host; u = &mysql_socket; } - else if (strstr(line, CONFIG_KEY_USER)) t = &mysql_user; - else if (strstr(line, CONFIG_KEY_PASSWD)) t = &mysql_passwd; - else if (strstr(line, CONFIG_KEY_DB)) t = &mysql_db; - else t = NULL; + else if (strstr(line, CONFIG_KEY_USER)) + t = &mysql_user; + else if (strstr(line, CONFIG_KEY_PASSWD)) + t = &mysql_passwd; + else if (strstr(line, CONFIG_KEY_DB)) + t = &mysql_db; + else + t = NULL; if (t) { strtok(line, "\""); @@ -280,11 +285,11 @@ init(void) static void cleanup(void) { - if (mysql_host) free(mysql_host); - if (mysql_socket) free(mysql_socket); - if (mysql_user) free(mysql_user); - if (mysql_passwd) free(mysql_passwd); - if (mysql_db) free(mysql_db); + free(mysql_host); + free(mysql_socket); + free(mysql_user); + free(mysql_passwd); + free(mysql_db); alpm_release(); mysql_close(c); -- 1.7.7
participants (1)
-
Dan McGee