fix: use column names from statement metadata in getRowData
Build and Test / build-and-test (push) Failing after 3m34s

This commit is contained in:
2026-05-30 09:26:36 -04:00
parent b6622c0a01
commit 469527f03c
+12 -11
View File
@@ -4,6 +4,9 @@ module Orville.SQLite.Internal (
getRowData, getRowData,
) where ) where
import Control.Monad (forM)
import Data.Maybe (fromMaybe)
import qualified Data.Text as T
import qualified Database.SQLite3 as SQLite3 import qualified Database.SQLite3 as SQLite3
import Database.SQLite3.Direct (columnCount) import Database.SQLite3.Direct (columnCount)
@@ -15,14 +18,12 @@ getRowData stmt cols = do
colCount <- columnCount stmt colCount <- columnCount stmt
let count :: Int = fromIntegral colCount let count :: Int = fromIntegral colCount
indexes = take count [0 :: SQLite3.ColumnIndex ..] indexes = take count [0 :: SQLite3.ColumnIndex ..]
mapM forM indexes $ \i -> do
( \i -> do let idx :: Int = fromIntegral i
let idx :: Int = fromIntegral i -- Try column name from statement metadata first, then fall back to provided names, then empty
colName = mName <- SQLite3.columnName stmt i
if idx < length cols let colName = case mName of
then cols !! idx Just n | not (T.null n) -> T.unpack n
else "" _ -> if idx < length cols then cols !! idx else ""
sqlVal <- SQLite3.column stmt i sqlVal <- SQLite3.column stmt i
pure (colName, sqlVal) pure (colName, sqlVal)
)
indexes