Menu

[r8314]: / trunk / src / plain / ZPlainDuckDb.pas  Maximize  Restore  History

Download this file

1768 lines (1421 with data), 75.7 kB

   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
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
{*********************************************************}
{ }
{ Zeos Database Objects }
{ Native Plain Drivers for DuckDB }
{ }
{ Originally written by Jan Baumgarten }
{ }
{*********************************************************}
{@********************************************************}
{ Copyright (c) 1999-2020 Zeos Development Group }
{ }
{ License Agreement: }
{ }
{ This library is distributed in the hope that it will be }
{ useful, but WITHOUT ANY WARRANTY; without even the }
{ implied warranty of MERCHANTABILITY or FITNESS FOR }
{ A PARTICULAR PURPOSE. See the GNU Lesser General }
{ Public License for more details. }
{ }
{ The source code of the ZEOS Libraries and packages are }
{ distributed under the Library GNU General Public }
{ License (see the file COPYING / COPYING.ZEOS) }
{ with the following modification: }
{ As a special exception, the copyright holders of this }
{ library give you permission to link this library with }
{ independent modules to produce an executable, }
{ regardless of the license terms of these independent }
{ modules, and to copy and distribute the resulting }
{ executable under terms of your choice, provided that }
{ you also meet, for each linked independent module, }
{ the terms and conditions of the license of that module. }
{ An independent module is a module which is not derived }
{ from or based on this library. If you modify this }
{ library, you may extend this exception to your version }
{ of the library, but you are not obligated to do so. }
{ If you do not wish to do so, delete this exception }
{ statement from your version. }
{ }
{ }
{ The project web site is located on: }
{ https://zeoslib.sourceforge.io/ (FORUM) }
{ http://sourceforge.net/p/zeoslib/tickets/ (BUGTRACKER)}
{ svn://svn.code.sf.net/p/zeoslib/code-0/trunk (SVN) }
{ }
{ http://www.sourceforge.net/projects/zeoslib. }
{ }
{ }
{ Zeos Development Group. }
{********************************************************@}
unit ZPlainDuckDb;
interface
{$I ZPlain.inc}
uses
{$ifdef FPC}ctypes,{$ENDIF} SysUtils, Classes, {$IFDEF MSEgui}mclasses,{$ENDIF}
ZCompatibility, ZPlainDriver;
{$IFNDEF ZEOS_DISABLE_DUCKDB}
const
WINDOWS_VS_DLL_LOCATION = 'duckdb.dll';
WINDOWS_MINGW_DLL_LOCATION = 'libduckdb.dll';
LINUX_DLL_LOCATION = 'libduckdb'+SharedSuffix;
//! An enum over DuckDB's internal types.
//enum DUCKDB_TYPE
DUCKDB_TYPE_INVALID = 0;
DUCKDB_TYPE_BOOLEAN = 1; // bool
DUCKDB_TYPE_TINYINT = 2; // int8_t
DUCKDB_TYPE_SMALLINT = 3; // int16_t
DUCKDB_TYPE_INTEGER = 4; // int32_t
DUCKDB_TYPE_BIGINT = 5; // int64_t
DUCKDB_TYPE_UTINYINT = 6; // uint8_t
DUCKDB_TYPE_USMALLINT = 7; // uint16_t
DUCKDB_TYPE_UINTEGER = 8; // uint32_t
DUCKDB_TYPE_UBIGINT = 9; // uint64_t
DUCKDB_TYPE_FLOAT = 10; // float
DUCKDB_TYPE_DOUBLE = 11; // double
DUCKDB_TYPE_TIMESTAMP = 12; // duckdb_timestamp, in microseconds
DUCKDB_TYPE_DATE = 13; // duckdb_date
DUCKDB_TYPE_TIME = 14; // duckdb_time
DUCKDB_TYPE_INTERVAL = 15; // duckdb_interval
DUCKDB_TYPE_HUGEINT = 16; // duckdb_hugeint
DUCKDB_TYPE_UHUGEINT = 32; // duckdb_uhugeint
DUCKDB_TYPE_VARCHAR = 17; // const char*
DUCKDB_TYPE_BLOB = 18; // duckdb_blob
DUCKDB_TYPE_DECIMAL = 19; // decimal
DUCKDB_TYPE_TIMESTAMP_S = 20; // duckdb_timestamp, in seconds
DUCKDB_TYPE_TIMESTAMP_MS = 21; // duckdb_timestamp, in milliseconds
DUCKDB_TYPE_TIMESTAMP_NS = 22; // duckdb_timestamp, in nanoseconds
DUCKDB_TYPE_ENUM = 23; // enum type, only useful as logical type
DUCKDB_TYPE_LIST = 24; // list type, only useful as logical type
DUCKDB_TYPE_STRUCT = 25; // struct type, only useful as logical type
DUCKDB_TYPE_MAP = 26; // map type, only useful as logical type
DUCKDB_TYPE_ARRAY = 33; // duckdb_array, only useful as logical type
DUCKDB_TYPE_UUID = 27; // duckdb_hugeint
DUCKDB_TYPE_UNION = 28; // union type, only useful as logical type
DUCKDB_TYPE_BIT = 29; // duckdb_bit
DUCKDB_TYPE_TIME_TZ = 30; // duckdb_time_tz
DUCKDB_TYPE_TIMESTAMP_TZ = 31; // duckdb_timestamp
DUCKDB_TYPE_ANY = 34; // ANY type
DUCKDB_TYPE_VARINT = 35; // duckdb_varint
DUCKDB_TYPE_SQLNULL = 36; // SQLNULL type
//! An enum over the returned state of different functions.
//enum duckdb_state
DuckDBSuccess = 0;
DuckDBError = 1;
//! An enum over the pending state of a pending query result.
//enum duckdb_pending_state
DUCKDB_PENDING_RESULT_READY = 0;
DUCKDB_PENDING_RESULT_NOT_READY = 1;
DUCKDB_PENDING_ERROR = 2;
DUCKDB_PENDING_NO_TASKS_AVAILABLE = 3;
//! An enum over DuckDB's different result types.
//enum duckdb_result_type
DUCKDB_RESULT_TYPE_INVALID = 0;
DUCKDB_RESULT_TYPE_CHANGED_ROWS = 1;
DUCKDB_RESULT_TYPE_NOTHING = 2;
DUCKDB_RESULT_TYPE_QUERY_RESULT = 3;
//! An enum over DuckDB's different statement types.
//enum duckdb_statement_type
DUCKDB_STATEMENT_TYPE_INVALID = 0;
DUCKDB_STATEMENT_TYPE_SELECT = 1;
DUCKDB_STATEMENT_TYPE_INSERT = 2;
DUCKDB_STATEMENT_TYPE_UPDATE = 3;
DUCKDB_STATEMENT_TYPE_EXPLAIN = 4;
DUCKDB_STATEMENT_TYPE_DELETE = 5;
DUCKDB_STATEMENT_TYPE_PREPARE = 6;
DUCKDB_STATEMENT_TYPE_CREATE = 7;
DUCKDB_STATEMENT_TYPE_EXECUTE = 8;
DUCKDB_STATEMENT_TYPE_ALTER = 9;
DUCKDB_STATEMENT_TYPE_TRANSACTION = 10;
DUCKDB_STATEMENT_TYPE_COPY = 11;
DUCKDB_STATEMENT_TYPE_ANALYZE = 12;
DUCKDB_STATEMENT_TYPE_VARIABLE_SET = 13;
DUCKDB_STATEMENT_TYPE_CREATE_FUNC = 14;
DUCKDB_STATEMENT_TYPE_DROP = 15;
DUCKDB_STATEMENT_TYPE_EXPORT = 16;
DUCKDB_STATEMENT_TYPE_PRAGMA = 17;
DUCKDB_STATEMENT_TYPE_VACUUM = 18;
DUCKDB_STATEMENT_TYPE_CALL = 19;
DUCKDB_STATEMENT_TYPE_SET = 20;
DUCKDB_STATEMENT_TYPE_LOAD = 21;
DUCKDB_STATEMENT_TYPE_RELATION = 22;
DUCKDB_STATEMENT_TYPE_EXTENSION = 23;
DUCKDB_STATEMENT_TYPE_LOGICAL_PLAN = 24;
DUCKDB_STATEMENT_TYPE_ATTACH = 25;
DUCKDB_STATEMENT_TYPE_DETACH = 26;
DUCKDB_STATEMENT_TYPE_MULTI = 27;
//! An enum over DuckDB's different result types.
//enum duckdb_error_type
DUCKDB_ERROR_INVALID = 0;
DUCKDB_ERROR_OUT_OF_RANGE = 1;
DUCKDB_ERROR_CONVERSION = 2;
DUCKDB_ERROR_UNKNOWN_TYPE = 3;
DUCKDB_ERROR_DECIMAL = 4;
DUCKDB_ERROR_MISMATCH_TYPE = 5;
DUCKDB_ERROR_DIVIDE_BY_ZERO = 6;
DUCKDB_ERROR_OBJECT_SIZE = 7;
DUCKDB_ERROR_INVALID_TYPE = 8;
DUCKDB_ERROR_SERIALIZATION = 9;
DUCKDB_ERROR_TRANSACTION = 10;
DUCKDB_ERROR_NOT_IMPLEMENTED = 11;
DUCKDB_ERROR_EXPRESSION = 12;
DUCKDB_ERROR_CATALOG = 13;
DUCKDB_ERROR_PARSER = 14;
DUCKDB_ERROR_PLANNER = 15;
DUCKDB_ERROR_SCHEDULER = 16;
DUCKDB_ERROR_EXECUTOR = 17;
DUCKDB_ERROR_CONSTRAINT = 18;
DUCKDB_ERROR_INDEX = 19;
DUCKDB_ERROR_STAT = 20;
DUCKDB_ERROR_CONNECTION = 21;
DUCKDB_ERROR_SYNTAX = 22;
DUCKDB_ERROR_SETTINGS = 23;
DUCKDB_ERROR_BINDER = 24;
DUCKDB_ERROR_NETWORK = 25;
DUCKDB_ERROR_OPTIMIZER = 26;
DUCKDB_ERROR_NULL_POINTER = 27;
DUCKDB_ERROR_IO = 28;
DUCKDB_ERROR_INTERRUPT = 29;
DUCKDB_ERROR_FATAL = 30;
DUCKDB_ERROR_INTERNAL = 31;
DUCKDB_ERROR_INVALID_INPUT = 32;
DUCKDB_ERROR_OUT_OF_MEMORY = 33;
DUCKDB_ERROR_PERMISSION = 34;
DUCKDB_ERROR_PARAMETER_NOT_RESOLVED = 35;
DUCKDB_ERROR_PARAMETER_NOT_ALLOWED = 36;
DUCKDB_ERROR_DEPENDENCY = 37;
DUCKDB_ERROR_HTTP = 38;
DUCKDB_ERROR_MISSING_EXTENSION = 39;
DUCKDB_ERROR_AUTOLOAD = 40;
DUCKDB_ERROR_SEQUENCE = 41;
DUCKDB_INVALID_CONFIGURATION = 42;
//! An enum over DuckDB's different cast modes.
//enum duckdb_cast_mode
DUCKDB_CAST_NORMAL = 0;
DUCKDB_CAST_TRY = 1;
type
// just for Delphi:
{$ifndef FPC}
cint8 = ShortInt;
cint16 = SmallInt;
cint32 = Integer;
cint64 = Int64;
cuint8 = Byte;
cuint16 = Word;
cuint32 = Cardinal;
cuint64 = UInt64;
cbool = longbool;
pcbool = ^longbool;
cfloat = Single;
cdouble = Double;
size_t = UIntPtr;
{$ENDIF}
// Inserted for the enums:
TDuckDB_State = cint32;
TDuckDB_Type = cint32;
TDuckDB_Pending_State = cint32;
TDuckDB_Result_Type = cint32;
TDuckDB_Statement_Type = cint32;
TDuckDB_Error_Type = cint32;
TDuckDB_Cast_Mode = cint32;
//! DuckDB's index type.
idx_t = cuint64;
Pidx_t = ^idx_t;
//! The callback that will be called to destroy data, e.g.,
//! bind data (if any), init data (if any), extra data for replacement scans (if any)
//typedef void (*duckdb_delete_callback_t)(void *data);
TDuckDb_Delete_Callback = procedure(data: Pointer); stdcall;
//! Used for threading, contains a task state. Must be destroyed with `duckdb_destroy_state`.
//typedef void *duckdb_task_state;
TDuckDb_Task_State = Pointer;
//===--------------------------------------------------------------------===//
// Types (no explicit freeing)
//===--------------------------------------------------------------------===//
//! Days are stored as days since 1970-01-01
//! Use the duckdb_from_date/duckdb_to_date function to extract individual information
TDuckDb_Date = packed record
days: cint32;
end;
TDuckDb_Date_Struct = packed record
year: cint32;
month: cint8;
day: cint8;
end;
//! Time is stored as microseconds since 00:00:00
//! Use the duckdb_from_time/duckdb_to_time function to extract individual information
TDuckDb_Time = packed record
micros: cint64;
end;
TDuckDb_Time_Struct = packed record
hour: cint8;
min: cint8;
sec: cint8;
micros: cint32;
end;
//! TIME_TZ is stored as 40 bits for int64_t micros, and 24 bits for int32_t offset
TDuckDb_Time_TZ = packed record
bits: cuint64;
end;
TDuckDb_Time_TZ_Struct = packed record
time: TDuckDb_Time_Struct;
offset: cint32;
end;
//! Timestamps are stored as microseconds since 1970-01-01
//! Use the duckdb_from_timestamp/duckdb_to_timestamp function to extract individual information
TDuckDb_TimeStamp = packed record
micros: cint64;
end;
TDuckDB_TimeStamp_Struct = packed record
date: TDuckDb_Date_Struct;
time: TDuckDb_Time_Struct;
end;
TDuckDb_Interval = packed record
months: cint32;
days: cint32;
micros: cint64;
end;
//! Hugeints are composed of a (lower, upper) component
//! The value of the hugeint is upper * 2^64 + lower
//! For easy usage, the functions duckdb_hugeint_to_double/duckdb_double_to_hugeint are recommended
TDuckDB_HugeInt = packed record
lower: cuint64;
upper: cint64;
end;
TDuckDB_UHugeInt = packed record
lower: cuint64;
upper: cuint64;
end;
//! Decimals are composed of a width and a scale, and are stored in a hugeint
TDuckDB_Decimal = packed record
width: cuint8;
scale: cuint8;
value: TDuckDB_HugeInt;
end;
//! A type holding information about the query execution progress
TDuckDB_Query_Progress_Type = packed record
percentage: double;
rows_processed: cuint64;
total_rows_to_process: cuint64;
end;
TDuckDB_String_Pointer = packed record
prefix: array [0..3] of AnsiChar;
ptr: PAnsiChar;
end;
//! The internal representation of a VARCHAR (string_t). If the VARCHAR does not
//! exceed 12 characters, then we inline it. Otherwise, we inline a prefix for faster
//! string comparisons and store a pointer to the remaining characters. This is a non-
//! owning structure, i.e., it does not have to be freed.
TDuckDB_String_T = packed record
length: cuint32;
case Boolean of
true: (Pointer: TDuckDB_String_Pointer);
false: (Inlined: Array[0..11] of AnsiChar);
end;
PDuckDB_String_T = ^TDuckDB_String_T;
//! The internal representation of a list metadata entry contains the list's offset in
//! the child vector, and its length. The parent vector holds these metadata entries,
//! whereas the child vector holds the data
TDuckDB_List_Entry = packed record
offset: cuint64;
length: cuint64;
end;
//! A column consists of a pointer to its internal data. Don't operate on this type directly.
//! Instead, use functions such as duckdb_column_data, duckdb_nullmask_data,
//! duckdb_column_type, and duckdb_column_name, which take the result and the column index
//! as their parameters
TDuckDB_Column = packed record
// deprecated, use duckdb_column_data
deprecated_data: Pointer;
// deprecated, use duckdb_nullmask_data
deprecated_nullmask: pcbool;
// deprecated, use duckdb_column_type
deprecated_type: cint32;
// deprecated, use duckdb_column_name
deprecated_name: PAnsiChar;
internal_data:Pointer;
end;
PDuckDB_Column = ^TDuckDB_Column;
//! A vector to a specified column in a data chunk. Lives as long as the
//! data chunk lives, i.e., must not be destroyed.
SDuckDB_Vector = packed record
internal_ptr: Pointer;
end;
TDuckDB_Vector = ^SDuckDB_Vector; // Note translated as T... because it is more consistent with the other DuckDB types
//===--------------------------------------------------------------------===//
// Types (explicit freeing/destroying)
//===--------------------------------------------------------------------===//
//! Strings are composed of a char pointer and a size. You must free string.data
//! with `duckdb_free`.
TDuckDB_String = packed record
data: PAnsiChar;
size: idx_t;
end;
//! BLOBs are composed of a byte pointer and a size. You must free blob.data
//! with `duckdb_free`.
TDuckDB_Blob = packed record
data: Pointer;
size: idx_t;
end;
//! A query result consists of a pointer to its internal data.
//! Must be freed with 'duckdb_destroy_result'.
TDuckDB_Result = packed record
// deprecated, use duckdb_column_count
deprecated_column_count: idx_t;
// deprecated, use duckdb_row_count
deprecated_row_count: idx_t;
// deprecated, use duckdb_rows_changed
deprecated_rows_changed: idx_t;
// deprecated, use duckdb_column_*-family of functions
deprecated_columns: PDuckDB_Column;
// deprecated, use duckdb_result_error
deprecated_error_message: PAnsiChar;
internal_data: Pointer;
end;
PDuckDB_Result = ^TDuckDB_Result;
//! A database object. Should be closed with `duckdb_close`.
SDuckDB_Database = packed record
internal_ptr: Pointer;
end;
TDuckDB_Database = ^SDuckDB_Database;
PDuckDB_Database = ^TDuckDB_Database;
//! A connection to a duckdb database. Must be closed with `duckdb_disconnect`.
SDuckDB_Connection = packed record
internal_ptr: Pointer;
end;
TDuckDB_Connection = ^SDuckDB_Connection;
PDuckDB_Connection = ^TDuckDB_Connection;
//! A prepared statement is a parameterized query that allows you to bind parameters to it.
//! Must be destroyed with `duckdb_destroy_prepare`.
SDuckDB_Prepared_Statement = packed record
internal_ptr: Pointer;
end;
TDuckDB_Prepared_Statement = ^SDuckDB_Prepared_Statement;
PDuckDB_Prepared_Statement = ^TDuckDB_Prepared_Statement;
//! Extracted statements. Must be destroyed with `duckdb_destroy_extracted`.
SDuckDB_Extracted_Statements = packed record
internal_ptr: Pointer;
end;
TDuckDB_Extracted_Statements = ^SDuckDB_Extracted_Statements;
//! The pending result represents an intermediate structure for a query that is not yet fully executed.
//! Must be destroyed with `duckdb_destroy_pending`.
SDuckdb_Pending_Result = packed record
internal_ptr: Pointer;
end;
TDuckdb_Pending_Result = ^SDuckdb_Pending_Result;
//! The appender enables fast data loading into DuckDB.
//! Must be destroyed with `duckdb_appender_destroy`.
SDuckDB_Appender = packed record
internal_ptr: Pointer;
end;
TDuckdb_Appender = ^SDuckDB_Appender;
//! The table description allows querying info about the table.
//! Must be destroyed with `duckdb_table_description_destroy`.
SDuckDB_Table_Description = packed record
internal_ptr: Pointer;
end;
TDuckdb_Table_Description = ^SDuckDB_Table_Description;
//! Can be used to provide start-up options for the DuckDB instance.
//! Must be destroyed with `duckdb_destroy_config`.
SDuckDB_Config = packed record
internal_ptr: Pointer;
end;
TDuckDB_Config = ^SDuckDB_Config;
PDuckDB_Config = ^TDuckDB_Config;
//! Holds an internal logical type.
//! Must be destroyed with `duckdb_destroy_logical_type`.
SDuckDB_Logical_Type = packed record
internal_ptr: Pointer;
end;
TDuckDB_Logical_Type = ^SDuckDB_Logical_Type;
//! Holds extra information used when registering a custom logical type.
//! Reserved for future use.
SDuckDB_Create_Type_Info = packed record
internal_ptr: Pointer;
end;
TDuckDB_Create_Type_Info = ^SDuckDB_Create_Type_Info;
//! Contains a data chunk from a duckdb_result.
//! Must be destroyed with `duckdb_destroy_data_chunk`.
SDuckDB_Data_Chunk = packed record
internal_ptr: Pointer;
end;
TDuckDB_Data_Chunk = ^SDuckDB_Data_Chunk;
//! Holds a DuckDB value, which wraps a type.
//! Must be destroyed with `duckdb_destroy_value`.
SDuckDB_Value = packed record
internal_ptr: Pointer;
end;
TDuckdb_Value = ^SDuckDB_Value;
//! Holds a recursive tree that matches the query plan.
SDuckdb_Profiling_Info = packed record
internal_ptr: Pointer;
end;
TDuckDB_Profiling_Info = ^SDuckdb_Profiling_Info;
// The following functions have been left out intentionally, because I think
// they are not necessary for a first driver implementation.
(*
//===--------------------------------------------------------------------===//
// C API Extension info
//===--------------------------------------------------------------------===//
//! Holds state during the C API extension intialization process
typedef struct _duckdb_extension_info {
void *internal_ptr;
} * duckdb_extension_info;
*)
//===--------------------------------------------------------------------===//
// Function types
//===--------------------------------------------------------------------===//
// ...
//===--------------------------------------------------------------------===//
// Scalar function types
//===--------------------------------------------------------------------===//
// ...
//===--------------------------------------------------------------------===//
// Aggregate function types
//===--------------------------------------------------------------------===//
// ...
//===--------------------------------------------------------------------===//
// Table function types
//===--------------------------------------------------------------------===//
// ...
//===--------------------------------------------------------------------===//
// Cast types
//===--------------------------------------------------------------------===//
// ...
//===--------------------------------------------------------------------===//
// Replacement scan types
//===--------------------------------------------------------------------===//
// ...
//===--------------------------------------------------------------------===//
// Arrow-related types
//===--------------------------------------------------------------------===//
// ...
//===--------------------------------------------------------------------===//
// DuckDB extension access
//===--------------------------------------------------------------------===//
/// ...
{** Represents a generic interface to SQLite native API. }
IZDuckDBPlainDriver = interface (IZPlainDriver)
['{BE9C27ED-A75E-46BE-9219-87A88E4E03E1}']
end;
TZDuckDBPlainDriver = class (TZAbstractPlainDriver, IZPlainDriver, IZDuckDBPlainDriver)
public
//===--------------------------------------------------------------------===//
// Functions
//===--------------------------------------------------------------------===//
//===--------------------------------------------------------------------===//
// Open Connect
//===--------------------------------------------------------------------===//
(*!
Creates a new database or opens an existing database file stored at the given path.
If no path is given a new in-memory database is created instead.
The instantiated database should be closed with 'duckdb_close'.
* @param path Path to the database file on disk, or `nullptr` or `:memory:` to open an in-memory database.
* @param out_database The result database object.
* @return `DuckDBSuccess` on success or `DuckDBError` on failure.
*)
DuckDB_Open: function(const path: PAnsiChar; out_database: PDuckDB_Database): TDuckDB_State; stdcall;
(*!
Extended version of duckdb_open. Creates a new database or opens an existing database file stored at the given path.
The instantiated database should be closed with 'duckdb_close'.
* @param path Path to the database file on disk, or `nullptr` or `:memory:` to open an in-memory database.
* @param out_database The result database object.
* @param config (Optional) configuration used to start up the database system.
* @param out_error If set and the function returns DuckDBError, this will contain the reason why the start-up failed.
Note that the error must be freed using `duckdb_free`.
* @return `DuckDBSuccess` on success or `DuckDBError` on failure.
*)
DuckDB_Open_Ext: function(const path: PAnsiChar; out_database: PDuckDB_Database; config: TDuckdb_Config;
out_error: PPAnsiChar): TDuckDB_State; stdcall;
(*!
Closes the specified database and de-allocates all memory allocated for that database.
This should be called after you are done with any database allocated through `duckdb_open` or `duckdb_open_ext`.
Note that failing to call `duckdb_close` (in case of e.g. a program crash) will not cause data corruption.
Still, it is recommended to always correctly close a database object after you are done with it.
* @param database The database object to shut down.
*)
DuckDB_Close: procedure(database: PDuckDB_Database); stdcall;
(*!
Opens a connection to a database. Connections are required to query the database, and store transactional state
associated with the connection.
The instantiated connection should be closed using 'duckdb_disconnect'.
* @param database The database file to connect to.
* @param out_connection The result connection object.
* @return `DuckDBSuccess` on success or `DuckDBError` on failure.
*)
Duckdb_Connect: function(database: TDuckDB_Database; out_connection: PDuckDB_Connection): TDuckDB_State; stdcall;
(*!
Interrupt running query
* @param connection The connection to interrupt
*)
DuckDB_Interrupt: procedure(connection: TDuckDB_Connection); stdcall;
(*!
Get progress of the running query
* @param connection The working connection
* @return -1 if no progress or a percentage of the progress
*)
DuckDB_Query_Progress: function(connection: TDuckDB_Connection): TDuckDB_Query_Progress_Type; stdcall;
(*!
Closes the specified connection and de-allocates all memory allocated for that connection.
* @param connection The connection to close.
*)
DuckDB_Disconnect: procedure(connection: PDuckDB_Connection); stdcall;
(*!
Returns the version of the linked DuckDB, with a version postfix for dev versions
Usually used for developing C extensions that must return this for a compatibility check.
*)
DuckDB_Library_Version: function(): PAnsiChar; stdcall;
//===--------------------------------------------------------------------===//
// Configuration
//===--------------------------------------------------------------------===//
(*!
Initializes an empty configuration object that can be used to provide start-up options for the DuckDB instance
through `duckdb_open_ext`.
The duckdb_config must be destroyed using 'duckdb_destroy_config'
This will always succeed unless there is a malloc failure.
Note that `duckdb_destroy_config` should always be called on the resulting config, even if the function returns
`DuckDBError`.
* @param out_config The result configuration object.
* @return `DuckDBSuccess` on success or `DuckDBError` on failure.
*)
DuckDB_Create_Config: function(out_config: PDuckDB_Config): TDuckDB_State; stdcall;
(*!
This returns the total amount of configuration options available for usage with `duckdb_get_config_flag`.
This should not be called in a loop as it internally loops over all the options.
* @return The amount of config options available.
*)
DuckDB_Config_Count: function(): size_t; stdcall;
(*!
Obtains a human-readable name and description of a specific configuration option. This can be used to e.g.
display configuration options. This will succeed unless `index` is out of range (i.e. `>= duckdb_config_count`).
The result name or description MUST NOT be freed.
* @param index The index of the configuration option (between 0 and `duckdb_config_count`)
* @param out_name A name of the configuration flag.
* @param out_description A description of the configuration flag.
* @return `DuckDBSuccess` on success or `DuckDBError` on failure.
*)
DuckDB_Get_Config_Flag: function(index: size_t; out_name: PPAnsiChar; out_description: PPAnsiChar): TDuckDB_State; stdcall;
(*!
Sets the specified option for the specified configuration. The configuration option is indicated by name.
To obtain a list of config options, see `duckdb_get_config_flag`.
In the source code, configuration options are defined in `config.cpp`.
This can fail if either the name is invalid, or if the value provided for the option is invalid.
* @param config The configuration object to set the option on.
* @param name The name of the configuration flag to set.
* @param option The value to set the configuration flag to.
* @return `DuckDBSuccess` on success or `DuckDBError` on failure.
*)
DuckDB_Set_Config: function(config: TDuckDB_Config; const name: PAnsiChar; const option: PAnsiChar): TDuckDB_State; stdcall;
(*!
Destroys the specified configuration object and de-allocates all memory allocated for the object.
* @param config The configuration object to destroy.
*)
DuckDB_Destroy_Config: procedure(config: PDuckDB_Config); stdcall;
//===--------------------------------------------------------------------===//
// Query Execution
//===--------------------------------------------------------------------===//
(*!
Executes a SQL query within a connection and stores the full (materialized) result in the out_result pointer.
If the query fails to execute, DuckDBError is returned and the error message can be retrieved by calling
`duckdb_result_error`.
Note that after running `duckdb_query`, `duckdb_destroy_result` must be called on the result object even if the
query fails, otherwise the error stored within the result will not be freed correctly.
* @param connection The connection to perform the query in.
* @param query The SQL query to run.
* @param out_result The query result.
* @return `DuckDBSuccess` on success or `DuckDBError` on failure.
*)
DuckDB_Query: function(connection: TDuckDB_Connection; const query: PAnsiChar; out_result: PDuckDB_Result): TDuckDB_State; stdcall;
(*!
Closes the result and de-allocates all memory allocated for that connection.
* @param result The result to destroy.
*)
DuckDB_Destroy_Result: procedure(result: PDuckDB_Result); stdcall;
(*!
Returns the column name of the specified column. The result should not need to be freed; the column names will
automatically be destroyed when the result is destroyed.
Returns `NULL` if the column is out of range.
* @param result The result object to fetch the column name from.
* @param col The column index.
* @return The column name of the specified column.
*)
DuckDB_Column_Name: function(result: PDuckDB_Result; col: idx_t): PAnsiChar; stdcall;
(*!
Returns the column type of the specified column.
Returns `DUCKDB_TYPE_INVALID` if the column is out of range.
* @param result The result object to fetch the column type from.
* @param col The column index.
* @return The column type of the specified column.
*)
DuckDB_Column_Type: function(result: PDuckDB_Result; col: idx_t): TDuckDB_Type; stdcall;
(*!
Returns the statement type of the statement that was executed
* @param result The result object to fetch the statement type from.
* @return duckdb_statement_type value or DUCKDB_STATEMENT_TYPE_INVALID
*)
DuckDB_Result_Statement_Type: function(result: TDuckDB_Result): TDuckDB_Statement_Type; stdcall;
(*!
Returns the logical column type of the specified column.
The return type of this call should be destroyed with `duckdb_destroy_logical_type`.
Returns `NULL` if the column is out of range.
* @param result The result object to fetch the column type from.
* @param col The column index.
* @return The logical column type of the specified column.
*)
DuckDB_Column_Logical_Type: function(result: PDuckDB_Result; col: idx_t): TDuckDB_Logical_Type; stdcall;
(*!
Returns the number of columns present in a the result object.
* @param result The result object.
* @return The number of columns present in the result object.
*)
DuckDB_Column_Count: function(result: PDuckDB_Result): idx_t; stdcall;
(*!
**DEPRECATION NOTICE**: This method is scheduled for removal in a future release.
Returns the number of rows present in the result object.
* @param result The result object.
* @return The number of rows present in the result object.
*)
DuckDB_Row_Count: function(result: PDuckDB_Result): idx_t; stdcall;
(*!
Returns the number of rows changed by the query stored in the result. This is relevant only for INSERT/UPDATE/DELETE
queries. For other queries the rows_changed will be 0.
* @param result The result object.
* @return The number of rows changed.
*)
DuckDB_Rows_Changed: function(result: PDuckDB_Result): idx_t; stdcall;
(*!
**DEPRECATED**: Prefer using `duckdb_result_get_chunk` instead.
Returns the data of a specific column of a result in columnar format.
The function returns a dense array which contains the result data. The exact type stored in the array depends on the
corresponding duckdb_type (as provided by `duckdb_column_type`). For the exact type by which the data should be
accessed, see the comments in [the types section](types) or the `DUCKDB_TYPE` enum.
For example, for a column of type `DUCKDB_TYPE_INTEGER`, rows can be accessed in the following manner:
```c
int32_t *data = (int32_t * ) duckdb_column_data(&result, 0);
printf("Data for row %d: %d\n", row, data[row]);
```
* @param result The result object to fetch the column data from.
* @param col The column index.
* @return The column data of the specified column.
*)
DuckDB_Column_Data: function(result: PDuckDB_Result; col: idx_t): Pointer; stdcall;
(*!
**DEPRECATED**: Prefer using `duckdb_result_get_chunk` instead.
Returns the nullmask of a specific column of a result in columnar format. The nullmask indicates for every row
whether or not the corresponding row is `NULL`. If a row is `NULL`, the values present in the array provided
by `duckdb_column_data` are undefined.
```c
int32_t *data = (int32_t * ) duckdb_column_data(&result, 0);
bool *nullmask = duckdb_nullmask_data(&result, 0);
if (nullmask[row]) {
printf("Data for row %d: NULL\n", row);
} else {
printf("Data for row %d: %d\n", row, data[row]);
}
```
* @param result The result object to fetch the nullmask from.
* @param col The column index.
* @return The nullmask of the specified column.
*)
DuckDB_Nullmask_Data: function(result: PDuckDB_Result; col: idx_t): pcbool; stdcall;
(*!
Returns the error message contained within the result. The error is only set if `duckdb_query` returns `DuckDBError`.
The result of this function must not be freed. It will be cleaned up when `duckdb_destroy_result` is called.
* @param result The result object to fetch the error from.
* @return The error of the result.
*)
DuckDB_Result_Error: function(result: PDuckDB_Result): PAnsiChar; stdcall;
(*!
Returns the result error type contained within the result. The error is only set if `duckdb_query` returns
`DuckDBError`.
* @param result The result object to fetch the error from.
* @return The error type of the result.
*)
DuckDB_Result_Error_Type: function(result: PDuckDB_Result): TDuckDB_Error_Type; stdcall;
//===--------------------------------------------------------------------===//
// Result Functions
//===--------------------------------------------------------------------===//
(*!
**DEPRECATION NOTICE**: This method is scheduled for removal in a future release.
Fetches a data chunk from the duckdb_result. This function should be called repeatedly until the result is exhausted.
The result must be destroyed with `duckdb_destroy_data_chunk`.
This function supersedes all `duckdb_value` functions, as well as the `duckdb_column_data` and `duckdb_nullmask_data`
functions. It results in significantly better performance, and should be preferred in newer code-bases.
If this function is used, none of the other result functions can be used and vice versa (i.e. this function cannot be
mixed with the legacy result functions).
Use `duckdb_result_chunk_count` to figure out how many chunks there are in the result.
* @param result The result object to fetch the data chunk from.
* @param chunk_index The chunk index to fetch from.
* @return The resulting data chunk. Returns `NULL` if the chunk index is out of bounds.
*)
DuckDB_Result_Get_Chunk: function(result: TDuckDB_Result; chunk_index: idx_t): TDuckDB_Data_Chunk; stdcall;
(*!
**DEPRECATION NOTICE**: This method is scheduled for removal in a future release.
Checks if the type of the internal result is StreamQueryResult.
* @param result The result object to check.
* @return Whether or not the result object is of the type StreamQueryResult
*)
DuckDB_Result_Is_Streaming: function(result: TDuckDB_Result): cbool; stdcall;
(*!
**DEPRECATION NOTICE**: This method is scheduled for removal in a future release.
Returns the number of data chunks present in the result.
* @param result The result object
* @return Number of data chunks present in the result.
*)
DuckDB_Result_Chunk_Count: function(result: TDuckDB_Result): idx_t; stdcall;
(*!
Returns the return_type of the given result, or DUCKDB_RETURN_TYPE_INVALID on error
* @param result The result object
* @return The return_type
*)
DuckDB_Result_Return_Type: function(result: TDuckDB_Result): TDuckDB_Result_Type; stdcall;
//===--------------------------------------------------------------------===//
// Safe Fetch Functions
//===--------------------------------------------------------------------===//
// These functions will perform conversions if necessary.
// On failure (e.g. if conversion cannot be performed or if the value is NULL) a default value is returned.
// Note that these functions are slow since they perform bounds checking and conversion
// For fast access of values prefer using `duckdb_result_get_chunk`
(*!
**DEPRECATION NOTICE**: This method is scheduled for removal in a future release.
* @return The boolean value at the specified location, or false if the value cannot be converted.
*)
DuckDB_Value_Boolean: function(result: PDuckDB_Result; col: idx_t; row: idx_t): cbool; stdcall;
(*!
**DEPRECATION NOTICE**: This method is scheduled for removal in a future release.
* @return The int8_t value at the specified location, or 0 if the value cannot be converted.
*)
DuckDB_Value_Int8: function(result: PDuckDB_Result; col: idx_t; row: idx_t): cint8; stdcall;
(*!
**DEPRECATION NOTICE**: This method is scheduled for removal in a future release.
* @return The int16_t value at the specified location, or 0 if the value cannot be converted.
*)
DuckDB_Value_Int16: function(result: PDuckDB_Result; col: idx_t; row: idx_t): cint16; stdcall;
(*!
**DEPRECATION NOTICE**: This method is scheduled for removal in a future release.
* @return The int32_t value at the specified location, or 0 if the value cannot be converted.
*)
DuckDB_Value_Int32: function(result: PDuckDB_Result; col: idx_t; row: idx_t): cint32; stdcall;
(*!
**DEPRECATION NOTICE**: This method is scheduled for removal in a future release.
* @return The int64_t value at the specified location, or 0 if the value cannot be converted.
*)
DuckDB_Value_Int64: function(result: PDuckDB_Result; col: idx_t; row: idx_t): cint64; stdcall;
(*!
**DEPRECATION NOTICE**: This method is scheduled for removal in a future release.
* @return The duckdb_hugeint value at the specified location, or 0 if the value cannot be converted.
*)
DuckDB_Value_Hugeint: function(result: PDuckDB_Result; col: idx_t; row: idx_t): TDuckDB_HugeInt; stdcall;
(*!
**DEPRECATION NOTICE**: This method is scheduled for removal in a future release.
* @return The duckdb_uhugeint value at the specified location, or 0 if the value cannot be converted.
*)
DuckDB_Value_UHugeint: function(result: PDuckDB_Result; col: idx_t; row: idx_t): TDuckDB_UHugeInt; stdcall;
(*!
**DEPRECATION NOTICE**: This method is scheduled for removal in a future release.
* @return The duckdb_decimal value at the specified location, or 0 if the value cannot be converted.
*)
DuckDB_Value_Decimal: function(result: PDuckDB_Result; col: idx_t; row: idx_t): TDuckDB_Decimal; stdcall;
(*!
**DEPRECATION NOTICE**: This method is scheduled for removal in a future release.
* @return The uint8_t value at the specified location, or 0 if the value cannot be converted.
*)
DuckDB_Value_UInt8: function(result: PDuckDB_Result; col: idx_t; row: idx_t): cuint8; stdcall;
(*!
**DEPRECATION NOTICE**: This method is scheduled for removal in a future release.
* @return The uint16_t value at the specified location, or 0 if the value cannot be converted.
*)
DuckDB_Value_UInt16: function(result: PDuckDB_Result; col: idx_t; row: idx_t): cuint16; stdcall;
(*!
**DEPRECATION NOTICE**: This method is scheduled for removal in a future release.
* @return The uint32_t value at the specified location, or 0 if the value cannot be converted.
*)
DuckDB_Value_UInt32: function(result: PDuckDB_Result; col: idx_t; row: idx_t): cuint32; stdcall;
(*!
**DEPRECATION NOTICE**: This method is scheduled for removal in a future release.
* @return The uint64_t value at the specified location, or 0 if the value cannot be converted.
*)
DuckDB_Value_UInt64: function(result: PDuckDB_Result; col: idx_t; row: idx_t): cuint64; stdcall;
(*!
**DEPRECATION NOTICE**: This method is scheduled for removal in a future release.
* @return The float value at the specified location, or 0 if the value cannot be converted.
*)
DuckDB_Value_Float: function(result: PDuckDB_Result; col: idx_t; row: idx_t): cfloat; stdcall;
(*!
**DEPRECATION NOTICE**: This method is scheduled for removal in a future release.
* @return The double value at the specified location, or 0 if the value cannot be converted.
*)
DuckDB_Value_Double: function(result: PDuckDB_Result; col: idx_t; row: idx_t): cdouble; stdcall;
(*!
**DEPRECATION NOTICE**: This method is scheduled for removal in a future release.
* @return The duckdb_date value at the specified location, or 0 if the value cannot be converted.
*)
DuckDB_Value_Date: function(result: PDuckDB_Result; col: idx_t; row: idx_t): TDuckDb_Date; stdcall;
(*!
**DEPRECATION NOTICE**: This method is scheduled for removal in a future release.
* @return The duckdb_time value at the specified location, or 0 if the value cannot be converted.
*)
DuckDB_Value_Time: function(result: PDuckDB_Result; col: idx_t; row: idx_t): TDuckDb_Time; stdcall;
(*!
**DEPRECATION NOTICE**: This method is scheduled for removal in a future release.
* @return The duckdb_timestamp value at the specified location, or 0 if the value cannot be converted.
*)
DuckDB_Value_Timestamp: function(result: PDuckDB_Result; col: idx_t; row: idx_t): TDuckDb_TimeStamp; stdcall;
(*!
**DEPRECATION NOTICE**: This method is scheduled for removal in a future release.
* @return The duckdb_interval value at the specified location, or 0 if the value cannot be converted.
*)
DuckDB_Value_Interval: function(result: PDuckDB_Result; col: idx_t; row: idx_t): TDuckDb_Interval; stdcall;
(*!
**DEPRECATED**: Use duckdb_value_string instead. This function does not work correctly if the string contains null
bytes.
* @return The text value at the specified location as a null-terminated string, or nullptr if the value cannot be
converted. The result must be freed with `duckdb_free`.
*)
DuckDB_Value_Varchar: function(result: PDuckDB_Result; col: idx_t; row: idx_t): PAnsiChar; stdcall;
(*!
**DEPRECATION NOTICE**: This method is scheduled for removal in a future release.
No support for nested types, and for other complex types.
The resulting field "string.data" must be freed with `duckdb_free.`
* @return The string value at the specified location. Attempts to cast the result value to string.
*)
DuckDB_Value_String: function(result: PDuckDB_Result; col: idx_t; row: idx_t): TDuckDB_String; stdcall;
(*!
**DEPRECATED**: Use duckdb_value_string_internal instead. This function does not work correctly if the string contains
null bytes.
* @return The char* value at the specified location. ONLY works on VARCHAR columns and does not auto-cast.
If the column is NOT a VARCHAR column this function will return NULL.
The result must NOT be freed.
*)
DuckDB_Value_Varchar_Internal: function(result: PDuckDB_Result; col: idx_t; row: idx_t): PAnsiChar; stdcall;
(*!
**DEPRECATED**: Use duckdb_value_string_internal instead. This function does not work correctly if the string contains
null bytes.
* @return The char* value at the specified location. ONLY works on VARCHAR columns and does not auto-cast.
If the column is NOT a VARCHAR column this function will return NULL.
The result must NOT be freed.
*)
DuckDB_Value_String_Internal: function(result: PDuckDB_Result; col: idx_t; row: idx_t): TDuckDB_String; stdcall;
(*!
**DEPRECATION NOTICE**: This method is scheduled for removal in a future release.
* @return The duckdb_blob value at the specified location. Returns a blob with blob.data set to nullptr if the
value cannot be converted. The resulting field "blob.data" must be freed with `duckdb_free.`
*)
DuckDB_Value_Blob: function(result: PDuckDB_Result; col: idx_t; row: idx_t): TDuckDB_Blob; stdcall;
(*!
**DEPRECATION NOTICE**: This method is scheduled for removal in a future release.
* @return Returns true if the value at the specified index is NULL, and false otherwise.
*)
DuckDB_Value_Is_Null: function(result: PDuckDB_Result; col: idx_t; row: idx_t): cbool; stdcall;
//===--------------------------------------------------------------------===//
// Helpers
//===--------------------------------------------------------------------===//
(*!
Allocate `size` bytes of memory using the duckdb internal malloc function. Any memory allocated in this manner
should be freed using `duckdb_free`.
* @param size The number of bytes to allocate.
* @return A pointer to the allocated memory region.
*)
DuckDB_Malloc: function(size: size_t): Pointer; stdcall;
(*!
Free a value returned from `duckdb_malloc`, `duckdb_value_varchar`, `duckdb_value_blob`, or
`duckdb_value_string`.
* @param ptr The memory region to de-allocate.
*)
DuckDB_free: procedure(ptr: Pointer); stdcall;
(*!
The internal vector size used by DuckDB.
This is the amount of tuples that will fit into a data chunk created by `duckdb_create_data_chunk`.
* @return The vector size.
*)
DuckDB_Vector_Size: function(): idx_t; stdcall;
(*!
Whether or not the duckdb_string_t value is inlined.
This means that the data of the string does not have a separate allocation.
*)
DuckDB_String_Is_Inlined: function(AString: TDuckDB_String_T): cbool; stdcall;
(*!
Get the string length of a string_t
* @param string The string to get the length of.
* @return The length.
*)
DuckDB_String_T_Length: function(AString: TDuckDB_String_T): cuint32; stdcall;
(*!
Get a pointer to the string data of a string_t
* @param string The string to get the pointer to.
* @return The pointer.
*)
DuckDB_String_T_Data: function(AString: PDuckDB_String_T): PAnsiChar; stdcall;
//===--------------------------------------------------------------------===//
// Date Time Timestamp Helpers
//===--------------------------------------------------------------------===//
(*!
Decompose a `duckdb_date` object into year, month and date (stored as `duckdb_date_struct`).
* @param date The date object, as obtained from a `DUCKDB_TYPE_DATE` column.
* @return The `duckdb_date_struct` with the decomposed elements.
*)
DuckDB_From_Date: function(ADate: TDuckDb_Date): TDuckDb_Date_Struct; stdcall;
(*!
Re-compose a `duckdb_date` from year, month and date (`duckdb_date_struct`).
* @param date The year, month and date stored in a `duckdb_date_struct`.
* @return The `duckdb_date` element.
*)
DuckDB_To_Date: function(date: TDuckDb_Date_Struct): TDuckDb_Date; stdcall;
(*!
Test a `duckdb_date` to see if it is a finite value.
* @param date The date object, as obtained from a `DUCKDB_TYPE_DATE` column.
* @return True if the date is finite, false if it is ±infinity.
*)
DuckDB_Is_Finite_Date: function(date: TDuckDb_Date): cbool; stdcall;
(*!
Decompose a `duckdb_time` object into hour, minute, second and microsecond (stored as `duckdb_time_struct`).
* @param time The time object, as obtained from a `DUCKDB_TYPE_TIME` column.
* @return The `duckdb_time_struct` with the decomposed elements.
*)
DuckDB_From_Time: function(ATime: TDuckDb_Time): TDuckDb_Time_Struct; stdcall;
(*!
Create a `duckdb_time_tz` object from micros and a timezone offset.
* @param micros The microsecond component of the time.
* @param offset The timezone offset component of the time.
* @return The `duckdb_time_tz` element.
*)
DuckDB_Create_Time_TZ: function(micros: cint64; offset: cint32): TDuckDb_Time_TZ; stdcall;
(*!
Decompose a TIME_TZ objects into micros and a timezone offset.
Use `duckdb_from_time` to further decompose the micros into hour, minute, second and microsecond.
* @param micros The time object, as obtained from a `DUCKDB_TYPE_TIME_TZ` column.
*)
DuckDB_From_Time_TZ: function(micros: TDuckDb_Time_TZ): TDuckDb_Time_TZ_Struct; stdcall;
(*!
Re-compose a `duckdb_time` from hour, minute, second and microsecond (`duckdb_time_struct`).
* @param time The hour, minute, second and microsecond in a `duckdb_time_struct`.
* @return The `duckdb_time` element.
*)
DuckDB_To_Time: function(ATime: TDuckDb_Time_Struct): TDuckDb_Time; stdcall;
(*!
Decompose a `duckdb_timestamp` object into a `duckdb_timestamp_struct`.
* @param ts The ts object, as obtained from a `DUCKDB_TYPE_TIMESTAMP` column.
* @return The `duckdb_timestamp_struct` with the decomposed elements.
*)
DuckDB_From_Timestamp: function(ts: TDuckDb_TimeStamp): TDuckDB_TimeStamp_Struct; stdcall;
(*!
Re-compose a `duckdb_timestamp` from a duckdb_timestamp_struct.
* @param ts The de-composed elements in a `duckdb_timestamp_struct`.
* @return The `duckdb_timestamp` element.
*)
DuckDB_To_Timestamp: function(ts: TDuckDB_TimeStamp_Struct): TDuckDb_TimeStamp; stdcall;
(*!
Test a `duckdb_timestamp` to see if it is a finite value.
* @param ts The timestamp object, as obtained from a `DUCKDB_TYPE_TIMESTAMP` column.
* @return True if the timestamp is finite, false if it is ±infinity.
*)
DuckDB_Is_Finite_Timestamp: function(ts: TDuckDb_TimeStamp): cbool; stdcall;
//===--------------------------------------------------------------------===//
// Hugeint Helpers
//===--------------------------------------------------------------------===//
(*!
Converts a duckdb_hugeint object (as obtained from a `DUCKDB_TYPE_HUGEINT` column) into a double.
* @param val The hugeint value.
* @return The converted `double` element.
*)
DuckDB_Hugeint_To_Double: function(val: TDuckDB_HugeInt): cdouble; stdcall;
(*!
Converts a double value to a duckdb_hugeint object.
If the conversion fails because the double value is too big the result will be 0.
* @param val The double value.
* @return The converted `duckdb_hugeint` element.
*)
DuckDB_Double_To_Hugeint: function(val: cdouble): TDuckDB_HugeInt; stdcall;
//===--------------------------------------------------------------------===//
// Unsigned Hugeint Helpers
//===--------------------------------------------------------------------===//
(*!
Converts a duckdb_uhugeint object (as obtained from a `DUCKDB_TYPE_UHUGEINT` column) into a double.
* @param val The uhugeint value.
* @return The converted `double` element.
*)
DuckDB_UHugeint_To_Double: function(val: TDuckDB_UHugeInt): cdouble; stdcall;
(*!
Converts a double value to a duckdb_uhugeint object.
If the conversion fails because the double value is too big the result will be 0.
* @param val The double value.
* @return The converted `duckdb_uhugeint` element.
*)
DuckDB_Double_To_UHugeint: function(val: cdouble): TDuckDB_UHugeInt; stdcall;
//===--------------------------------------------------------------------===//
// Decimal Helpers
//===--------------------------------------------------------------------===//
(*!
Converts a double value to a duckdb_decimal object.
If the conversion fails because the double value is too big, or the width/scale are invalid the result will be 0.
* @param val The double value.
* @return The converted `duckdb_decimal` element.
*)
DuckDB_Double_To_Decimal: function(val: cdouble; width: cuint8; scale: cuint8): TDuckDB_Decimal; stdcall;
(*!
Converts a duckdb_decimal object (as obtained from a `DUCKDB_TYPE_DECIMAL` column) into a double.
* @param val The decimal value.
* @return The converted `double` element.
*)
DuckDB_Decimal_To_Double: function(val: TDuckDB_Decimal): cdouble; stdcall;
//===--------------------------------------------------------------------===//
// Prepared Statements
//===--------------------------------------------------------------------===//
// A prepared statement is a parameterized query that allows you to bind parameters to it.
// * This is useful to easily supply parameters to functions and avoid SQL injection attacks.
// * This is useful to speed up queries that you will execute several times with different parameters.
// Because the query will only be parsed, bound, optimized and planned once during the prepare stage,
// rather than once per execution.
// For example:
// SELECT * FROM tbl WHERE id=?
// Or a query with multiple parameters:
// SELECT * FROM tbl WHERE id=$1 OR name=$2
(*!
Create a prepared statement object from a query.
Note that after calling `duckdb_prepare`, the prepared statement should always be destroyed using
`duckdb_destroy_prepare`, even if the prepare fails.
If the prepare fails, `duckdb_prepare_error` can be called to obtain the reason why the prepare failed.
* @param connection The connection object
* @param query The SQL query to prepare
* @param out_prepared_statement The resulting prepared statement object
* @return `DuckDBSuccess` on success or `DuckDBError` on failure.
*)
DuckDB_Prepare: function(connection: TDuckDB_Connection; const query: PAnsiChar; out_prepared_statement: TDuckDB_Prepared_Statement): TDuckDB_State; stdcall;
(*!
Closes the prepared statement and de-allocates all memory allocated for the statement.
* @param prepared_statement The prepared statement to destroy.
*)
DuckDB_Destroy_Prepare: procedure(prepared_statement: PDuckDB_Prepared_Statement); stdcall;
(*!
Returns the error message associated with the given prepared statement.
If the prepared statement has no error message, this returns `nullptr` instead.
The error message should not be freed. It will be de-allocated when `duckdb_destroy_prepare` is called.
* @param prepared_statement The prepared statement to obtain the error from.
* @return The error message, or `nullptr` if there is none.
*)
DuckDB_Prepare_Error: function(prepared_statement: TDuckDB_Prepared_Statement): PAnsiChar; stdcall;
(*!
Returns the number of parameters that can be provided to the given prepared statement.
Returns 0 if the query was not successfully prepared.
* @param prepared_statement The prepared statement to obtain the number of parameters for.
*)
DuckDB_NParams: function(prepared_statement: TDuckDB_Prepared_Statement): idx_t; stdcall;
(*!
Returns the name used to identify the parameter
The returned string should be freed using `duckdb_free`.
Returns NULL if the index is out of range for the provided prepared statement.
* @param prepared_statement The prepared statement for which to get the parameter name from.
*)
DuckDB_Parameter_Name: function(prepared_statement: TDuckDB_Prepared_Statement; index: idx_t): PAnsiChar; stdcall;
(*!
Returns the parameter type for the parameter at the given index.
Returns `DUCKDB_TYPE_INVALID` if the parameter index is out of range or the statement was not successfully prepared.
* @param prepared_statement The prepared statement.
* @param param_idx The parameter index.
* @return The parameter type
*)
DuckDB_Param_Type: function(prepared_statement: TDuckDB_Prepared_Statement; param_idx: idx_t): TDuckDB_Type; stdcall;
(*!
Clear the params bind to the prepared statement.
*)
DuckDB_Clear_Bindings: function(prepared_statement: TDuckDB_Prepared_Statement): TDuckDB_State; stdcall;
(*!
Returns the statement type of the statement to be executed
* @param statement The prepared statement.
* @return duckdb_statement_type value or DUCKDB_STATEMENT_TYPE_INVALID
*)
DuckDB_Prepared_Statement_Type: function(statement: TDuckDB_Prepared_Statement): TDuckDB_Statement_Type; stdcall;
//===--------------------------------------------------------------------===//
// Bind Values To Prepared Statements
//===--------------------------------------------------------------------===//
(*!
Binds a value to the prepared statement at the specified index.
*)
DuckDB_Bind_Value: function(prepared_statement: TDuckDB_Prepared_Statement; param_idx: idx_t; val: TDuckdb_Value): TDuckDB_State; stdcall;
(*!
Retrieve the index of the parameter for the prepared statement, identified by name
*)
DuckDB_Bind_Parameter_Index: function(prepared_statement: TDuckDB_Prepared_Statement; param_idx_out: Pidx_t; name: PAnsiChar): TDuckDB_State; stdcall;
(*!
Binds a bool value to the prepared statement at the specified index.
*)
DuckDB_Bind_Boolean: function(prepared_statement: TDuckDB_Prepared_Statement; param_idx: idx_t; val: cbool): TDuckDB_State; stdcall;
(*!
Binds an int8_t value to the prepared statement at the specified index.
*)
DuckDB_Bind_Int8: function(prepared_statement: TDuckDB_Prepared_Statement; param_idx: idx_t; val: cint8): TDuckDB_State; stdcall;
(*!
Binds an int16_t value to the prepared statement at the specified index.
*)
DuckDB_Bind_Int16: function(prepared_statement: TDuckDB_Prepared_Statement; param_idx: idx_t; val: cint16): TDuckDB_State; stdcall;
(*!
Binds an int32_t value to the prepared statement at the specified index.
*)
DuckDB_Bind_Int32: function(prepared_statement: TDuckDB_Prepared_Statement; param_idx: idx_t; val: cint32): TDuckDB_State; stdcall;
(*!
Binds an int64_t value to the prepared statement at the specified index.
*)
DuckDB_Bind_Int64: function(prepared_statement: TDuckDB_Prepared_Statement; param_idx: idx_t; val: cint64): TDuckDB_State; stdcall;
(*!
Binds a duckdb_hugeint value to the prepared statement at the specified index.
*)
DuckDB_Bind_Hugeint: function(prepared_statement: TDuckDB_Prepared_Statement; param_idx: idx_t; val: TDuckDB_HugeInt): TDuckDB_State; stdcall;
(*!
Binds an duckdb_uhugeint value to the prepared statement at the specified index.
*)
DuckDB_Bind_UHugeint: function(prepared_statement: TDuckDB_Prepared_Statement; param_idx: idx_t; val: TDuckDB_UHugeInt): TDuckDB_State; stdcall;
(*!
Binds a duckdb_decimal value to the prepared statement at the specified index.
*)
DuckDB_Bind_Decimal: function(prepared_statement: TDuckDB_Prepared_Statement; param_idx: idx_t; val: TDuckDB_Decimal): TDuckDB_State; stdcall;
(*!
Binds an uint8_t value to the prepared statement at the specified index.
*)
DuckDB_Bind_UInt8: function(prepared_statement: TDuckDB_Prepared_Statement; param_idx: idx_t; val: cuint8): TDuckDB_State; stdcall;
(*!
Binds an uint16_t value to the prepared statement at the specified index.
*)
DuckDB_Bind_UInt16: function(prepared_statement: TDuckDB_Prepared_Statement; param_idx: idx_t; val: cuint16): TDuckDB_State; stdcall;
(*!
Binds an uint32_t value to the prepared statement at the specified index.
*)
DuckDB_Bind_UInt32: function(prepared_statement: TDuckDB_Prepared_Statement; param_idx: idx_t; val: cuint32): TDuckDB_State; stdcall;
(*!
Binds an uint64_t value to the prepared statement at the specified index.
*)
DuckDB_Bind_Uint64: function(prepared_statement: TDuckDB_Prepared_Statement; param_idx: idx_t; val: cuint64): TDuckDB_State; stdcall;
(*!
Binds a float value to the prepared statement at the specified index.
*)
DuckDB_Bind_Float: function(prepared_statement: TDuckDB_Prepared_Statement; param_idx: idx_t; val: cfloat): TDuckDB_State; stdcall;
(*!
Binds a double value to the prepared statement at the specified index.
*)
DuckDB_Bind_Double: function(prepared_statement: TDuckDB_Prepared_Statement; param_idx: idx_t; val: cdouble): TDuckDB_State; stdcall;
(*!
Binds a duckdb_date value to the prepared statement at the specified index.
*)
DuckDB_Bind_Date: function(prepared_statement: TDuckDB_Prepared_Statement; param_idx: idx_t; val: TDuckDb_Date): TDuckDB_State; stdcall;
(*!
Binds a duckdb_time value to the prepared statement at the specified index.
*)
DuckDB_Bind_Time: function(prepared_statement: TDuckDB_Prepared_Statement; param_idx: idx_t; val: TDuckDb_Time): TDuckDB_State; stdcall;
(*!
Binds a duckdb_timestamp value to the prepared statement at the specified index.
*)
DuckDB_Bind_Timestamp: function(prepared_statement: TDuckDB_Prepared_Statement; param_idx: idx_t; val: TDuckDb_TimeStamp): TDuckDB_State; stdcall;
(*!
Binds a duckdb_timestamp value to the prepared statement at the specified index.
*)
DuckDB_Bind_Timestamp_TZ: function(prepared_statement: TDuckDB_Prepared_Statement; param_idx: idx_t; val: TDuckDb_TimeStamp): TDuckDB_State; stdcall;
(*!
Binds a duckdb_interval value to the prepared statement at the specified index.
*)
DuckDB_Bind_Interval: function(prepared_statement: TDuckDB_Prepared_Statement; param_idx: idx_t; val: TDuckDb_Interval): TDuckDB_State; stdcall;
(*!
Binds a null-terminated varchar value to the prepared statement at the specified index.
*)
DuckDB_Bind_Varchar: function(prepared_statement: TDuckDB_Prepared_Statement; param_idx: idx_t; val: PAnsiChar): TDuckDB_State; stdcall;
(*!
Binds a varchar value to the prepared statement at the specified index.
*)
DuckDB_Bind_Varchar_Length: function(prepared_statement: TDuckDB_Prepared_Statement; param_idx: idx_t; val: PAnsiChar; length: idx_t): TDuckDB_State; stdcall;
(*!
Binds a blob value to the prepared statement at the specified index.
*)
DuckDB_Bind_Blob: function(prepared_statement: TDuckDB_Prepared_Statement; param_idx: idx_t; data: Pointer; length: idx_t): TDuckDB_State; stdcall;
(*!
Binds a NULL value to the prepared statement at the specified index.
*)
DuckDB_Bind_Null: function(prepared_statement: TDuckDB_Prepared_Statement; param_idx: idx_t): TDuckDB_State; stdcall;
//===--------------------------------------------------------------------===//
// Execute Prepared Statements
//===--------------------------------------------------------------------===//
(*!
Executes the prepared statement with the given bound parameters, and returns a materialized query result.
This method can be called multiple times for each prepared statement, and the parameters can be modified
between calls to this function.
Note that the result must be freed with `duckdb_destroy_result`.
* @param prepared_statement The prepared statement to execute.
* @param out_result The query result.
* @return `DuckDBSuccess` on success or `DuckDBError` on failure.
*)
DuckDB_Execute_Prepared: function(prepared_statement: TDuckDB_Prepared_Statement; out_result: PDuckDB_Result): TDuckDB_State; stdcall;
(*!
**DEPRECATION NOTICE**: This method is scheduled for removal in a future release.
Executes the prepared statement with the given bound parameters, and returns an optionally-streaming query result.
To determine if the resulting query was in fact streamed, use `duckdb_result_is_streaming`
This method can be called multiple times for each prepared statement, and the parameters can be modified
between calls to this function.
Note that the result must be freed with `duckdb_destroy_result`.
* @param prepared_statement The prepared statement to execute.
* @param out_result The query result.
* @return `DuckDBSuccess` on success or `DuckDBError` on failure.
*)
DuckDB_Execute_Prepared_Streaming: function(prepared_statement: TDuckDB_Prepared_Statement; out_result: PDuckDB_Result): TDuckDB_State; stdcall;
protected
function GetUnicodeCodePageName: String; override;
procedure LoadCodePages; override;
function Clone: IZPlainDriver; override;
procedure LoadApi; override;
public
constructor Create;
function GetProtocol: string; override;
function GetDescription: string; override;
end;
{$ENDIF ZEOS_DISABLE_DUCKDB}
implementation
{$IFNDEF ZEOS_DISABLE_DUCKDB}
uses ZPlainLoader, ZEncoding{$IFDEF WITH_UNITANSISTRINGS}, AnsiStrings{$ENDIF};
{ TZSQLitePlainDriver }
function TZDuckDBPlainDriver.GetUnicodeCodePageName: String;
begin
Result := 'UTF8'
end;
procedure TZDuckDBPlainDriver.LoadCodePages;
begin
{ MultiByte }
AddCodePage('UTF8', 1, ceUTF8, zCP_UTF8, 'URF-8', 4);
end;
constructor TZDuckDBPlainDriver.Create;
begin
inherited create;
FLoader := TZNativeLibraryLoader.Create([]);
{$IFDEF MSWINDOWS}
FLoader.AddLocation(WINDOWS_VS_DLL_LOCATION);
FLoader.AddLocation(WINDOWS_MINGW_DLL_LOCATION);
{$ELSE}
FLoader.AddLocation(LINUX_DLL_LOCATION);
FLoader.AddLocation(LINUX_DLL_LOCATION+'.0');
{$ENDIF}
LoadCodePages;
end;
function TZDuckDBPlainDriver.Clone: IZPlainDriver;
begin
Result := TZDuckDBPlainDriver.Create;
end;
procedure TZDuckDBPlainDriver.LoadApi;
begin
{ ************** Load adresses of API Functions ************* }
with Loader do begin
@DuckDB_Open := GetAddress('duckdb_open');
@DuckDB_Open_Ext := GetAddress('duckdb_open_ext');
@DuckDB_Close := GetAddress('duckdb_close');
@DuckDB_Connect := GetAddress('duckdb_connect');
@DuckDB_Interrupt := GetAddress('duckdb_interrupt');
@DuckDB_Query_Progress := GetAddress('duckdb_query_progress');
@DuckDB_Disconnect := GetAddress('duckdb_disconnect');
@DuckDB_Library_Version := GetAddress('duckdb_library_version');
@DuckDB_Create_Config := GetAddress('duckdb_create_config');
@DuckDB_Config_Count := GetAddress('duckdb_config_count');
@DuckDB_Get_Config_Flag := GetAddress('duckdb_get_config_flag');
@DuckDB_Set_Config := GetAddress('duckdb_set_config');
@DuckDB_Destroy_Config := GetAddress('duckdb_destroy_config');
@DuckDB_Query := GetAddress('duckdb_query');
@DuckDB_Destroy_Result := GetAddress('duckdb_destroy_result');
@DuckDB_Column_Name := GetAddress('duckdb_column_name');
@DuckDB_Column_Type := GetAddress('duckdb_column_type');
@DuckDB_Result_Statement_Type := GetAddress('duckdb_result_statement_type');
@DuckDB_Column_Logical_Type := GetAddress('duckdb_column_logical_type');
@DuckDB_Column_Count := GetAddress('duckdb_column_count');
@DuckDB_Row_Count := GetAddress('duckdb_row_count');
@DuckDB_Rows_Changed := GetAddress('duckdb_rows_changed');
@DuckDB_Column_Data := GetAddress('duckdb_column_data');
@DuckDB_Nullmask_Data := GetAddress('duckdb_nullmask_data');
@DuckDB_Result_Error := GetAddress('duckdb_result_error');
@DuckDB_Result_Error_Type := GetAddress('duckdb_result_error_type');
@DuckDB_Result_Get_Chunk := GetAddress('duckdb_result_get_chunk');
@DuckDB_Result_Is_Streaming := GetAddress('duckdb_result_is_streaming');
@DuckDB_Result_Chunk_Count := GetAddress('duckdb_result_chunk_count');
@DuckDB_Result_Return_Type := GetAddress('duckdb_result_return_type');
@DuckDB_Value_Boolean := GetAddress('duckdb_value_boolean');
@DuckDB_Value_Int8 := GetAddress('duckdb_value_int8');
@DuckDB_Value_Int16 := GetAddress('duckdb_value_int16');
@DuckDB_Value_Int32 := GetAddress('duckdb_value_int32');
@DuckDB_Value_Int64 := GetAddress('duckdb_value_int64');
@DuckDB_Value_Hugeint := GetAddress('duckdb_value_hugeint');
@DuckDB_Value_UHugeint := GetAddress('duckdb_value_uhugeint');
@DuckDB_Value_Decimal := GetAddress('duckdb_value_decimal');
@DuckDB_Value_UInt8 := GetAddress('duckdb_value_uint8');
@DuckDB_Value_UInt16 := GetAddress('duckdb_value_uint16');
@DuckDB_Value_UInt32 := GetAddress('duckdb_value_uint32');
@DuckDB_Value_UInt64 := GetAddress('duckdb_value_uint64');
@DuckDB_Value_Float := GetAddress('duckdb_value_float');
@DuckDB_Value_Double := GetAddress('duckdb_value_double');
@DuckDB_Value_Date := GetAddress('duckdb_value_date');
@DuckDB_Value_Time := GetAddress('duckdb_value_time');
@DuckDB_Value_Timestamp := GetAddress('duckdb_value_timestamp');
@DuckDB_Value_Interval := GetAddress('duckdb_value_interval');
@DuckDB_Value_Varchar := GetAddress('duckdb_value_varchar');
@DuckDB_Value_String := GetAddress('duckdb_value_string');
@DuckDB_Value_Varchar_Internal := GetAddress('duckdb_value_varchar_internal');
@DuckDB_Value_String_Internal := GetAddress('duckdb_value_string_internal');
@DuckDB_Value_Blob := GetAddress('duckdb_value_blob');
@DuckDB_Value_Is_Null := GetAddress('duckdb_value_is_null');
@DuckDB_Malloc := GetAddress('duckdb_malloc');
@DuckDB_free := GetAddress('duckdb_free');
@DuckDB_Vector_Size := GetAddress('duckdb_vector_size');
@DuckDB_String_Is_Inlined := GetAddress('duckdb_string_is_inlined');
@DuckDB_String_T_Length := GetAddress('duckdb_string_t_length');
@DuckDB_String_T_Data := GetAddress('duckdb_string_t_data');
@DuckDB_From_Date := GetAddress('duckdb_from_date');
@DuckDB_To_Date := GetAddress('duckdb_to_date');
@DuckDB_Is_Finite_Date := GetAddress('duckdb_is_finite_date');
@DuckDB_From_Time := GetAddress('duckdb_from_time');
@DuckDB_Create_Time_TZ := GetAddress('duckdb_create_time_tz');
@DuckDB_From_Time_TZ := GetAddress('duckdb_from_time_tz');
@DuckDB_To_Time := GetAddress('duckdb_to_time');
@DuckDB_From_Timestamp := GetAddress('duckdb_from_timestamp');
@DuckDB_To_Timestamp := GetAddress('duckdb_to_timestamp');
@DuckDB_Is_Finite_Timestamp := GetAddress('duckdb_is_finite_timestamp');
@DuckDB_Hugeint_To_Double := GetAddress('duckdb_hugeint_to_double');
@DuckDB_Double_To_Hugeint := GetAddress('duckdb_double_to_hugeint');
@DuckDB_UHugeint_To_Double := GetAddress('duckdb_uhugeint_to_double');
@DuckDB_Double_To_UHugeint := GetAddress('duckdb_double_to_uhugeint');
@DuckDB_Double_To_Decimal := GetAddress('duckdb_double_to_decimal');
@DuckDB_Decimal_To_Double := GetAddress('duckdb_decimal_do_double');
@DuckDB_Prepare := GetAddress('duckdb_prepare');
@DuckDB_Destroy_Prepare := GetAddress('duckdb_destroy_prepare');
@DuckDB_Prepare_Error := GetAddress('duckdb_prepare_error');
@DuckDB_NParams := GetAddress('duckdb_nparams');
@DuckDB_Parameter_Name := GetAddress('duckdb_parameter_name');
@DuckDB_Param_Type := GetAddress('duckdb_param_type');
@DuckDB_Clear_Bindings := GetAddress('duckdb_clear_bindings');
@DuckDB_Prepared_Statement_Type := GetAddress('duckdb_prepared_statement_type');
@DuckDB_Bind_Value := GetAddress('duckdb_bind_value');
@DuckDB_Bind_Parameter_Index := GetAddress('duckdb_bind_parameter_index');
@DuckDB_Bind_Boolean := GetAddress('duckdb_bind_boolean');
@DuckDB_Bind_Int8 := GetAddress('duckdb_bind_int8');
@DuckDB_Bind_Int16 := GetAddress('duckdb_bind_int16');
@DuckDB_Bind_Int32 := GetAddress('duckdb_bind_int32');
@DuckDB_Bind_Int64 := GetAddress('duckdb_bind_int64');
@DuckDB_Bind_Hugeint := GetAddress('duckdb_bind_hugeint');
@DuckDB_Bind_UHugeint := GetAddress('duckdb_bind_uhugeint');
@DuckDB_Bind_Decimal := GetAddress('duckdb_bind_decimal');
@DuckDB_Bind_UInt8 := GetAddress('duckdb_bind_uint8');
@DuckDB_Bind_UInt16 := GetAddress('duckdb_bind_uint16');
@DuckDB_Bind_UInt32 := GetAddress('duckdb_bind_uint32');
@DuckDB_Bind_UInt64 := GetAddress('duckdb_bind_uint64');
@DuckDB_Bind_Float := GetAddress('duckdb_bind_float');
@DuckDB_Bind_Double := GetAddress('duckdb_bind_double');
@DuckDB_Bind_Date := GetAddress('duckdb_bind_date');
@DuckDB_Bind_Time := GetAddress('duckdb_bind_time');
@DuckDB_Bind_Timestamp := GetAddress('duckdb_bind_timestamp');
@DuckDB_Bind_Timestamp_TZ := GetAddress('duckdb_bind_timestamp_tz');
@DuckDB_Bind_Interval := GetAddress('duckdb_bind_interval');
@DuckDB_Bind_Varchar := GetAddress('duckdb_bind_varchar');
@DuckDB_Bind_Varchar_Length := GetAddress('duckdb_bind_varchar_length');
@DuckDB_Bind_Blob := GetAddress('duckdb_bind_blob');
@DuckDB_Bind_Null := GetAddress('duckdb_bind_null');
@DuckDB_Execute_Prepared := GetAddress('duckdb_execute_prepared');
@DuckDB_Execute_Prepared_Streaming := GetAddress('duckdb_execute_prepared_streaming');
end;
end;
function TZDuckDBPlainDriver.GetProtocol: string;
begin
Result := 'DuckDB';
end;
function TZDuckDBPlainDriver.GetDescription: string;
begin
Result := 'Native Plain Driver for DuckDB';
end;
{$ENDIF ZEOS_DISABLE_DUCKDB}
end.
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.