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
|
/*
+----------------------------------------------------------------------+
| PHP HTML Embedded Scripting Language Version 3.0 |
+----------------------------------------------------------------------+
| Copyright (c) 1997,1998 PHP Development Team (See Credits file) |
+----------------------------------------------------------------------+
| This program is free software; you can redistribute it and/or modify |
| it under the terms of one of the following licenses: |
| |
| A) the GNU General Public License as published by the Free Software |
| Foundation; either version 2 of the License, or (at your option) |
| any later version. |
| |
| B) the PHP License as published by the PHP Development Team and |
| included in the distribution in the file: LICENSE |
| |
| This program 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 General Public License for more details. |
| |
| You should have received a copy of both licenses referred to here. |
| If you did not, or have any questions about PHP licensing, please |
| contact core@php.net. |
+----------------------------------------------------------------------+
| Authors: Zeev Suraski <bourbon@netvision.net.il> |
| Jouni Ahto <jah@cultnet.fi> (large object interface) |
+----------------------------------------------------------------------+
*/
/* $Id: pgsql.c,v 1.62 1998/05/21 23:57:34 zeev Exp $ */
#include <stdlib.h>
#ifndef MSVC5
#include "config.h"
#endif
#include "php.h"
#include "internal_functions.h"
#include "php3_pgsql.h"
#if HAVE_PGSQL
#include "php3_list.h"
function_entry pgsql_functions[] = {
{"pg_connect", php3_pgsql_connect, NULL},
{"pg_pconnect", php3_pgsql_pconnect, NULL},
{"pg_close", php3_pgsql_close, NULL},
{"pg_cmdtuples", php3_pgsql_cmdtuples, NULL},
{"pg_dbname", php3_pgsql_dbname, NULL},
{"pg_errormessage", php3_pgsql_error_message, NULL},
{"pg_options", php3_pgsql_options, NULL},
{"pg_port", php3_pgsql_port, NULL},
{"pg_tty", php3_pgsql_tty, NULL},
{"pg_host", php3_pgsql_host, NULL},
{"pg_exec", php3_pgsql_exec, NULL},
{"pg_numrows", php3_pgsql_num_rows, NULL},
{"pg_numfields", php3_pgsql_num_fields, NULL},
{"pg_fieldname", php3_pgsql_field_name, NULL},
{"pg_fieldsize", php3_pgsql_field_size, NULL},
{"pg_fieldtype", php3_pgsql_field_type, NULL},
{"pg_fieldnum", php3_pgsql_field_number, NULL},
{"pg_result", php3_pgsql_result, NULL},
{"pg_fieldprtlen", php3_pgsql_data_length, NULL},
{"pg_fieldisnull", php3_pgsql_data_isnull, NULL},
{"pg_freeresult", php3_pgsql_free_result, NULL},
{"pg_getlastoid", php3_pgsql_last_oid, NULL},
{"pg_locreate", php3_pgsql_lo_create, NULL},
{"pg_lounlink", php3_pgsql_lo_unlink, NULL},
{"pg_loopen", php3_pgsql_lo_open, NULL},
{"pg_loclose", php3_pgsql_lo_close, NULL},
{"pg_loread", php3_pgsql_lo_read, NULL},
{"pg_lowrite", php3_pgsql_lo_write, NULL},
{"pg_loreadall", php3_pgsql_lo_readall, NULL},
{NULL, NULL, NULL}
};
php3_module_entry pgsql_module_entry = {
"PostgreSQL", pgsql_functions, php3_minit_pgsql, NULL, php3_rinit_pgsql, NULL, NULL, STANDARD_MODULE_PROPERTIES
};
#if COMPILE_DL
php3_module_entry *get_module() { return &pgsql_module_entry; }
#endif
extern int php3_header(void);
THREAD_LS pgsql_module php3_pgsql_module;
static void _close_pgsql_link(PGconn *link)
{
PQfinish(link);
php3_pgsql_module.num_links--;
}
static void _close_pgsql_plink(PGconn *link)
{
PQfinish(link);
php3_pgsql_module.num_persistent--;
php3_pgsql_module.num_links--;
}
static void _free_ptr(pgLofp *lofp)
{
efree(lofp);
}
int php3_minit_pgsql(INIT_FUNC_ARGS)
{
if (cfg_get_long("pgsql.allow_persistent",&php3_pgsql_module.allow_persistent)==FAILURE) {
php3_pgsql_module.allow_persistent=1;
}
if (cfg_get_long("pgsql.max_persistent",&php3_pgsql_module.max_persistent)==FAILURE) {
php3_pgsql_module.max_persistent=-1;
}
if (cfg_get_long("pgsql.max_links",&php3_pgsql_module.max_links)==FAILURE) {
php3_pgsql_module.max_links=-1;
}
php3_pgsql_module.num_persistent=0;
php3_pgsql_module.le_link = register_list_destructors(_close_pgsql_link,NULL);
php3_pgsql_module.le_plink = register_list_destructors(NULL,_close_pgsql_plink);
php3_pgsql_module.le_result = register_list_destructors(PQclear,NULL);
php3_pgsql_module.le_lofp = register_list_destructors(_free_ptr,NULL);
php3_pgsql_module.le_string = register_list_destructors(_free_ptr,NULL);
return SUCCESS;
}
int php3_rinit_pgsql(INIT_FUNC_ARGS)
{
php3_pgsql_module.default_link=-1;
php3_pgsql_module.num_links = php3_pgsql_module.num_persistent;
return SUCCESS;
}
void php3_pgsql_do_connect(INTERNAL_FUNCTION_PARAMETERS,int persistent)
{
char *host=NULL,*port=NULL,*options=NULL,*tty=NULL,*dbname=NULL,*connstring=NULL;
char *hashed_details;
int hashed_details_length;
PGconn *pgsql;
switch(ARG_COUNT(ht)) {
case 1: { /* new style, using connection string */
pval *yyconnstring;
if (getParameters(ht, 1, &yyconnstring) == FAILURE) {
RETURN_FALSE;
}
convert_to_string(yyconnstring);
connstring = yyconnstring->value.str.val;
hashed_details_length = yyconnstring->value.str.len+5+1;
hashed_details = (char *) emalloc(hashed_details_length+1);
sprintf(hashed_details,"pgsql_%s",connstring); /* SAFE */
}
break;
case 3: { /* host, port, dbname */
pval *yyhost, *yyport, *yydbname;
if (getParameters(ht, 3, &yyhost, &yyport, &yydbname) == FAILURE) {
RETURN_FALSE;
}
convert_to_string(yyhost);
convert_to_string(yyport);
convert_to_string(yydbname);
host = yyhost->value.str.val;
port = yyport->value.str.val;
dbname = yydbname->value.str.val;
options=tty=NULL;
hashed_details_length = yyhost->value.str.len+yyport->value.str.len+yydbname->value.str.len+5+5;
hashed_details = (char *) emalloc(hashed_details_length+1);
sprintf(hashed_details,"pgsql_%s_%s___%s",host,port,dbname); /* SAFE */
}
break;
case 4: { /* host, port, options, dbname */
pval *yyhost, *yyport, *yyoptions, *yydbname;
if (getParameters(ht, 4, &yyhost, &yyport, &yyoptions, &yydbname) == FAILURE) {
RETURN_FALSE;
}
convert_to_string(yyhost);
convert_to_string(yyport);
convert_to_string(yyoptions);
convert_to_string(yydbname);
host = yyhost->value.str.val;
port = yyport->value.str.val;
options = yyoptions->value.str.val;
dbname = yydbname->value.str.val;
tty=NULL;
hashed_details_length = yyhost->value.str.len+yyport->value.str.len+yyoptions->value.str.len+yydbname->value.str.len+5+5;
hashed_details = (char *) emalloc(hashed_details_length+1);
sprintf(hashed_details,"pgsql_%s_%s_%s__%s",host,port,options,dbname); /* SAFE */
}
break;
case 5: { /* host, port, options, tty, dbname */
pval *yyhost, *yyport, *yyoptions, *yytty, *yydbname;
if (getParameters(ht, 5, &yyhost, &yyport, &yyoptions, &yytty, &yydbname) == FAILURE) {
RETURN_FALSE;
}
convert_to_string(yyhost);
convert_to_string(yyport);
convert_to_string(yyoptions);
convert_to_string(yytty);
convert_to_string(yydbname);
host = yyhost->value.str.val;
port = yyport->value.str.val;
options = yyoptions->value.str.val;
tty = yytty->value.str.val;
dbname = yydbname->value.str.val;
hashed_details_length = yyhost->value.str.len+yyport->value.str.len+yyoptions->value.str.len+yytty->value.str.len+yydbname->value.str.len+5+5;
hashed_details = (char *) emalloc(hashed_details_length+1);
sprintf(hashed_details,"pgsql_%s_%s_%s_%s_%s",host,port,options,tty,dbname); /* SAFE */
}
break;
default:
WRONG_PARAM_COUNT;
break;
}
if (persistent) {
list_entry *le;
/* try to find if we already have this link in our persistent list */
if (hash_find(plist, hashed_details, hashed_details_length+1, (void **) &le)==FAILURE) { /* we don't */
list_entry new_le;
if (php3_pgsql_module.max_links!=-1 && php3_pgsql_module.num_links>=php3_pgsql_module.max_links) {
php3_error(E_WARNING,"PostgresSQL: Too many open links (%d)",php3_pgsql_module.num_links);
efree(hashed_details);
RETURN_FALSE;
}
if (php3_pgsql_module.max_persistent!=-1 && php3_pgsql_module.num_persistent>=php3_pgsql_module.max_persistent) {
php3_error(E_WARNING,"PostgresSQL: Too many open persistent links (%d)",php3_pgsql_module.num_persistent);
efree(hashed_details);
RETURN_FALSE;
}
/* create the link */
if (connstring) {
pgsql=PQconnectdb(connstring);
} else {
pgsql=PQsetdb(host,port,options,tty,dbname);
}
if (pgsql==NULL || PQstatus(pgsql)==CONNECTION_BAD) {
php3_error(E_WARNING,"Unable to connect to PostgresSQL server: %s",PQerrorMessage(pgsql));
efree(hashed_details);
RETURN_FALSE;
}
/* hash it up */
new_le.type = php3_pgsql_module.le_plink;
new_le.ptr = pgsql;
if (hash_update(plist, hashed_details, hashed_details_length+1, (void *) &new_le, sizeof(list_entry), NULL)==FAILURE) {
efree(hashed_details);
RETURN_FALSE;
}
php3_pgsql_module.num_links++;
php3_pgsql_module.num_persistent++;
} else { /* we do */
if (le->type != php3_pgsql_module.le_plink) {
RETURN_FALSE;
}
/* ensure that the link did not die */
if (PQstatus(le->ptr)==CONNECTION_BAD) { /* the link died */
if (connstring) {
le->ptr=PQconnectdb(connstring);
} else {
le->ptr=PQsetdb(host,port,options,tty,dbname);
}
if (le->ptr==NULL || PQstatus(le->ptr)==CONNECTION_BAD) {
php3_error(E_WARNING,"PostgresSQL link lost, unable to reconnect");
hash_del(plist,hashed_details,hashed_details_length+1);
efree(hashed_details);
RETURN_FALSE;
}
}
pgsql = (PGconn *) le->ptr;
}
return_value->value.lval = php3_list_insert(pgsql,php3_pgsql_module.le_plink);
return_value->type = IS_LONG;
} else {
list_entry *index_ptr,new_index_ptr;
/* first we check the hash for the hashed_details key. if it exists,
* it should point us to the right offset where the actual pgsql link sits.
* if it doesn't, open a new pgsql link, add it to the resource list,
* and add a pointer to it with hashed_details as the key.
*/
if (hash_find(list,hashed_details,hashed_details_length+1,(void **) &index_ptr)==SUCCESS) {
int type,link;
void *ptr;
if (index_ptr->type != le_index_ptr) {
RETURN_FALSE;
}
link = (int) index_ptr->ptr;
ptr = php3_list_find(link,&type); /* check if the link is still there */
if (ptr && (type==php3_pgsql_module.le_link || type==php3_pgsql_module.le_plink)) {
return_value->value.lval = php3_pgsql_module.default_link = link;
return_value->type = IS_LONG;
efree(hashed_details);
return;
} else {
hash_del(list,hashed_details,hashed_details_length+1);
}
}
if (php3_pgsql_module.max_links!=-1 && php3_pgsql_module.num_links>=php3_pgsql_module.max_links) {
php3_error(E_WARNING,"PostgresSQL: Too many open links (%d)",php3_pgsql_module.num_links);
efree(hashed_details);
RETURN_FALSE;
}
if (connstring) {
pgsql=PQconnectdb(connstring);
} else {
pgsql=PQsetdb(host,port,options,tty,dbname);
}
if (pgsql==NULL || PQstatus(pgsql)==CONNECTION_BAD) {
php3_error(E_WARNING,"Unable to connect to PostgresSQL server: %s",PQerrorMessage(pgsql));
efree(hashed_details);
RETURN_FALSE;
}
/* add it to the list */
return_value->value.lval = php3_list_insert(pgsql,php3_pgsql_module.le_link);
return_value->type = IS_LONG;
/* add it to the hash */
new_index_ptr.ptr = (void *) return_value->value.lval;
new_index_ptr.type = le_index_ptr;
if (hash_update(list,hashed_details,hashed_details_length+1,(void *) &new_index_ptr, sizeof(list_entry), NULL)==FAILURE) {
efree(hashed_details);
RETURN_FALSE;
}
php3_pgsql_module.num_links++;
}
efree(hashed_details);
php3_pgsql_module.default_link=return_value->value.lval;
}
int php3_pgsql_get_default_link(INTERNAL_FUNCTION_PARAMETERS)
{
if (php3_pgsql_module.default_link==-1) { /* no link opened yet, implicitly open one */
HashTable tmp;
hash_init(&tmp,0,NULL,NULL,0);
php3_pgsql_do_connect(&tmp,return_value,list,plist,0);
hash_destroy(&tmp);
}
return php3_pgsql_module.default_link;
}
void php3_pgsql_connect(INTERNAL_FUNCTION_PARAMETERS)
{
php3_pgsql_do_connect(INTERNAL_FUNCTION_PARAM_PASSTHRU,0);
}
void php3_pgsql_pconnect(INTERNAL_FUNCTION_PARAMETERS)
{
php3_pgsql_do_connect(INTERNAL_FUNCTION_PARAM_PASSTHRU,1);
}
void php3_pgsql_close(INTERNAL_FUNCTION_PARAMETERS)
{
pval *pgsql_link;
int id,type;
PGconn *pgsql;
switch (ARG_COUNT(ht)) {
case 0:
id = php3_pgsql_module.default_link;
break;
case 1:
if (getParameters(ht, 1, &pgsql_link)==FAILURE) {
RETURN_FALSE;
}
convert_to_long(pgsql_link);
id = pgsql_link->value.lval;
break;
default:
WRONG_PARAM_COUNT;
break;
}
pgsql = (PGconn *) php3_list_find(id,&type);
if (type!=php3_pgsql_module.le_link && type!=php3_pgsql_module.le_plink) {
php3_error(E_WARNING,"%d is not a PostgresSQL link index",id);
RETURN_FALSE;
}
php3_list_delete(pgsql_link->value.lval);
RETURN_TRUE;
}
#define PHP3_PG_DBNAME 1
#define PHP3_PG_ERROR_MESSAGE 2
#define PHP3_PG_OPTIONS 3
#define PHP3_PG_PORT 4
#define PHP3_PG_TTY 5
#define PHP3_PG_HOST 6
void php3_pgsql_get_link_info(INTERNAL_FUNCTION_PARAMETERS, int entry_type)
{
pval *pgsql_link;
int id,type;
PGconn *pgsql;
switch(ARG_COUNT(ht)) {
case 0:
id = php3_pgsql_module.default_link;
break;
case 1:
if (getParameters(ht, 1, &pgsql_link)==FAILURE) {
RETURN_FALSE;
}
convert_to_long(pgsql_link);
id = pgsql_link->value.lval;
break;
default:
WRONG_PARAM_COUNT;
break;
}
pgsql = (PGconn *) php3_list_find(id,&type);
if (type!=php3_pgsql_module.le_link && type!=php3_pgsql_module.le_plink) {
php3_error(E_WARNING,"%d is not a PostgresSQL link index",id);
RETURN_FALSE;
}
switch(entry_type) {
case PHP3_PG_DBNAME:
return_value->value.str.val = PQdb(pgsql);
break;
case PHP3_PG_ERROR_MESSAGE:
return_value->value.str.val = PQerrorMessage(pgsql);
break;
case PHP3_PG_OPTIONS:
return_value->value.str.val = PQoptions(pgsql);
break;
case PHP3_PG_PORT:
return_value->value.str.val = PQport(pgsql);
break;
case PHP3_PG_TTY:
return_value->value.str.val = PQtty(pgsql);
break;
case PHP3_PG_HOST:
return_value->value.str.val = PQhost(pgsql);
break;
default:
RETURN_FALSE;
}
return_value->value.str.len = strlen(return_value->value.str.val);
return_value->value.str.val = (char *) estrdup(return_value->value.str.val);
return_value->type = IS_STRING;
}
void php3_pgsql_dbname(INTERNAL_FUNCTION_PARAMETERS)
{
php3_pgsql_get_link_info(INTERNAL_FUNCTION_PARAM_PASSTHRU,PHP3_PG_DBNAME);
}
void php3_pgsql_error_message(INTERNAL_FUNCTION_PARAMETERS)
{
php3_pgsql_get_link_info(INTERNAL_FUNCTION_PARAM_PASSTHRU,PHP3_PG_ERROR_MESSAGE);
}
void php3_pgsql_options(INTERNAL_FUNCTION_PARAMETERS)
{
php3_pgsql_get_link_info(INTERNAL_FUNCTION_PARAM_PASSTHRU,PHP3_PG_OPTIONS);
}
void php3_pgsql_port(INTERNAL_FUNCTION_PARAMETERS)
{
php3_pgsql_get_link_info(INTERNAL_FUNCTION_PARAM_PASSTHRU,PHP3_PG_PORT);
}
void php3_pgsql_tty(INTERNAL_FUNCTION_PARAMETERS)
{
php3_pgsql_get_link_info(INTERNAL_FUNCTION_PARAM_PASSTHRU,PHP3_PG_TTY);
}
void php3_pgsql_host(INTERNAL_FUNCTION_PARAMETERS)
{
php3_pgsql_get_link_info(INTERNAL_FUNCTION_PARAM_PASSTHRU,PHP3_PG_HOST);
}
void php3_pgsql_exec(INTERNAL_FUNCTION_PARAMETERS)
{
pval *query,*pgsql_link;
int id,type;
PGconn *pgsql;
PGresult *pgsql_result;
ExecStatusType status;
switch(ARG_COUNT(ht)) {
case 1:
if (getParameters(ht, 1, &query)==FAILURE) {
RETURN_FALSE;
}
id = php3_pgsql_module.default_link;
break;
case 2:
if (getParameters(ht, 2, &pgsql_link, &query)==FAILURE) {
RETURN_FALSE;
}
convert_to_long(pgsql_link);
id = pgsql_link->value.lval;
break;
default:
WRONG_PARAM_COUNT;
break;
}
pgsql = (PGconn *) php3_list_find(id,&type);
if (type!=php3_pgsql_module.le_link && type!=php3_pgsql_module.le_plink) {
php3_error(E_WARNING,"%d is not a PostgresSQL link index",id);
RETURN_FALSE;
}
convert_to_string(query);
pgsql_result=PQexec(pgsql,query->value.str.val);
if (pgsql_result) {
status = PQresultStatus(pgsql_result);
} else {
status = (ExecStatusType) PQstatus(pgsql);
}
switch (status) {
case PGRES_EMPTY_QUERY:
case PGRES_BAD_RESPONSE:
case PGRES_NONFATAL_ERROR:
case PGRES_FATAL_ERROR:
php3_error(E_WARNING,"PostgresSQL query failed: %s",PQerrorMessage(pgsql));
RETURN_FALSE;
break;
case PGRES_COMMAND_OK: /* successful command that did not return rows */
default:
if (pgsql_result) {
return_value->value.lval = php3_list_insert(pgsql_result,php3_pgsql_module.le_result);
return_value->type = IS_LONG;
} else {
RETURN_FALSE;
}
break;
}
}
#define PHP3_PG_NUM_ROWS 1
#define PHP3_PG_NUM_FIELDS 2
#define PHP3_PG_CMD_TUPLES 3
void php3_pgsql_get_result_info(INTERNAL_FUNCTION_PARAMETERS, int entry_type)
{
pval *result;
PGresult *pgsql_result;
int type;
if (ARG_COUNT(ht)!=1 || getParameters(ht, 1, &result)==FAILURE) {
WRONG_PARAM_COUNT;
}
convert_to_long(result);
pgsql_result = (PGresult *) php3_list_find(result->value.lval,&type);
if (type!=php3_pgsql_module.le_result) {
php3_error(E_WARNING,"%d is not a PostgresSQL result index",result->value.lval);
RETURN_FALSE;
}
switch (entry_type) {
case PHP3_PG_NUM_ROWS:
return_value->value.lval = PQntuples(pgsql_result);
break;
case PHP3_PG_NUM_FIELDS:
return_value->value.lval = PQnfields(pgsql_result);
break;
case PHP3_PG_CMD_TUPLES:
#if HAVE_PQCMDTUPLES
return_value->value.lval = atoi(PQcmdTuples(pgsql_result));
#else
php3_error(E_WARNING,"This compilation does not support pg_cmdtuples()");
return_value->value.lval = 0;
#endif
break;
default:
RETURN_FALSE;
}
return_value->type = IS_LONG;
}
void php3_pgsql_num_rows(INTERNAL_FUNCTION_PARAMETERS)
{
php3_pgsql_get_result_info(INTERNAL_FUNCTION_PARAM_PASSTHRU,PHP3_PG_NUM_ROWS);
}
void php3_pgsql_num_fields(INTERNAL_FUNCTION_PARAMETERS)
{
php3_pgsql_get_result_info(INTERNAL_FUNCTION_PARAM_PASSTHRU,PHP3_PG_NUM_FIELDS);
}
void php3_pgsql_cmdtuples(INTERNAL_FUNCTION_PARAMETERS)
{
php3_pgsql_get_result_info(INTERNAL_FUNCTION_PARAM_PASSTHRU,PHP3_PG_CMD_TUPLES);
}
char *get_field_name(PGconn *pgsql, Oid oid, HashTable *list)
{
PGresult *result;
char hashed_oid_key[32];
list_entry *field_type;
char *ret=NULL;
/* try to lookup the type in the resource list */
snprintf(hashed_oid_key,31,"pgsql_oid_%d",(int) oid);
hashed_oid_key[31]=0;
if (hash_find(list,hashed_oid_key,strlen(hashed_oid_key)+1,(void **) &field_type)==SUCCESS) {
ret = estrdup((char *)field_type->ptr);
} else { /* hash all oid's */
int i,num_rows;
int oid_offset,name_offset;
char *tmp_oid, *tmp_name;
list_entry new_oid_entry;
if ((result=PQexec(pgsql,"select oid,typname from pg_type"))==NULL) {
return empty_string;
}
num_rows=PQntuples(result);
oid_offset = PQfnumber(result,"oid");
name_offset = PQfnumber(result,"typname");
for (i=0; i<num_rows; i++) {
if ((tmp_oid=PQgetvalue(result,i,oid_offset))==NULL) {
continue;
}
snprintf(hashed_oid_key,31,"pgsql_oid_%s",tmp_oid);
if ((tmp_name=PQgetvalue(result,i,name_offset))==NULL) {
continue;
}
new_oid_entry.type = php3_pgsql_module.le_string;
new_oid_entry.ptr = estrdup(tmp_name);
hash_update(list,hashed_oid_key,strlen(hashed_oid_key)+1,(void *) &new_oid_entry, sizeof(list_entry), NULL);
if (!ret && atoi(tmp_oid)==oid) {
ret = estrdup(tmp_name);
}
}
}
return ret;
}
#define PHP3_PG_FIELD_NAME 1
#define PHP3_PG_FIELD_SIZE 2
#define PHP3_PG_FIELD_TYPE 3
void php3_pgsql_get_field_info(INTERNAL_FUNCTION_PARAMETERS, int entry_type)
{
pval *result,*field;
PGresult *pgsql_result;
int type;
if (ARG_COUNT(ht)!=2 || getParameters(ht, 2, &result, &field)==FAILURE) {
WRONG_PARAM_COUNT;
}
convert_to_long(result);
pgsql_result = (PGresult *) php3_list_find(result->value.lval,&type);
if (type!=php3_pgsql_module.le_result) {
php3_error(E_WARNING,"%d is not a PostgresSQL result index",result->value.lval);
RETURN_FALSE;
}
convert_to_long(field);
if (field->value.lval<0 || field->value.lval>=PQnfields(pgsql_result)) {
php3_error(E_WARNING,"Bad field offset specified");
RETURN_FALSE;
}
switch (entry_type) {
case PHP3_PG_FIELD_NAME:
return_value->value.str.val = PQfname(pgsql_result,field->value.lval);
return_value->value.str.len = strlen(return_value->value.str.val);
return_value->value.str.val = estrndup(return_value->value.str.val,return_value->value.str.len);
return_value->type = IS_STRING;
break;
case PHP3_PG_FIELD_SIZE:
return_value->value.lval = PQfsize(pgsql_result,field->value.lval);
return_value->type = IS_LONG;
break;
case PHP3_PG_FIELD_TYPE:
return_value->value.str.val = get_field_name(pgsql_result->conn,PQftype(pgsql_result,field->value.lval),list);
return_value->value.str.len = strlen(return_value->value.str.val);
return_value->type = IS_STRING;
break;
default:
RETURN_FALSE;
}
}
void php3_pgsql_field_name(INTERNAL_FUNCTION_PARAMETERS)
{
php3_pgsql_get_field_info(INTERNAL_FUNCTION_PARAM_PASSTHRU,PHP3_PG_FIELD_NAME);
}
void php3_pgsql_field_size(INTERNAL_FUNCTION_PARAMETERS)
{
php3_pgsql_get_field_info(INTERNAL_FUNCTION_PARAM_PASSTHRU,PHP3_PG_FIELD_SIZE);
}
void php3_pgsql_field_type(INTERNAL_FUNCTION_PARAMETERS)
{
php3_pgsql_get_field_info(INTERNAL_FUNCTION_PARAM_PASSTHRU,PHP3_PG_FIELD_TYPE);
}
void php3_pgsql_field_number(INTERNAL_FUNCTION_PARAMETERS)
{
pval *result,*field;
PGresult *pgsql_result;
int type;
if (ARG_COUNT(ht)!=2 || getParameters(ht, 2, &result, &field)==FAILURE) {
WRONG_PARAM_COUNT;
}
convert_to_long(result);
pgsql_result = (PGresult *) php3_list_find(result->value.lval,&type);
if (type!=php3_pgsql_module.le_result) {
php3_error(E_WARNING,"%d is not a PostgresSQL result index",result->value.lval);
RETURN_FALSE;
}
convert_to_string(field);
return_value->value.lval = PQfnumber(pgsql_result,field->value.str.val);
return_value->type = IS_LONG;
}
void php3_pgsql_result(INTERNAL_FUNCTION_PARAMETERS)
{
pval *result, *row, *field=NULL;
PGresult *pgsql_result;
int type,field_offset;
if (ARG_COUNT(ht)!=3 || getParameters(ht, 3, &result, &row, &field)==FAILURE) {
WRONG_PARAM_COUNT;
}
convert_to_long(result);
pgsql_result = (PGresult *) php3_list_find(result->value.lval,&type);
if (type!=php3_pgsql_module.le_result) {
php3_error(E_WARNING,"%d is not a PostgresSQL result index",result->value.lval);
RETURN_FALSE;
}
convert_to_long(row);
if (row->value.lval<0 || row->value.lval>=PQntuples(pgsql_result)) {
php3_error(E_WARNING,"Unable to jump to row %d on PostgresSQL result index %d",row->value.lval,result->value.lval);
RETURN_FALSE;
}
switch(field->type) {
case IS_STRING:
field_offset = PQfnumber(pgsql_result,field->value.str.val);
break;
default:
convert_to_long(field);
field_offset = field->value.lval;
break;
}
if (field_offset<0 || field_offset>=PQnfields(pgsql_result)) {
php3_error(E_WARNING,"Bad column offset specified");
RETURN_FALSE;
}
return_value->value.str.val = PQgetvalue(pgsql_result,row->value.lval,field_offset);
return_value->value.str.len = (return_value->value.str.val ? strlen(return_value->value.str.val) : 0);
return_value->value.str.val = safe_estrndup(return_value->value.str.val,return_value->value.str.len);
return_value->type = IS_STRING;
}
#define PHP3_PG_DATA_LENGTH 1
#define PHP3_PG_DATA_ISNULL 2
void php3_pgsql_data_info(INTERNAL_FUNCTION_PARAMETERS, int entry_type)
{
pval *result,*row,*field;
PGresult *pgsql_result;
int type,field_offset;
if (ARG_COUNT(ht)!=3 || getParameters(ht, 3, &result, &row, &field)==FAILURE) {
WRONG_PARAM_COUNT;
}
convert_to_long(result);
pgsql_result = (PGresult *) php3_list_find(result->value.lval,&type);
if (type!=php3_pgsql_module.le_result) {
php3_error(E_WARNING,"%d is not a PostgresSQL result index",result->value.lval);
RETURN_FALSE;
}
convert_to_long(row);
if (row->value.lval<0 || row->value.lval>=PQntuples(pgsql_result)) {
php3_error(E_WARNING,"Unable to jump to row %d on PostgresSQL result index %d",row->value.lval,result->value.lval);
RETURN_FALSE;
}
switch(field->type) {
case IS_STRING:
field_offset = PQfnumber(pgsql_result,field->value.str.val);
break;
default:
convert_to_long(field);
field_offset = field->value.lval;
break;
}
if (field_offset<0 || field_offset>=PQnfields(pgsql_result)) {
php3_error(E_WARNING,"Bad column offset specified");
RETURN_FALSE;
}
switch (entry_type) {
case PHP3_PG_DATA_LENGTH:
return_value->value.lval = PQgetlength(pgsql_result,row->value.lval,field_offset);
break;
case PHP3_PG_DATA_ISNULL:
return_value->value.lval = PQgetisnull(pgsql_result,row->value.lval,field_offset);
break;
}
return_value->type = IS_LONG;
}
void php3_pgsql_data_length(INTERNAL_FUNCTION_PARAMETERS)
{
php3_pgsql_data_info(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP3_PG_DATA_LENGTH);
}
void php3_pgsql_data_isnull(INTERNAL_FUNCTION_PARAMETERS)
{
php3_pgsql_data_info(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP3_PG_DATA_ISNULL);
}
void php3_pgsql_free_result(INTERNAL_FUNCTION_PARAMETERS)
{
pval *result;
PGresult *pgsql_result;
int type;
if (ARG_COUNT(ht)!=1 || getParameters(ht, 1, &result)==FAILURE) {
WRONG_PARAM_COUNT;
}
convert_to_long(result);
if (result->value.lval==0) {
RETURN_FALSE;
}
pgsql_result = (PGresult *) php3_list_find(result->value.lval,&type);
if (type!=php3_pgsql_module.le_result) {
php3_error(E_WARNING,"%d is not a PostgresSQL result index",result->value.lval);
RETURN_FALSE;
}
php3_list_delete(result->value.lval);
RETURN_TRUE;
}
void php3_pgsql_last_oid(INTERNAL_FUNCTION_PARAMETERS)
{
pval *result;
PGresult *pgsql_result;
int type;
if (ARG_COUNT(ht)!=1 || getParameters(ht, 1, &result)==FAILURE) {
WRONG_PARAM_COUNT;
}
convert_to_long(result);
pgsql_result = (PGresult *) php3_list_find(result->value.lval,&type);
if (type!=php3_pgsql_module.le_result) {
php3_error(E_WARNING,"%d is not a PostgresSQL result index",result->value.lval);
RETURN_FALSE;
}
return_value->value.str.val = (char *) PQoidStatus(pgsql_result);
if (return_value->value.str.val) {
return_value->value.str.len = strlen(return_value->value.str.val);
return_value->value.str.val = estrndup(return_value->value.str.val, return_value->value.str.len);
return_value->type = IS_STRING;
} else {
return_value->value.str.val = empty_string;
}
}
void php3_pgsql_lo_create(INTERNAL_FUNCTION_PARAMETERS)
{
pval *pgsql_link;
PGconn *pgsql;
Oid pgsql_oid;
int id, type;
switch(ARG_COUNT(ht)) {
case 0:
id = php3_pgsql_module.default_link;
break;
case 1:
if (getParameters(ht, 1, &pgsql_link)==FAILURE) {
RETURN_FALSE;
}
convert_to_long(pgsql_link);
id = pgsql_link->value.lval;
break;
default:
WRONG_PARAM_COUNT;
break;
}
pgsql = (PGconn *) php3_list_find(id,&type);
if (type!=php3_pgsql_module.le_link && type!=php3_pgsql_module.le_plink) {
php3_error(E_WARNING,"%d is not a PostgresSQL link index",id);
RETURN_FALSE;
}
/* XXX: Archive modes not supported until I get some more data. Don't think anybody's
using it anyway. I believe it's also somehow related to the 'time travel' feature of
PostgreSQL, that's on the list of features to be removed... Create modes not supported.
What's the use of an object that can be only written to, but not read from, and vice
versa? Beats me... And the access type (r/w) must be specified again when opening
the object, probably (?) overrides this. (Jouni)
*/
if ((pgsql_oid=lo_creat(pgsql, INV_READ|INV_WRITE))==0) {
php3_error(E_WARNING,"Unable to create PostgresSQL large object");
RETURN_FALSE;
}
return_value->value.lval = pgsql_oid;
return_value->type = IS_LONG;
}
void php3_pgsql_lo_unlink(INTERNAL_FUNCTION_PARAMETERS)
{
pval *pgsql_link, *oid;
PGconn *pgsql;
Oid pgsql_oid;
int id, type;
switch(ARG_COUNT(ht)) {
case 1:
if (getParameters(ht, 1, &oid)==FAILURE) {
RETURN_FALSE;
}
convert_to_long(oid);
pgsql_oid = oid->value.lval;
id = php3_pgsql_module.default_link;
break;
case 2:
if (getParameters(ht, 2, &pgsql_link, &oid)==FAILURE) {
RETURN_FALSE;
}
convert_to_long(pgsql_link);
id = pgsql_link->value.lval;
convert_to_long(oid);
pgsql_oid = oid->value.lval;
break;
default:
WRONG_PARAM_COUNT;
break;
}
pgsql = (PGconn *) php3_list_find(id,&type);
if (type!=php3_pgsql_module.le_link && type!=php3_pgsql_module.le_plink) {
php3_error(E_WARNING,"%d is not a PostgresSQL link index",id);
RETURN_FALSE;
}
if (lo_unlink(pgsql, pgsql_oid)==-1) {
php3_error(E_WARNING,"Unable to delete PostgresSQL large object %d", (int) pgsql_oid);
RETURN_FALSE;
}
RETURN_TRUE;
}
void php3_pgsql_lo_open(INTERNAL_FUNCTION_PARAMETERS)
{
pval *pgsql_link, *oid, *mode;
PGconn *pgsql;
Oid pgsql_oid;
int id, type, pgsql_mode=0, pgsql_lofd;
int create=0;
char *mode_string=NULL;
pgLofp *pgsql_lofp;
switch(ARG_COUNT(ht)) {
case 2:
if (getParameters(ht, 2, &oid, &mode)==FAILURE) {
RETURN_FALSE;
}
convert_to_long(oid);
pgsql_oid = oid->value.lval;
convert_to_string(mode);
mode_string = mode->value.str.val;
id = php3_pgsql_module.default_link;
break;
case 3:
if (getParameters(ht, 3, &pgsql_link, &oid, &mode)==FAILURE) {
RETURN_FALSE;
}
convert_to_long(pgsql_link);
id = pgsql_link->value.lval;
convert_to_long(oid);
pgsql_oid = oid->value.lval;
convert_to_string(mode);
mode_string = mode->value.str.val;
break;
default:
WRONG_PARAM_COUNT;
break;
}
pgsql = (PGconn *) php3_list_find(id,&type);
if (type!=php3_pgsql_module.le_link && type!=php3_pgsql_module.le_plink) {
php3_error(E_WARNING,"%d is not a PostgresSQL link index",id);
RETURN_FALSE;
}
/* r/w/+ is little bit more PHP-like than INV_READ/INV_WRITE and a lot of
faster to type. Unfortunately, doesn't behave the same way as fopen()...
(Jouni)
*/
if (strchr(mode_string, 'r')==mode_string) {
pgsql_mode |= INV_READ;
if (strchr(mode_string, '+')==mode_string+1) {
pgsql_mode |= INV_WRITE;
}
}
if (strchr(mode_string, 'w')==mode_string) {
pgsql_mode |= INV_WRITE;
create = 1;
if (strchr(mode_string, '+')==mode_string+1) {
pgsql_mode |= INV_READ;
}
}
pgsql_lofp = (pgLofp *) emalloc(sizeof(pgLofp));
if ((pgsql_lofd=lo_open(pgsql, pgsql_oid, pgsql_mode))==-1) {
if (create) {
if ((pgsql_oid=lo_creat(pgsql, INV_READ|INV_WRITE))==0) {
efree(pgsql_lofp);
php3_error(E_WARNING,"Unable to create PostgresSQL large object");
RETURN_FALSE;
} else {
if ((pgsql_lofd=lo_open(pgsql, pgsql_oid, pgsql_mode))==-1) {
if (lo_unlink(pgsql, pgsql_oid)==-1) {
efree(pgsql_lofp);
php3_error(E_WARNING,"Something's really messed up!!! Your database is badly corrupted in a way NOT related to PHP.");
RETURN_FALSE;
}
efree(pgsql_lofp);
php3_error(E_WARNING,"Unable to open PostgresSQL large object");
RETURN_FALSE;
} else {
pgsql_lofp->conn = pgsql;
pgsql_lofp->lofd = pgsql_lofd;
return_value->value.lval = php3_list_insert(pgsql_lofp, php3_pgsql_module.le_lofp);
return_value->type = IS_LONG;
}
}
} else {
php3_error(E_WARNING,"Unable to open PostgresSQL large object");
RETURN_FALSE;
}
} else {
pgsql_lofp->conn = pgsql;
pgsql_lofp->lofd = pgsql_lofd;
return_value->value.lval = php3_list_insert(pgsql_lofp, php3_pgsql_module.le_lofp);
return_value->type = IS_LONG;
}
}
void php3_pgsql_lo_close(INTERNAL_FUNCTION_PARAMETERS)
{
pval *pgsql_lofp;
int id, type;
pgLofp *pgsql;
switch(ARG_COUNT(ht)) {
case 1:
if (getParameters(ht, 1, &pgsql_lofp)==FAILURE) {
RETURN_FALSE;
}
convert_to_long(pgsql_lofp);
id = pgsql_lofp->value.lval;
break;
default:
WRONG_PARAM_COUNT;
break;
}
pgsql = (pgLofp *) php3_list_find(id,&type);
if (type!=php3_pgsql_module.le_lofp) {
php3_error(E_WARNING,"%d is not a PostgresSQL large object index",id);
RETURN_FALSE;
}
if (lo_close((PGconn *)pgsql->conn, pgsql->lofd)<0) {
php3_error(E_WARNING,"Unable to close PostgresSQL large object descriptor %d", pgsql->lofd);
RETVAL_FALSE;
} else {
RETVAL_TRUE;
}
php3_list_delete(id);
return;
}
void php3_pgsql_lo_read(INTERNAL_FUNCTION_PARAMETERS)
{
pval *pgsql_id, *len;
int id, buf_len, type;
char *buf;
pgLofp *pgsql;
switch(ARG_COUNT(ht)) {
case 2:
if (getParameters(ht, 2, &pgsql_id, &len)==FAILURE) {
RETURN_FALSE;
}
convert_to_long(pgsql_id);
id = pgsql_id->value.lval;
convert_to_long(len);
buf_len = len->value.lval;
break;
default:
WRONG_PARAM_COUNT;
break;
}
pgsql = (pgLofp *) php3_list_find(id,&type);
if (type!=php3_pgsql_module.le_lofp) {
php3_error(E_WARNING,"%d is not a PostgresSQL large object index",id);
RETURN_FALSE;
}
buf = (char *) emalloc(sizeof(char)*(buf_len+1));
if (!lo_read((PGconn *)pgsql->conn, pgsql->lofd, buf, buf_len)) {
efree(buf);
RETURN_FALSE;
}
return_value->value.str.val = buf;
return_value->value.str.len = strlen(return_value->value.str.val);
return_value->type = IS_STRING;
}
void php3_pgsql_lo_write(INTERNAL_FUNCTION_PARAMETERS)
{
pval *pgsql_id, *str;
int id, buf_len, nbytes, type;
char *buf;
pgLofp *pgsql;
switch(ARG_COUNT(ht)) {
case 2:
if (getParameters(ht, 2, &pgsql_id, &str)==FAILURE) {
RETURN_FALSE;
}
convert_to_long(pgsql_id);
id = pgsql_id->value.lval;
convert_to_string(str);
buf = str->value.str.val;
break;
default:
WRONG_PARAM_COUNT;
break;
}
pgsql = (pgLofp *) php3_list_find(id,&type);
if (type!=php3_pgsql_module.le_lofp) {
php3_error(E_WARNING,"%d is not a PostgresSQL large object index",id);
RETURN_FALSE;
}
buf_len = strlen(buf);
if ((nbytes = lo_write((PGconn *)pgsql->conn, pgsql->lofd, buf, buf_len))==-1) {
RETURN_FALSE;
}
return_value->value.lval = nbytes;
return_value->type = IS_LONG;
}
void php3_pgsql_lo_readall(INTERNAL_FUNCTION_PARAMETERS)
{
pval *pgsql_id;
int i, id, nbytes, tbytes, type;
char buf[8192];
pgLofp *pgsql;
int output=1;
switch(ARG_COUNT(ht)) {
case 1:
if (getParameters(ht, 1, &pgsql_id)==FAILURE) {
RETURN_FALSE;
}
convert_to_long(pgsql_id);
id = pgsql_id->value.lval;
break;
default:
WRONG_PARAM_COUNT;
break;
}
pgsql = (pgLofp *) php3_list_find(id,&type);
if (type!=php3_pgsql_module.le_lofp) {
php3_error(E_WARNING,"%d is not a PostgresSQL large object index",id);
RETURN_FALSE;
}
output=php3_header();
tbytes = 0;
while ((nbytes = lo_read((PGconn *)pgsql->conn, pgsql->lofd, buf, 8192))>0) {
for(i=0; i<nbytes; i++) {
if (output) PUTC(buf[i]);
}
tbytes += i;
}
return_value->value.lval = tbytes;
return_value->type = IS_LONG;
}
#endif
|