MCPcopy Create free account
hub / github.com/acl-dev/acl / db_add_name

Method db_add_name

lib_acl_cpp/app/ndb/ctl_server/db_ctl.cpp:120–156  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

118}
119
120unsigned 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
158database* db_ctl::db_create(const char* dbname, const char* dbuser /* = NULL */,
159 const char* dbpass /* = NULL */)

Callers

nothing calls this directly

Calls 5

get_first_rowMethod · 0.80
field_intMethod · 0.80
free_resultMethod · 0.80
sql_updateMethod · 0.45
sql_selectMethod · 0.45

Tested by

no test coverage detected