Skip to content

Commit e3e39b0

Browse files
committed
Improved getRow(from:sql:params:) to determine if a column value is NULL
1 parent 7bc33a0 commit e3e39b0

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

Sources/SQLiteAdapter/SQLiteAdapter.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -379,11 +379,15 @@ open class SQLite: SQLiteType {
379379

380380
while sqlite3_step(sqlStatement) == SQLITE_ROW {
381381
rowValues = SQLValues([])
382-
for (index,value) in table.columnTypes.enumerated() {
382+
for (index, value) in table.columnTypes.enumerated() {
383383

384384
let index = Int32(index) // column serial number, should start with 0
385385

386386
// Check for data types of returned values
387+
guard sqlite3_column_type(sqlStatement, index) != SQLITE_NULL else {
388+
rowValues.append((value.type, nil))
389+
continue
390+
}
387391
switch value.type {
388392
case .INT:
389393
let intValue = sqlite3_column_int64(sqlStatement, index)
@@ -463,7 +467,6 @@ open class SQLite: SQLiteType {
463467
}
464468
}
465469

466-
/// Returns the id of the last row inserted
467470
public func getLastInsertID() -> Int {
468471
return Int(sqlite3_last_insert_rowid(dbPointer))
469472
}

0 commit comments

Comments
 (0)