PostgreSQL Source Code: src/interfaces/libpq/fe-exec.c Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13

14

16

17#include <ctype.h>

18#include <fcntl.h>

19#include <limits.h>

20

21#ifdef WIN32

22#include "win32.h"

23#else

25#endif

26

30

31

33 "PGRES_EMPTY_QUERY",

34 "PGRES_COMMAND_OK",

35 "PGRES_TUPLES_OK",

36 "PGRES_COPY_OUT",

37 "PGRES_COPY_IN",

38 "PGRES_BAD_RESPONSE",

39 "PGRES_NONFATAL_ERROR",

40 "PGRES_FATAL_ERROR",

41 "PGRES_COPY_BOTH",

42 "PGRES_SINGLE_TUPLE",

43 "PGRES_PIPELINE_SYNC",

44 "PGRES_PIPELINE_ABORTED",

45 "PGRES_TUPLES_CHUNK"

46};

47

48

52 .errMsg = "out of memory\n",

53};

54

55

56

57

58

61

62

65 const char **errmsgp);

69 const char *command,

70 const char *stmtName,

71 int nParams,

72 const Oid *paramTypes,

73 const char *const *paramValues,

74 const int *paramLengths,

75 const int *paramFormats,

76 int resultFormat);

82 const char *target);

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#define PGRESULT_DATA_BLOCKSIZE 2048

143#define PGRESULT_ALIGN_BOUNDARY MAXIMUM_ALIGNOF

144#define PGRESULT_BLOCK_OVERHEAD Max(sizeof(PGresult_data), PGRESULT_ALIGN_BOUNDARY)

145#define PGRESULT_SEP_ALLOC_THRESHOLD (PGRESULT_DATA_BLOCKSIZE / 2)

146

147

148

149

150

151

152

153

154

155

156

157

160{

162

164 if (!result)

165 return NULL;

166

167 result->ntups = 0;

170 result->tuples = NULL;

177 result->events = NULL;

179 result->errMsg = NULL;

187

189 {

190

193

194

195 switch (status)

196 {

205

206 break;

207 default:

208

210 break;

211 }

212

213

215 {

219 {

221 return NULL;

222 }

224 }

225 }

226 else

227 {

228

234 }

235

236 return result;

237}

238

239

240

241

242

243

244

245

246

247

248int

250{

251 int i;

252

253

255 return false;

256

257

259 return false;

260

261

262 if (numAttributes <= 0 || !attDescs)

263 return true;

264

267

269 return false;

270

273

274

277 {

280 else

282

284 return false;

285

288 }

289

290 return true;

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

319{

321 int i;

322

323 if (!src)

324 return NULL;

325

328 return NULL;

329

330

333

334

336 {

338 {

340 return NULL;

341 }

342 }

343

344

346 {

347 int tup,

348 field;

349

350 for (tup = 0; tup < src->ntups; tup++)

351 {

352 for (field = 0; field < src->numAttributes; field++)

353 {

357 {

359 return NULL;

360 }

361 }

362 }

363 }

364

365

368

369

371 {

373 &dest->memorySize);

374 if (dest->events)

375 {

377 return NULL;

378 }

380 }

381

382

383 for (i = 0; i < dest->nEvents; i++)

384 {

385

387 {

389

390 evt.src = src;

393 dest->events[i].passThrough))

394 dest->events[i].resultInitialized = true;

395 }

396 }

397

399}

400

401

402

403

404

405

406

409{

411 size_t msize;

412 int i;

413

414 if (!events || count <= 0)

415 return NULL;

416

417 msize = count * sizeof(PGEvent);

419 if (!newEvents)

420 return NULL;

421

422 for (i = 0; i < count; i++)

423 {

426 newEvents[i].data = NULL;

428 newEvents[i].name = strdup(events[i].name);

429 if (!newEvents[i].name)

430 {

431 while (--i >= 0)

433 free(newEvents);

434 return NULL;

435 }

436 msize += strlen(events[i].name) + 1;

437 }

438

439 *memSize += msize;

440 return newEvents;

441}

442

443

444

445

446

447

448

449

450

451int

453{

455 const char *errmsg = NULL;

456

457

459 return false;

460

461

463 return false;

464

465

466 if (tup_num < 0 || tup_num > res->ntups)

467 {

469 "row number %d is out of range 0..%d",

470 tup_num, res->ntups);

471 return false;

472 }

473

474

475 if (tup_num == res->ntups)

476 {

478 int i;

479

482 true);

483

484 if (!tup)

485 goto fail;

486

487

489 {

492 }

493

494

496 goto fail;

497 }

498

499 attval = &res->tuples[tup_num][field_num];

500

501

503 {

506 }

507 else if (len <= 0)

508 {

509 attval->len = 0;

511 }

512 else

513 {

515 if (!attval->value)

516 goto fail;

520 }

521

522 return true;

523

524

525

526

527

528fail:

532

533 return false;

534}

535

536

537

538

539

540

541

542void *

544{

545

547 return NULL;

548

550}

551

552

553

554

555

556

557

558

559

560

561

562void *

564{

565 char *space;

567

568 if (!res)

569 return NULL;

570

571 if (nBytes <= 0)

573

574

575

576

577

578 if (isBinary)

579 {

581

582 if (offset)

583 {

586 }

587 }

588

589

590 if (nBytes <= (size_t) res->spaceLeft)

591 {

595 return space;

596 }

597

598

599

600

601

602

603

605 {

607

609 if (!block)

610 return NULL;

614 {

615

616

617

618

621 }

622 else

623 {

624

625 block->next = NULL;

627 res->spaceLeft = 0;

628 }

629 return space;

630 }

631

632

634 if (!block)

635 return NULL;

639 if (isBinary)

640 {

641

644 }

645 else

646 {

647

650 }

651

655 return space;

656}

657

658

659

660

661

662size_t

664{

665 if (!res)

666 return 0;

668}

669

670

671

672

673

674char *

676{

677 char *space = (char *) pqResultAlloc(res, strlen(str) + 1, false);

678

679 if (space)

680 strcpy(space, str);

681 return space;

682}

683

684

685

686

687

688

689

690

691void

693{

694 char *msg;

695

696 if (!res)

697 return;

698

699

700

701

702

703

704

705

708 else

709 msg = NULL;

710 if (msg)

712 else

714}

715

716

717

718

719

720void

722{

724 int i;

725

726

727 if (!res)

728 return;

729

731 return;

732

733

735 {

736

738 {

740

744 }

746 }

747

749

750

751 while ((block = res->curBlock) != NULL)

752 {

755 }

756

757

759

760

767

768

769

771}

772

773

774

775

776

777

778void

780{

786}

787

788

789

790

791

792

793

794

795

796

797

798

799

800

801

802void

804{

805

807

809}

810

811

812

813

814

815

816

817

818

819static void

821{

822

823

824

825

826

828 {

830

832 }

833 else

835

837}

838

839

840

841

842

843

844

845

846

847

848

849

852{

854

856 if (res)

857 {

858

859

860

861

862

865 }

866 else

867 {

868

869

870

871

872

875

876

880

881

882

883

884

885

887 if (res)

888 {

889

890

891

892

896 }

897 else

898 {

899

900

901

902

903

904

905

907

908

909

910

911

912 }

913 }

914

915

916

917

918

919

920

922 conn->error_result = false;

924

925 return res;

926}

927

928

929

930

931

932

933

934

935

936

937void

939{

940 char msgBuf[1024];

941 va_list args;

943

945 return;

946

947

948 va_start(args, fmt);

950 va_end(args);

951 msgBuf[sizeof(msgBuf) - 1] = '\0';

952

953

955 if (!res)

956 return;

958

959

960

961

965

966

967

968

969

970

974 else

976

977

978

979

982}

983

984

985

986

987

988

989

990

991

992static bool

