2019-02-25 16:11
Page 1

Databases (TDA357 / DIT621)

Databases in software applications

[xkcd 327: Exploits of a Mom]

Page 2
Databases (TDA357 / DIT621)

Today

Databases in software applications

Page 3

Databases in software applications

Database connectivity

Page 4

Database connectivity in Haskell

HDBC

Page 5

Installing HDBC

Page 6

Programming with HDBC

Connecting to a PostgreSQL database

Page 7
Programming with HDBC

Running statements (without query results)

Page 8
Programming with HDBC

Transactions

Page 9
Programming with HDBC

Running statements and retreiving query results

Page 10
Programming with HDBC

SqlValue

Page 11

Strings with placeholders

Page 12

SQL injection

Page 13

SQL injection example

Bad programming

Page 14
SQL injection example

Good programming

unregisterStudent :: Connection -> String -> String -> IO ()
unregisterStudent conn student course =
  run conn "DELETE FROM Registered WHERE course=? AND student=?"
           [toSql course,toSql student]
Page 15

An unusual SQL injection example

Page 16

Prepared Statements

Page 17

Prepared Statements (2)

Page 18

Examples

Page 19

Concluding remarks

Recommendations

Page 20
Concluding remarks

HDBC pitfalls

Page 21
Concluding remarks

Further reading