alholden
05/01/2025, 9:51 PMThe column name "EMPLOYEE_ID" is invalid. Column names must be valid variable names. They must start with a letter and can only include letters, numbers, and underscores.
bdw429s
05/01/2025, 9:52 PMbdw429s
05/01/2025, 9:52 PMJoseph Bullock-Palser
05/01/2025, 9:56 PMalholden
05/01/2025, 9:59 PMalholden
05/01/2025, 10:00 PMbdw429s
05/01/2025, 10:01 PMalholden
05/01/2025, 10:01 PMalholden
05/01/2025, 10:01 PMalholden
05/01/2025, 10:06 PMbdw429s
05/01/2025, 10:08 PMbdw429s
05/01/2025, 10:08 PMalholden
05/01/2025, 10:20 PMalholden
05/01/2025, 10:20 PMalholden
05/01/2025, 10:21 PMalholden
05/01/2025, 10:23 PMalholden
05/01/2025, 10:23 PMalholden
05/01/2025, 10:25 PMIftkhar
05/02/2025, 1:36 AMcolName
) based on the first column name, and then using that same column name (colName
) for every column, which is incorrect.
That's why ColdFusion throws the error:
> The column name "EMPLOYEE_ID" is invalid. Column names must be valid variable names.
> They must start with a letter and can only include letters, numbers, and underscores.
This error is misleading in your case - because the real problem is reusing the same column name (likely "EMPLOYEE_ID"
) for all columns.
Please try this:
function csvToQuery(csvString) {
var rowDelim = chr(10); // Default line break
var colDelim = ","; // Default column separator
var newQuery = QueryNew("");
var columnNames = [];
var rows = [];
var i = 1;
var j = 1;
csvString = trim(csvString);
// Optional rowDelim and colDelim overrides
if (arrayLen(arguments) >= 2) rowDelim = arguments[2];
if (arrayLen(arguments) >= 3) colDelim = arguments[3];
// Split into rows
rows = listToArray(csvString, rowDelim);
// Parse header row and create columns
var headers = listToArray(rows[1], colDelim);
for (i = 1; i <= arrayLen(headers); i++) {
columnNames[i] = trim(uCase(replace(headers[i], " ", "_", "all")));
queryAddColumn(newQuery, columnNames[i], []);
}
// Parse and add remaining rows
for (i = 2; i <= arrayLen(rows); i++) {
var rowData = listToArray(rows[i], colDelim);
queryAddRow(newQuery);
for (j = 1; j <= arrayLen(columnNames); j++) {
if (j <= arrayLen(rowData)) {
var cellValue = trim(replace(rowData[j], chr(34), "", "all"));
querySetCell(newQuery, columnNames[j], cellValue, i - 1);
}
}
}
return newQuery;
}
alholden
05/02/2025, 8:51 PMalholden
05/02/2025, 9:03 PMrows
, I'm starting to suspect that this provider's csv file is not using chr 10 or 12 as cr/lf delimiters.
Therefore, I think it's parsing the entire csv string's contents as the first or "headers" row.alholden
05/02/2025, 9:38 PMalholden
05/02/2025, 9:41 PM*queryAddColumn*(newQuery, columnNames[i], []);
_*The column name "EMPLOYEE_ID" is invalid.*_
Column names must be valid variable names. They must start with a letter and can only include letters, numbers, and underscores.
So this little project is dead for the weekend.
Sad for the project, happy for the weekend. 🎉alholden
05/02/2025, 9:48 PMbdw429s
05/02/2025, 9:55 PMbdw429s
05/02/2025, 9:55 PMalholden
05/02/2025, 10:30 PMalholden
05/02/2025, 10:32 PMcsvToQuery
function of theirs does a replace chr(34) on the cell contents, but not the headers. I need to dig up some old developer and slap him for my oversight.alholden
05/02/2025, 10:33 PM