994{

996 {

997

998

999

1000

1001

1002

1003

1004

1005

1006

1007

1008 int newSize;

1010

1011

1012

1013

1014

1018 newSize = INT_MAX;

1019 else

1020 {

1021 *errmsgp = libpq_gettext("PGresult cannot support more than INT_MAX tuples");

1022 return false;

1023 }

1024

1025

1026

1027

1028

1029

1030#if INT_MAX >= (SIZE_MAX / 2)

1031 if (newSize > SIZE_MAX / sizeof(PGresAttValue *))

1032 {

1034 return false;

1035 }

1036#endif

1037

1038 if (res->tuples == NULL)

1041 else

1044 if (!newTuples)

1045 return false;

1049 res->tuples = newTuples;

1050 }

1053 return true;

1054}

1055

1056

1057

1058

1059void

1061{

1063

1067 strlen(value) + 1,

1068 true);

1069 if (!pfield)

1070 return;

1071 pfield->code = code;

1075}

1076

1077

1078

1079

1080void

1082{

1085

1086

1087

1088

1089 for (pstatus = conn->pstatus, prev = NULL;

1090 pstatus != NULL;

1091 prev = pstatus, pstatus = pstatus->next)

1092 {

1093 if (strcmp(pstatus->name, name) == 0)

1094 {

1095 if (prev)

1097 else

1099 free(pstatus);

1100 break;

1101 }

1102 }

1103

1104

1105

1106

1108 strlen(name) + strlen(value) + 2);

1109 if (pstatus)

1110 {

1111 char *ptr;

1112

1114 pstatus->name = ptr;

1115 strcpy(ptr, name);

1116 ptr += strlen(name) + 1;

1117 pstatus->value = ptr;

1118 strcpy(ptr, value);

1121 }

1122

1123

1124

1125

1126

1127

1128

1129

1130 if (strcmp(name, "client_encoding") == 0)

1131 {

1133

1137 }

1138 else if (strcmp(name, "standard_conforming_strings") == 0)

1139 {

1142 }

1143 else if (strcmp(name, "server_version") == 0)

1144 {

1145

1146 int cnt;

1147 int vmaj,

1148 vmin,

1149 vrev;

1150

1151 cnt = sscanf(value, "%d.%d.%d", &vmaj, &vmin, &vrev);

1152

1153 if (cnt == 3)

1154 {

1155

1156 conn->sversion = (100 * vmaj + vmin) * 100 + vrev;

1157 }

1158 else if (cnt == 2)

1159 {

1160 if (vmaj >= 10)

1161 {

1162

1164 }

1165 else

1166 {

1167

1169 }

1170 }

1171 else if (cnt == 1)

1172 {

1173

1175 }

1176 else

1178 }

1179 else if (strcmp(name, "default_transaction_read_only") == 0)

1180 {

1183 }

1184 else if (strcmp(name, "in_hot_standby") == 0)

1185 {

1188 }

1189 else if (strcmp(name, "scram_iterations") == 0)

1190 {

1192 }

1193}

1194

1195

1196

1197

1198

1199

1200

1201

1202

1203

1204

1205int

1207{

1212 int i;

1213

1214

1215

1216

1217

1218

1219

1220

1221

1223 {

1224

1228 if (!res)

1229 return 0;

1230

1232

1235 }

1236

1237

1238

1239

1240

1241

1242

1243

1244

1245

1248 if (tup == NULL)

1249 return 0;

1250

1251 for (i = 0; i < nfields; i++)

1252 {

1253 int clen = columns[i].len;

1254

1255 if (clen < 0)

1256 {

1257

1260 }

1261 else

1262 {

1264 char *val;

1265

1267 if (val == NULL)

1268 return 0;

1269

1270

1271 memcpy(val, columns[i].value, clen);

1272 val[clen] = '\0';

1273

1274 tup[i].len = clen;

1276 }

1277 }

1278

1279

1281 return 0;

1282

1283

1284

1285

1286

1289

1290 return 1;

1291}

1292

1293

1294

1295

1296

1297

1298

1299

1300

1301

1302

1303

1304

1307{

1309

1311 {

1313 if (entry == NULL)

1314 {

1316 return NULL;

1317 }

1318 }

1319 else

1320 {

1323 }

1324 entry->next = NULL;

1325 entry->query = NULL;

1326

1327 return entry;

1328}

1329

1330

1331

1332

1333

1334

1335

1336

1337

1338static void

1340{

1342

1345 else

1347

1349

1351 {

1354

1355

1356

1357

1358

1359

1360

1363 break;

1364

1366

1367

1368

1369

1370

1371

1372

1373

1377 break;

1378 }

1379}

1380

1381

1382

1383

1384

1385static void

1387{

1388 if (entry == NULL)

1389 return;

1390

1391

1393

1394 if (entry->query)

1395 {

1397 entry->query = NULL;

1398 }

1399

1402}

1403

1404

1405

1406

1407

1408

1409

1410

1411

1412

1413

1414

1415int

1417{

1419}

1420

1421int

1423{

1425}

1426

1427static int

1429{

1431

1433 return 0;

1434

1435

1436 if (!query)

1437 {

1439 return 0;

1440 }

1441

1443 {

1445 "PQsendQuery");

1446 return 0;

1447 }

1448

1450 if (entry == NULL)

1451 return 0;

1452

1453

1454

1458 {

1459

1461 return 0;

1462 }

1463

1464

1466

1467 entry->query = strdup(query);

1468

1469

1470

1471

1472

1474 goto sendFailed;

1475

1476

1478

1479 return 1;

1480

1481sendFailed:

1483

1484 return 0;

1485}

1486

1487

1488

1489

1490

1491int

1493 const char *command,

1494 int nParams,

1495 const Oid *paramTypes,

1496 const char *const *paramValues,

1497 const int *paramLengths,

1498 const int *paramFormats,

1499 int resultFormat)

1500{

1502 return 0;

1503

1504

1505 if (!command)

1506 {

1508 return 0;

1509 }

1511 {

1514 return 0;

1515 }

1516

1518 command,

1519 "",

1520 nParams,

1521 paramTypes,

1522 paramValues,

1523 paramLengths,

1524 paramFormats,

1525 resultFormat);

1526}

1527

1528

1529

1530

1531

1532

1533

1534

1535int

1537 const char *stmtName, const char *query,

1538 int nParams, const Oid *paramTypes)

1539{

1541

1543 return 0;

1544

1545

1546 if (!stmtName)

1547 {

1549 return 0;

1550 }

1551 if (!query)

1552 {

1554 return 0;

1555 }

1557 {

1560 return 0;

1561 }

1562

1564 if (entry == NULL)

1565 return 0;

1566

1567

1571 goto sendFailed;

1572

1573 if (nParams > 0 && paramTypes)

1574 {

1575 int i;

1576

1578 goto sendFailed;

1579 for (i = 0; i < nParams; i++)

1580 {

1582 goto sendFailed;

1583 }

1584 }

1585 else

1586 {

1588 goto sendFailed;

1589 }

1591 goto sendFailed;

1592

1593

1595 {

1598 goto sendFailed;

1599 }

1600

1601

1603

1604

1605

1606 entry->query = strdup(query);

1607

1608

1609

1610

1611

1612

1614 goto sendFailed;

1615

1616

1618

1619 return 1;

1620

1621sendFailed:

1623

1624 return 0;

1625}

1626

1627

1628

1629

1630

1631

1632int

1634 const char *stmtName,

1635 int nParams,

1636 const char *const *paramValues,

1637 const int *paramLengths,

1638 const int *paramFormats,

1639 int resultFormat)

1640{

1642 return 0;

1643

1644

1645 if (!stmtName)

1646 {

1648 return 0;

1649 }

1651 {

1654 return 0;

1655 }

1656

1658 NULL,

1659 stmtName,

1660 nParams,

1661 NULL,

1662 paramValues,

1663 paramLengths,

1664 paramFormats,

1665 resultFormat);

