This file is indexed.

/usr/share/doc/libghc-hdbc-doc/html/HDBC.txt is in libghc-hdbc-doc 2.4.0.0-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

   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
  46
  47
  48
  49
  50
  51
  52
  53
  54
  55
  56
  57
  58
  59
  60
  61
  62
  63
  64
  65
  66
  67
  68
  69
  70
  71
  72
  73
  74
  75
  76
  77
  78
  79
  80
  81
  82
  83
  84
  85
  86
  87
  88
  89
  90
  91
  92
  93
  94
  95
  96
  97
  98
  99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
 168
 169
 170
 171
 172
 173
 174
 175
 176
 177
 178
 179
 180
 181
 182
 183
 184
 185
 186
 187
 188
 189
 190
 191
 192
 193
 194
 195
 196
 197
 198
 199
 200
 201
 202
 203
 204
 205
 206
 207
 208
 209
 210
 211
 212
 213
 214
 215
 216
 217
 218
 219
 220
 221
 222
 223
 224
 225
 226
 227
 228
 229
 230
 231
 232
 233
 234
 235
 236
 237
 238
 239
 240
 241
 242
 243
 244
 245
 246
 247
 248
 249
 250
 251
 252
 253
 254
 255
 256
 257
 258
 259
 260
 261
 262
 263
 264
 265
 266
 267
 268
 269
 270
 271
 272
 273
 274
 275
 276
 277
 278
 279
 280
 281
 282
 283
 284
 285
 286
 287
 288
 289
 290
 291
 292
 293
 294
 295
 296
 297
 298
 299
 300
 301
 302
 303
 304
 305
 306
 307
 308
 309
 310
 311
 312
 313
 314
 315
 316
 317
 318
 319
 320
 321
 322
 323
 324
 325
 326
 327
 328
 329
 330
 331
 332
 333
 334
 335
 336
 337
 338
 339
 340
 341
 342
 343
 344
 345
 346
 347
 348
 349
 350
 351
 352
 353
 354
 355
 356
 357
 358
 359
 360
 361
 362
 363
 364
 365
 366
 367
 368
 369
 370
 371
 372
 373
 374
 375
 376
 377
 378
 379
 380
 381
 382
 383
 384
 385
 386
 387
 388
 389
 390
 391
 392
 393
 394
 395
 396
 397
 398
 399
 400
 401
 402
 403
 404
 405
 406
 407
 408
 409
 410
 411
 412
 413
 414
 415
 416
 417
 418
 419
 420
 421
 422
 423
 424
 425
 426
 427
 428
 429
 430
 431
 432
 433
 434
 435
 436
 437
 438
 439
 440
 441
 442
 443
 444
 445
 446
 447
 448
 449
 450
 451
 452
 453
 454
 455
 456
 457
 458
 459
 460
 461
 462
 463
 464
 465
 466
 467
 468
 469
 470
 471
 472
 473
 474
 475
 476
 477
 478
 479
 480
 481
 482
 483
 484
 485
 486
 487
 488
 489
 490
 491
 492
 493
 494
 495
 496
 497
 498
 499
 500
 501
 502
 503
 504
 505
 506
 507
 508
 509
 510
 511
 512
 513
 514
 515
 516
 517
 518
 519
 520
 521
 522
 523
 524
 525
 526
 527
 528
 529
 530
 531
 532
 533
 534
 535
 536
 537
 538
 539
 540
 541
 542
 543
 544
 545
 546
 547
 548
 549
 550
 551
 552
 553
 554
 555
 556
 557
 558
 559
 560
 561
 562
 563
 564
 565
 566
 567
 568
 569
 570
 571
 572
 573
 574
 575
 576
 577
 578
 579
 580
 581
 582
 583
 584
 585
 586
 587
 588
 589
 590
 591
 592
 593
 594
 595
 596
 597
 598
 599
 600
 601
 602
 603
 604
 605
 606
 607
 608
 609
 610
 611
 612
 613
 614
 615
 616
 617
 618
 619
 620
 621
 622
 623
 624
 625
 626
 627
 628
 629
 630
 631
 632
 633
 634
 635
 636
 637
 638
 639
 640
 641
 642
 643
 644
 645
 646
 647
 648
 649
 650
 651
 652
 653
 654
 655
 656
 657
 658
 659
 660
 661
 662
 663
 664
 665
 666
 667
 668
 669
 670
 671
 672
 673
 674
 675
 676
 677
 678
 679
 680
 681
 682
 683
 684
 685
 686
 687
 688
 689
 690
 691
 692
 693
 694
 695
 696
 697
 698
 699
 700
 701
 702
 703
 704
 705
 706
 707
 708
 709
 710
 711
 712
 713
 714
 715
 716
 717
 718
 719
 720
 721
 722
 723
 724
 725
 726
 727
 728
 729
 730
 731
 732
 733
 734
 735
 736
 737
 738
 739
 740
 741
 742
 743
 744
 745
 746
 747
 748
 749
 750
 751
 752
 753
 754
 755
 756
 757
 758
 759
 760
 761
 762
 763
 764
 765
 766
 767
 768
 769
 770
 771
 772
 773
 774
 775
 776
 777
 778
 779
 780
 781
 782
 783
 784
 785
 786
 787
 788
 789
 790
 791
 792
 793
 794
 795
 796
 797
 798
 799
 800
 801
 802
 803
 804
 805
 806
 807
 808
 809
 810
 811
 812
 813
 814
 815
 816
 817
 818
 819
 820
 821
 822
 823
 824
 825
 826
 827
 828
 829
 830
 831
 832
 833
 834
 835
 836
 837
 838
 839
 840
 841
 842
 843
 844
 845
 846
 847
 848
 849
 850
 851
 852
 853
 854
 855
 856
 857
 858
 859
 860
 861
 862
 863
 864
 865
 866
 867
 868
 869
 870
 871
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/


-- | Haskell Database Connectivity
--   
--   HDBC provides an abstraction layer between Haskell programs and SQL
--   relational databases. This lets you write database code once, in
--   Haskell, and have it work with any number of backend SQL databases
--   (MySQL, Oracle, PostgreSQL, ODBC-compliant databases, etc.)
@package HDBC
@version 2.4.0.0

module Database.HDBC.Locale
defaultTimeLocale :: TimeLocale

-- | As the semantic of System.Locale.iso8601DateFormat has changed with
--   old-locale-1.0.0.2 in a non-compatible way, we now define our own
--   (compatible) version of it.
iso8601DateFormat :: Maybe String -> String

module Database.HDBC.SqlValue

