作者honyihon (lantis)
看板Database
標題[SQL ] c++ 批量輸入MySQL
時間Thu Oct 2 18:34:14 2014
資料庫名稱:MySQL
資料庫版本:Ubuntu 系統
內容/問題描述:批量insert 使用c++ 實作幫我看看哪裡有問題
code (主要是str裡面的東西送到令一個函式輸入)我每100筆丟過去
-------------------------
int count=0;
string str;
typedef double* DynamicMatrix[l+m];
// DynamicMatrix Count;
typedef double* DynamicMatrix2[l+m];
//DynamicMatrix2 Prob;
for(int i=0; i<(l+m); i++)
{
for(int j=0; j<(l+m); j++)
{
//--------------------------------------------------
if (count <= 100)
{
// concatinate the string with prev str
str += ' (i,j,combine[i],combine[j])'+',';
}
if (count ==100 || count == 0)
{
// execute the string
mysqlinsert(str);
// initialize str as empty string
str = 'INSERT INTO EM (
sourceindex,targetindex,source,target) VALUES';
count = 0;
}
}
}
--------------------------------------------------------
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 163.22.21.92
※ 文章網址: http://www.ptt.cc/bbs/Database/M.1412246058.A.C76.html
推 GoalBased: 錯誤訊息貼出來啊 10/02 18:35
推 GoalBased: 還有..不知道是我太久沒寫C了嗎 字串相加應該是用 "" ? 10/02 18:36
→ tedcat: insert後面的value如果是字串都要用單引號包住吧? 10/03 09:20
→ honyihon: str +=(i,j,combine[i],combine[j])+','; 改成這樣 10/03 15:29
→ honyihon: 先cout 出來括弧都消失了 10/03 15:30