1666}

1667

1668

1669

1670

1671

1672static bool

1674{

1676 return false;

1677

1678

1679

1680

1681

1682

1685

1686

1688 {

1690 return false;

1691 }

1692

1693

1696 {

1698 return false;

1699 }

1700

1702 {

1703

1704

1705

1706

1707

1708

1709

1710

1711

1712

1713

1715 {

1721

1722 break;

1723

1728 return false;

1729 }

1730 }

1731 else

1732 {

1733

1734

1735

1736

1738

1739

1743 }

1744

1745

1746 return true;

1747}

1748

1749

1750

1751

1752

1753

1754

1755

1756static int

1758 const char *command,

1759 const char *stmtName,

1760 int nParams,

1761 const Oid *paramTypes,

1762 const char *const *paramValues,

1763 const int *paramLengths,

1764 const int *paramFormats,

1765 int resultFormat)

1766{

1767 int i;

1769

1771 if (entry == NULL)

1772 return 0;

1773

1774

1775

1776

1777

1778

1779

1780 if (command)

1781 {

1782

1786 goto sendFailed;

1787 if (nParams > 0 && paramTypes)

1788 {

1790 goto sendFailed;

1791 for (i = 0; i < nParams; i++)

1792 {

1794 goto sendFailed;

1795 }

1796 }

1797 else

1798 {

1800 goto sendFailed;

1801 }

1803 goto sendFailed;

1804 }

1805

1806

1810 goto sendFailed;

1811

1812

1813 if (nParams > 0 && paramFormats)

1814 {

1816 goto sendFailed;

1817 for (i = 0; i < nParams; i++)

1818 {

1820 goto sendFailed;

1821 }

1822 }

1823 else

1824 {

1826 goto sendFailed;

1827 }

1828

1830 goto sendFailed;

1831

1832

1833 for (i = 0; i < nParams; i++)

1834 {

1835 if (paramValues && paramValues[i])

1836 {

1837 int nbytes;

1838

1839 if (paramFormats && paramFormats[i] != 0)

1840 {

1841

1842 if (paramLengths)

1843 nbytes = paramLengths[i];

1844 else

1845 {

1847 goto sendFailed;

1848 }

1849 }

1850 else

1851 {

1852

1853 nbytes = strlen(paramValues[i]);

1854 }

1857 goto sendFailed;

1858 }

1859 else

1860 {

1861

1863 goto sendFailed;

1864 }

1865 }

1868 goto sendFailed;

1870 goto sendFailed;

1871

1872

1877 goto sendFailed;

1878

1879

1884 goto sendFailed;

1885

1886

1888 {

1891 goto sendFailed;

1892 }

1893

1894

1896

1897

1898

1899 if (command)

1900 entry->query = strdup(command);

1901

1902

1903

1904

1905

1906

1908 goto sendFailed;

1909

1910

1912

1913 return 1;

1914

1915sendFailed:

1917

1918 return 0;

1919}

1920

1921

1922

1923

1924static bool

1926{

1927

1928

1929

1930

1932 return false;

1934 return false;

1938 return false;

1940 return false;

1941 return true;

1942}

1943

1944

1945

1946

1947int

1949{

1951 {

1955 return 1;

1956 }

1957 else

1958 return 0;

1959}

1960

1961

1962

1963

1964int

1966{

1968 {

1972 return 1;

1973 }

1974 else

1975 return 0;

1976}

1977

1978

1979

1980

1981

1982

1983int

1985{

1987 return 0;

1988

1989

1990

1991

1992

1993

1995 {

1997 return 0;

1998 }

1999

2000

2001

2002

2003

2004

2005

2007 return 0;

2008

2009

2010 return 1;

2011}

2012

2013

2014

2015

2016

2017

2018

2019static void

2021{

2023}

2024

2025

2026

2027

2028

2029

2030int

2032{

2034 return false;

2035

2036

2038

2039

2040

2041

2042

2043

2044

2045

2046

2048}

2049

2050

2051

2052

2053

2054

2055

2056

2057

2058

2059

2060

2063{

2065

2067 return NULL;

2068

2069

2071

2072

2074 {

2075 int flushResult;

2076

2077

2078

2079

2080

2081 while ((flushResult = pqFlush(conn)) > 0)

2082 {

2084 {

2085 flushResult = -1;

2086 break;

2087 }

2088 }

2089

2090

2091

2092

2093

2094

2095

2096

2097 if (flushResult ||

2100 {

2101

2105 }

2106

2107

2109

2110

2111

2112

2113

2115 {

2119 }

2120 }

2121

2122

2124 {

2126 res = NULL;

2127 break;

2130

2131

2132

2133

2134

2135

2136

2138 res = NULL;

2139 break;

2140

2143

2144

2145

2146

2147

2148

2149

2150

2151

2153 {

2155 break;

2156 }

2157

2158

2161

2163 {

2164

2165

2166

2167

2169

2170

2171

2172

2173

2174

2175

2176

2177

2178

2179

2180

2183 }

2184 else

2185 {

2186

2188 }

2189 break;

2192

2194 break;

2197 break;

2200 break;

2203 break;

2204 default:

2209 break;

2210 }

2211

2212

2213 if (res && res->nEvents > 0)

2215

2216 return res;

2217}

2218

2219

2220

2221

2222

2225{

2226

2227

2228

2229

2230

2231

2232

2233

2235 {

2239 }

2240

2241

2244

2245

2247}

2248

2249

2250

2251

2252

2253

2254

2255

2256

2257

2258

2259

2260

2263{

2265 return NULL;

2267 return NULL;

2269}

2270

2271

2272

2273

2274

2277 const char *command,

2278 int nParams,

2279 const Oid *paramTypes,

2280 const char *const *paramValues,

2281 const int *paramLengths,

2282 const int *paramFormats,

2283 int resultFormat)

2284{

2286 return NULL;

2288 nParams, paramTypes, paramValues, paramLengths,

2289 paramFormats, resultFormat))

2290 return NULL;

2292}

2293

2294

2295

2296

2297

2298

2299

2300

2301

2302

2303

2304

2307 const char *stmtName, const char *query,

2308 int nParams, const Oid *paramTypes)

2309{

2311 return NULL;

2313 return NULL;

2315}

2316

2317

2318

2319

2320

2321

2324 const char *stmtName,

2325 int nParams,

2326 const char *const *paramValues,

2327 const int *paramLengths,

2328 const int *paramFormats,

2329 int resultFormat)

2330{

2332 return NULL;

2334 nParams, paramValues, paramLengths,

2335 paramFormats, resultFormat))

2336 return NULL;

2338}

2339

2340

2341

2342

2343static bool

2345{

2347

2349 return false;

2350

2351

2352

2353

2354

2355

2358

2360 {

2361 libpq_append_conn_error(conn, "synchronous command execution functions are not allowed in pipeline mode");

2362 return false;

2363 }

2364

2365

2366

2367

2368

2370 {

2372

2373 PQclear(result);

2375 {

2376

2378 libpq_gettext("COPY terminated by new PQexec")) < 0)

2379 return false;

2380

2381 }

2383 {

2384

2385

2386

2387

2389

2390 }

2392 {

2393

2395 return false;

2396 }

2397

2399 return false;

2400 }

2401

2402

2403 return true;

2404}

2405

2406

2407

2408

2411{

2414

2415

2416

2417

2418

2419

2420

2421

2422

2423

2424

2425

2426 lastResult = NULL;

2428 {

2430 lastResult = result;

2435 break;

2436 }

2437

2438 return lastResult;

2439}

2440

2441

2442

2443

2444

2445

2446

2447

2448

2449

2450

2451

2452

2453

2456{

2458 return NULL;

2460 return NULL;

2462}

