File: lazy.hs

package info (click to toggle)
haskelldb 0.9.cvs.601-5
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 680 kB
  • ctags: 35
  • sloc: haskell: 4,392; sh: 1,792; makefile: 143
file content (45 lines) | stat: -rw-r--r-- 1,011 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import Database.HaskellDB

import TestConnect

import Dp037.Lazy_test

{-
 Uses table created with:
 CREATE TABLE lazy_test (doc_id INT NOT NULL, body TEXT NOT NULL);
-}

docSize = 1000
numRecords = 10000
getRecords = 10
lazy = False

addDoc db bdy di = 
    insert db lazy_test (doc_id << constant di # body << constant bdy)

doc_body = replicate docSize 'x'

insertData db = mapM (addDoc db doc_body) [1..numRecords]

deleteData db = delete db lazy_test (\_ -> constant True)

countN db n = 
    do
    rs <- (if lazy then lazyQuery else strictQuery) db (table lazy_test)
    return (length (take n rs))

test db =
    do
    putStrLn $ "Deleting data..."
    deleteData db
    putStrLn $ "Adding " ++ show numRecords ++ " records..."
    insertData db
    putStrLn $ "Counting " ++ show getRecords ++ " "
		 ++ (if lazy then "lazy" else "strict") ++ " results ..."
    n <- countN db getRecords 
    putStrLn $ "n = " ++ show n
    putStrLn $ "Deleting data..."
    deleteData db

main = argConnect test