MCPcopy Create free account
hub / github.com/Meituan-Dianping/SQLAdvisor / get_key_name

Function get_key_name

sqladvisor/main.cc:1031–1068  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1029}
1030
1031_SET_C get_key_name(const char *field_name, char *table_name,
1032 int seq_in_index) {
1033 if (options.verbose)
1034 sql_print_information(
1035 "第%d步:开始验证表中是否已存在相关索引。表名:%s, 字段名:%s, 在索引中的位置:%d \n", STEP_CNT++,
1036 table_name, field_name, seq_in_index);
1037 MYSQL *conn = mysql_init(NULL);
1038 if (conn == NULL || table_name == NULL || field_name == NULL) {
1039 finish_with_error(conn);
1040 }
1041 if (mysql_real_connect(conn, options.host, options.username,
1042 options.password, options.dbname, options.port, NULL, 0) == NULL) {
1043 finish_with_error(conn);
1044 }
1045 mysql_query(conn, "set names utf8");
1046 GString *table_exist_index_sql = g_string_new(NULL);
1047 g_string_sprintf(table_exist_index_sql,
1048 "show index from %s where Column_name ='%s' and Seq_in_index =%d",
1049 table_name, field_name, seq_in_index);
1050 print_sql(table_exist_index_sql->str);
1051 if (mysql_query(conn, table_exist_index_sql->str)) {
1052 finish_with_error(conn);
1053 }
1054 MYSQL_RES *result = mysql_store_result(conn);
1055 if (result == NULL) {
1056 finish_with_error(conn);
1057 }
1058 MYSQL_ROW row;
1059 _SET_C s_key;
1060 int num_fields = mysql_num_fields(result);
1061 while ((row = mysql_fetch_row(result))) {
1062 s_key.insert(strdup(row[INDEX_KEY_NAME]));
1063 }
1064 g_string_free(table_exist_index_sql, TRUE);
1065 mysql_free_result(result);
1066 mysql_close(conn);
1067 return s_key;
1068}
1069
1070bool isPrimary(const char *field_name, char *table_name) {
1071 if (options.verbose)

Callers 1

print_indexFunction · 0.85

Calls 8

sql_print_informationFunction · 0.85
finish_with_errorFunction · 0.85
print_sqlFunction · 0.85
mysql_num_fieldsFunction · 0.85
mysql_fetch_rowFunction · 0.85
mysql_free_resultFunction · 0.85
mysql_closeFunction · 0.85
insertMethod · 0.45

Tested by

no test coverage detected