2463

2464

2465

2466

2467

2468

2469

2470

2471

2472

2475{

2477 return NULL;

2479 return NULL;

2481}

2482

2483

2484

2485

2486

2487

2488

2489

2490int

2492{

2494}

2495

2496

2497

2498

2499

2500

2501

2502

2503int

2505{

2507}

2508

2509

2510

2511

2512

2513

2514

2515

2516

2517

2518

2519

2522{

2524 return NULL;

2526 return NULL;

2528}

2529

2530

2531

2532

2533

2534

2535

2536

2537

2540{

2542 return NULL;

2544 return NULL;

2546}

2547

2548

2549

2550

2551

2552

2553

2554

2555int

2557{

2559}

2560

2561

2562

2563

2564

2565

2566

2567

2568int

2570{

2572}

2573

2574

2575

2576

2577

2578

2579

2580

2581

2582

2583

2584

2585

2586

2587

2588static int

2590{

2592

2593

2594 if (!target)

2595 target = "";

2596

2598 return 0;

2599

2601 if (entry == NULL)

2602 return 0;

2603

2604

2609 goto sendFailed;

2610

2611

2613 {

2616 goto sendFailed;

2617 }

2618

2619

2621 {

2623 }

2625 {

2627 }

2628 else

2629 {

2631 goto sendFailed;

2632 }

2633

2634

2635

2636

2637

2638

2640 goto sendFailed;

2641

2642

2644

2645 return 1;

2646

2647sendFailed:

2649

2650 return 0;

2651}

2652

2653

2654

2655

2656

2657

2658

2659

2660

2661

2662

2663

2664

2665

2668{

2670

2672 return NULL;

2673

2674

2676

2678 if (event)

2679 {

2683 event->next = NULL;

2684 }

2685 return event;

2686}

2687

2688

2689

2690

2691

2692

2693

2694int

2696{

2698 return -1;

2701 {

2703 return -1;

2704 }

2705

2706

2707

2708

2709

2710

2711

2712

2713

2715

2716 if (nbytes > 0)

2717 {

2718

2719

2720

2721

2722

2723

2725 {

2727 return -1;

2731 }

2732

2736 return -1;

2737 }

2738 return 1;

2739}

2740

2741

2742

2743

2744

2745

2746

2747

2748int

2750{

2752 return -1;

2755 {

2757 return -1;

2758 }

2759

2760

2761

2762

2763

2764 if (errormsg)

2765 {

2766

2770 return -1;

2771 }

2772 else

2773 {

2774

2777 return -1;

2778 }

2779

2780

2781

2782

2783

2786 {

2789 return -1;

2790 }

2791

2792

2795 else

2797

2798

2800 return -1;

2801

2802 return 1;

2803}

2804

2805

2806

2807

2808

2809

2810

2811

2812

2813

2814

2815int

2817{

2818 *buffer = NULL;

2820 return -2;

2823 {

2825 return -2;

2826 }

2828}

2829

2830

2831

2832

2833

2834

2835

2836

2837

2838

2839

2840

2841

2842

2843

2844

2845

2846

2847

2848

2849

2850

2851

2852

2853int

2855{

2856 if (!buffer || length <= 0)

2857 return EOF;

2858 *buffer = '\0';

2859

2860 if (length < 3)

2861 return EOF;

2862

2864 return EOF;

2865

2867}

2868

2869

2870

2871

2872

2873

2874

2875

2876

2877

2878

2879

2880

2881

2882

2883

2884

2885

2886

2887

2888

2889

2890

2891

2892

2893

2894

2895

2896

2897

2898

2899

2900int

2902{

2904 return -1;

2905

2907}

2908

2909

2910

2911

2912

2913

2914

2915

2916

2917int

2919{

2921}

2922

2923

2924

2925

2926

2927int

2929{

2931 return 0;

2932 else

2933 return EOF;

2934}

2935

2936

2937

2938

2939

2940

2941

2942

2943

2944

2945

2946

2947

2948int

2950{

2952 return 0;

2953

2955}

2956

2957

2958

2959

2960

2961

2962

2963

2964

2965

2966

2967

2968

2969

2970

2971

2972

2973

2974

2975

2976

2977

2978

2981 int fnid,

2982 int *result_buf,

2983 int *result_len,

2984 int result_is_int,

2986 int nargs)

2987{

2988 *result_len = 0;

2989

2991 return NULL;

2992

2993

2994

2995

2996

2997

3000

3002 {

3004 return NULL;

3005 }

3006

3009 {

3011 return NULL;

3012 }

3013

3015 result_buf, result_len,

3016 result_is_int,

3017 args, nargs);

3018}

3019

3020

3021

3022

3023

3024

3025

3026

3027

3028

3029

3030

3031

3032

3033

3034

3035

3036

3037

3038

3039

3040

3041int

3043{

3045 return 0;

3046

3047

3049 return 1;

3050

3052 {

3054 return 0;

3055 }

3056

3058

3059 return 1;

3060}

3061

3062

3063

3064

3065

3066

3067

3068

3069

3070

3071

3072int

3074{

3076 return 0;

3077

3082 return 1;

3083

3085 {

3088

3090 return 0;

3091

3094 return 0;

3095

3098

3099 break;

3100

3105 }

3106

3107

3109 {

3111 return 0;

3112 }

3113

3116

3117

3119 return 0;

3120 return 1;

3121}

3122

3123

3124

3125

3126

3127

3128

3129

3130

3131

3132

3133

3134

3135

3136

3137

3138

3139

3140

3141void

3143{

3145

3147 return;

3148

3149

3150

3151

3152

3154 return;

3155

3156

3157

3158

3160 return;

3161

3162

3165

3166

3169

3170

3171 prevquery->next = NULL;

3173}

3174

3175

3176

3177

3178

3179static void

3181{

3183 {

3190

3191 return;

3192

3194

3195

3196

3197

3198

3199

3201 {

3203 break;

3204 }

3205 return;

3206

3209

3210 break;

3211 }

3212

3213

3214

3215

3216

3220

3221

3222

3223

3224

3226 {

3228 return;

3229 }

3230

3231

3232

3233

3234

3236

3237

3239

3242 {

3243

3244

3245

3246

3247

3248

3249

3250

3253 {

3256 return;

3257 }

3259 }

3260 else

3261 {

3262

3264 }

3265}

3266

3267

3268

3269

3270

3271int

3273{

3275}

3276

3277

3278

3279

3280

3281int

3283{

3285}

3286

3287

3288

3289

3290

3291

3292

3293static int

3295{

3297

3299 return 0;

3300

3302 {

3304 return 0;

3305 }

3306

3308 {

3312

3314 "internal error: cannot send pipeline while in COPY\n");

3315 return 0;

3321

3322 break;

3323 }

3324

3326 if (entry == NULL)

3327 return 0;

3328

3330 entry->query = NULL;

3331

3332

3335 goto sendFailed;

3336

3337

3338

3339

3340

3341

3342

3343 if (immediate_flush)

3344 {

3346 goto sendFailed;

3347 }

3348 else

3349 {

3351 goto sendFailed;

3352 }

3353

3354

3356

3357 return 1;

3358

3359sendFailed:

3361

3362 return 0;

3363}

3364

3365

3366

3367

3368

3369

3370int

3372{

3374 return 0;

3375

3376

3378 {

3380 return 0;

3381 }

3382

3383

3386 {

3388 return 0;

3389 }

3390

3393 {

3394 return 0;

3395 }

3396

3397

3398

3399

3400

3401

3403 return 0;

3404

3405 return 1;

3406}

3407

3408

3409

3412{

3413 if (!res)

3416}

3417

3418char *

3420{

3422 return libpq_gettext("invalid ExecStatusType code");

3424}

3425

3426char *

3428{

3429 if (!res || !res->errMsg)

3430 return "";

3432}

