| 118 | } |
| 119 | |
| 120 | unsigned int db_ctl::db_add_name(const char* name, name_type_t type) |
| 121 | { |
| 122 | char sql[256]; |
| 123 | |
| 124 | // ���������ݿ��¼ |
| 125 | snprintf(sql, sizeof(sql), "insert into tbl_name_type(name, type)" |
| 126 | " values('%s', %d)", name, (int) type); |
| 127 | |
| 128 | // ���ع������ݿ��¼�Ƿ��Ѿ����� |
| 129 | (void) ctl_conn_->sql_update(sql); |
| 130 | |
| 131 | // ��ѯ���ݿ�������Ӧ��ID�� |
| 132 | snprintf(sql, sizeof(sql), "select id from tbl_name_type" |
| 133 | " where name='%s' and type=0", name); |
| 134 | if (ctl_conn_->sql_select(sql) == false) |
| 135 | { |
| 136 | logger_error("create db(%s) error", name); |
| 137 | return (unsigned int) -1; |
| 138 | } |
| 139 | const acl::db_row* first_row = ctl_conn_->get_first_row(); |
| 140 | if (first_row == NULL) |
| 141 | { |
| 142 | logger_error("create db(%s) error, sql(%s)", name, sql); |
| 143 | return (unsigned int) -1; |
| 144 | } |
| 145 | |
| 146 | unsigned int id = (unsigned int) first_row->field_int("id", -1); |
| 147 | if (id == (unsigned int) -1) |
| 148 | { |
| 149 | ctl_conn_->free_result(); |
| 150 | logger_error("create db(%s) error, id(-1) invalid", name); |
| 151 | return (unsigned int) -1; |
| 152 | } |
| 153 | |
| 154 | ctl_conn_->free_result(); |
| 155 | return id; |
| 156 | } |
| 157 | |
| 158 | database* db_ctl::db_create(const char* dbname, const char* dbuser /* = NULL */, |
| 159 | const char* dbpass /* = NULL */) |
nothing calls this directly
no test coverage detected