Skip to content
This repository was archived by the owner on Apr 21, 2026. It is now read-only.

Commit 58a378b

Browse files
committed
wip
1 parent 7aa6b99 commit 58a378b

1 file changed

Lines changed: 16 additions & 11 deletions

File tree

public/miscellaneous/migrate-data.cfm

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -162,22 +162,28 @@ function buildInsert(required string tableName, required query data, required nu
162162
}
163163
}
164164
165-
// Pre-scan batch to detect which columns contain date values in any row.
166-
// This ensures NULL values in those columns get CAST too (CockroachDB
167-
// requires consistent types across all rows in a multi-row VALUES clause).
168-
var dateCols = {};
165+
// Pre-scan batch to detect which columns are purely date columns.
166+
// A column is a "date column" if it has at least one date value AND no
167+
// non-date, non-null values. This ensures consistent types across all
168+
// rows in a multi-row VALUES clause (CockroachDB requirement).
169+
var dateColCandidates = {}; // columns with at least one date
170+
var dateColExcluded = {}; // columns with a non-date non-null value
169171
for (var r = arguments.startRow; r <= arguments.endRow; r++) {
170172
for (var col in columns) {
171173
var colLower = lCase(col);
172-
if (!structKeyExists(boolCols, colLower) && !structKeyExists(dateCols, colLower)) {
173-
var scanVal = arguments.data[col][r];
174-
if (!isNull(scanVal) && isDate(scanVal) && !(isSimpleValue(scanVal) && scanVal == "")
175-
&& (!isSimpleValue(scanVal) || reFind("(^\d{4}[-/]|^\{ts\s)", scanVal))) {
176-
dateCols[colLower] = true;
174+
if (structKeyExists(boolCols, colLower) || structKeyExists(dateColExcluded, colLower)) continue;
175+
var scanVal = arguments.data[col][r];
176+
if (!isNull(scanVal) && isSimpleValue(scanVal) && scanVal != "") {
177+
if (isDate(scanVal)) {
178+
dateColCandidates[colLower] = true;
179+
} else {
180+
dateColExcluded[colLower] = true;
181+
structDelete(dateColCandidates, colLower);
177182
}
178183
}
179184
}
180185
}
186+
var dateCols = dateColCandidates;
181187
182188
var valueClauses = [];
183189
var params = {};
@@ -204,8 +210,7 @@ function buildInsert(required string tableName, required query data, required nu
204210
var boolVal = (isBoolean(val) && val) || (isNumeric(val) && val == 1);
205211
params[paramName] = { value: boolVal ? "true" : "false", cfsqltype: "cf_sql_varchar" };
206212
arrayAppend(placeholders, "CAST(:#paramName# AS BOOLEAN)");
207-
} else if (structKeyExists(dateCols, colLower) && isDate(val)
208-
&& (!isSimpleValue(val) || reFind("(^\d{4}[-/]|^\{ts\s)", val))) {
213+
} else if (structKeyExists(dateCols, colLower)) {
209214
// Convert timestamps to ISO string to avoid JDBC {ts '...'} escape format
210215
params[paramName] = { value: dateTimeFormat(val, "yyyy-MM-dd HH:nn:ss"), cfsqltype: "cf_sql_varchar" };
211216
arrayAppend(placeholders, "CAST(:#paramName# AS TIMESTAMP)");

0 commit comments

Comments
 (0)