3433

3434char *

3438{

3440

3441

3442

3443

3444

3445

3446 if (!res ||

3449 return strdup(libpq_gettext("PGresult is not an error result\n"));

3450

3452

3454

3455

3457 {

3459 return strdup(libpq_gettext("out of memory\n"));

3460 }

3461

3462 return workBuf.data;

3463}

3464

3465char *

3467{

3469

3470 if (!res)

3471 return NULL;

3472 for (pfield = res->errFields; pfield != NULL; pfield = pfield->next)

3473 {

3474 if (pfield->code == fieldcode)

3476 }

3477 return NULL;

3478}

3479

3480int

3482{

3483 if (!res)

3484 return 0;

3485 return res->ntups;

3486}

3487

3488int

3490{

3491 if (!res)

3492 return 0;

3494}

3495

3496int

3498{

3499 if (!res)

3500 return 0;

3502}

3503

3504

3505

3506

3507

3508

3509static int

3511{

3512 if (!res)

3513 return false;

3514 if (field_num < 0 || field_num >= res->numAttributes)

3515 {

3517 "column number %d is out of range 0..%d",

3519 return false;

3520 }

3521 return true;

3522}

3523

3524static int

3526 int tup_num, int field_num)

3527{

3528 if (!res)

3529 return false;

3530 if (tup_num < 0 || tup_num >= res->ntups)

3531 {

3533 "row number %d is out of range 0..%d",

3534 tup_num, res->ntups - 1);

3535 return false;

3536 }

3537 if (field_num < 0 || field_num >= res->numAttributes)

3538 {

3540 "column number %d is out of range 0..%d",

3542 return false;

3543 }

3544 return true;

3545}

3546

3547static int

3549{

3550 if (!res)

3551 return false;

3552 if (param_num < 0 || param_num >= res->numParameters)

3553 {

3555 "parameter number %d is out of range 0..%d",

3557 return false;

3558 }

3559

3560 return true;

3561}

3562

3563

3564

3565

3566char *

3568{

3570 return NULL;

3573 else

3574 return NULL;

3575}

3576

3577

3578

3579

3580

3581

3582

3583

3584

3585

3586

3587

3588int

3590{

3591 char *field_case;

3592 bool in_quotes;

3593 bool all_lower = true;

3594 const char *iptr;

3595 char *optr;

3596 int i;

3597

3598 if (!res)

3599 return -1;

3600

3601

3602

3603

3604

3605 if (field_name == NULL ||

3606 field_name[0] == '\0' ||

3608 return -1;

3609

3610

3611

3612

3613

3614 for (iptr = field_name; *iptr; iptr++)

3615 {

3616 char c = *iptr;

3617

3618 if (c == '"' || c != pg_tolower((unsigned char) c))

3619 {

3620 all_lower = false;

3621 break;

3622 }

3623 }

3624

3625 if (all_lower)

3627 if (strcmp(field_name, res->attDescs[i].name) == 0)

3628 return i;

3629

3630

3631

3632

3633

3634

3635

3636

3637 field_case = strdup(field_name);

3638 if (field_case == NULL)

3639 return -1;

3640

3641 in_quotes = false;

3642 optr = field_case;

3643 for (iptr = field_case; *iptr; iptr++)

3644 {

3645 char c = *iptr;

3646

3647 if (in_quotes)

3648 {

3649 if (c == '"')

3650 {

3651 if (iptr[1] == '"')

3652 {

3653

3654 *optr++ = '"';

3655 iptr++;

3656 }

3657 else

3658 in_quotes = false;

3659 }

3660 else

3661 *optr++ = c;

3662 }

3663 else if (c == '"')

3664 in_quotes = true;

3665 else

3666 {

3668 *optr++ = c;

3669 }

3670 }

3671 *optr = '\0';

3672

3674 {

3675 if (strcmp(field_case, res->attDescs[i].name) == 0)

3676 {

3677 free(field_case);

3678 return i;

3679 }

3680 }

3681 free(field_case);

3682 return -1;

3683}

3684

3687{

3692 else

3694}

3695

3696int

3698{

3700 return 0;

3703 else

3704 return 0;

3705}

3706

3707int

3709{

3711 return 0;

3714 else

3715 return 0;

3716}

3717

3720{

3725 else

3727}

3728

3729int

3731{

3733 return 0;

3736 else

3737 return 0;

3738}

3739

3740int

3742{

3744 return 0;

3747 else

3748 return 0;

3749}

3750

3751char *

3753{

3754 if (!res)

3755 return NULL;

3757}

3758

3759

3760

3761

3762

3763

3764char *

3766{

3767

3768

3769

3770

3771 static char buf[24];

3772

3773 size_t len;

3774

3775 if (!res || strncmp(res->cmdStatus, "INSERT ", 7) != 0)

3776 return "";

3777

3778 len = strspn(res->cmdStatus + 7, "0123456789");

3779 if (len > sizeof(buf) - 1)

3780 len = sizeof(buf) - 1;

3783

3784 return buf;

3785}

3786

3787

3788

3789

3790

3791

3794{

3795 char *endptr = NULL;

3796 unsigned long result;

3797

3798 if (!res ||

3799 strncmp(res->cmdStatus, "INSERT ", 7) != 0 ||

3803

3804 result = strtoul(res->cmdStatus + 7, &endptr, 10);

3805

3806 if (!endptr || (*endptr != ' ' && *endptr != '\0'))

3808 else

3809 return (Oid) result;

3810}

3811

3812

3813

3814

3815

3816

3817

3818

3819

3820

3821char *

3823{

3824 char *p,

3825 *c;

3826

3827 if (!res)

3828 return "";

3829

3830 if (strncmp(res->cmdStatus, "INSERT ", 7) == 0)

3831 {

3833

3834 while (*p && *p != ' ')

3835 p++;

3836 if (*p == 0)

3837 goto interpret_error;

3838 p++;

3839 }

3840 else if (strncmp(res->cmdStatus, "SELECT ", 7) == 0 ||

3841 strncmp(res->cmdStatus, "DELETE ", 7) == 0 ||

3842 strncmp(res->cmdStatus, "UPDATE ", 7) == 0)

3844 else if (strncmp(res->cmdStatus, "FETCH ", 6) == 0 ||

3845 strncmp(res->cmdStatus, "MERGE ", 6) == 0)

3847 else if (strncmp(res->cmdStatus, "MOVE ", 5) == 0 ||

3848 strncmp(res->cmdStatus, "COPY ", 5) == 0)

3850 else

3851 return "";

3852

3853

3854 for (c = p; *c; c++)

3855 {

3856 if (!isdigit((unsigned char) *c))

3857 goto interpret_error;

3858 }

3859 if (c == p)

3860 goto interpret_error;

3861

3862 return p;

3863

3864interpret_error:

3866 "could not interpret result from server: %s",

3868 return "";

3869}

3870

3871

3872

3873

3874

3875char *

3877{

3879 return NULL;

3880 return res->tuples[tup_num][field_num].value;

3881}

3882

3883

3884

3885

3886int

3888{

3890 return 0;

3892 return res->tuples[tup_num][field_num].len;

3893 else

3894 return 0;

3895}

3896

3897

3898

3899

3900int

3902{

3904 return 1;

3906 return 1;

3907 else

3908 return 0;

3909}

3910

3911

3912

3913

3914int

3916{

3917 if (!res)

3918 return 0;

3920}

3921

3922

3923

3924

3927{

3932 else

3934}

3935

3936

3937

3938

3939

3940

3941

3942

3943int

3945{

3946 bool barg;

3947

3949 return -1;

3950

3951 barg = (arg ? true : false);

3952

3953

3955 return 0;

3956

3957

3958

3959

3960

3961

3962

3963

3964

3965

3968

3969

3971 return -1;

3972

3974

3975 return 0;

3976}

3977

3978

3979

3980

3981

3982int

3984{

3986 return false;

3988}

3989

3990

3991int

3993{

3994 return true;

3995}

3996

3997

3998

3999int

4001{

4003 return -1;

4005}

4006

4007

4008

4009

4010

4011

4012

4013

4014

4015static int

4017{

4021 return 0;

4022}

4023

4024

4025

4026

4027

4028

4029

4030

4031void

4033{

4035}

4036

4037

4038

4039

4040

4041

4042

4043

4044

4045#undef PQfreeNotify

4047

4048void

4050{

4052}

4053

4054

4055

4056

4057

4058

4059

4060

4061

4062

4063

4064

4065

4066

4067

4068

4069

4070static size_t

4072 char *to, const char *from, size_t length,

4074 int encoding, bool std_strings)

4075{

4076 const char *source = from;

4077 char *target = to;

4079 bool already_complained = false;

4080

4083

4085 {

4087 int charlen;

4088 int i;

4089

4090

4092 {

4093

4095 *target++ = c;

4096

4097 *target++ = c;

4100 continue;

4101 }

4102

4103

4106

4109 {

4110

4111

4112

4113

4114

4115

4116

4117

4118

4119

4120

4121

4122

4123

4124

4125

4126

4127

4128

4129

4130

4131

4132

4133

4134

4135

4138 if (conn && !already_complained)

4139 {

4142 else

4144

4145 already_complained = true;

4146 }

4147

4149 target += 2;

4150

4151

4152

4153

4154

4155

4158 }

4159 else

4160 {

4161

4162 for (i = 0; i < charlen; i++)

4163 {

4164 *target++ = *source++;

4166 }

4167 }

4168 }

4169

4170

4171 *target = '\0';

4172

4173 return target - to;

4174}

4175

4176size_t

4178 char *to, const char *from, size_t length,

4180{

4182 {

4183

4184 *to = '\0';

4187 return 0;

4188 }

4189

4192

4196}

4197

4198size_t

4200{

4204}

4205

4206

4207

4208

4209

4210

4211

4212

4213static char *

4215{

4216 const char *s;

4217 char *result;

4218 char *rp;

4219 int num_quotes = 0;

4220 int num_backslashes = 0;

4222 size_t result_size;

4223 char quote_char = as_ident ? '"' : '\'';

4224 bool validated_mb = false;

4225

4226

4228 return NULL;

4229

4232

4233

4234

4235

4236

4237 s = str;

4239 {

4240 if (*s == quote_char)

4241 ++num_quotes;

4242 else if (*s == '\\')

4243 ++num_backslashes;

4245 {

4246 int charlen;

4247

4248

4251

4253 {

4254

4256 return NULL;

4257 }

4258

4259

4260

4261

4262

4263

4264

4265

4266

4267

4268

4269 if (!validated_mb)

4270 {

4273 {

4275 return NULL;

4276 }

4277 validated_mb = true;

4278 }

4279

4280

4281 s += charlen - 1;

4283 }

4284 }

4285

4286

4287 result_size = input_len + num_quotes + 3;

4288 if (!as_ident && num_backslashes > 0)

4289 result_size += num_backslashes + 2;

4290 result = rp = (char *) malloc(result_size);

4291 if (rp == NULL)

4292 {

4294 return NULL;

4295 }

4296

4297

4298

4299

4300

4301

4302

4303

4304 if (!as_ident && num_backslashes > 0)

4305 {

4306 *rp++ = ' ';

4307 *rp++ = 'E';

4308 }

4309

4310

4311 *rp++ = quote_char;

4312

4313

4314

4315

4316

4317

4318

4319

4320

4321

4322

4323

4324 if (num_quotes == 0 && (num_backslashes == 0 || as_ident))

4325 {

4326 memcpy(rp, str, input_len);

4327 rp += input_len;

4328 }

4329 else

4330 {

4331 s = str;

4333 {

4334 if (*s == quote_char || (!as_ident && *s == '\\'))

4335 {

4336 *rp++ = *s;

4337 *rp++ = *s;

4338 }

4340 *rp++ = *s;

4341 else

4342 {

4344

4345 while (1)

4346 {

4347 *rp++ = *s;

4348 if (--i == 0)

4349 break;

4351 ++s;

4352 }

4353 }

4354 }

4355 }

4356

4357

4358 *rp++ = quote_char;

4359 *rp = '\0';

4360

4361 return result;

4362}

4363

4364char *

4366{

4368}

4369

4370char *

4372{

4374}

4375

4376

4377static const char hextbl[] = "0123456789abcdef";

4378

4380 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,

4381 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,

4382 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,

4383 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1,

4384 -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1,

4385 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,

4386 -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1,

4387 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,

4388};