-- | <a>SqlValue</a> is he main type for expressing Haskell values to SQL
--   databases.
--   
--   <i>INTRODUCTION TO SQLVALUE</i>
--   
--   This type is used to marshall Haskell data to and from database APIs.
--   HDBC driver interfaces will do their best to use the most accurate and
--   efficient way to send a particular value to the database server.
--   
--   Values read back from the server are constructed with the most
--   appropriate <a>SqlValue</a> constructor. <a>fromSql</a> or
--   <a>safeFromSql</a> can then be used to convert them into whatever type
--   is needed locally in Haskell.
--   
--   Most people will use <a>toSql</a> and <a>fromSql</a> instead of
--   manipulating <a>SqlValue</a>s directly.
--   
--   <i>EASY CONVERSIONS BETWEEN HASKELL TYPES</i>
--   
--   Conversions are powerful; for instance, you can call <a>fromSql</a> on
--   a SqlInt32 and get a String or a Double out of it. This class attempts
--   to Do The Right Thing whenever possible, and will raise an error when
--   asked to do something incorrect. In particular, when converting to any
--   type except a Maybe, <a>SqlNull</a> as the input will cause an error
--   to be raised.
--   
--   Conversions are implemented in terms of the <a>Data.Convertible</a>
--   module, part of the convertible package. You can refer to its
--   documentation, and import that module, if you wish to parse the Left
--   result from <a>safeFromSql</a> yourself, or write your own conversion
--   instances.
--   
--   Here are some notes about conversion:
--   
--   <ul>
--   <li>Fractions of a second are not preserved on time values</li>
--   <li>There is no <tt>safeToSql</tt> because <a>toSql</a> never
--   fails.</li>
--   </ul>
--   
--   See also <a>toSql</a>, <a>safeFromSql</a>, <a>fromSql</a>,
--   <a>nToSql</a>, <a>iToSql</a>, <a>posixToSql</a>.
--   
--   <i>ERROR CONDITIONS</i>
--   
--   There may sometimes be an error during conversion. For instance, if
--   you have a <a>SqlString</a> and are attempting to convert it to an
--   Integer, but it doesn't parse as an Integer, you will get an error.
--   This will be indicated as an exception if using <a>fromSql</a>, or a
--   Left result if using <a>safeFromSql</a>.
--   
--   <i>SPECIAL NOTE ON POSIXTIME</i>
--   
--   Note that a <a>NominalDiffTime</a> or <a>POSIXTime</a> is converted to
--   <a>SqlDiffTime</a> by <a>toSql</a>. HDBC cannot differentiate between
--   <a>NominalDiffTime</a> and <a>POSIXTime</a> since they are the same
--   underlying type. You must construct <a>SqlPOSIXTime</a> manually or
--   via <a>posixToSql</a>, or use <a>SqlUTCTime</a>.
--   
--   <i>DETAILS ON SQL TYPES</i>
--   
--   HDBC database backends are expected to marshal date and time data back
--   and forth using the appropriate representation for the underlying
--   database engine. Databases such as PostgreSQL with builtin date and
--   time types should see automatic conversion between these Haskell types
--   to database types. Other databases will be presented with an integer
--   or a string. Care should be taken to use the same type on the Haskell
--   side as you use on the database side. For instance, if your database
--   type lacks timezone information, you ought not to use ZonedTime, but
--   instead LocalTime or UTCTime. Database type systems are not always as
--   rich as Haskell. For instance, for data stored in a TIMESTAMP WITHOUT
--   TIME ZONE column, HDBC may not be able to tell if it is intended as
--   UTCTime or LocalTime data, and will happily convert it to both, upon
--   your request. It is your responsibility to ensure that you treat
--   timezone issues with due care.
--   
--   This behavior also exists for other types. For instance, many
--   databases do not have a Rational type, so they will just use the show
--   function and store a Rational as a string.
--   
--   The conversion between Haskell types and database types is complex,
--   and generic code in HDBC or its backends cannot possibly accomodate
--   every possible situation. In some cases, you may be best served by
--   converting your Haskell type to a String, and passing that to the
--   database.
--   
--   <i>UNICODE AND BYTESTRINGS</i>
--   
--   Beginning with HDBC v2.0, interactions with a database are presumed to
--   occur in UTF-8.
--   
--   To accomplish this, whenever a ByteString must be converted to or from
--   a String, the ByteString is assumed to be in UTF-8 encoding, and will
--   be decoded or encoded as appropriate. Database drivers will generally
--   present text or string data they have received from the database as a
--   SqlValue holding a ByteString, which <a>fromSql</a> will automatically
--   convert to a String, and thus automatically decode UTF-8, when you
--   need it. In the other direction, database drivers will generally
--   convert a <a>SqlString</a> to a ByteString in UTF-8 encoding before
--   passing it to the database engine.
--   
--   If you are handling some sort of binary data that is not in UTF-8, you
--   can of course work with the ByteString directly, which will bypass any
--   conversion.
--   
--   Due to lack of support by database engines, lazy ByteStrings are not
--   passed to database drivers. When you use <a>toSql</a> on a lazy
--   ByteString, it will be converted to a strict ByteString for storage.
--   Similarly, <a>fromSql</a> will convert a strict ByteString to a lazy
--   ByteString if you demand it.
--   
--   <i>EQUALITY OF SQLVALUE</i>
--   
--   Two SqlValues are considered to be equal if one of these hold. The
--   first comparison that can be made is controlling; if none of these
--   comparisons can be made, then they are not equal:
--   
--   <ul>
--   <li>Both are NULL</li>
--   <li>Both represent the same type and the encapsulated values are
--   considered equal by applying (==) to them</li>
--   <li>The values of each, when converted to a string, are equal.</li>
--   </ul>
--   
--   <i>STRING VERSIONS OF TIMES</i>
--   
--   Default string representations are given as comments below where such
--   are non-obvious. These are used for <a>fromSql</a> when a
--   <a>String</a> is desired. They are also defaults for representing data
--   to SQL backends, though individual backends may override them when a
--   different format is demanded by the underlying database. Date and time
--   formats use ISO8601 date format, with HH:MM:SS added for time, and
--   -HHMM added for timezone offsets.
--   
--   <i>DEPRECATED CONSTRUCTORS</i>
--   
--   <a>SqlEpochTime</a> and <a>SqlTimeDiff</a> are no longer created
--   automatically by any <a>toSql</a> or <a>fromSql</a> functions or
--   database backends. They may still be manually constructed, but are
--   expected to be removed in a future version. Although these two
--   constructures will be removed, support for marshalling to and from the
--   old System.Time data will be maintained as long as System.Time is,
--   simply using the newer data types for conversion.
data SqlValue
SqlString :: String -> SqlValue
SqlByteString :: ByteString -> SqlValue
SqlWord32 :: Word32 -> SqlValue
SqlWord64 :: Word64 -> SqlValue
SqlInt32 :: Int32 -> SqlValue
SqlInt64 :: Int64 -> SqlValue
SqlInteger :: Integer -> SqlValue
SqlChar :: Char -> SqlValue
SqlBool :: Bool -> SqlValue
SqlDouble :: Double -> SqlValue
SqlRational :: Rational -> SqlValue

-- | Local YYYY-MM-DD (no timezone)
SqlLocalDate :: Day -> SqlValue

-- | Local HH:MM:SS (no timezone)
SqlLocalTimeOfDay :: TimeOfDay -> SqlValue

-- | Local HH:MM:SS -HHMM. Converts to and from (TimeOfDay, TimeZone).
SqlZonedLocalTimeOfDay :: TimeOfDay -> TimeZone -> SqlValue

-- | Local YYYY-MM-DD HH:MM:SS (no timezone)
SqlLocalTime :: LocalTime -> SqlValue

-- | Local YYYY-MM-DD HH:MM:SS -HHMM. Considered equal if both convert to
--   the same UTC time.
SqlZonedTime :: ZonedTime -> SqlValue

-- | UTC YYYY-MM-DD HH:MM:SS
SqlUTCTime :: UTCTime -> SqlValue

-- | Calendar diff between seconds. Rendered as Integer when converted to
--   String, but greater precision may be preserved for other types or to
--   underlying database.
SqlDiffTime :: NominalDiffTime -> SqlValue

-- | Time as seconds since midnight Jan 1 1970 UTC. Integer rendering as
--   for <a>SqlDiffTime</a>.
SqlPOSIXTime :: POSIXTime -> SqlValue

-- | DEPRECATED Representation of ClockTime or CalendarTime. Use
--   SqlPOSIXTime instead.
SqlEpochTime :: Integer -> SqlValue

-- | DEPRECATED Representation of TimeDiff. Use SqlDiffTime instead.
SqlTimeDiff :: Integer -> SqlValue

-- | NULL in SQL or Nothing in Haskell
SqlNull :: SqlValue

-- | Conversions to and from <a>SqlValue</a>s and standard Haskell types.
--   
--   This function converts from an <a>SqlValue</a> to a Haskell value.
--   Many people will use the simpler <a>fromSql</a> instead. This function
--   is simply a restricted-type wrapper around <a>safeConvert</a>.
safeFromSql :: Convertible SqlValue a => SqlValue -> ConvertResult a

-- | Convert a value to an <a>SqlValue</a>. This function is simply a
--   restricted-type wrapper around <a>convert</a>. See extended notes on
--   <a>SqlValue</a>.
toSql :: Convertible a SqlValue => a -> SqlValue

-- | Convert from an <a>SqlValue</a> to a Haskell value. Any problem is
--   indicated by calling <a>error</a>. This function is simply a
--   restricted-type wrapper around <a>convert</a>. See extended notes on
--   <a>SqlValue</a>.
fromSql :: Convertible SqlValue a => SqlValue -> a

-- | Converts any Integral type to a <a>SqlValue</a> by using toInteger.
nToSql :: Integral a => a -> SqlValue

-- | Convenience function for using numeric literals in your program.
iToSql :: Int -> SqlValue

-- | Convenience function for converting <a>POSIXTime</a> to a
--   <a>SqlValue</a>, because <a>toSql</a> cannot do the correct thing in
--   this instance.
posixToSql :: POSIXTime -> SqlValue
instance Typeable SqlValue
instance Typeable TimeDiff
instance Typeable ClockTime
instance Show SqlValue
instance Convertible SqlValue a => Convertible SqlValue (Maybe a)
instance Convertible a SqlValue => Convertible (Maybe a) SqlValue
instance Convertible SqlValue CalendarTime
instance Convertible CalendarTime SqlValue
instance Convertible SqlValue DiffTime
instance Convertible DiffTime SqlValue
instance Convertible SqlValue TimeDiff
instance Convertible TimeDiff SqlValue
instance Convertible SqlValue ClockTime
instance Convertible ClockTime SqlValue
instance Convertible SqlValue NominalDiffTime
instance Convertible NominalDiffTime SqlValue
instance Convertible SqlValue UTCTime
instance Convertible UTCTime SqlValue
instance Convertible SqlValue ZonedTime
instance Convertible ZonedTime SqlValue
instance Convertible SqlValue LocalTime
instance Convertible LocalTime SqlValue
instance Convertible SqlValue (TimeOfDay, TimeZone)
instance Convertible (TimeOfDay, TimeZone) SqlValue
instance Convertible SqlValue TimeOfDay
instance Convertible TimeOfDay SqlValue
instance Convertible SqlValue Day
instance Convertible Day SqlValue
instance Convertible SqlValue Rational
instance Convertible Rational SqlValue
instance Convertible SqlValue Double
instance Convertible Double SqlValue
instance Convertible SqlValue Char
instance Convertible Char SqlValue
instance Convertible SqlValue Bool
instance Convertible Bool SqlValue
instance Convertible SqlValue Integer
instance Convertible Integer SqlValue
instance Convertible SqlValue Word64
instance Convertible Word64 SqlValue
instance Convertible SqlValue Word32
instance Convertible Word32 SqlValue
instance Convertible SqlValue Int64
instance Convertible Int64 SqlValue
instance Convertible SqlValue Int32
instance Convertible Int32 SqlValue
instance Convertible SqlValue Int
instance Convertible Int SqlValue
instance Convertible SqlValue ByteString
instance Convertible ByteString SqlValue
instance Convertible SqlValue ByteString
instance Convertible ByteString SqlValue
instance Convertible SqlValue Text
instance Convertible Text SqlValue
instance Convertible SqlValue Text
instance Convertible Text SqlValue
instance Convertible SqlValue String
instance Convertible String SqlValue
instance Convertible SqlValue SqlValue
instance Eq SqlValue


