From 469527f03ce8687d9cbb2baeaae96902f95a96f1 Mon Sep 17 00:00:00 2001 From: James Brechtel Date: Sat, 30 May 2026 09:26:36 -0400 Subject: [PATCH] fix: use column names from statement metadata in getRowData --- src/Orville/SQLite/Internal.hs | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/Orville/SQLite/Internal.hs b/src/Orville/SQLite/Internal.hs index 3959354..4300245 100644 --- a/src/Orville/SQLite/Internal.hs +++ b/src/Orville/SQLite/Internal.hs @@ -4,6 +4,9 @@ module Orville.SQLite.Internal ( getRowData, ) where +import Control.Monad (forM) +import Data.Maybe (fromMaybe) +import qualified Data.Text as T import qualified Database.SQLite3 as SQLite3 import Database.SQLite3.Direct (columnCount) @@ -15,14 +18,12 @@ getRowData stmt cols = do colCount <- columnCount stmt let count :: Int = fromIntegral colCount indexes = take count [0 :: SQLite3.ColumnIndex ..] - mapM - ( \i -> do - let idx :: Int = fromIntegral i - colName = - if idx < length cols - then cols !! idx - else "" - sqlVal <- SQLite3.column stmt i - pure (colName, sqlVal) - ) - indexes + forM indexes $ \i -> do + let idx :: Int = fromIntegral i + -- Try column name from statement metadata first, then fall back to provided names, then empty + mName <- SQLite3.columnName stmt i + let colName = case mName of + Just n | not (T.null n) -> T.unpack n + _ -> if idx < length cols then cols !! idx else "" + sqlVal <- SQLite3.column stmt i + pure (colName, sqlVal)