4389

4390static inline char

4392{

4393 int res = -1;

4394

4395 if (c > 0 && c < 127)

4397

4398 return (char) res;

4399}

4400

4401

4402

4403

4404

4405

4406

4407

4408

4409

4410

4411

4412

4413

4414

4415

4416

4417static unsigned char *

4419 const unsigned char *from, size_t from_length,

4420 size_t *to_length, bool std_strings, bool use_hex)

4421{

4422 const unsigned char *vp;

4423 unsigned char *rp;

4424 unsigned char *result;

4425 size_t i;

4426 size_t len;

4427 size_t bslash_len = (std_strings ? 1 : 2);

4428

4429

4430

4431

4432 len = 1;

4433

4434 if (use_hex)

4435 {

4436 len += bslash_len + 1 + 2 * from_length;

4437 }

4438 else

4439 {

4440 vp = from;

4441 for (i = from_length; i > 0; i--, vp++)

4442 {

4443 if (*vp < 0x20 || *vp > 0x7e)

4444 len += bslash_len + 3;

4445 else if (*vp == '\'')

4446 len += 2;

4447 else if (*vp == '\\')

4448 len += bslash_len + bslash_len;

4449 else

4451 }

4452 }

4453

4454 *to_length = len;

4455 rp = result = (unsigned char *) malloc(len);

4456 if (rp == NULL)

4457 {

4460 return NULL;

4461 }

4462

4463 if (use_hex)

4464 {

4465 if (!std_strings)

4466 *rp++ = '\\';

4467 *rp++ = '\\';

4468 *rp++ = 'x';

4469 }

4470

4471 vp = from;

4472 for (i = from_length; i > 0; i--, vp++)

4473 {

4474 unsigned char c = *vp;

4475

4476 if (use_hex)

4477 {

4478 *rp++ = hextbl[(c >> 4) & 0xF];

4479 *rp++ = hextbl[c & 0xF];

4480 }

4482 {

4483 if (!std_strings)

4484 *rp++ = '\\';

4485 *rp++ = '\\';

4486 *rp++ = (c >> 6) + '0';

4487 *rp++ = ((c >> 3) & 07) + '0';

4488 *rp++ = (c & 07) + '0';

4489 }

4490 else if (c == '\'')

4491 {

4492 *rp++ = '\'';

4493 *rp++ = '\'';

4494 }

4495 else if (c == '\\')

4496 {

4497 if (!std_strings)

4498 {

4499 *rp++ = '\\';

4500 *rp++ = '\\';

4501 }

4502 *rp++ = '\\';

4503 *rp++ = '\\';

4504 }

4505 else

4506 *rp++ = c;

4507 }

4508 *rp = '\0';

4509

4510 return result;

4511}

4512

4513unsigned char *

4515 const unsigned char *from, size_t from_length,

4516 size_t *to_length)

4517{

4519 return NULL;

4520

4523

4527}

4528

4529unsigned char *

4530PQescapeBytea(const unsigned char *from, size_t from_length, size_t *to_length)

4531{

4534 false );

4535}

4536

4537

4538#define ISFIRSTOCTDIGIT(CH) ((CH) >= '0' && (CH) <= '3')

4539#define ISOCTDIGIT(CH) ((CH) >= '0' && (CH) <= '7')

4540#define OCTVAL(CH) ((CH) - '0')

4541

4542

4543

4544

4545

4546

4547

4548

4549

4550

4551

4552

4553

4554unsigned char *

4556{

4557 size_t strtextlen,

4558 buflen;

4559 unsigned char *buffer,

4561 size_t i,

4562 j;

4563

4564 if (strtext == NULL)

4565 return NULL;

4566

4567 strtextlen = strlen((const char *) strtext);

4568

4569 if (strtext[0] == '\\' && strtext[1] == 'x')

4570 {

4571 const unsigned char *s;

4572 unsigned char *p;

4573

4574 buflen = (strtextlen - 2) / 2;

4575

4576 buffer = (unsigned char *) malloc(buflen > 0 ? buflen : 1);

4577 if (buffer == NULL)

4578 return NULL;

4579

4580 s = strtext + 2;

4581 p = buffer;

4582 while (*s)

4583 {

4584 char v1,

4585 v2;

4586

4587

4588

4589

4590

4592 if (!*s || v1 == (char) -1)

4593 continue;

4595 if (v2 != (char) -1)

4596 *p++ = (v1 << 4) | v2;

4597 }

4598

4599 buflen = p - buffer;

4600 }

4601 else

4602 {

4603

4604

4605

4606

4607 buffer = (unsigned char *) malloc(strtextlen + 1);

4608 if (buffer == NULL)

4609 return NULL;

4610

4611 for (i = j = 0; i < strtextlen;)

4612 {

4613 switch (strtext[i])

4614 {

4615 case '\\':

4616 i++;

4617 if (strtext[i] == '\\')

4618 buffer[j++] = strtext[i++];

4619 else

4620 {

4624 {

4625 int byte;

4626

4627 byte = OCTVAL(strtext[i++]);

4628 byte = (byte << 3) + OCTVAL(strtext[i++]);

4629 byte = (byte << 3) + OCTVAL(strtext[i++]);

4630 buffer[j++] = byte;

4631 }

4632 }

4633

4634

4635

4636

4637

4638

4639

4640

4641 break;

4642

4643 default:

4644 buffer[j++] = strtext[i++];

4645 break;

4646 }

4647 }

4648 buflen = j;

4649 }

4650

4651

4652

4654

4655

4657 {

4658 free(buffer);

4659 return NULL;

4660 }

4661

4662 *retbuflen = buflen;

4664}

#define unconstify(underlying_type, expr)

#define IS_HIGHBIT_SET(ch)

#define SQL_STR_DOUBLE(ch, escape_backslash)

int errmsg(const char *fmt,...)

static int PQsendQueryInternal(PGconn *conn, const char *query, bool newQuery)

int PQsendQueryParams(PGconn *conn, const char *command, int nParams, const Oid *paramTypes, const char *const *paramValues, const int *paramLengths, const int *paramFormats, int resultFormat)

int PQsendQueryContinue(PGconn *conn, const char *query)

int PQgetlength(const PGresult *res, int tup_num, int field_num)

int PQsetSingleRowMode(PGconn *conn)

static char get_hex(char c)

int PQbinaryTuples(const PGresult *res)

int PQflush(PGconn *conn)

PGresult * PQcopyResult(const PGresult *src, int flags)

void PQfreemem(void *ptr)

static unsigned char * PQescapeByteaInternal(PGconn *conn, const unsigned char *from, size_t from_length, size_t *to_length, bool std_strings, bool use_hex)

int PQgetline(PGconn *conn, char *buffer, int length)

void * pqResultAlloc(PGresult *res, size_t nBytes, bool isBinary)

static bool canChangeResultMode(PGconn *conn)

static size_t PQescapeStringInternal(PGconn *conn, char *to, const char *from, size_t length, int *error, int encoding, bool std_strings)

Oid PQftype(const PGresult *res, int field_num)

char * PQresultVerboseErrorMessage(const PGresult *res, PGVerbosity verbosity, PGContextVisibility show_context)

PGresult * PQdescribePrepared(PGconn *conn, const char *stmt)

PGresult * PQexecParams(PGconn *conn, const char *command, int nParams, const Oid *paramTypes, const char *const *paramValues, const int *paramLengths, const int *paramFormats, int resultFormat)

int PQexitPipelineMode(PGconn *conn)

PGresult * PQexecPrepared(PGconn *conn, const char *stmtName, int nParams, const char *const *paramValues, const int *paramLengths, const int *paramFormats, int resultFormat)

int PQsendClosePortal(PGconn *conn, const char *portal)

static PGcmdQueueEntry * pqAllocCmdQueueEntry(PGconn *conn)

int PQsetResultAttrs(PGresult *res, int numAttributes, PGresAttDesc *attDescs)

unsigned char * PQunescapeBytea(const unsigned char *strtext, size_t *retbuflen)

void pqSaveMessageField(PGresult *res, char code, const char *value)

static int check_tuple_field_number(const PGresult *res, int tup_num, int field_num)

PGresult * pqPrepareAsyncResult(PGconn *conn)

static void pqSaveWriteError(PGconn *conn)

int PQenterPipelineMode(PGconn *conn)

void pqCommandQueueAdvance(PGconn *conn, bool isReadyForQuery, bool gotSync)

void pqSetResultError(PGresult *res, PQExpBuffer errorMessage, int offset)

size_t PQescapeStringConn(PGconn *conn, char *to, const char *from, size_t length, int *error)

void pqSaveErrorResult(PGconn *conn)

PGresult * PQclosePrepared(PGconn *conn, const char *stmt)

char *const pgresStatus[]

char * PQgetvalue(const PGresult *res, int tup_num, int field_num)

#define PGRESULT_DATA_BLOCKSIZE

PGresult * PQclosePortal(PGconn *conn, const char *portal)

static int pqPipelineSyncInternal(PGconn *conn, bool immediate_flush)

PGresult * PQgetResult(PGconn *conn)

ExecStatusType PQresultStatus(const PGresult *res)

Oid PQparamtype(const PGresult *res, int param_num)

static int check_param_number(const PGresult *res, int param_num)

int pqRowProcessor(PGconn *conn, const char **errmsgp)

int PQnparams(const PGresult *res)

void PQclear(PGresult *res)

int PQsendClosePrepared(PGconn *conn, const char *stmt)

char * PQcmdTuples(PGresult *res)

static PGresult * PQexecFinish(PGconn *conn)

int PQfformat(const PGresult *res, int field_num)

static void pqAppendCmdQueueEntry(PGconn *conn, PGcmdQueueEntry *entry)

static int PQsendQueryGuts(PGconn *conn, const char *command, const char *stmtName, int nParams, const Oid *paramTypes, const char *const *paramValues, const int *paramLengths, const int *paramFormats, int resultFormat)

int PQendcopy(PGconn *conn)

static int pqPipelineFlush(PGconn *conn)

int PQputCopyEnd(PGconn *conn, const char *errormsg)

static int PQsendTypedCommand(PGconn *conn, char command, char type, const char *target)

int PQsendPipelineSync(PGconn *conn)

int PQntuples(const PGresult *res)

int PQputnbytes(PGconn *conn, const char *buffer, int nbytes)

int PQputline(PGconn *conn, const char *string)

int PQgetlineAsync(PGconn *conn, char *buffer, int bufsize)

static const PGresult OOM_result

#define PGRESULT_BLOCK_OVERHEAD

int PQputCopyData(PGconn *conn, const char *buffer, int nbytes)

static PGresult * getCopyResult(PGconn *conn, ExecStatusType copytype)

PGresult * PQmakeEmptyPGresult(PGconn *conn, ExecStatusType status)

static PGEvent * dupEvents(PGEvent *events, int count, size_t *memSize)

