Skip to content

Commit

Permalink
Changed string escaping for test data export
Browse files Browse the repository at this point in the history
Changed string escaping for test data export

GSvar: correctly escape test data in SQL
  • Loading branch information
ubuntolog committed Dec 11, 2023
1 parent e805665 commit b91c171
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions src/cppNGSD/NGSD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8963,16 +8963,12 @@ void NGSD::exportTable(const QString& table, QTextStream& out, QString where_cla
for (int i=0; i<field_count; i++)
{
QString field_value = query.value(field_names[i]).toString();
if (((field_value.isEmpty()) || (field_value=="0")) && (table_info.fieldInfo()[i].is_nullable)) field_value = "NULL";
field_value = field_value.replace("'", "\\'");
field_value = field_value.replace("\"", "\\\"");
field_value = field_value.replace("\r", "\\r");
field_value = field_value.replace("\n", "\\n");
values.append(field_value);
if (((field_value.isEmpty()) || (field_value=="0")) && (table_info.fieldInfo()[i].is_nullable)) field_value = "NULL";
values.append(escapeText(field_value));
}

QString insert_query = "('" + values.join("', '") + "')";
insert_query = insert_query.replace("'NULL'", "NULL");
QString insert_query = "(" + values.join(", ") + ")";
insert_query = insert_query.replace("'NULL'", "NULL");
out << insert_query;

if (row_count>=1000)
Expand Down

0 comments on commit b91c171

Please sign in to comment.