-- | Definitions of, and utilities for, specifying what type of data is
--   represented by a column.
--   
--   Written by John Goerzen, jgoerzen@complete.org
module Database.HDBC.ColTypes

-- | The description of a column.
--   
--   Fields are Nothing if the database backend cannot supply the requested
--   information.
--   
--   The colSize field works like this:
--   
--   For character types, the maximum width of the column. For numeric
--   types, the total number of digits allowed. See the ODBC manual for
--   more.
--   
--   The colOctetLength field is defined for character and binary types,
--   and gives the number of bytes the column requires, regardless of
--   encoding.
data SqlColDesc
SqlColDesc :: SqlTypeId -> Maybe Int -> Maybe Int -> Maybe Int -> Maybe Bool -> SqlColDesc

-- | Type of data stored here
colType :: SqlColDesc -> SqlTypeId

-- | The size of a column
colSize :: SqlColDesc -> Maybe Int

-- | The maximum size in octets
colOctetLength :: SqlColDesc -> Maybe Int

-- | Digits to the right of the period
colDecDigits :: SqlColDesc -> Maybe Int

-- | Whether NULL is acceptable
colNullable :: SqlColDesc -> Maybe Bool

-- | The type identifier for a given column.
--   
--   This represents the type of data stored in the column in the
--   underlying SQL engine. It does not form the entire column type; see
--   <a>SqlColDesc</a> for that.
--   
--   These types correspond mainly to those defined by ODBC.
data SqlTypeId

-- | Fixed-width character strings
SqlCharT :: SqlTypeId

-- | Variable-width character strings
SqlVarCharT :: SqlTypeId

-- | Variable-width character strings, max length implementation dependant
SqlLongVarCharT :: SqlTypeId

-- | Fixed-width Unicode strings
SqlWCharT :: SqlTypeId

-- | Variable-width Unicode strings
SqlWVarCharT :: SqlTypeId

-- | Variable-width Unicode strings, max length implementation dependant
SqlWLongVarCharT :: SqlTypeId

-- | Signed exact values
SqlDecimalT :: SqlTypeId

-- | Signed exact integer values
SqlNumericT :: SqlTypeId

-- | 16-bit integer values
SqlSmallIntT :: SqlTypeId

-- | 32-bit integer values
SqlIntegerT :: SqlTypeId
SqlRealT :: SqlTypeId

-- | Signed inexact floating-point values
SqlFloatT :: SqlTypeId

-- | Signed inexact double-precision values
SqlDoubleT :: SqlTypeId

-- | A single bit
SqlBitT :: SqlTypeId

-- | 8-bit integer values
SqlTinyIntT :: SqlTypeId

-- | 64-bit integer values
SqlBigIntT :: SqlTypeId

-- | Fixed-length binary data
SqlBinaryT :: SqlTypeId

-- | Variable-length binary data
SqlVarBinaryT :: SqlTypeId

-- | Variable-length binary data, max length implementation dependant
SqlLongVarBinaryT :: SqlTypeId

-- | A date
SqlDateT :: SqlTypeId

-- | A time, no timezone
SqlTimeT :: SqlTypeId

-- | A time, with timezone
SqlTimeWithZoneT :: SqlTypeId

-- | Combined date and time, no timezone
SqlTimestampT :: SqlTypeId

-- | Combined date and time, with timezone
SqlTimestampWithZoneT :: SqlTypeId

-- | UTC date/time
SqlUTCDateTimeT :: SqlTypeId

-- | UTC time
SqlUTCTimeT :: SqlTypeId

-- | A time or date difference
SqlIntervalT :: SqlInterval -> SqlTypeId

-- | Global unique identifier
SqlGUIDT :: SqlTypeId

-- | A type not represented here; implementation-specific information in
--   the String
SqlUnknownT :: String -> SqlTypeId

-- | The different types of intervals in SQL.
data SqlInterval

-- | Difference in months
SqlIntervalMonthT :: SqlInterval

-- | Difference in years
SqlIntervalYearT :: SqlInterval

-- | Difference in years+months
SqlIntervalYearToMonthT :: SqlInterval

-- | Difference in days
SqlIntervalDayT :: SqlInterval

-- | Difference in hours
SqlIntervalHourT :: SqlInterval

-- | Difference in minutes
SqlIntervalMinuteT :: SqlInterval

-- | Difference in seconds
SqlIntervalSecondT :: SqlInterval

-- | Difference in days+hours
SqlIntervalDayToHourT :: SqlInterval

-- | Difference in days+minutes
SqlIntervalDayToMinuteT :: SqlInterval

-- | Difference in days+seconds
SqlIntervalDayToSecondT :: SqlInterval

-- | Difference in hours+minutes
SqlIntervalHourToMinuteT :: SqlInterval

-- | Difference in hours+seconds
SqlIntervalHourToSecondT :: SqlInterval

-- | Difference in minutes+seconds
SqlIntervalMinuteToSecondT :: SqlInterval
instance Typeable SqlInterval
instance Typeable SqlTypeId
instance Typeable SqlColDesc
instance Eq SqlInterval
instance Show SqlInterval
instance Read SqlInterval
instance Eq SqlTypeId
instance Show SqlTypeId
instance Read SqlTypeId
instance Eq SqlColDesc
instance Read SqlColDesc
instance Show SqlColDesc

module Database.HDBC.Statement
data Statement
Statement :: ([SqlValue] -> IO Integer) -> IO () -> ([[SqlValue]] -> IO ()) -> IO () -> IO (Maybe [SqlValue]) -> IO [String] -> String -> IO [(String, SqlColDesc)] -> Statement

-- | Execute the prepared statement, passing in the given positional
--   parameters (that should take the place of the question marks in the
--   call to <tt>prepare</tt>).
--   
--   For non-SELECT queries, the return value is the number of rows
--   modified, if known. If no rows were modified, you get 0. If the value
--   is unknown, you get -1. All current HDBC drivers support this function
--   and should never return -1.
--   
--   For SELECT queries, you will always get 0.
--   
--   This function should automatically call finish() to finish the
--   previous execution, if necessary.
execute :: Statement -> [SqlValue] -> IO Integer

-- | Execute the statement as-is, without supplying any positional
--   parameters. This is intended for statements for which the results
--   aren't interesting or present (e.g., DDL or DML commands). If your
--   query contains placeholders, this will certainly fail; use
--   <a>execute</a> instead.
executeRaw :: Statement -> IO ()

-- | Execute the query with many rows. The return value is the return value
--   from the final row as if you had called <a>execute</a> on it.
--   
--   Due to optimizations that are possible due to different databases and
--   driver designs, this can often be significantly faster than using
--   <a>execute</a> multiple times since queries need to be compiled only
--   once.
--   
--   This is most useful for non-SELECT statements.
executeMany :: Statement -> [[SqlValue]] -> IO ()

-- | Abort a query in progress -- usually not needed.
finish :: Statement -> IO ()

-- | Fetches one row from the DB. Returns <a>Nothing</a> if there are no
--   more rows. Will automatically call <a>finish</a> when the last row is
--   read.
fetchRow :: Statement -> IO (Maybe [SqlValue])

-- | Returns a list of the column names in the result. For maximum
--   portability, you should not assume that information is available until
--   after an <a>execute</a> function has been run.
--   
--   Information is returned here directly as returned by the underlying
--   database layer. Note that different databases have different rules
--   about capitalization of return values and about representation of
--   names of columns that are not simple columns. For this reason, it is
--   suggested that you treat this information for display purposes only.
--   Failing that, you should convert to lower (or upper) case, and use
--   <tt>AS</tt> clauses for anything other than simple columns.
--   
--   A simple getColumnNames implementation could simply apply <tt>map
--   fst</tt> to the return value of <a>describeResult</a>.
getColumnNames :: Statement -> IO [String]

-- | The original query that this <a>Statement</a> was prepared with.
originalQuery :: Statement -> String

-- | Obtain information about the columns in the result set. Must be run
--   only after <a>execute</a>. The String in the result set is the column
--   name.
--   
--   You should expect this to be returned in the same manner as a result
--   from <a>fetchAllRows'</a>.
--   
--   All results should be converted to lowercase for you before you see
--   them.
--   
--   Please see caveats under <a>getColumnNames</a> for information on the
--   column name field here.
describeResult :: Statement -> IO [(String, SqlColDesc)]

-- | The main HDBC exception object. As much information as possible is
--   passed from the database through to the application through this
--   object.
--   
--   Errors generated in the Haskell layer will have seNativeError set to
--   -1.
data SqlError
SqlError :: String -> Int -> String -> SqlError
seState :: SqlError -> String
seNativeError :: SqlError -> Int
seErrorMsg :: SqlError -> String

-- | Converts any Integral type to a <a>SqlValue</a> by using toInteger.
nToSql :: Integral a => a -> SqlValue

-- | Convenience function for using numeric literals in your program.
iToSql :: Int -> SqlValue

-- | Convenience function for converting <a>POSIXTime</a> to a
--   <a>SqlValue</a>, because <a>toSql</a> cannot do the correct thing in
--   this instance.
posixToSql :: POSIXTime -> SqlValue

-- | Convert from an <a>SqlValue</a> to a Haskell value. Any problem is
--   indicated by calling <a>error</a>. This function is simply a
--   restricted-type wrapper around <a>convert</a>. See extended notes on
--   <a>SqlValue</a>.
fromSql :: Convertible SqlValue a => SqlValue -> a

-- | Conversions to and from <a>SqlValue</a>s and standard Haskell types.
--   
--   This function converts from an <a>SqlValue</a> to a Haskell value.
--   Many people will use the simpler <a>fromSql</a> instead. This function
--   is simply a restricted-type wrapper around <a>safeConvert</a>.
safeFromSql :: Convertible SqlValue a => SqlValue -> ConvertResult a

