Commit 4d553425 authored by dinesh's avatar dinesh

bug fix for duplicate module name upload

parent 845cdae3
...@@ -94,20 +94,23 @@ static int storejsontodb(const struct json *jsonobj, const char *db) ...@@ -94,20 +94,23 @@ static int storejsontodb(const struct json *jsonobj, const char *db)
struct db_query *q; struct db_query *q;
handle = db_open(db); handle = db_open(db);
query = talloc_asprintf(NULL, "SELECT module from search where module=\"%s\";", jsonobj->module); query = talloc_asprintf(NULL, "SELECT module, author from search where module=\"%s\";", jsonobj->module);
q = db_query(handle, query); q = db_query(handle, query);
desc = strjoin(NULL, jsonobj->desc,"\n"); desc = strjoin(NULL, jsonobj->desc,"\n");
strreplace(desc, '\'', ' '); strreplace(desc, '\'', ' ');
depends = strjoin(NULL, jsonobj->depends,"\n"); depends = strjoin(NULL, jsonobj->depends,"\n");
if (!q->num_rows) if (q->num_rows && streq(jsonobj->author, q->rows[0][1]))
cmd = talloc_asprintf(NULL, "UPDATE search set author=\"%s\", title=\"%s\", desc=\'%s\' depends=\'%s\' where module=\"%s\";",
jsonobj->author, jsonobj->title, desc, depends, jsonobj->module);
else if (!q->num_rows)
cmd = talloc_asprintf(NULL, "INSERT INTO search VALUES(\"%s\",\"%s\",\"%s\", \'%s\', \'%s\', 0);", cmd = talloc_asprintf(NULL, "INSERT INTO search VALUES(\"%s\",\"%s\",\"%s\", \'%s\', \'%s\', 0);",
jsonobj->module, jsonobj->author, jsonobj->title, depends, desc); jsonobj->module, jsonobj->author, jsonobj->title, depends, desc);
else else
cmd = talloc_asprintf(NULL, "UPDATE search set author=\"%s\", title=\"%s\", desc=\'%s\' depends=\'%s\' where module=\"%s\";", cmd = talloc_asprintf(NULL, "INSERT INTO search VALUES(\"%s-%s\",\"%s\",\"%s\", \'%s\', \'%s\', 0);",
jsonobj->author, jsonobj->title, desc, depends, jsonobj->module); jsonobj->module, jsonobj->author, jsonobj->author, jsonobj->title, depends, desc);
db_command(handle, cmd); db_command(handle, cmd);
db_close(handle); db_close(handle);
talloc_free(depends); talloc_free(depends);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment