La documentazione HDBC afferma:
fetchAllRows :: Statement -> IO [[SqlValue]]Source
Lazily fetch all rows from an executed Statement.
You can think of this as hGetContents applied to a database result set.
The result of this is a lazy list, and each new row will be read, lazily, from the database as the list is processed.
When you have exhausted the list, the Statement will be finished.
Please note that the careless use of this function can lead to some unpleasant behavior. In particular, if you have not consumed the entire list, then attempt to finish or re-execute the statement, and then attempt to consume more elements from the list, the result will almost certainly not be what you want.
But then, similar caveats apply with hGetContents.
Bottom line: this is a very convenient abstraction; use it wisely.
Use fetchAllRows' if you need something that is strict, without all these caveats.
Allora, mi chiedo, a quale livello si estende la pigrizia?
Dì, posso avere
conn <- connectSqlite3 databaseFilePath
rows <- quickQuery conn ("SELECT * FROM foo") []
mapM_ bar $ take n rows
disconnect conn
In realtà recupera solo n
righe? Come, dal punto di vista del database, sarà equivalente a SELECT * FROM foo LIMIT (n)
? Perché recuperare tutte le righe a livello di driver di database e poi take
ing n
di esse sembra essere sciocco e tipo di sconfitte lo scopo.
Se è pigro fino al database stesso, come viene implementato? Sta usando i cursori?
So che ci sono diversi driver per HDBC da solo. Sto solo chiedendo il principio di implementazione.