-1

我有一个正在执行 mysql 查询的 C 代码。但是现在我想更新程序中我无法执行的特定列。谁能帮帮我吗。

conn = mysql_init(NULL);   // MySQL Database connection //
mysql_real_connect(conn, NULL, NULL, NULL, "bypass_new", 0, NULL, 0);
mysql_query(conn, "SELECT txnum, rxnum from data");
result = mysql_store_result(conn);
num_fields = mysql_num_fields(result);
k = 0;      

while ((row = mysql_fetch_row(result)))
{
  if(row[0])(p_info + k)->callingP   = row[0];
  if(row[1])(p_info + k)->calledP    = row[1];
  mysql_query(conn, "update data set flag_imei=1 where txnum=row[0]");
  k++;
 }
4

1 回答 1

1

尝试以下伪代码想法,它比您提到的更快和优化:

 k = 0;      
 myIDsArray = array();

 while ((row = mysql_fetch_row(result)))
 {
   if(row[0])(p_info + k)->callingP   = row[0];
   if(row[1])(p_info + k)->calledP    = row[1];

   myIDsArray.addId(row[0]);

   k++;
 }

  myString = [myIDsArray joinByString:","];
  myQuery = "update data set flag_imei=1 where txnum in ( " . myString . " ) ";
  mysql_query(conn, myQuery);
于 2012-11-13T14:30:37.757 回答