fix: use column names from statement metadata in getRowData
Build and Test / build-and-test (push) Failing after 3m34s
Build and Test / build-and-test (push) Failing after 3m34s
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user