Skip to content

Commit 61a1300

Browse files
authored
Merge pull request #1812 from wheels-dev/update-sqlite-documentation
Update sqlite documentation with migration restrictions
2 parents 55803e3 + cd9a814 commit 61a1300

File tree

2 files changed

+50
-6
lines changed

2 files changed

+50
-6
lines changed

core/src/wheels/Global.cfc

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -434,12 +434,10 @@ component output="false" {
434434
}
435435

436436
if (structKeyExists(server, "boxlang")) {
437-
local.headerMap = local.response.getResponseHeaderMap();
438-
if (structKeyExists(local.headerMap, "Content-Type")) {
439-
local.headerArray = local.headerMap["Content-Type"];
440-
if (arrayLen(local.headerArray) > 0 && !isNull(local.headerArray[1])) {
441-
local.rv = local.headerArray[1];
442-
}
437+
local.request = local.response.getRequest();
438+
local.header = local.request.getHeader("Content-Type");
439+
if(!isNull(local.header)) {
440+
local.rv = local.header;
443441
}
444442
} else {
445443
if (local.response.containsHeader("Content-Type")) {

docs/src/database-interaction-through-models/using-sqlite.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,52 @@ user = model("User").create({username: "john"});
217217
// createdAt and updatedAt are automatically set as ISO 8601 text
218218
```
219219

220+
### DateTime Handling in Migrations
221+
222+
SQLite does not support ColdFusion datetime literals (for example `{ts '2025-01-01 10:00:00'}` or any datetime expression generated by CFML functions). Instead, SQLite stores all datetime values using the TEXT datatype in ISO-8601 format.
223+
224+
Because of this, when working inside migrations, you must not pass any CFML datetime literal to SQLite, or it will throw an error.
225+
226+
`addRecord()` and `updateRecord()` Handling
227+
228+
Unlike `removeRecord()`, the `addRecord()` and `updateRecord()` migration functions can safely accept ColdFusion datetime literals.
229+
230+
If you pass a CFML datetime literal (e.g., now(), createDateTime(), {ts '...'}) into addRecord() or updateRecord(), the migration system automatically converts the value into a valid SQLite-friendly ISO-8601 text string before inserting or updating the record.
231+
232+
This means:
233+
234+
```javascript
235+
addRecord(table = "products", data = { createdAt = now() })
236+
237+
and
238+
239+
updateRecord(table = "products", data = { updatedAt = createDateTime(2025,1,1,10,0,0) }, where = "id = 5")
240+
```
241+
242+
will both work correctly.
243+
244+
#### removeRecord() Restrictions
245+
246+
removeRecord() does not convert datetime literals.
247+
Therefore, you must never use CFML datetime expressions inside the where clause in removeRecord().
248+
249+
ColdFusion date/time functions (e.g. now(), dateAdd(), createDateTime()) generate CFML datetime literals which SQLite cannot understand.
250+
251+
SQLite expects datetime values to be plain quoted text strings.
252+
253+
Correct Usage in removeRecord()
254+
255+
If you need to match a datetime using removeRecord(), manually provide the value as text:
256+
257+
```javascript
258+
removeRecord(table = "products", where = "time = '2025-12-08 10:30:00'")
259+
260+
Incorrect Usage (Will Fail):
261+
removeRecord(table = "products", where = "time = #now()#")
262+
```
263+
264+
ColdFusion expands now() into a datetime literal which SQLite cannot parse.
265+
220266
### Migrations
221267

222268
Create and run migrations normally:

0 commit comments

Comments
 (0)