-- | Convert a value to an <a>SqlValue</a>. This function is simply a
--   restricted-type wrapper around <a>convert</a>. See extended notes on
--   <a>SqlValue</a>.
toSql :: Convertible a SqlValue => a -> SqlValue

-- | <a>SqlValue</a> is he main type for expressing Haskell values to SQL
--   databases.
--   
--   <i>INTRODUCTION TO SQLVALUE</i>
--   
--   This type is used to marshall Haskell data to and from database APIs.
--   HDBC driver interfaces will do their best to use the most accurate and
--   efficient way to send a particular value to the database server.
--   
--   Values read back from the server are constructed with the most
--   appropriate <a>SqlValue</a> constructor. <a>fromSql</a> or
--   <a>safeFromSql</a> can then be used to convert them into whatever type
--   is needed locally in Haskell.
--   
--   Most people will use <a>toSql</a> and <a>fromSql</a> instead of
--   manipulating <a>SqlValue</a>s directly.
--   
--   <i>EASY CONVERSIONS BETWEEN HASKELL TYPES</i>
--   
--   Conversions are powerful; for instance, you can call <a>fromSql</a> on
--   a SqlInt32 and get a String or a Double out of it. This class attempts
--   to Do The Right Thing whenever possible, and will raise an error when
--   asked to do something incorrect. In particular, when converting to any
--   type except a Maybe, <a>SqlNull</a> as the input will cause an error
--   to be raised.
--   
--   Conversions are implemented in terms of the <a>Data.Convertible</a>
--   module, part of the convertible package. You can refer to its
--   documentation, and import that module, if you wish to parse the Left
--   result from <a>safeFromSql</a> yourself, or write your own conversion
--   instances.
--   
--   Here are some notes about conversion:
--   
--   <ul>
--   <li>Fractions of a second are not preserved on time values</li>
--   <li>There is no <tt>safeToSql</tt> because <a>toSql</a> never
--   fails.</li>
--   </ul>
--   
--   See also <a>toSql</a>, <a>safeFromSql</a>, <a>fromSql</a>,
--   <a>nToSql</a>, <a>iToSql</a>, <a>posixToSql</a>.
--   
--   <i>ERROR CONDITIONS</i>
--   
--   There may sometimes be an error during conversion. For instance, if
--   you have a <a>SqlString</a> and are attempting to convert it to an
--   Integer, but it doesn't parse as an Integer, you will get an error.
--   This will be indicated as an exception if using <a>fromSql</a>, or a
--   Left result if using <a>safeFromSql</a>.
--   
--   <i>SPECIAL NOTE ON POSIXTIME</i>
--   
--   Note that a <a>NominalDiffTime</a> or <a>POSIXTime</a> is converted to
--   <a>SqlDiffTime</a> by <a>toSql</a>. HDBC cannot differentiate between
--   <a>NominalDiffTime</a> and <a>POSIXTime</a> since they are the same
--   underlying type. You must construct <a>SqlPOSIXTime</a> manually or
--   via <a>posixToSql</a>, or use <a>SqlUTCTime</a>.
--   
--   <i>DETAILS ON SQL TYPES</i>
--   
--   HDBC database backends are expected to marshal date and time data back
--   and forth using the appropriate representation for the underlying
--   database engine. Databases such as PostgreSQL with builtin date and
--   time types should see automatic conversion between these Haskell types
--   to database types. Other databases will be presented with an integer
--   or a string. Care should be taken to use the same type on the Haskell
--   side as you use on the database side. For instance, if your database
--   type lacks timezone information, you ought not to use ZonedTime, but
--   instead LocalTime or UTCTime. Database type systems are not always as
--   rich as Haskell. For instance, for data stored in a TIMESTAMP WITHOUT
--   TIME ZONE column, HDBC may not be able to tell if it is intended as
--   UTCTime or LocalTime data, and will happily convert it to both, upon
--   your request. It is your responsibility to ensure that you treat
--   timezone issues with due care.
--   
--   This behavior also exists for other types. For instance, many
--   databases do not have a Rational type, so they will just use the show
--   function and store a Rational as a string.
--   
--   The conversion between Haskell types and database types is complex,
--   and generic code in HDBC or its backends cannot possibly accomodate
--   every possible situation. In some cases, you may be best served by
--   converting your Haskell type to a String, and passing that to the
--   database.
--   
--   <i>UNICODE AND BYTESTRINGS</i>
--   
--   Beginning with HDBC v2.0, interactions with a database are presumed to
--   occur in UTF-8.
--   
--   To accomplish this, whenever a ByteString must be converted to or from
--   a String, the ByteString is assumed to be in UTF-8 encoding, and will
--   be decoded or encoded as appropriate. Database drivers will generally
--   present text or string data they have received from the database as a
--   SqlValue holding a ByteString, which <a>fromSql</a> will automatically
--   convert to a String, and thus automatically decode UTF-8, when you
--   need it. In the other direction, database drivers will generally
--   convert a <a>SqlString</a> to a ByteString in UTF-8 encoding before
--   passing it to the database engine.
--   
--   If you are handling some sort of binary data that is not in UTF-8, you
--   can of course work with the ByteString directly, which will bypass any
--   conversion.
--   
--   Due to lack of support by database engines, lazy ByteStrings are not
--   passed to database drivers. When you use <a>toSql</a> on a lazy
--   ByteString, it will be converted to a strict ByteString for storage.
--   Similarly, <a>fromSql</a> will convert a strict ByteString to a lazy
--   ByteString if you demand it.
--   
--   <i>EQUALITY OF SQLVALUE</i>
--   
--   Two SqlValues are considered to be equal if one of these hold. The
--   first comparison that can be made is controlling; if none of these
--   comparisons can be made, then they are not equal:
--   
--   <ul>
--   <li>Both are NULL</li>
--   <li>Both represent the same type and the encapsulated values are
--   considered equal by applying (==) to them</li>
--   <li>The values of each, when converted to a string, are equal.</li>
--   </ul>
--   
--   <i>STRING VERSIONS OF TIMES</i>
--   
--   Default string representations are given as comments below where such
--   are non-obvious. These are used for <a>fromSql</a> when a
--   <a>String</a> is desired. They are also defaults for representing data
--   to SQL backends, though individual backends may override them when a
--   different format is demanded by the underlying database. Date and time
--   formats use ISO8601 date format, with HH:MM:SS added for time, and
--   -HHMM added for timezone offsets.
--   
--   <i>DEPRECATED CONSTRUCTORS</i>
--   
--   <a>SqlEpochTime</a> and <a>SqlTimeDiff</a> are no longer created
--   automatically by any <a>toSql</a> or <a>fromSql</a> functions or
--   database backends. They may still be manually constructed, but are
--   expected to be removed in a future version. Although these two
--   constructures will be removed, support for marshalling to and from the
--   old System.Time data will be maintained as long as System.Time is,
--   simply using the newer data types for conversion.
data SqlValue
SqlString :: String -> SqlValue
SqlByteString :: ByteString -> SqlValue
SqlWord32 :: Word32 -> SqlValue
SqlWord64 :: Word64 -> SqlValue
SqlInt32 :: Int32 -> SqlValue
SqlInt64 :: Int64 -> SqlValue
SqlInteger :: Integer -> SqlValue
SqlChar :: Char -> SqlValue
SqlBool :: Bool -> SqlValue
SqlDouble :: Double -> SqlValue
SqlRational :: Rational -> SqlValue

-- | Local YYYY-MM-DD (no timezone)
SqlLocalDate :: Day -> SqlValue

-- | Local HH:MM:SS (no timezone)
SqlLocalTimeOfDay :: TimeOfDay -> SqlValue

-- | Local HH:MM:SS -HHMM. Converts to and from (TimeOfDay, TimeZone).
SqlZonedLocalTimeOfDay :: TimeOfDay -> TimeZone -> SqlValue

-- | Local YYYY-MM-DD HH:MM:SS (no timezone)
SqlLocalTime :: LocalTime -> SqlValue

-- | Local YYYY-MM-DD HH:MM:SS -HHMM. Considered equal if both convert to
--   the same UTC time.
SqlZonedTime :: ZonedTime -> SqlValue

-- | UTC YYYY-MM-DD HH:MM:SS
SqlUTCTime :: UTCTime -> SqlValue

-- | Calendar diff between seconds. Rendered as Integer when converted to
--   String, but greater precision may be preserved for other types or to
--   underlying database.
SqlDiffTime :: NominalDiffTime -> SqlValue

-- | Time as seconds since midnight Jan 1 1970 UTC. Integer rendering as
--   for <a>SqlDiffTime</a>.
SqlPOSIXTime :: POSIXTime -> SqlValue

-- | DEPRECATED Representation of ClockTime or CalendarTime. Use
--   SqlPOSIXTime instead.
SqlEpochTime :: Integer -> SqlValue

-- | DEPRECATED Representation of TimeDiff. Use SqlDiffTime instead.
SqlTimeDiff :: Integer -> SqlValue

-- | NULL in SQL or Nothing in Haskell
SqlNull :: SqlValue
instance Typeable SqlError
instance Eq SqlError
instance Show SqlError
instance Read SqlError
instance Exception SqlError


-- | Types for HDBC.
--   
--   Please note: this module is intended for authors of database driver
--   libraries only. Authors of applications using HDBC should use
--   <a>HDBC</a> exclusively.
--   
--   Written by John Goerzen, jgoerzen@complete.org
module Database.HDBC.Types

