| 22 |
#include <errno.h> |
#include <errno.h> |
| 23 |
#include <stdlib.h> |
#include <stdlib.h> |
| 24 |
|
|
| 25 |
int load_section_config_from_db(MYSQL *db) |
int load_section_config_from_db(void) |
| 26 |
{ |
{ |
| 27 |
|
MYSQL *db; |
| 28 |
MYSQL_RES *rs, *rs2; |
MYSQL_RES *rs, *rs2; |
| 29 |
MYSQL_ROW row, row2; |
MYSQL_ROW row, row2; |
| 30 |
char sql[SQL_BUFFER_LEN]; |
char sql[SQL_BUFFER_LEN]; |
| 33 |
SECTION_LIST *p_section; |
SECTION_LIST *p_section; |
| 34 |
int ret; |
int ret; |
| 35 |
|
|
| 36 |
|
db = db_open(); |
| 37 |
|
if (db == NULL) |
| 38 |
|
{ |
| 39 |
|
log_error("db_open() error: %s\n", mysql_error(db)); |
| 40 |
|
return -2; |
| 41 |
|
} |
| 42 |
|
|
| 43 |
snprintf(sql, sizeof(sql), |
snprintf(sql, sizeof(sql), |
| 44 |
"SELECT section_config.SID, sname, title, section_config.CID, read_user_level, write_user_level, " |
"SELECT section_config.SID, sname, section_config.title, section_config.CID, " |
| 45 |
"section_config.enable * section_class.enable AS enable " |
"read_user_level, write_user_level, section_config.enable * section_class.enable AS enable " |
| 46 |
"FROM section_config INNER JOIN section_class ON section_config.CID = sectioN_class.CID " |
"FROM section_config INNER JOIN section_class ON section_config.CID = section_class.CID " |
| 47 |
"ORDER BY section_config.SID"); |
"ORDER BY section_config.SID"); |
| 48 |
|
|
| 49 |
if (mysql_query(db, sql) != 0) |
if (mysql_query(db, sql) != 0) |
| 50 |
{ |
{ |
| 51 |
log_error("Query section_list error: %s\n", mysql_error(db)); |
log_error("Query section_list error: %s\n", mysql_error(db)); |
| 52 |
return -1; |
return -3; |
| 53 |
} |
} |
| 54 |
if ((rs = mysql_store_result(db)) == NULL) |
if ((rs = mysql_store_result(db)) == NULL) |
| 55 |
{ |
{ |
| 56 |
log_error("Get section_list data failed\n"); |
log_error("Get section_list data failed\n"); |
| 57 |
return -1; |
return -3; |
| 58 |
} |
} |
| 59 |
|
|
| 60 |
|
ret = 0; |
| 61 |
while ((row = mysql_fetch_row(rs))) |
while ((row = mysql_fetch_row(rs))) |
| 62 |
{ |
{ |
| 63 |
sid = atoi(row[0]); |
sid = atoi(row[0]); |
| 73 |
if (mysql_query(db, sql) != 0) |
if (mysql_query(db, sql) != 0) |
| 74 |
{ |
{ |
| 75 |
log_error("Query section_master error: %s\n", mysql_error(db)); |
log_error("Query section_master error: %s\n", mysql_error(db)); |
| 76 |
return -2; |
ret = -3; |
| 77 |
|
break; |
| 78 |
} |
} |
| 79 |
if ((rs2 = mysql_store_result(db)) == NULL) |
if ((rs2 = mysql_store_result(db)) == NULL) |
| 80 |
{ |
{ |
| 81 |
log_error("Get section_master data failed\n"); |
log_error("Get section_master data failed\n"); |
| 82 |
return -2; |
ret = -3; |
| 83 |
|
break; |
| 84 |
} |
} |
| 85 |
if ((row2 = mysql_fetch_row(rs2))) |
if ((row2 = mysql_fetch_row(rs2))) |
| 86 |
{ |
{ |
| 100 |
p_section = section_list_create(sid, row[1], row[2], ""); |
p_section = section_list_create(sid, row[1], row[2], ""); |
| 101 |
if (p_section == NULL) |
if (p_section == NULL) |
| 102 |
{ |
{ |
| 103 |
log_error("load_section_config_from_db() error: load new section sid = %d sname = %s\n", sid, row[1]); |
log_error("section_list_create() error: load new section sid = %d sname = %s\n", sid, row[1]); |
| 104 |
|
ret = -4; |
| 105 |
break; |
break; |
| 106 |
} |
} |
| 107 |
|
|
| 143 |
} |
} |
| 144 |
mysql_free_result(rs); |
mysql_free_result(rs); |
| 145 |
|
|
| 146 |
return 0; |
mysql_close(db); |
| 147 |
|
|
| 148 |
|
return ret; |
| 149 |
} |
} |