Reputation: 419
void write_token_to_data()
{
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(mysqlinsert2(i,j,combine[i],combine[j]))
{
cout<<"insert OK!!"<<endl;
}
else
{
cout<<"insert failed"<<endl;
}
}
}
}//end of function
here is my question how can i change this sub function ,that i can keep i ,j combine[i], combine[j] until the number 100 , and throw these four value into the mysqlinsert function and free the array in the for loop index 101 and continue record the value ,long story short,i want break this mysql insert into small part
Upvotes: 0
Views: 234
Reputation: 296
- You can contruct a string in the form
(i,j,cobine[i],combine[j]) for each iteration.
- Inorder to insert a multiple rows in a single query.
[Normal insert query for multiple records
INSERT INTO Table ( Column1, Column2 ) VALUES
( Value1, Value2 ), ( Value1, Value2 )
]
- also rewrite mysqlinsert2(i,j,combine[i],combine[j]) into *mysqlinsert2(str)*.and execute the string.
for(int i=0; i<(l+m); i++){
for(int j=0; j<(l+m); j++){
if (till count => 100) {
// concatinate the string with prev str
str += (i,j,combine[i],combine[j])+',';
}
if (count reaches hundred || count = 0) {
// execute the string
mysqlinsert2(str);
// initialize str as empty string
str = 'INSERT INTO Table ( Column1, Column2, column3, column4 ) VALUES';
count = 0;
}
}
}
Upvotes: 1