-- | Main database handle object.
--   
--   An <a>IConnection</a> object is created by specific functions in the
--   module for an individual database. That is, the connect function --
--   which creates this object -- is not standardized through the HDBC
--   interface.
--   
--   A connection is closed by a call to <a>disconnect</a>.
--   
--   A call to <a>commit</a> is required to make sure that your changes get
--   committed to the database. In other words, HDBC has <i>no support for
--   autocommit</i>, which we consider an outdated notion.
class IConnection conn where runRaw conn sql = do { sth <- prepare conn sql; _ <- execute sth [] `finally` finish sth; return () }
disconnect :: IConnection conn => conn -> IO ()
commit :: IConnection conn => conn -> IO ()
rollback :: IConnection conn => conn -> IO ()
runRaw :: IConnection conn => conn -> String -> IO ()
run :: IConnection conn => conn -> String -> [SqlValue] -> IO Integer
prepare :: IConnection conn => conn -> String -> IO Statement
clone :: IConnection conn => conn -> IO conn
hdbcDriverName :: IConnection conn => conn -> String
hdbcClientVer :: IConnection conn => conn -> String
proxiedClientName :: IConnection conn => conn -> String
proxiedClientVer :: IConnection conn => conn -> String
dbServerVer :: IConnection conn => conn -> String
dbTransactionSupport :: IConnection conn => conn -> Bool
getTables :: IConnection conn => conn -> IO [String]
describeTable :: IConnection conn => conn -> String -> IO [(String, SqlColDesc)]
data Statement
Statement :: ([SqlValue] -> IO Integer) -> IO () -> ([[SqlValue]] -> IO ()) -> IO () -> IO (Maybe [SqlValue]) -> IO [String] -> String -> IO [(String, SqlColDesc)] -> Statement

-- | Execute the prepared statement, passing in the given positional
--   parameters (that should take the place of the question marks in the
--   call to <tt>prepare</tt>).
--   
--   For non-SELECT queries, the return value is the number of rows
--   modified, if known. If no rows were modified, you get 0. If the value
--   is unknown, you get -1. All current HDBC drivers support this function
--   and should never return -1.
--   
--   For SELECT queries, you will always get 0.
--   
--   This function should automatically call finish() to finish the
--   previous execution, if necessary.
execute :: Statement -> [SqlValue] -> IO Integer

-- | Execute the statement as-is, without supplying any positional
--   parameters. This is intended for statements for which the results
--   aren't interesting or present (e.g., DDL or DML commands). If your
--   query contains placeholders, this will certainly fail; use
--   <a>execute</a> instead.
executeRaw :: Statement -> IO ()

-- | Execute the query with many rows. The return value is the return value
--   from the final row as if you had called <a>execute</a> on it.
--   
--   Due to optimizations that are possible due to different databases and
--   driver designs, this can often be significantly faster than using
--   <a>execute</a> multiple times since queries need to be compiled only
--   once.
--   
--   This is most useful for non-SELECT statements.
executeMany :: Statement -> [[SqlValue]] -> IO ()

-- | Abort a query in progress -- usually not needed.
finish :: Statement -> IO ()

-- | Fetches one row from the DB. Returns <a>Nothing</a> if there are no
--   more rows. Will automatically call <a>finish</a> when the last row is
--   read.
fetchRow :: Statement -> IO (Maybe [SqlValue])

-- | Returns a list of the column names in the result. For maximum
--   portability, you should not assume that information is available until
--   after an <a>execute</a> function has been run.
--   
--   Information is returned here directly as returned by the underlying
--   database layer. Note that different databases have different rules
--   about capitalization of return values and about representation of
--   names of columns that are not simple columns. For this reason, it is
--   suggested that you treat this information for display purposes only.
--   Failing that, you should convert to lower (or upper) case, and use
--   <tt>AS</tt> clauses for anything other than simple columns.
--   
--   A simple getColumnNames implementation could simply apply <tt>map
--   fst</tt> to the return value of <a>describeResult</a>.
getColumnNames :: Statement -> IO [String]

-- | The original query that this <a>Statement</a> was prepared with.
originalQuery :: Statement -> String

-- | Obtain information about the columns in the result set. Must be run
--   only after <a>execute</a>. The String in the result set is the column
--   name.
--   
--   You should expect this to be returned in the same manner as a result
--   from <a>fetchAllRows'</a>.
--   
--   All results should be converted to lowercase for you before you see
--   them.
--   
--   Please see caveats under <a>getColumnNames</a> for information on the
--   column name field here.
describeResult :: Statement -> IO [(String, SqlColDesc)]

-- | The main HDBC exception object. As much information as possible is
--   passed from the database through to the application through this
--   object.
--   
--   Errors generated in the Haskell layer will have seNativeError set to
--   -1.
data SqlError
SqlError :: String -> Int -> String -> SqlError
seState :: SqlError -> String
seNativeError :: SqlError -> Int
seErrorMsg :: SqlError -> String

-- | Converts any Integral type to a <a>SqlValue</a> by using toInteger.
nToSql :: Integral a => a -> SqlValue

-- | Convenience function for using numeric literals in your program.
iToSql :: Int -> SqlValue

-- | Convenience function for converting <a>POSIXTime</a> to a
--   <a>SqlValue</a>, because <a>toSql</a> cannot do the correct thing in
--   this instance.
posixToSql :: POSIXTime -> SqlValue

-- | Convert from an <a>SqlValue</a> to a Haskell value. Any problem is
--   indicated by calling <a>error</a>. This function is simply a
--   restricted-type wrapper around <a>convert</a>. See extended notes on
--   <a>SqlValue</a>.
fromSql :: Convertible SqlValue a => SqlValue -> a

-- | Conversions to and from <a>SqlValue</a>s and standard Haskell types.
--   
--   This function converts from an <a>SqlValue</a> to a Haskell value.
--   Many people will use the simpler <a>fromSql</a> instead. This function
--   is simply a restricted-type wrapper around <a>safeConvert</a>.
safeFromSql :: Convertible SqlValue a => SqlValue -> ConvertResult a

-- | Convert a value to an <a>SqlValue</a>. This function is simply a
--   restricted-type wrapper around <a>convert</a>. See extended notes on
--   <a>SqlValue</a>.
toSql :: Convertible a SqlValue => a -> SqlValue

