Skip to content

Commit

Permalink
Query for JSON conversion is fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
beingfranklin committed Dec 8, 2020
1 parent 67b2691 commit 0d0e4e4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
11 changes: 6 additions & 5 deletions app/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,6 @@ main = do
let converRes = sqlRowToString res
mapM_ putStrLn converRes
putStrLn "\n****************"
-- TODO - JSON Conversion code is below
-- sqlValue <- getUnprocessedSQLHolidays conn
-- print $ show sqlValue
-- print "Done!"
-- putStrLn "\n****************"
putStrLn "\nSee the holidays between specific dates... "
putStrLn "\nInput the start date [DD-MMM-YY] "
startDate <- getLine
Expand Down Expand Up @@ -82,6 +77,12 @@ main = do
_ -> syntaxErrorGlobal
putStrLn "\n****************"
putStrLn $ "Number of rows in Table is " ++ show (length res)
putStrLn "\n****************"
-- TODO - JSON Conversion code is below
sqlValue <- getUnprocessedSQLHolidays conn
print $ show sqlValue
print "Done!"
putStrLn "\n****************"


syntaxErrorGlobal :: IO ()
Expand Down
13 changes: 10 additions & 3 deletions src/Database.hs
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,17 @@ sqlRowToString :: [[SqlValue]] -> [String]
sqlRowToString xs = map (fromSql :: SqlValue -> String) (concat xs)

-- | Method to retrieve all the SQLs on the database.
getUnprocessedSQLHolidays :: Connection -> IO [(String, String, String)]
getUnprocessedSQLHolidays :: Connection -> IO [(String, String, String, String, Bool, Bool)]
getUnprocessedSQLHolidays conn = do
res <- quickQuery' conn "SELECT date, localName, name FROM holidays" []
return $ map (\xs -> (fromSql (xs !! 0), fromSql (xs !! 1), fromSql (xs !! 2))) res
res <-
quickQuery'
conn
"SELECT holidays.date, holidays.localName, holidays.name, countries.countryCode, countries.global, countries.fixed FROM holidays \
\INNER JOIN countries \
\WHERE countries.id=holidays.id \
\ORDER BY countries.id ASC"
[]
return $ map (\xs -> (fromSql (xs !! 0), fromSql (xs !! 1), fromSql (xs !! 2), fromSql (xs !! 3), fromSql (xs !! 4), fromSql (xs !! 5))) res

getUnprocessedSQLCountries :: Connection -> IO [(String, Bool)]
getUnprocessedSQLCountries conn = do
Expand Down

0 comments on commit 0d0e4e4

Please sign in to comment.