Commits

Charles Deakins committed ed40def

Remodeled codeIndex.hs SQL query.

Comments (0)

Files changed (1)

 getLastSixImages :: IO [[SqlValue]]
 getLastSixImages = do
                         conn <- connectSqlite3 "./databaseDir/imageDatabase.db"
-                        a <- liftIO $ quickQuery' conn "SELECT name FROM images WHERE number = (SELECT max(number) FROM images)" []
-                        b <- liftIO $ quickQuery' conn "SELECT name FROM images WHERE number = ((SELECT max(number) FROM images) - 1)" [] 
-                        c <- liftIO $ quickQuery' conn "SELECT name FROM images WHERE number = ((SELECT max(number) FROM images) - 2)" [] 
-                        d <- liftIO $ quickQuery' conn "SELECT name FROM images WHERE number = ((SELECT max(number) FROM images) - 3)" [] 
-                        e <- liftIO $ quickQuery' conn "SELECT name FROM images WHERE number = ((SELECT max(number) FROM images) - 4)" [] 
-                        f <- liftIO $ quickQuery' conn "SELECT name FROM images WHERE number = ((SELECT max(number) FROM images) - 5)" [] 
-                        disconnect conn
-                        return (a ++ b ++ c ++ d ++ e ++ f)
+                        all <- liftIO $ quickQuery' conn "SELECT name FROM images WHERE number >= (SELECT max(number-5) FROM images) AND number <= (SELECT max(number) FROM images) ORDER BY number DESC;" []
+                        disconnect conn 
+                        return all
 
 {-
  - input: [[SqlByteString "filename0.jpg"],.........,[SqlByteString "filename5.jpg"]]