-- | <a>SqlValue</a> is he main type for expressing Haskell values to SQL
--   databases.
--   
--   <i>INTRODUCTION TO SQLVALUE</i>
--   
--   This type is used to marshall Haskell data to and from database APIs.
--   HDBC driver interfaces will do their best to use the most accurate and
--   efficient way to send a particular value to the database server.
--   
--   Values read back from the server are constructed with the most
--   appropriate <a>SqlValue</a> constructor. <a>fromSql</a> or
--   <a>safeFromSql</a> can then be used to convert them into whatever type
--   is needed locally in Haskell.
--   
--   Most people will use <a>toSql</a> and <a>fromSql</a> instead of
--   manipulating <a>SqlValue</a>s directly.
--   
--   <i>EASY CONVERSIONS BETWEEN HASKELL TYPES</i>
--   
--   Conversions are powerful; for instance, you can call <a>fromSql</a> on
--   a SqlInt32 and get a String or a Double out of it. This class attempts
--   to Do The Right Thing whenever possible, and will raise an error when
--   asked to do something incorrect. In particular, when converting to any
--   type except a Maybe, <a>SqlNull</a> as the input will cause an error
--   to be raised.
--   
--   Conversions are implemented in terms of the <a>Data.Convertible</a>
--   module, part of the convertible package. You can refer to its
--   documentation, and import that module, if you wish to parse the Left
--   result from <a>safeFromSql</a> yourself, or write your own conversion
--   instances.
--   
--   Here are some notes about conversion:
--   
--   <ul>
--   <li>Fractions of a second are not preserved on time values</li>
--   <li>There is no <tt>safeToSql</tt> because <a>toSql</a> never
--   fails.</li>
--   </ul>
--   
--   See also <a>toSql</a>, <a>safeFromSql</a>, <a>fromSql</a>,
--   <a>nToSql</a>, <a>iToSql</a>, <a>posixToSql</a>.
--   
--   <i>ERROR CONDITIONS</i>
--   
--   There may sometimes be an error during conversion. For instance, if
--   you have a <a>SqlString</a> and are attempting to convert it to an
--   Integer, but it doesn't parse as an Integer, you will get an error.
--   This will be indicated as an exception if using <a>fromSql</a>, or a
--   Left result if using <a>safeFromSql</a>.
--   
--   <i>SPECIAL NOTE ON POSIXTIME</i>
--   
--   Note that a <a>NominalDiffTime</a> or <a>POSIXTime</a> is converted to
--   <a>SqlDiffTime</a> by <a>toSql</a>. HDBC cannot differentiate between
--   <a>NominalDiffTime</a> and <a>POSIXTime</a> since they are the same
--   underlying type. You must construct <a>SqlPOSIXTime</a> manually or
--   via <a>posixToSql</a>, or use <a>SqlUTCTime</a>.
--   
--   <i>DETAILS ON SQL TYPES</i>
--   
--   HDBC database backends are expected to marshal date and time data back
--   and forth using the appropriate representation for the underlying
--   database engine. Databases such as PostgreSQL with builtin date and
--   time types should see automatic conversion between these Haskell types
--   to database types. Other databases will be presented with an integer
--   or a string. Care should be taken to use the same type on the Haskell
--   side as you use on the database side. For instance, if your database
--   type lacks timezone information, you ought not to use ZonedTime, but
--   instead LocalTime or UTCTime. Database type systems are not always as
--   rich as Haskell. For instance, for data stored in a TIMESTAMP WITHOUT
--   TIME ZONE column, HDBC may not be able to tell if it is intended as
--   UTCTime or LocalTime data, and will happily convert it to both, upon
--   your request. It is your responsibility to ensure that you treat
--   timezone issues with due care.
--   
--   This behavior also exists for other types. For instance, many
--   databases do not have a Rational type, so they will just use the show
--   function and store a Rational as a string.
--   
--   The conversion between Haskell types and database types is complex,
--   and generic code in HDBC or its backends cannot possibly accomodate
--   every possible situation. In some cases, you may be best served by
--   converting your Haskell type to a String, and passing that to the
--   database.
--   
--   <i>UNICODE AND BYTESTRINGS</i>
--   
--   Beginning with HDBC v2.0, interactions with a database are presumed to
--   occur in UTF-8.
--   
--   To accomplish this, whenever a ByteString must be converted to or from
--   a String, the ByteString is assumed to be in UTF-8 encoding, and will
--   be decoded or encoded as appropriate. Database drivers will generally
--   present text or string data they have received from the database as a
--   SqlValue holding a ByteString, which <a>fromSql</a> will automatically
--   convert to a String, and thus automatically decode UTF-8, when you
--   need it. In the other direction, database drivers will generally
--   convert a <a>SqlString</a> to a ByteString in UTF-8 encoding before
--   passing it to the database engine.
--   
--   If you are handling some sort of binary data that is not in UTF-8, you
--   can of course work with the ByteString directly, which will bypass any
--   conversion.
--   
--   Due to lack of support by database engines, lazy ByteStrings are not
--   passed to database drivers. When you use <a>toSql</a> on a lazy
--   ByteString, it will be converted to a strict ByteString for storage.
--   Similarly, <a>fromSql</a> will convert a strict ByteString to a lazy
--   ByteString if you demand it.
--   
--   <i>EQUALITY OF SQLVALUE</i>
--   
--   Two SqlValues are considered to be equal if one of these hold. The
--   first comparison that can be made is controlling; if none of these
--   comparisons can be made, then they are not equal:
--   
--   <ul>
--   <li>Both are NULL</li>
--   <li>Both represent the same type and the encapsulated values are
--   considered equal by applying (==) to them</li>
--   <li>The values of each, when converted to a string, are equal.</li>
--   </ul>
--   
--   <i>STRING VERSIONS OF TIMES</i>
--   
--   Default string representations are given as comments below where such
--   are non-obvious. These are used for <a>fromSql</a> when a
--   <a>String</a> is desired. They are also defaults for representing data
--   to SQL backends, though individual backends may override them when a
--   different format is demanded by the underlying database. Date and time
--   formats use ISO8601 date format, with HH:MM:SS added for time, and
--   -HHMM added for timezone offsets.
--   
--   <i>DEPRECATED CONSTRUCTORS</i>
--   
--   <a>SqlEpochTime</a> and <a>SqlTimeDiff</a> are no longer created
--   automatically by any <a>toSql</a> or <a>fromSql</a> functions or
--   database backends. They may still be manually constructed, but are
--   expected to be removed in a future version. Although these two
--   constructures will be removed, support for marshalling to and from the
--   old System.Time data will be maintained as long as System.Time is,
--   simply using the newer data types for conversion.
data SqlValue
SqlString :: String -> SqlValue
SqlByteString :: ByteString -> SqlValue
SqlWord32 :: Word32 -> SqlValue
SqlWord64 :: Word64 -> SqlValue
SqlInt32 :: Int32 -> SqlValue
SqlInt64 :: Int64 -> SqlValue
SqlInteger :: Integer -> SqlValue
SqlChar :: Char -> SqlValue
SqlBool :: Bool -> SqlValue
SqlDouble :: Double -> SqlValue
SqlRational :: Rational -> SqlValue

-- | Local YYYY-MM-DD (no timezone)
SqlLocalDate :: Day -> SqlValue

-- | Local HH:MM:SS (no timezone)
SqlLocalTimeOfDay :: TimeOfDay -> SqlValue

-- | Local HH:MM:SS -HHMM. Converts to and from (TimeOfDay, TimeZone).
SqlZonedLocalTimeOfDay :: TimeOfDay -> TimeZone -> SqlValue

-- | Local YYYY-MM-DD HH:MM:SS (no timezone)
SqlLocalTime :: LocalTime -> SqlValue

-- | Local YYYY-MM-DD HH:MM:SS -HHMM. Considered equal if both convert to
--   the same UTC time.
SqlZonedTime :: ZonedTime -> SqlValue

-- | UTC YYYY-MM-DD HH:MM:SS
SqlUTCTime :: UTCTime -> SqlValue

-- | Calendar diff between seconds. Rendered as Integer when converted to
--   String, but greater precision may be preserved for other types or to
--   underlying database.
SqlDiffTime :: NominalDiffTime -> SqlValue

-- | Time as seconds since midnight Jan 1 1970 UTC. Integer rendering as
--   for <a>SqlDiffTime</a>.
SqlPOSIXTime :: POSIXTime -> SqlValue

-- | DEPRECATED Representation of ClockTime or CalendarTime. Use
--   SqlPOSIXTime instead.
SqlEpochTime :: Integer -> SqlValue

-- | DEPRECATED Representation of TimeDiff. Use SqlDiffTime instead.
SqlTimeDiff :: Integer -> SqlValue

-- | NULL in SQL or Nothing in Haskell
SqlNull :: SqlValue

-- | Sometimes, it is annoying to use typeclasses with Haskell's type
--   system. In those situations, you can use a ConnWrapper. You can create
--   one with:
--   
--   <pre>
--   let wrapped = ConnWrapper iconn
--   </pre>
--   
--   You can then use this directly, since a ConnWrapper is also an
--   <a>IConnection</a>. However, you will not be able to use private
--   database functions on it.
--   
--   Or, you can use <a>withWConn</a>.
data ConnWrapper
ConnWrapper :: conn -> ConnWrapper

-- | Unwrap a <a>ConnWrapper</a> and pass the embedded <a>IConnection</a>
--   to a function. Example:
--   
--   <pre>
--   withWConn wrapped run $ "SELECT * from foo where bar = 1" []
--   </pre>
withWConn :: ConnWrapper -> (forall conn. IConnection conn => conn -> b) -> b
instance IConnection ConnWrapper


-- | Utilities for database backend drivers.
--   
--   Please note: this module is intended for authors of database driver
--   libraries only. Authors of applications using HDBC should use
--   <a>HDBC</a> exclusively.
--   
--   Written by John Goerzen, jgoerzen@complete.org
module Database.HDBC.DriverUtils
type ChildList = MVar [Weak Statement]

-- | Close all children. Intended to be called by the <a>disconnect</a>
--   function in <tt>Connection</tt>.
--   
--   There may be a potential race condition wherein a call to newSth at
--   the same time as a call to this function may result in the new child
--   not being closed.
closeAllChildren :: ChildList -> IO ()

-- | Adds a new child to the existing list. Also takes care of registering
--   a finalizer for it, to remove it from the list when possible.
addChild :: ChildList -> Statement -> IO ()


-- | Welcome to HDBC, the Haskell Database Connectivity library.
--   
--   Written by John Goerzen, jgoerzen@complete.org
module Database.HDBC