PGresult * PQprepare(PGconn *conn, const char *stmtName, const char *query, int nParams, const Oid *paramTypes)

static bool static_std_strings

char * PQresultErrorMessage(const PGresult *res)

void pqInternalNotice(const PGNoticeHooks *hooks, const char *fmt,...)

int PQsendDescribePrepared(PGconn *conn, const char *stmt)

char * PQfname(const PGresult *res, int field_num)

static const char hextbl[]

static bool PQexecStart(PGconn *conn)

size_t PQescapeString(char *to, const char *from, size_t length)

int PQconsumeInput(PGconn *conn)

static char * PQescapeInternal(PGconn *conn, const char *str, size_t len, bool as_ident)

#define ISFIRSTOCTDIGIT(CH)

static void parseInput(PGconn *conn)

Oid PQftable(const PGresult *res, int field_num)

int PQfnumber(const PGresult *res, const char *field_name)

unsigned char * PQescapeBytea(const unsigned char *from, size_t from_length, size_t *to_length)

void pqSaveParameterStatus(PGconn *conn, const char *name, const char *value)

int PQsetnonblocking(PGconn *conn, int arg)

char * PQescapeLiteral(PGconn *conn, const char *str, size_t len)

PGresult * PQfn(PGconn *conn, int fnid, int *result_buf, int *result_len, int result_is_int, const PQArgBlock *args, int nargs)

int PQsendPrepare(PGconn *conn, const char *stmtName, const char *query, int nParams, const Oid *paramTypes)

#define PGRESULT_SEP_ALLOC_THRESHOLD

PGresult * PQdescribePortal(PGconn *conn, const char *portal)

int PQfmod(const PGresult *res, int field_num)

void pqClearAsyncResult(PGconn *conn)

int PQgetisnull(const PGresult *res, int tup_num, int field_num)

int PQftablecol(const PGresult *res, int field_num)

int PQsetChunkedRowsMode(PGconn *conn, int chunkSize)

static int static_client_encoding

char * PQresultErrorField(const PGresult *res, int fieldcode)

int PQsetvalue(PGresult *res, int tup_num, int field_num, char *value, int len)

int PQsendQuery(PGconn *conn, const char *query)

char * PQcmdStatus(PGresult *res)

int PQpipelineSync(PGconn *conn)

char * PQoidStatus(const PGresult *res)

int PQsendDescribePortal(PGconn *conn, const char *portal)

char * PQresStatus(ExecStatusType status)

size_t PQresultMemorySize(const PGresult *res)

void * PQresultAlloc(PGresult *res, size_t nBytes)

int PQisBusy(PGconn *conn)

PGresult * PQexec(PGconn *conn, const char *query)

unsigned char * PQescapeByteaConn(PGconn *conn, const unsigned char *from, size_t from_length, size_t *to_length)

int PQsendQueryPrepared(PGconn *conn, const char *stmtName, int nParams, const char *const *paramValues, const int *paramLengths, const int *paramFormats, int resultFormat)

static void pqPipelineProcessQueue(PGconn *conn)

char * PQescapeIdentifier(PGconn *conn, const char *str, size_t len)

int PQsendFlushRequest(PGconn *conn)

int PQisnonblocking(const PGconn *conn)

char * pqResultStrdup(PGresult *res, const char *str)

Oid PQoidValue(const PGresult *res)

static bool pqAddTuple(PGresult *res, PGresAttValue *tup, const char **errmsgp)

#define PGRESULT_ALIGN_BOUNDARY

int PQnfields(const PGresult *res)

static int check_field_number(const PGresult *res, int field_num)

int PQfsize(const PGresult *res, int field_num)

PGnotify * PQnotifies(PGconn *conn)

static bool PQsendQueryStart(PGconn *conn, bool newQuery)

static const int8 hexlookup[128]

int PQgetCopyData(PGconn *conn, char **buffer, int async)

static void pqRecycleCmdQueueEntry(PGconn *conn, PGcmdQueueEntry *entry)

void PQfreeNotify(PGnotify *notify)

int pqPutc(char c, PGconn *conn)

int pqReadData(PGconn *conn)

int pqPutInt(int value, size_t bytes, PGconn *conn)

int pqCheckOutBufferSpace(size_t bytes_needed, PGconn *conn)

int pqFlush(PGconn *conn)

int pqPutMsgStart(char msg_type, PGconn *conn)

int pqWait(int forRead, int forWrite, PGconn *conn)

int pqPutnchar(const void *s, size_t len, PGconn *conn)

int pqPuts(const char *s, PGconn *conn)

int pqPutMsgEnd(PGconn *conn)

void pqBuildErrorMessage3(PQExpBuffer msg, const PGresult *res, PGVerbosity verbosity, PGContextVisibility show_context)

void pqParseInput3(PGconn *conn)

int pqEndcopy3(PGconn *conn)

PGresult * pqFunctionCall3(PGconn *conn, Oid fnid, int *result_buf, int *actual_result_len, int result_is_int, const PQArgBlock *args, int nargs)

int pqGetlineAsync3(PGconn *conn, char *buffer, int bufsize)

int pqGetCopyData3(PGconn *conn, char **buffer, int async)

int pqGetline3(PGconn *conn, char *s, int maxlen)

Assert(PointerIsAligned(start, uint64))

if(TABLE==NULL||TABLE_index==NULL)

int PQfireResultCreateEvents(PGconn *conn, PGresult *res)

#define PG_COPYRES_TUPLES

struct pg_result PGresult

#define PG_COPYRES_EVENTS

#define PG_COPYRES_NOTICEHOOKS

#define PQ_QUERY_PARAM_MAX_LIMIT

struct pgParameterStatus pgParameterStatus

#define pqClearConnErrorState(conn)

union pgresult_data PGresult_data

#define pqIsnonblocking(conn)

#define OUTBUFFER_THRESHOLD

#define pgHavePendingResult(conn)

void libpq_append_conn_error(PGconn *conn, const char *fmt,...)

static rewind_source * source

#define pg_char_to_encoding

unsigned char pg_tolower(unsigned char ch)

size_t strnlen(const char *str, size_t maxlen)

#define PG_DIAG_SEVERITY_NONLOCALIZED

#define PG_DIAG_MESSAGE_PRIMARY

void initPQExpBuffer(PQExpBuffer str)

void appendPQExpBufferStr(PQExpBuffer str, const char *data)

void termPQExpBuffer(PQExpBuffer str)

#define PQExpBufferBroken(str)

#define PQExpBufferDataBroken(buf)

PQnoticeReceiver noticeRec

PQnoticeProcessor noticeProc

struct PGcmdQueueEntry * next

struct pgMessageField * next

char contents[FLEXIBLE_ARRAY_MEMBER]

struct pgParameterStatus * next

PGTernaryBool in_hot_standby

PGcmdQueueEntry * cmd_queue_recycle

PGcmdQueueEntry * cmd_queue_tail

PGTernaryBool default_transaction_read_only

pgParameterStatus * pstatus

PQExpBufferData errorMessage

PGAsyncStatusType asyncStatus

int scram_sha_256_iterations

PGpipelineStatus pipelineStatus

PGNoticeHooks noticeHooks

PGcmdQueueEntry * cmd_queue_head

PGNoticeHooks noticeHooks

char cmdStatus[CMDSTATUS_LEN]

PGMessageField * errFields

PGresParamDesc * paramDescs

ExecStatusType resultStatus

static StringInfoData tmpbuf

void pg_encoding_set_invalid(int encoding, char *dst)

int pg_encoding_mblen_or_incomplete(int encoding, const char *mbstr, size_t remaining)

int pg_encoding_verifymbstr(int encoding, const char *mbstr, int len)

int pg_encoding_mblen(int encoding, const char *mbstr)

int pg_encoding_verifymbchar(int encoding, const char *mbstr, int len)