version 1.5, 2000/07/17 10:38:39
|
version 1.6, 2000/07/19 21:15:41
|
Line 79 int close_sql(void) {
|
Line 79 int close_sql(void) {
|
* * |
* * |
************************************************************************/ |
************************************************************************/ |
|
|
|
#define MAX_QUERY 8000 |
|
#define SMALL_QUERY 500 |
|
|
int sql_update_id(const char *table, int id, |
int sql_update_id(const char *table, int id, |
const char *field, const char *value) { |
const char *field, const char *value) { |
MYSQL_RES *result; |
MYSQL_RES *result; |
char query[1000]; |
char query[MAX_QUERY]; |
int nb_fields = 0; |
int nb_fields = 0; |
|
int left = MAX_QUERY - 1; |
|
int len; |
|
char *end; |
|
|
if ((table == NULL) || |
if ((table == NULL) || |
(field == NULL) || (value == NULL)) |
(field == NULL) || (value == NULL)) |
return(-1); |
return(-1); |
|
|
snprintf(query, 999, "UPDATE %s SET %s='%s' WHERE ID=%d", |
len = snprintf(query, left, "UPDATE %s SET %s='", table, field); |
table, field, value, id); |
if (len < 0) { |
query[999] = 0; |
fprintf(stderr, "sql_update_id : %s(%d).%s overflow\n", |
if (mysql_query(sql, query)) { |
table, id, field); |
|
return(-1); |
|
} |
|
end = &query[len]; |
|
left -= len; |
|
len = strlen(value); |
|
if (len * 2 >= left) { |
|
fprintf(stderr, "sql_update_id : %s(%d).%s overflow\n", |
|
table, id, field); |
|
return(-1); |
|
} |
|
len = mysql_escape_string(end, value, len); |
|
left -= len; |
|
if (left <= 0) { |
|
fprintf(stderr, "sql_update_id : %s(%d).%s overflow\n", |
|
table, id, field); |
|
return(-1); |
|
} |
|
end += len; |
|
len = snprintf(end, left, "' WHERE ID=%d", id); |
|
if (len < 0) { |
|
fprintf(stderr, "sql_update_id : %s(%d).%s overflow\n", |
|
table, id, field); |
|
return(-1); |
|
} |
|
end += len; |
|
query[MAX_QUERY - 1] = 0; |
|
|
|
if (mysql_real_query(sql, query, (unsigned int) (end - query))) { |
printf("sql_update_id: UPDATE %s %d failed: %s\n", |
printf("sql_update_id: UPDATE %s %d failed: %s\n", |
table, id, mysql_error(sql)); |
table, id, mysql_error(sql)); |
return(-1); |
return(-1); |
Line 116 int sql_update_id(const char *table, int
|
Line 149 int sql_update_id(const char *table, int
|
int sql_blind_insert(const char *table, const char *key, |
int sql_blind_insert(const char *table, const char *key, |
const char *value, int id) { |
const char *value, int id) { |
MYSQL_RES *result; |
MYSQL_RES *result; |
char query[1000]; |
char query[MAX_QUERY]; |
|
int left = MAX_QUERY - 1; |
|
int len; |
|
char *end; |
|
|
if ((table == NULL) || |
if ((table == NULL) || |
(key == NULL) || (value == NULL)) |
(key == NULL) || (value == NULL)) |
Line 126 int sql_blind_insert(const char *table,
|
Line 162 int sql_blind_insert(const char *table,
|
* Search first for the ID if it already exists |
* Search first for the ID if it already exists |
*/ |
*/ |
if (id > 0) { |
if (id > 0) { |
snprintf(query, 999, "INSERT INTO %s (ID, %s) VALUES (%d, '%s')", |
len = snprintf(query, left, "INSERT INTO %s (ID, %s) VALUES (%d, '", |
table, key, id, value); |
table, key, id); |
|
if (len < 0) { |
|
fprintf(stderr, "sql_blind_insert : %s(%d).%s overflow\n", |
|
table, id, key); |
|
return(-1); |
|
} |
|
end = &query[len]; |
|
left -= len; |
|
len = strlen(value); |
|
if (len * 2 >= left) { |
|
fprintf(stderr, "sql_blind_insert : %s(%d).%s overflow\n", |
|
table, id, key); |
|
return(-1); |
|
} |
|
len = mysql_escape_string(end, value, len); |
|
left -= len; |
|
if (left <= 0) { |
|
fprintf(stderr, "sql_blind_insert : %s(%d).%s overflow\n", |
|
table, id, key); |
|
return(-1); |
|
} |
|
end += len; |
|
len = snprintf(end, left, "')"); |
|
if (len < 0) { |
|
fprintf(stderr, "sql_blind_insert : %s(%d).%s overflow\n", |
|
table, id, key); |
|
return(-1); |
|
} |
|
end += len; |
|
query[MAX_QUERY - 1] = 0; |
|
|
} else { |
} else { |
snprintf(query, 999, "INSERT INTO %s (%s) VALUES ('%s')", |
len = snprintf(query, left, "INSERT INTO %s (%s) VALUES ('", |
table, key, value); |
table, key); |
|
if (len < 0) { |
|
fprintf(stderr, "sql_blind_insert : %s.%s overflow\n", |
|
table, key); |
|
return(-1); |
|
} |
|
end = &query[len]; |
|
left -= len; |
|
len = strlen(value); |
|
if (len * 2 >= left) { |
|
fprintf(stderr, "sql_blind_insert : %s.%s overflow\n", |
|
table, key); |
|
return(-1); |
|
} |
|
len = mysql_escape_string(end, value, len); |
|
left -= len; |
|
if (left <= 0) { |
|
fprintf(stderr, "sql_blind_insert : %s.%s overflow\n", |
|
table, key); |
|
return(-1); |
|
} |
|
end += len; |
|
len = snprintf(end, left, "')"); |
|
if (len < 0) { |
|
fprintf(stderr, "sql_blind_insert : %s.%s overflow\n", |
|
table, key); |
|
return(-1); |
|
} |
|
end += len; |
|
query[MAX_QUERY - 1] = 0; |
|
|
} |
} |
query[999] = 0; |
query[MAX_QUERY - 1] = 0; |
if (mysql_query(sql,query)) { |
if (mysql_real_query(sql, query, (unsigned int) (end - query))) { |
|
#ifdef SQL_DEBUG |
|
fprintf(stderr, "sql_blind_insert Error: %s\n", mysql_error(sql)); |
|
#endif |
return(-1); |
return(-1); |
} |
} |
result = mysql_store_result(sql); |
result = mysql_store_result(sql); |
Line 152 int sql_update(const char *table, const
|
Line 251 int sql_update(const char *table, const
|
const char *field, const char *value) { |
const char *field, const char *value) { |
MYSQL_RES *result; |
MYSQL_RES *result; |
MYSQL_ROW row; |
MYSQL_ROW row; |
char query[1000]; |
char query[MAX_QUERY]; |
int id; |
int id; |
int nb_fields = 0; |
int nb_fields = 0; |
|
int left = MAX_QUERY - 1; |
|
int len; |
|
char *end; |
|
|
if ((name == NULL) || (table == NULL) || |
if ((name == NULL) || (table == NULL) || |
(field == NULL) || (value == NULL)) |
(field == NULL) || (value == NULL)) |
Line 163 int sql_update(const char *table, const
|
Line 265 int sql_update(const char *table, const
|
/* |
/* |
* Search first for the ID if it already exists |
* Search first for the ID if it already exists |
*/ |
*/ |
snprintf(query, 999, "SELECT ID FROM %s WHERE Name='%s'", table, name); |
snprintf(query, MAX_QUERY - 1, "SELECT ID FROM %s WHERE Name='%s'", table, name); |
query[999] = 0; |
query[MAX_QUERY - 1] = 0; |
if (mysql_query(sql,query)) { |
if (mysql_query(sql,query)) { |
printf("sql_update: SELECT failed\n"); |
printf("sql_update: SELECT failed\n"); |
return(-1); |
return(-1); |
Line 182 int sql_update(const char *table, const
|
Line 284 int sql_update(const char *table, const
|
printf("sql_update: ID non numeric %s\n", row[0]); |
printf("sql_update: ID non numeric %s\n", row[0]); |
return(-1); |
return(-1); |
} |
} |
snprintf(query, 999, "UPDATE %s SET %s='%s' WHERE ID=%d", |
|
table, field, value, id); |
left = MAX_QUERY - 1; |
query[999] = 0; |
len = snprintf(query, left, "UPDATE %s SET %s='", table, field); |
|
if (len < 0) { |
|
fprintf(stderr, "sql_update : %s(%d).%s overflow\n", |
|
table, id, field); |
|
return(-1); |
|
} |
|
end = &query[len]; |
|
left -= len; |
|
len = strlen(value); |
|
if (len * 2 >= left) { |
|
fprintf(stderr, "sql_update : %s(%d).%s overflow\n", |
|
table, id, field); |
|
return(-1); |
|
} |
|
len = mysql_escape_string(end, value, len); |
|
left -= len; |
|
if (left <= 0) { |
|
fprintf(stderr, "sql_update : %s(%d).%s overflow\n", |
|
table, id, field); |
|
return(-1); |
|
} |
|
end += len; |
|
len = snprintf(end, left, "' WHERE ID=%d", id); |
|
if (len < 0) { |
|
fprintf(stderr, "sql_update : %s(%d).%s overflow\n", |
|
table, id, field); |
|
return(-1); |
|
} |
|
end += len; |
|
query[MAX_QUERY - 1] = 0; |
|
|
mysql_free_result(result); |
mysql_free_result(result); |
if (mysql_query(sql, query)) { |
if (mysql_real_query(sql, query, (unsigned int) (end - query))) { |
printf("sql_update: UPDATE failed: %s\n", mysql_error(sql)); |
printf("sql_update: UPDATE failed: %s\n", mysql_error(sql)); |
return(-1); |
return(-1); |
} |
} |
Line 205 int sql_update(const char *table, const
|
Line 337 int sql_update(const char *table, const
|
/* |
/* |
* Propagate an insert |
* Propagate an insert |
*/ |
*/ |
snprintf(query, 999, |
snprintf(query, MAX_QUERY - 1, |
"INSERT INTO %s (Name,%s) VALUES ('%s','%s')", |
"INSERT INTO %s (Name,%s) VALUES ('%s','%s')", |
table, field, name, value); |
table, field, name, value); |
query[999] = 0; |
query[MAX_QUERY - 1] = 0; |
mysql_free_result(result); |
mysql_free_result(result); |
if (mysql_query(sql, query)) { |
if (mysql_query(sql, query)) { |
printf("sql_update: INSERT failed: %s\n", mysql_error(sql)); |
printf("sql_update: INSERT failed: %s\n", mysql_error(sql)); |
Line 230 int sql_update(const char *table, const
|
Line 362 int sql_update(const char *table, const
|
return(nb_fields); |
return(nb_fields); |
} |
} |
|
|
int sql_get_key(const char *table, const char *name) { |
int sql_get_key(const char *table, const char *name, const char *value) { |
int id; |
int id; |
MYSQL_RES *result; |
MYSQL_RES *result; |
MYSQL_ROW row; |
MYSQL_ROW row; |
char query[200]; |
char query[SMALL_QUERY]; |
|
|
if ((table == NULL) || (name == NULL)) |
if ((table == NULL) || (name == NULL)) |
return(-1); |
return(-1); |
Line 242 int sql_get_key(const char *table, const
|
Line 374 int sql_get_key(const char *table, const
|
/* |
/* |
* Search first for the ID if it already exists |
* Search first for the ID if it already exists |
*/ |
*/ |
snprintf(query, 199, "SELECT ID FROM %s WHERE Name='%s'", table, name); |
snprintf(query, SMALL_QUERY - 1, "SELECT ID FROM %s WHERE %s='%s'", |
query[199] = 0; |
table, name, value); |
|
query[SMALL_QUERY - 1] = 0; |
if (mysql_query(sql,query)) { |
if (mysql_query(sql,query)) { |
printf("sql_create: SELECT %s failed %s\n", name, mysql_error(sql)); |
printf("sql_create: SELECT %s failed %s\n", name, mysql_error(sql)); |
return(-1); |
return(-1); |
Line 280 int sql_get_key(const char *table, const
|
Line 413 int sql_get_key(const char *table, const
|
* Do a creation |
* Do a creation |
*/ |
*/ |
|
|
snprintf(query, 199, "INSERT INTO %s (Name) VALUES ('%s')", table, name); |
snprintf(query, SMALL_QUERY - 1, "INSERT INTO %s (%s) VALUES ('%s')", |
query[199] = 0; |
table, name, value); |
|
query[SMALL_QUERY - 1] = 0; |
if (mysql_query(sql,query)) { |
if (mysql_query(sql,query)) { |
printf("sql_get_key: INSERT %s failed %s\n", name, mysql_error(sql)); |
printf("sql_get_key: INSERT %s failed %s\n", name, mysql_error(sql)); |
return(-1); |
return(-1); |
Line 297 int sql_read_key(const char *table, cons
|
Line 431 int sql_read_key(const char *table, cons
|
int id; |
int id; |
MYSQL_RES *result; |
MYSQL_RES *result; |
MYSQL_ROW row; |
MYSQL_ROW row; |
char query[200]; |
char query[SMALL_QUERY]; |
|
|
if ((table == NULL) || (name == NULL)) |
if ((table == NULL) || (name == NULL)) |
return(-1); |
return(-1); |
Line 305 int sql_read_key(const char *table, cons
|
Line 439 int sql_read_key(const char *table, cons
|
/* |
/* |
* Search for the ID it has to exist |
* Search for the ID it has to exist |
*/ |
*/ |
snprintf(query, 199, "SELECT ID FROM %s WHERE Name='%s'", table, name); |
snprintf(query, SMALL_QUERY - 1, "SELECT ID FROM %s WHERE Name='%s'", table, name); |
query[199] = 0; |
query[SMALL_QUERY - 1] = 0; |
if (mysql_query(sql,query)) { |
if (mysql_query(sql,query)) { |
printf("sql_create: SELECT %s failed %s\n", name, mysql_error(sql)); |
printf("sql_create: SELECT %s failed %s\n", name, mysql_error(sql)); |
return(-1); |
return(-1); |
Line 345 int sql_read_info_key(const char *table,
|
Line 479 int sql_read_info_key(const char *table,
|
int id; |
int id; |
MYSQL_RES *result; |
MYSQL_RES *result; |
MYSQL_ROW row; |
MYSQL_ROW row; |
char query[200]; |
char query[SMALL_QUERY]; |
|
|
if ((table == NULL) || (name == NULL) || (value == NULL)) |
if ((table == NULL) || (name == NULL) || (value == NULL)) |
return(-1); |
return(-1); |
Line 353 int sql_read_info_key(const char *table,
|
Line 487 int sql_read_info_key(const char *table,
|
/* |
/* |
* Search for the ID it has to exist |
* Search for the ID it has to exist |
*/ |
*/ |
snprintf(query, 199, "SELECT ID FROM %s WHERE %s='%s'", table, name, value); |
snprintf(query, SMALL_QUERY - 1, "SELECT ID FROM %s WHERE %s='%s'", table, name, value); |
query[199] = 0; |
query[SMALL_QUERY - 1] = 0; |
if (mysql_query(sql,query)) { |
if (mysql_query(sql,query)) { |
printf("sql_create: SELECT %s failed %s\n", name, mysql_error(sql)); |
printf("sql_create: SELECT %s failed %s\n", name, mysql_error(sql)); |
return(-1); |
return(-1); |
Line 502 filename varchar(255) NOT NULL, \n\
|
Line 636 filename varchar(255) NOT NULL, \n\
|
Name varchar(50) NOT NULL, \n\ |
Name varchar(50) NOT NULL, \n\ |
Version varchar(50) NOT NULL, \n\ |
Version varchar(50) NOT NULL, \n\ |
Release varchar(50) NOT NULL, \n\ |
Release varchar(50) NOT NULL, \n\ |
|
Arch varchar(15) NOT NULL, \n\ |
Dist int(11), \n\ |
Dist int(11), \n\ |
URL varchar(255), \n\ |
URL varchar(255), \n\ |
URLSrc varchar(255), \n\ |
URLSrc varchar(255), \n\ |
Line 512 Summary varchar(255), \n\
|
Line 647 Summary varchar(255), \n\
|
Description text, \n\ |
Description text, \n\ |
Copyright varchar(255), \n\ |
Copyright varchar(255), \n\ |
PRIMARY KEY (ID), \n\ |
PRIMARY KEY (ID), \n\ |
KEY Name (Name(10)) \n\ |
KEY filename (filename(80)) \n\ |
)"; |
)"; |
|
|
if (mysql_query(sql,query)) { |
if (mysql_query(sql,query)) { |
Line 526 KEY Name (Name(10)) \n\
|
Line 661 KEY Name (Name(10)) \n\
|
int sql_rebuild_files(void) { |
int sql_rebuild_files(void) { |
const char *query = |
const char *query = |
"CREATE TABLE Files ( \n\ |
"CREATE TABLE Files ( \n\ |
ReleaseID int(11) NOT NULL, \n\ |
ID int(11) NOT NULL, \n\ |
Path varchar(255) NOT NULL, \n\ |
Path varchar(255) NOT NULL, \n\ |
KEY ReleaseID (ReleaseID), \n\ |
UNIQUE KEY id (ID,Path(80)), \n\ |
KEY Path (Path(20)) \n\ |
INDEX (ID), \n\ |
|
INDEX (Path) \n\ |
)"; |
)"; |
|
|
if (mysql_query(sql,query)) { |
if (mysql_query(sql,query)) { |
Line 655 int sql_add_mirror(const char *Name, con
|
Line 791 int sql_add_mirror(const char *Name, con
|
return(sql_blind_insert("Mirrors", "URL", URL, distrib)); |
return(sql_blind_insert("Mirrors", "URL", URL, distrib)); |
} |
} |
|
|
|
int sql_add_file(const char *filename, int package) { |
|
if ((filename == NULL) || (package <= 0)) |
|
return(-1); |
|
|
|
return(sql_blind_insert("Files", "Path", filename, package)); |
|
} |
|
|
int sql_add_package(const char *filename, |
int sql_add_package(const char *filename, |
const char *Name, const char *Version, const char *Release, |
const char *Name, const char *Version, const char *Release, |
int dist, const char *URL, const char *URLSrc, const char *Vendor, |
const char *Arch, |
|
int dist, const char *URL, const char *URLSrc, int vendor, |
const char *Packager, const char *Category, const char *Summary, |
const char *Packager, const char *Category, const char *Summary, |
const char *Description, const char *Copyright) { |
const char *Description, const char *Copyright) { |
int id; |
int id; |
int vendor; |
/* int packager; |
/* int packager; */ |
char intStr[15]; */ |
int nb_fields = 0; |
int nb_fields = 0; |
char intStr[15]; |
|
|
|
if ((filename == NULL) || (URL == NULL) || (dist <= 0)) |
if (filename == NULL) |
|
return(-1); |
|
|
|
if (dist < 0) |
return(-1); |
return(-1); |
if ((Name == NULL) || (Version == NULL) || (Release == NULL)) |
if ((Name == NULL) || (Version == NULL) || (Release == NULL) || |
|
(Arch == NULL)) |
return(-1); |
return(-1); |
|
|
id = sql_get_key("Packages", filename); |
|
|
id = sql_get_key("Packages", "filename", filename); |
if (id <= 0) |
if (id <= 0) |
return(-1); |
return(-1); |
nb_fields = 1; |
nb_fields = 1; |
if (Vendor != NULL) { |
|
vendor = sql_get_key("Vendors", Vendor); |
|
sprintf(intStr, "%d", vendor); |
|
nb_fields += sql_update_id("Packages", id, "Vendor", intStr); |
|
} |
|
/******* |
/******* |
if (Packager != NULL) { |
if (Packager != NULL) { |
packager = sql_get_key("People", Packager); |
packager = sql_get_key("People", Packager); |
Line 688 int sql_add_package(const char *filename
|
Line 831 int sql_add_package(const char *filename
|
} |
} |
*******/ |
*******/ |
if (Name != NULL) |
if (Name != NULL) |
nb_fields += sql_update_id("Packages", id, "Package", Name); |
nb_fields += sql_update_id("Packages", id, "Name", Name); |
if (Version != NULL) |
if (Version != NULL) |
nb_fields += sql_update_id("Packages", id, "Version", Version); |
nb_fields += sql_update_id("Packages", id, "Version", Version); |
if (Release != NULL) |
if (Release != NULL) |
nb_fields += sql_update_id("Packages", id, "Release", Release); |
nb_fields += sql_update_id("Packages", id, "Release", Release); |
|
if (Release != NULL) |
|
nb_fields += sql_update_id("Packages", id, "Arch", Arch); |
if (Category != NULL) |
if (Category != NULL) |
nb_fields += sql_update_id("Packages", id, "Category", Category); |
nb_fields += sql_update_id("Packages", id, "Category", Category); |
if (URL != NULL) |
if (URL != NULL) |
Line 707 int sql_add_package(const char *filename
|
Line 852 int sql_add_package(const char *filename
|
if (Copyright != NULL) |
if (Copyright != NULL) |
nb_fields += sql_update_id("Packages", id, "Copyright", Copyright); |
nb_fields += sql_update_id("Packages", id, "Copyright", Copyright); |
|
|
return(nb_fields); |
return(id); |
} |
} |
|
|
int sql_add_distrib(const char *Name, const char *Vendor, |
int sql_add_distrib(const char *Name, const char *Vendor, |
Line 720 int sql_add_distrib(const char *Name, co
|
Line 865 int sql_add_distrib(const char *Name, co
|
if (Name == NULL) |
if (Name == NULL) |
return(-1); |
return(-1); |
|
|
id = sql_get_key("Distribs", Name); |
id = sql_get_key("Distribs", "Name", Name); |
nb_fields = 1; |
nb_fields = 1; |
if (Vendor != NULL) { |
if (Vendor != NULL) { |
vendor = sql_get_key("Vendors", Vendor); |
vendor = sql_get_key("Vendors", "Name", Vendor); |
sprintf(VendorStr, "%d", vendor); |
sprintf(VendorStr, "%d", vendor); |
nb_fields += sql_update_id("Distribs", id, "Vendor", VendorStr); |
nb_fields += sql_update_id("Distribs", id, "Vendor", VendorStr); |
} |
} |
Line 749 int sql_add_vendor(const char *Name, con
|
Line 894 int sql_add_vendor(const char *Name, con
|
if (Name == NULL) |
if (Name == NULL) |
return(-1); |
return(-1); |
|
|
id = sql_get_key("Vendors", Name); |
id = sql_get_key("Vendors", "Name", Name); |
nb_fields = 1; |
nb_fields = 1; |
if (URL != NULL) |
if (URL != NULL) |
nb_fields += sql_update_id("Vendors", id, "URL", URL); |
nb_fields += sql_update_id("Vendors", id, "URL", URL); |
Line 768 void sql_add_metadata_base(const char *U
|
Line 913 void sql_add_metadata_base(const char *U
|
sql_blind_insert("Metadata", "URL", URL, -1); |
sql_blind_insert("Metadata", "URL", URL, -1); |
} |
} |
|
|
|
/************************************************************************ |
|
* * |
|
* Export functions * |
|
* * |
|
************************************************************************/ |
|
|
|
void sql_show_config(void) { |
|
MYSQL_RES *result; |
|
MYSQL_ROW row; |
|
|
|
|
|
mysql_query(sql,"SELECT Name,Value URL FROM Config"); |
|
result = mysql_use_result(sql); |
|
|
|
while((row = mysql_fetch_row(result))) |
|
{ |
|
if (row[0] == NULL) |
|
printf("NULL !\n"); |
|
else { |
|
if (row[1] == NULL) |
|
printf("%s : no url\n", row[0]); |
|
else |
|
printf("%s : %s\n", row[0], row[1]); |
|
} |
|
} |
|
if(mysql_errno(sql)) { |
|
fprintf(stderr, "Error: %s\n", mysql_error(sql)); |
|
} |
|
|
|
} |
|
|
|
void sql_show_metadata(void) { |
|
MYSQL_RES *result; |
|
MYSQL_ROW row; |
|
|
|
|
|
mysql_query(sql,"SELECT URL FROM Metadata"); |
|
result = mysql_use_result(sql); |
|
|
|
while((row = mysql_fetch_row(result))) |
|
{ |
|
if (row[0] == NULL) |
|
printf("NULL !\n"); |
|
else { |
|
printf("%s\n", row[0]); |
|
} |
|
} |
|
if(mysql_errno(sql)) { |
|
fprintf(stderr, "Error: %s\n", mysql_error(sql)); |
|
} |
|
|
|
} |
|
|
|
void sql_show_mirrors(void) { |
|
MYSQL_RES *result; |
|
MYSQL_ROW row; |
|
|
|
|
|
mysql_query(sql,"SELECT URL FROM Mirrors"); |
|
result = mysql_use_result(sql); |
|
|
|
while((row = mysql_fetch_row(result))) |
|
{ |
|
if (row[0] == NULL) |
|
printf("NULL !\n"); |
|
else { |
|
printf("%s\n", row[0]); |
|
} |
|
} |
|
if(mysql_errno(sql)) { |
|
fprintf(stderr, "Error: %s\n", mysql_error(sql)); |
|
} |
|
} |
|
|
void sql_show_vendors(void) { |
void sql_show_vendors(void) { |
MYSQL_RES *result; |
MYSQL_RES *result; |
MYSQL_ROW row; |
MYSQL_ROW row; |
Line 823 void sql_show_distribs(void) {
|
Line 1042 void sql_show_distribs(void) {
|
} |
} |
|
|
int sql_show_table_stats(const char *table, const char *key) { |
int sql_show_table_stats(const char *table, const char *key) { |
char query[1000]; |
char query[MAX_QUERY]; |
MYSQL_RES *result; |
MYSQL_RES *result; |
MYSQL_ROW row; |
MYSQL_ROW row; |
int res; |
int res; |
Line 831 int sql_show_table_stats(const char *tab
|
Line 1050 int sql_show_table_stats(const char *tab
|
/* |
/* |
* Search first for the ID if it already exists |
* Search first for the ID if it already exists |
*/ |
*/ |
snprintf(query, 999, "SELECT COUNT(%s) FROM %s", key, table); |
snprintf(query, MAX_QUERY - 1, "SELECT COUNT(%s) FROM %s", key, table); |
query[999] = 0; |
query[MAX_QUERY - 1] = 0; |
if (mysql_query(sql,query)) { |
if (mysql_query(sql,query)) { |
printf("sql_show_table_stats: SELECT COUNT failed: %s\n", |
printf("sql_show_table_stats: SELECT COUNT failed: %s\n", |
mysql_error(sql)); |
mysql_error(sql)); |
Line 921 int sql_show_stats(void) {
|
Line 1140 int sql_show_stats(void) {
|
#ifndef STANDALONE |
#ifndef STANDALONE |
|
|
int readConfigSql(void) { |
int readConfigSql(void) { |
char query[1000]; |
char query[MAX_QUERY]; |
MYSQL_RES *result; |
MYSQL_RES *result; |
MYSQL_ROW row; |
MYSQL_ROW row; |
int dir = 0; |
int dir = 0; |
Line 929 int readConfigSql(void) {
|
Line 1148 int readConfigSql(void) {
|
/* |
/* |
* General configuration informations |
* General configuration informations |
*/ |
*/ |
snprintf(query, 999, "SELECT Name,Value FROM Config"); |
snprintf(query, MAX_QUERY - 1, "SELECT Name,Value FROM Config"); |
query[999] = 0; |
query[MAX_QUERY - 1] = 0; |
if (mysql_query(sql,query)) { |
if (mysql_query(sql,query)) { |
printf("sql_check_tables: SELECT Config failed %s\n", |
printf("sql_check_tables: SELECT Config failed %s\n", |
mysql_error(sql)); |
mysql_error(sql)); |
Line 962 int readConfigSql(void) {
|
Line 1181 int readConfigSql(void) {
|
/* |
/* |
* The metadata mirror list. |
* The metadata mirror list. |
*/ |
*/ |
snprintf(query, 999, "SELECT URL FROM Metadata"); |
snprintf(query, MAX_QUERY - 1, "SELECT URL FROM Metadata"); |
query[999] = 0; |
query[MAX_QUERY - 1] = 0; |
if (mysql_query(sql,query)) { |
if (mysql_query(sql,query)) { |
printf("sql_check_tables: SELECT Metadata failed %s\n", |
printf("sql_check_tables: SELECT Metadata failed %s\n", |
mysql_error(sql)); |
mysql_error(sql)); |
Line 989 int readConfigSql(void) {
|
Line 1208 int readConfigSql(void) {
|
/* |
/* |
* The distribution lists |
* The distribution lists |
*/ |
*/ |
snprintf(query, 999, "SELECT Directory,Name,URL,URLSrc,Path FROM Distribs"); |
snprintf(query, MAX_QUERY - 1, "SELECT Directory,Name,URL,URLSrc,Path FROM Distribs"); |
query[999] = 0; |
query[MAX_QUERY - 1] = 0; |
if (mysql_query(sql,query)) { |
if (mysql_query(sql,query)) { |
printf("sql_check_tables: SELECT Distribs failed %s\n", |
printf("sql_check_tables: SELECT Distribs failed %s\n", |
mysql_error(sql)); |
mysql_error(sql)); |
Line 1024 int readConfigSql(void) {
|
Line 1243 int readConfigSql(void) {
|
/* |
/* |
* The Mirrors |
* The Mirrors |
*/ |
*/ |
snprintf(query, 999, "SELECT Distribs.Directory,Mirrors.URL FROM Distribs,Mirrors WHERE Distribs.ID = Mirrors.ID"); |
snprintf(query, MAX_QUERY - 1, "SELECT Distribs.Directory,Mirrors.URL FROM Distribs,Mirrors WHERE Distribs.ID = Mirrors.ID"); |
query[999] = 0; |
query[MAX_QUERY - 1] = 0; |
if (mysql_query(sql,query)) { |
if (mysql_query(sql,query)) { |
printf("sql_check_tables: SELECT Distribs failed %s\n", |
printf("sql_check_tables: SELECT Distribs failed %s\n", |
mysql_error(sql)); |
mysql_error(sql)); |
Line 1121 void sqlConfigEntry(const char *rpmdir,
|
Line 1340 void sqlConfigEntry(const char *rpmdir,
|
#ifdef STANDALONE |
#ifdef STANDALONE |
void usage(const char *name) { |
void usage(const char *name) { |
printf("%s: usage\n", name); |
printf("%s: usage\n", name); |
|
printf(" stats: show database usage statistics\n"); |
printf(" vendors: list the registered vendors\n"); |
printf(" vendors: list the registered vendors\n"); |
printf(" distribs: list the registered distribs\n"); |
printf(" distribs: list the registered distribs\n"); |
|
printf(" metadata: list the registered metadata servers\n"); |
|
printf(" mirrors: list the registered mirrors\n"); |
printf(" add distrib name [vendor [directory [path [url [ urlsrc [description]]]]]]\n"); |
printf(" add distrib name [vendor [directory [path [url [ urlsrc [description]]]]]]\n"); |
printf(" add vendor name [url [description]]\n"); |
printf(" add vendor name [url [description]]\n"); |
printf(" add mirror distrib url\n"); |
printf(" add mirror distrib url\n"); |
Line 1145 int main(int argc, char **argv) {
|
Line 1367 int main(int argc, char **argv) {
|
|
|
if (!strcmp(argv[1], "vendors")) |
if (!strcmp(argv[1], "vendors")) |
sql_show_vendors(); |
sql_show_vendors(); |
|
else if (!strcmp(argv[1], "metadata")) |
|
sql_show_metadata(); |
|
else if (!strcmp(argv[1], "mirrors")) |
|
sql_show_mirrors(); |
else if (!strcmp(argv[1], "distribs")) |
else if (!strcmp(argv[1], "distribs")) |
sql_show_distribs(); |
sql_show_distribs(); |
|
else if (!strcmp(argv[1], "config")) |
|
sql_show_config(); |
else if (!strcmp(argv[1], "stats")) |
else if (!strcmp(argv[1], "stats")) |
sql_show_stats(); |
sql_show_stats(); |
else if (!strcmp(argv[1], "add")) { |
else if (!strcmp(argv[1], "add")) { |