-- | <a>SqlValue</a> is he main type for expressing Haskell values to SQL
--   databases.
--   
--   <i>INTRODUCTION TO SQLVALUE</i>
--   
--   This type is used to marshall Haskell data to and from database APIs.
--   HDBC driver interfaces will do their best to use the most accurate and
--   efficient way to send a particular value to the database server.
--   
--   Values read back from the server are constructed with the most
--   appropriate <a>SqlValue</a> constructor. <a>fromSql</a> or
--   <a>safeFromSql</a> can then be used to convert them into whatever type
--   is needed locally in Haskell.
--   
--   Most people will use <a>toSql</a> and <a>fromSql</a> instead of
--   manipulating <a>SqlValue</a>s directly.
--   
--   <i>EASY CONVERSIONS BETWEEN HASKELL TYPES</i>
--   
--   Conversions are powerful; for instance, you can call <a>fromSql</a> on
--   a SqlInt32 and get a String or a Double out of it. This class attempts
--   to Do The Right Thing whenever possible, and will raise an error when
--   asked to do something incorrect. In particular, when converting to any
--   type except a Maybe, <a>SqlNull</a> as the input will cause an error
--   to be raised.
--   
--   Conversions are implemented in terms of the <a>Data.Convertible</a>
--   module, part of the convertible package. You can refer to its
--   documentation, and import that module, if you wish to parse the Left
--   result from <a>safeFromSql</a> yourself, or write your own conversion
--   instances.
--   
--   Here are some notes about conversion:
--   
--   <ul>
--   <li>Fractions of a second are not preserved on time values</li>
--   <li>There is no <tt>safeToSql</tt> because <a>toSql</a> never
--   fails.</li>
--   </ul>
--   
--   See also <a>toSql</a>, <a>safeFromSql</a>, <a>fromSql</a>,
--   <a>nToSql</a>, <a>iToSql</a>, <a>posixToSql</a>.
--   
--   <i>ERROR CONDITIONS</i>
--   
--   There may sometimes be an error during conversion. For instance, if
--   you have a <a>SqlString</a> and are attempting to convert it to an
--   Integer, but it doesn't parse as an Integer, you will get an error.
--   This will be indicated as an exception if using <a>fromSql</a>, or a
--   Left result if using <a>safeFromSql</a>.
--   
--   <i>SPECIAL NOTE ON POSIXTIME</i>
--   
--   Note that a <a>NominalDiffTime</a> or <a>POSIXTime</a> is converted to
--   <a>SqlDiffTime</a> by <a>toSql</a>. HDBC cannot differentiate between
--   <a>NominalDiffTime</a> and <a>POSIXTime</a> since they are the same
--   underlying type. You must construct <a>SqlPOSIXTime</a> manually or
--   via <a>posixToSql</a>, or use <a>SqlUTCTime</a>.
--   
--   <i>DETAILS ON SQL TYPES</i>
--   
--   HDBC database backends are expected to marshal date and time data back
--   and forth using the appropriate representation for the underlying
--   database engine. Databases such as PostgreSQL with builtin date and
--   time types should see automatic conversion between these Haskell types
--   to database types. Other databases will be presented with an integer
--   or a string. Care should be taken to use the same type on the Haskell
--   side as you use on the database side. For instance, if your database
--   type lacks timezone information, you ought not to use ZonedTime, but
--   instead LocalTime or UTCTime. Database type systems are not always as
--   rich as Haskell. For instance, for data stored in a TIMESTAMP WITHOUT
--   TIME ZONE column, HDBC may not be able to tell if it is intended as
--   UTCTime or LocalTime data, and will happily convert it to both, upon
--   your request. It is your responsibility to ensure that you treat
--   timezone issues with due care.
--   
--   This behavior also exists for other types. For instance, many
--   databases do not have a Rational type, so they will just use the show
--   function and store a Rational as a string.
--   
--   The conversion between Haskell types and database types is complex,
--   and generic code in HDBC or its backends cannot possibly accomodate
--   every possible situation. In some cases, you may be best served by
--   converting your Haskell type to a String, and passing that to the
--   database.
--   
--   <i>UNICODE AND BYTESTRINGS</i>
--   
--   Beginning with HDBC v2.0, interactions with a database are presumed to
--   occur in UTF-8.
--   
--   To accomplish this, whenever a ByteString must be converted to or from
--   a String, the ByteString is assumed to be in UTF-8 encoding, and will
--   be decoded or encoded as appropriate. Database drivers will generally
--   present text or string data they have received from the database as a
--   SqlValue holding a ByteString, which <a>fromSql</a> will automatically
--   convert to a String, and thus automatically decode UTF-8, when you
--   need it. In the other direction, database drivers will generally
--   convert a <a>SqlString</a> to a ByteString in UTF-8 encoding before
--   passing it to the database engine.
--   
--   If you are handling some sort of binary data that is not in UTF-8, you
--   can of course work with the ByteString directly, which will bypass any
--   conversion.
--   
--   Due to lack of support by database engines, lazy ByteStrings are not
--   passed to database drivers. When you use <a>toSql</a> on a lazy
--   ByteString, it will be converted to a strict ByteString for storage.
--   Similarly, <a>fromSql</a> will convert a strict ByteString to a lazy
--   ByteString if you demand it.
--   
--   <i>EQUALITY OF SQLVALUE</i>
--   
--   Two SqlValues are considered to be equal if one of these hold. The
--   first comparison that can be made is controlling; if none of these
--   comparisons can be made, then they are not equal:
--   
--   <ul>
--   <li>Both are NULL</li>
--   <li>Both represent the same type and the encapsulated values are
--   considered equal by applying (==) to them</li>
--   <li>The values of each, when converted to a string, are equal.</li>
--   </ul>
--   
--   <i>STRING VERSIONS OF TIMES</i>
--   
--   Default string representations are given as comments below where such
--   are non-obvious. These are used for <a>fromSql</a> when a
--   <a>String</a> is desired. They are also defaults for representing data
--   to SQL backends, though individual backends may override them when a
--   different format is demanded by the underlying database. Date and time
--   formats use ISO8601 date format, with HH:MM:SS added for time, and
--   -HHMM added for timezone offsets.
--   
--   <i>DEPRECATED CONSTRUCTORS</i>
--   
--   <a>SqlEpochTime</a> and <a>SqlTimeDiff</a> are no longer created
--   automatically by any <a>toSql</a> or <a>fromSql</a> functions or
--   database backends. They may still be manually constructed, but are
--   expected to be removed in a future version. Although these two
--   constructures will be removed, support for marshalling to and from the
--   old System.Time data will be maintained as long as System.Time is,
--   simply using the newer data types for conversion.
data SqlValue
SqlString :: String -> SqlValue
SqlByteString :: ByteString -> SqlValue
SqlWord32 :: Word32 -> SqlValue
SqlWord64 :: Word64 -> SqlValue
SqlInt32 :: Int32 -> SqlValue
SqlInt64 :: Int64 -> SqlValue
SqlInteger :: Integer -> SqlValue
SqlChar :: Char -> SqlValue
SqlBool :: Bool -> SqlValue
SqlDouble :: Double -> SqlValue
SqlRational :: Rational -> SqlValue

-- | Local YYYY-MM-DD (no timezone)
SqlLocalDate :: Day -> SqlValue

-- | Local HH:MM:SS (no timezone)
SqlLocalTimeOfDay :: TimeOfDay -> SqlValue

-- | Local HH:MM:SS -HHMM. Converts to and from (TimeOfDay, TimeZone).
SqlZonedLocalTimeOfDay :: TimeOfDay -> TimeZone -> SqlValue

-- | Local YYYY-MM-DD HH:MM:SS (no timezone)
SqlLocalTime :: LocalTime -> SqlValue

-- | Local YYYY-MM-DD HH:MM:SS -HHMM. Considered equal if both convert to
--   the same UTC time.
SqlZonedTime :: ZonedTime -> SqlValue

-- | UTC YYYY-MM-DD HH:MM:SS
SqlUTCTime :: UTCTime -> SqlValue

-- | Calendar diff between seconds. Rendered as Integer when converted to
--   String, but greater precision may be preserved for other types or to
--   underlying database.
SqlDiffTime :: NominalDiffTime -> SqlValue

-- | Time as seconds since midnight Jan 1 1970 UTC. Integer rendering as
--   for <a>SqlDiffTime</a>.
SqlPOSIXTime :: POSIXTime -> SqlValue

-- | DEPRECATED Representation of ClockTime or CalendarTime. Use
--   SqlPOSIXTime instead.
SqlEpochTime :: Integer -> SqlValue

-- | DEPRECATED Representation of TimeDiff. Use SqlDiffTime instead.
SqlTimeDiff :: Integer -> SqlValue

-- | NULL in SQL or Nothing in Haskell
SqlNull :: SqlValue

-- | Convert a value to an <a>SqlValue</a>. This function is simply a
--   restricted-type wrapper around <a>convert</a>. See extended notes on
--   <a>SqlValue</a>.
toSql :: Convertible a SqlValue => a -> SqlValue

-- | Convert from an <a>SqlValue</a> to a Haskell value. Any problem is
--   indicated by calling <a>error</a>. This function is simply a
--   restricted-type wrapper around <a>convert</a>. See extended notes on
--   <a>SqlValue</a>.
fromSql :: Convertible SqlValue a => SqlValue -> a

-- | Conversions to and from <a>SqlValue</a>s and standard Haskell types.
--   
--   This function converts from an <a>SqlValue</a> to a Haskell value.
--   Many people will use the simpler <a>fromSql</a> instead. This function
--   is simply a restricted-type wrapper around <a>safeConvert</a>.
safeFromSql :: Convertible SqlValue a => SqlValue -> ConvertResult a

-- | Converts any Integral type to a <a>SqlValue</a> by using toInteger.
nToSql :: Integral a => a -> SqlValue

-- | Convenience function for using numeric literals in your program.
iToSql :: Int -> SqlValue

-- | Convenience function for converting <a>POSIXTime</a> to a
--   <a>SqlValue</a>, because <a>toSql</a> cannot do the correct thing in
--   this instance.
posixToSql :: POSIXTime -> SqlValue

-- | Main database handle object.
--   
--   An <a>IConnection</a> object is created by specific functions in the
--   module for an individual database. That is, the connect function --
--   which creates this object -- is not standardized through the HDBC
--   interface.
--   
--   A connection is closed by a call to <a>disconnect</a>.
--   
--   A call to <a>commit</a> is required to make sure that your changes get
--   committed to the database. In other words, HDBC has <i>no support for
--   autocommit</i>, which we consider an outdated notion.
class IConnection conn where runRaw conn sql = do { sth <- prepare conn sql; _ <- execute sth [] `finally` finish sth; return () }
disconnect :: IConnection conn => conn -> IO ()
commit :: IConnection conn => conn -> IO ()
rollback :: IConnection conn => conn -> IO ()
runRaw :: IConnection conn => conn -> String -> IO ()
run :: IConnection conn => conn -> String -> [SqlValue] -> IO Integer
prepare :: IConnection conn => conn -> String -> IO Statement
clone :: IConnection conn => conn -> IO conn
hdbcDriverName :: IConnection conn => conn -> String
hdbcClientVer :: IConnection conn => conn -> String
proxiedClientName :: IConnection conn => conn -> String
proxiedClientVer :: IConnection conn => conn -> String
dbServerVer :: IConnection conn => conn -> String
dbTransactionSupport :: IConnection conn => conn -> Bool
getTables :: IConnection conn => conn -> IO [String]
describeTable :: IConnection conn => conn -> String -> IO [(String, SqlColDesc)]

