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

Function is_this_table

sqladvisor/main.cc:669–713  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

667}
668
669bool is_this_table(const char * field_name, char * table_name) {
670 MYSQL *con = mysql_init(NULL);
671 if (con == NULL || table_name == NULL || field_name == NULL) {
672 finish_with_error(con);
673 }
674
675 if (mysql_real_connect(con, options.host, options.username,
676 options.password, DBNAME, options.port, NULL, 0) == NULL) {
677 finish_with_error(con);
678 }
679 mysql_query(con, "set names utf8"); //指定字符集,确保能够执行含中文的SQL
680
681 GString *table_count_sql = g_string_new(NULL);
682 ulonglong table_count;
683 g_string_sprintf(table_count_sql,
684 "select count(*) from columns where TABLE_NAME = '%s' and COLUMN_NAME = '%s'",
685 table_name, field_name);
686
687 print_sql(table_count_sql->str);
688
689 if (mysql_query(con, table_count_sql->str)) {
690 finish_with_error(con);
691 }
692
693 MYSQL_RES *result = mysql_store_result(con);
694 if (result == NULL) {
695 finish_with_error(con);
696 }
697
698 int num_fields = mysql_num_fields(result);
699
700 MYSQL_ROW row;
701
702 if ((row = mysql_fetch_row(result))) {
703 table_count = atoi(row[AFFECT_ROWS]);
704 }
705 g_string_free(table_count_sql, TRUE);
706 mysql_free_result(result);
707 mysql_close(con);
708
709 if (table_count == 0)
710 return false;
711 else
712 return true;
713}
714
715void mysql_sql_parse_index(Field_Description *field_desp) {
716 INDEX_FIELD * field_index = new INDEX_FIELD(field_desp);

Callers 1

find_table_by_fieldFunction · 0.85

Calls 7

finish_with_errorFunction · 0.85
print_sqlFunction · 0.85
mysql_num_fieldsFunction · 0.85
mysql_fetch_rowFunction · 0.85
atoiFunction · 0.85
mysql_free_resultFunction · 0.85
mysql_closeFunction · 0.85

Tested by

no test coverage detected