getQueryStringFromJsonMultipleListTemp method
String
getQueryStringFromJsonMultipleListTemp({
- required dynamic model,
- String specificKeyInList = "",
- required dynamic multipleDataList,
Implementation
String getQueryStringFromJsonMultipleListTemp({required dynamic model, String specificKeyInList = "", required dynamic multipleDataList}) {
StringBuffer query = StringBuffer();
query.write("INSERT INTO " + model.runtimeType.toString() + " (");
Map<String, String> fieldNameList = model.getDataTypeMap();
int i = 0;
fieldNameList.forEach((field, type) {
if (i == fieldNameList.length - 1) {
query.write("$field ) VALUES ");
} else {
query.write("$field, ");
}
i++;
});
StringBuffer multipleValue = StringBuffer();
for (int i = 0; i < multipleDataList!.length; i++) {
// Loof for All Object
StringBuffer totalValue = StringBuffer();
int l = 0;
for (int j = 0; j < multipleDataList[i]!.length; j++) {
StringBuffer singleModelTotalValue = StringBuffer();
singleModelTotalValue.write("(");
// final Map<String, dynamic> data = multipleDataList[i][j];
Map<String, dynamic>? data ;
if(specificKeyInList != ""){
if(multipleDataList[i][j][specificKeyInList] != null) {
data = multipleDataList[i][j][specificKeyInList];
}
}else{
if(multipleDataList[i][j] != null) {
data = multipleDataList[i][j];
}
}
//String fieldValue = "";
//int k = 0;
//Map for Single Object
if(data != null ) {
if (data.length > 0) {
if (l == 0) {
singleModelTotalValue.write("(");
l++;
} else {
singleModelTotalValue.write(",(");
l++;
}
fieldNameList.forEach((fieldName, type) {
try {
//Map for Single Field
data!.forEach((key, value) {
if (fieldName == key) {
//fieldValue = value.toString();
throw 'Break Map'; // Stop iteration when the key is Matched
}
});
} catch (e) {
}
/* fieldValue = fieldValue.replaceAll("'", "''");
if (k == fieldNameList!.length - 1) {
singleModelTotalValue.write("'$fieldValue')");
} else {
singleModelTotalValue.write("'$fieldValue',");
}*/
totalValue.write("$singleModelTotalValue");
//k++;
});
//totalValue.write("$singleModelTotalValue,");
if (j == multipleDataList[i]!.length - 1) {
totalValue.write("$singleModelTotalValue");
} else {
totalValue.write("$singleModelTotalValue,");
}
}
}
}
// debugPrint("totalValue : "+totalValue.toString() );
if (i == multipleDataList!.length - 1) {
multipleValue.write("$totalValue");
} else {
multipleValue.write("$totalValue,");
}
}
query.write(multipleValue);
return query.toString();
}