-- | Sometimes, it is annoying to use typeclasses with Haskell's type
--   system. In those situations, you can use a ConnWrapper. You can create
--   one with:
--   
--   <pre>
--   let wrapped = ConnWrapper iconn
--   </pre>
--   
--   You can then use this directly, since a ConnWrapper is also an
--   <a>IConnection</a>. However, you will not be able to use private
--   database functions on it.
--   
--   Or, you can use <a>withWConn</a>.
data ConnWrapper
ConnWrapper :: conn -> ConnWrapper

-- | Unwrap a <a>ConnWrapper</a> and pass the embedded <a>IConnection</a>
--   to a function. Example:
--   
--   <pre>
--   withWConn wrapped run $ "SELECT * from foo where bar = 1" []
--   </pre>
withWConn :: ConnWrapper -> (forall conn. IConnection conn => conn -> b) -> b

-- | Like <a>run</a>, but take a list of Maybe Strings instead of
--   <a>SqlValue</a>s.
sRun :: IConnection conn => conn -> String -> [Maybe String] -> IO Integer

-- | Strict version of <a>quickQuery</a>.
quickQuery' :: IConnection conn => conn -> String -> [SqlValue] -> IO [[SqlValue]]

-- | A quick way to do a query. Similar to preparing, executing, and then
--   calling <a>fetchAllRows</a> on a statement. See also
--   <a>quickQuery'</a>
quickQuery :: IConnection conn => conn -> String -> [SqlValue] -> IO [[SqlValue]]

-- | Execute some code. If any uncaught exception occurs, run
--   <a>rollback</a> and re-raise it. Otherwise, run <a>commit</a> and
--   return.
--   
--   This function, therefore, encapsulates the logical property that a
--   transaction is all about: all or nothing.
--   
--   The <a>IConnection</a> object passed in is passed directly to the
--   specified function as a convenience.
--   
--   This function traps <i>all</i> uncaught exceptions, not just
--   SqlErrors. Therefore, you will get a rollback for any exception that
--   you don't handle. That's probably what you want anyway.
--   
--   Since all operations in HDBC are done in a transaction, this function
--   doesn't issue an explicit "begin" to the server. You should ideally
--   have called <a>commit</a> or <a>rollback</a> before calling this
--   function. If you haven't, this function will commit or rollback more
--   than just the changes made in the included action.
--   
--   If there was an error while running <a>rollback</a>, this error will
--   not be reported since the original exception will be propogated back.
--   (You'd probably like to know about the root cause for all of this
--   anyway.) Feedback on this behavior is solicited.
withTransaction :: IConnection conn => conn -> (conn -> IO a) -> IO a
data Statement

-- | Execute the prepared statement, passing in the given positional
--   parameters (that should take the place of the question marks in the
--   call to <tt>prepare</tt>).
--   
--   For non-SELECT queries, the return value is the number of rows
--   modified, if known. If no rows were modified, you get 0. If the value
--   is unknown, you get -1. All current HDBC drivers support this function
--   and should never return -1.
--   
--   For SELECT queries, you will always get 0.
--   
--   This function should automatically call finish() to finish the
--   previous execution, if necessary.
execute :: Statement -> [SqlValue] -> IO Integer

-- | Execute the statement as-is, without supplying any positional
--   parameters. This is intended for statements for which the results
--   aren't interesting or present (e.g., DDL or DML commands). If your
--   query contains placeholders, this will certainly fail; use
--   <a>execute</a> instead.
executeRaw :: Statement -> IO ()

-- | Like <a>execute</a>, but take a list of Maybe Strings instead of
--   <a>SqlValue</a>s.
sExecute :: Statement -> [Maybe String] -> IO Integer

-- | Execute the query with many rows. The return value is the return value
--   from the final row as if you had called <a>execute</a> on it.
--   
--   Due to optimizations that are possible due to different databases and
--   driver designs, this can often be significantly faster than using
--   <a>execute</a> multiple times since queries need to be compiled only
--   once.
--   
--   This is most useful for non-SELECT statements.
executeMany :: Statement -> [[SqlValue]] -> IO ()

-- | Like <a>executeMany</a>, but take a list of Maybe Strings instead of
--   <a>SqlValue</a>s.
sExecuteMany :: Statement -> [[Maybe String]] -> IO ()

-- | Fetches one row from the DB. Returns <a>Nothing</a> if there are no
--   more rows. Will automatically call <a>finish</a> when the last row is
--   read.
fetchRow :: Statement -> IO (Maybe [SqlValue])

-- | Like <a>fetchRow</a>, but instead of returning a list, return an
--   association list from column name to value.
--   
--   The keys of the column names are lowercase versions of the data
--   returned by <a>getColumnNames</a>. Please heed the warnings there.
--   Additionally, results are undefined if multiple columns are returned
--   with identical names.
fetchRowAL :: Statement -> IO (Maybe [(String, SqlValue)])

-- | Similar to <a>fetchRowAL</a>, but return a Map instead of an
--   association list.
fetchRowMap :: Statement -> IO (Maybe (Map String SqlValue))

-- | Like <a>fetchRow</a>, but return a list of Maybe Strings instead of
--   <a>SqlValue</a>s.
sFetchRow :: Statement -> IO (Maybe [Maybe String])

-- | Lazily fetch all rows from an executed <a>Statement</a>.
--   
--   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 <a>Statement</a> will be
--   <a>finish</a>ed.
--   
--   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 <a>finish</a> 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 <a>fetchAllRows'</a> if you need something that is strict, without
--   all these caveats.
fetchAllRows :: Statement -> IO [[SqlValue]]

-- | Strict version of <a>fetchAllRows</a>. Does not have the side-effects
--   of <a>fetchAllRows</a>, but forces the entire result set to be
--   buffered in memory.
fetchAllRows' :: Statement -> IO [[SqlValue]]

-- | Like <a>fetchAllRows</a>, but instead of returning a list for each
--   row, return an association list for each row, from column name to
--   value.
--   
--   See <a>fetchRowAL</a> for more details.
fetchAllRowsAL :: Statement -> IO [[(String, SqlValue)]]

-- | Strict version of <a>fetchAllRowsAL</a>
fetchAllRowsAL' :: Statement -> IO [[(String, SqlValue)]]

-- | Like <a>fetchAllRowsAL</a>, but return a list of Maps instead of a
--   list of association lists.
fetchAllRowsMap :: Statement -> IO [Map String SqlValue]

-- | Strict version of <a>fetchAllRowsMap</a>
fetchAllRowsMap' :: Statement -> IO [Map String SqlValue]

-- | Like <a>fetchAllRows</a>, but return Maybe Strings instead of
--   <a>SqlValue</a>s.
sFetchAllRows :: Statement -> IO [[Maybe String]]

-- | Strict version of <a>sFetchAllRows</a>.
sFetchAllRows' :: Statement -> IO [[Maybe String]]

-- | Returns a list of the column names in the result. For maximum
--   portability, you should not assume that information is available until
--   after an <a>execute</a> function has been run.
--   
--   Information is returned here directly as returned by the underlying
--   database layer. Note that different databases have different rules
--   about capitalization of return values and about representation of
--   names of columns that are not simple columns. For this reason, it is
--   suggested that you treat this information for display purposes only.
--   Failing that, you should convert to lower (or upper) case, and use
--   <tt>AS</tt> clauses for anything other than simple columns.
--   
--   A simple getColumnNames implementation could simply apply <tt>map
--   fst</tt> to the return value of <a>describeResult</a>.
getColumnNames :: Statement -> IO [String]

-- | Obtain information about the columns in the result set. Must be run
--   only after <a>execute</a>. The String in the result set is the column
--   name.
--   
--   You should expect this to be returned in the same manner as a result
--   from <a>fetchAllRows'</a>.
--   
--   All results should be converted to lowercase for you before you see
--   them.
--   
--   Please see caveats under <a>getColumnNames</a> for information on the
--   column name field here.
describeResult :: Statement -> IO [(String, SqlColDesc)]

-- | Abort a query in progress -- usually not needed.
finish :: Statement -> IO ()

-- | The original query that this <a>Statement</a> was prepared with.
originalQuery :: Statement -> String

-- | The main HDBC exception object. As much information as possible is
--   passed from the database through to the application through this
--   object.
--   
--   Errors generated in the Haskell layer will have seNativeError set to
--   -1.
data SqlError
SqlError :: String -> Int -> String -> SqlError
seState :: SqlError -> String
seNativeError :: SqlError -> Int
seErrorMsg :: SqlError -> String

-- | A utility function to throw a <a>SqlError</a>. The mechanics of
--   throwing such a thing differ between GHC 6.8.x, Hugs, and GHC 6.10.
--   This function takes care of the special cases to make it simpler.
--   
--   With GHC 6.10, it is a type-restricted alias for throw. On all other
--   systems, it is a type-restricted alias for throwDyn.
throwSqlError :: SqlError -> IO a

-- | Execute the given IO action.
--   
--   If it raises a <a>SqlError</a>, then execute the supplied handler and
--   return its return value. Otherwise, proceed as normal.
catchSql :: IO a -> (SqlError -> IO a) -> IO a

-- | Like <a>catchSql</a>, with the order of arguments reversed.
handleSql :: (SqlError -> IO a) -> IO a -> IO a

-- | Given an Exception, return Just SqlError if it was an SqlError, or
--   Nothing otherwise. Useful with functions like catchJust.
sqlExceptions :: SqlError -> Maybe SqlError

-- | Catches <a>SqlError</a>s, and re-raises them as IO errors with fail.
--   Useful if you don't care to catch SQL errors, but want to see a sane
--   error message if one happens. One would often use this as a high-level
--   wrapper around SQL calls.
handleSqlError :: IO a -> IO a