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
|
<html>
<head>
<title>AOLserver</title>
</head>
<body>
<h1>Database C Library Functions</h1>
<p>
$Header: /cvsroot/aolserver/aolserver.com/docs/devel/c/index.html,v 1.1 2002/03/07 19:15:35 kriston Exp $
<p>
<h2><a name= href=./>Ns_Db0or1Row</a></h2>
Execute an SQL statement that must return 1 row
<h3>Syntax</h3>
<pre>
Ns_Set *Ns_Db0or1Row(
Ns_DbHandle *handle,
char *sql,
int *nrows
);
</pre>
<h3>Description</h3>
The Ns_Db0or1Row function sends the given SQL statement to the
database and immediately processes the results. On zero rows, a newly
allocated Ns_Set with its keys set to the column names and values
uninitialized is returned and nrows is set to 0. On one row, a newly
allocated Ns_Set containing the values is returned and nrows is set to
1. You must eventually free this row using Ns_SetFree.
<p>
Note that an SQL select statement that does not return a row is
different from an SQL DML statement that does not return a row but
modifies the database. In the former case, Ns_Db0or1Row still returns
a newly allocated Ns_Set with the column names as the field key names
of the rows that would have been returned had any of the rows in the
database matched the select criteria. In the latter case, Ns_Db0or1Row
returns an error.
<p>
If the SQL statement returns more than one row or some database error
occurs, Ns_Db0or1Row returns NULL. Detailed error messages may have
accumulated in an internal buffer in the Ns_DbHandle.
<h3>Examples</h3>
<pre>
Ns_Set *row;
int nrows;
Ns_DbHandle *handle;
if ((handle = Ns_DbPoolGetHandle("aPoolName")) != NULL) {
row = Ns_Db0or1Row(handle, "select aName from aTable",
&nrows);
if (row != NULL && nrows == 1) {
char *value;
value = Ns_SetGet(row, "aName");
/* use `value' here */
Ns_SetFree(row);
}
}
</pre>
<p>
<hr>
<br>
<h2><a name= href=./>Ns_Db1Row</a></h2>
Execute an SQL statement that must return one row
<h3>Syntax</h3>
<pre>
Ns_Set *Ns_Db1Row(
Ns_DbHandle *handle,
char *sql
);
</pre>
<h3>Description</h3>
The Ns_Db1Row function calls the Ns_Db0or1Row function with the given
SQL statement. If Ns_Db0or1Row returns 1 row, Ns_Db1Row returns the
newly allocated Ns_Set for the row. You must eventually free this row
using Ns_SetFree. If NsDb0or1Row returns zero rows, Ns_Db1Row returns
NULL.
<p>
If the SQL statement returns zero rows or a database error has
occurred, Ns_Db1Row returns NULL. Detailed error messages may have
accumulated in an internal buffer in the Ns_DbHandle.
<h3>Examples</h3>
<pre>
Ns_Set *row;
Ns_DbHandle *handle;
if ((handle = Ns_DbPoolGetHandle("aPoolName")) != NULL) {
row = Ns_Db1Row(handle, "select aName from aTable");
if (row != NULL) {
char *value;
value = Ns_SetGet(row, "aName");
/* use `value' here */
Ns_SetFree(row);
}
}
</pre>
<p>
<hr>
<br>
<h2><a name= href=./>Ns_DbBindRow</a></h2>
Return an Ns_Set structure of column names to be returned by the
previously-executed SQL command
<h3>Syntax</h3>
<pre>
Ns_Set *Ns_DbBindRow (
Ns_DbHandle *handle
);
</pre>
<h3>Description</h3>
The Ns_DbBindRow function returns an Ns_Set structure whose key names
are the column names of rows to be returned by the SQL command
previously-executed by Ns_DbExec. If the SQL command does not return
rows (i.e., the Ns_DbExec function did not return NS_ROWS), NS_ERROR
is returned.
</pre>
<p>
<hr>
<br>
<h2><a name= href=./>Ns_DbBouncePool</a></h2>
Mark all database handles stale
<h3>Syntax</h3>
<pre>
int Ns_DbBouncePool(
char *poolname
);
</pre>
<h3>Description</h3>
All database handles for the specified database pool are marked stale.
When any database handle currently open is put back into the pool, its
connection to the database will be reset.
</pre>
<p>
<hr>
<br>
<h2><a name= href=./>Ns_DbCancel</a></h2>
Cancel an active SQL select statement
<h3>Syntax</h3>
<pre>
int Ns_DbCancel(
Ns_DbHandle *handle
);
</pre>
<h3>Description</h3>
The Ns_DbCancel function is similar to the Ns_DbFlush function, but
instead of allowing the select statement to complete and send all
selected rows, Ns_DbCancel sends a cancels message to the database.
This can result in faster interruption of a long-running query.
Ns_DbCancel returns NS_OK on success and NS_ERROR on error.
</pre>
<p>
<hr>
<br>
<h2><a name= href=./>Ns_DbDML</a></h2>
Execute an SQL DML statement
<h3>Syntax</h3>
<pre>
int Ns_DbDML(
Ns_DbHandle *handle,
char *sql
);
</pre>
<h3>Description</h3>
The Ns_DbDML function executes SQL that should be a data manipulation
language statement such as an insert or update, or data definition
language such as a create table. If the statement was executed
successfully, Ns_DbDML returns NS_OK. If the statement results in rows
being returned or a other database error, Ns_DbDML returns NS_ERROR.
Detailed error messages may have accumulated in an internal buffer in
the Ns_DbHandle.
<h3>Examples</h3>
<pre>
Ns_DbHandle *handle;
int status;
if ((handle = Ns_DbPoolGetHandle("aPoolName")) != NULL) {
status = Ns_DbDML(handle,
"insert into aTable (colName1,colName2) values (1,2)");
if (status != NS_OK) {
/* handle error condition */
}
}
</pre>
<p>
<hr>
<br>
<h2><a name= href=./>Ns_DbDriverDbType</a></h2>
Get database type
<h3>Syntax</h3>
<pre>
char* Ns_DbDriverDbType (
Ns_DbHandle* handle
);
</pre>
<h3>Description</h3>
Return the string name of the database type (e.g., "sybase").
</pre>
<p>
<hr>
<br>
<h2><a name= href=./>Ns_DbDriverName</a></h2>
Get driver for database
<h3>Syntax</h3>
<pre>
char *Ns_DbDriverName(
Ns_DbHandle *handle
);
</pre>
<h3>Description</h3>
The Ns_DbDriverName function returns the name of the database driver
associated with handle.
<p>
The storage for the string returned is owned by the database driver
and must not be freed or modified in any way.
</pre>
<p>
<hr>
<br>
<h2><a name= href=./>Ns_DbExec</a></h2>
Execute an SQL command
<h3>Syntax</h3>
<pre>
int Ns_DbExec (
Ns_DbHandle *handle,
char *sql
);
</pre>
<h3>Description</h3>
The Ns_DbExec function executes the specified SQL command on the
specified database connection. Ns_DbExec returns one of the following
status codes:
<p>
NS_ERROR
<p>
if the SQL command fails
<p>
NS_DML
<p>
if the SQL command is DML (Data Manipulation Language) or DDL (Data
Definition Language)
<p>
NS_ROWS
<p>
if the SQL command will return rows (such as a SELECT command)
<p>
This function allows you to write a true ad hoc query tool and process
SQL statements without knowing ahead of time if they return rows or
are DDL or DML statements.
</pre>
<p>
<hr>
<br>
<h2><a name= href=./>Ns_DbFlush</a></h2>
Flush any waiting rows
<h3>Syntax</h3>
<pre>
int Ns_DbFlush(
Ns_DbHandle *handle
);
</pre>
<h3>Description</h3>
The Ns_DbFlush function fetches and dumps any waiting rows after an
Ns_DbSelect. This function is useful when you have already fetched all
the rows you intend to process. Ns_DbFlush returns NS_OK after
successfully flushing the database or NS_ERROR on error.
<p>
Ns_DbFlush is called automatically when Ns_DbHandle's are returned to
their pools with the Ns_DbPutHandle function to make sure the handle
is ready the next time it is used.
<p>
Some database drivers will also cancel any active transactions when
Ns_DbFlush is called.
</pre>
<p>
<hr>
<br>
<h2><a name= href=./>Ns_DbGetRow</a></h2>
Fetch the next waiting row after an Ns_DbSelect
<h3>Syntax</h3>
<pre>
int Ns_DbGetRow(
Ns_DbHandle *handle,
Ns_Set *row
);
</pre>
<h3>Description</h3>
The Ns_DbGetRow function fetches the next row waiting to be retrieved
after an Ns_DbSelect. The row Ns_Set must be the result of a previous
Ns_DbSelect. Ns_DbGetRow frees any existing values of the set and sets
the values to the next row fetched from the database. Possible return
values are:
<p>
NS_OK
<p>
A row has been fetched and more rows may be waiting.
<p>
NS_END_DATA
<p>
No row has been fetched and there are no more rows waiting.
<p>
NS_ERROR
<p>
A database error occurred, or the function has already returned
NS_END_DATA but has been called again anyway.
<p>
You cannot call Ns_DbDML, Ns_Db1Row, or Ns_Db0or1Row with the same
database handle while fetching rows from the database in an
Ns_DbGetRow loop. Doing so flushes any waiting rows and a subsequent
call to Ns_DbGetRow will fail. You can do so if you use separate
database handles.
<h3>Examples</h3>
<pre>
Ns_DbHandle *handle;
Ns_Set *row;
int status;
handle = Ns_DbPoolGetHandle("mypool");
row = Ns_DbSelect(handle, "select * from mytable");
if (row == NULL) {
/*... handle select error ...*/
}
while ((status = Ns_DbGetRow(handle, row)) == NS_OK) {
/*... process the row fetched from the database ...*/
}
if (status != NS_END_DATA) {
/*... handle get row error ...*/
}
</pre>
<p>
<hr>
<br>
<h2><a name= href=./>Ns_DbInterpretSqlFile</a></h2>
Parse DML statements and send to database
<h3>Syntax</h3>
<pre>
int Ns_DbInterpretSqlFile (
Ns_DbHandle* handle,
char* filename
);
</pre>
<h3>Description</h3>
Parse DML statements from an SQL file and send them to the database
for execution.
</pre>
<p>
<hr>
<br>
<h2><a name= href=./>Ns_DbPoolAllowable</a></h2>
Determine if pool is available
<h3>Syntax</h3>
<pre>
int Ns_DbPoolAllowable(
char *hServer,
char *poolname
);
</pre>
<h3>Description</h3>
The Ns_DbPoolAllowable function returns NS_TRUE if the specified pool
poolname is available on the server hServer. It returns NS_FALSE if
the pool does not exist or if the server is not allowed to use this
pool. See the "ns/server/server-name/module/nscgi" section in the
AOLserver Administrator's Guide for information on setting allowable
pools for a server.
</pre>
<p>
<hr>
<br>
<h2><a name= href=./>Ns_DbPoolDefault</a></h2>
Get default pool
<h3>Syntax</h3>
<pre>
char* Ns_DbPoolDefault (
char* server
);
</pre>
<h3>Description</h3>
Return the string name of default pool or NULL if no default is
defined.
</pre>
<p>
<hr>
<br>
<h2><a name= href=./>Ns_DbPool<h3>Description</h3>
</a></h2>
Get pool description
<h3>Syntax</h3>
<pre>
char *Ns_DbPool<h3>Description</h3>
(
char *poolname
);
</pre>
<h3>Description</h3>
The Ns_DbPool<h3>Description</h3>
function returns the description associated
with the specified pool in the AOLserver configuration file.
<p>
The storage for the string returned is located in the configuration
data memory. You must not deallocate or modify this string in any way.
</pre>
<p>
<hr>
<br>
<h2><a name= href=./>Ns_DbPoolGetHandle</a></h2>
Get database handle from pool
<h3>Syntax</h3>
<pre>
Ns_DbHandle *Ns_DbPoolGetHandle(
char *poolname
);
</pre>
<h3>Description</h3>
The Ns_DbPoolGetHandle function gets a database handle from the pool
specified by poolname. It returns NULL on error. Details relating to
error conditions are written to the server log. You must request all
the database handles you will need for a specific pool with one call
to Ns_DbPoolGetHandle (if you need only one handle) or
Ns_DbPoolGetMultipleHandles (if you need more than one handle).
<h3>Examples</h3>
<pre>
Ns_DbHandle *handle;
if ((handle = Ns_DbPoolGetHandle("aPoolName")) != NULL) {
Ns_Set *row;
row = Ns_DbSelect(handle, "select * from aTable");
...
}
</pre>
<p>
<hr>
<br>
<h2><a name= href=./>Ns_DbPoolGetMultipleHandles</a></h2>
Get multiple database handles from pool
<h3>Syntax</h3>
<pre>
int Ns_DbPoolGetMultipleHandles(
Ns_DbHandle **handles,
char *poolname,
int nhandles
);
</pre>
<h3>Description</h3>
The Ns_DbPoolGetMultipleHandles function gets a database handle from
the pool specified by poolname and returns an array of handles
(handles). If all of the specified number of handles (nhandles) are
not available, the function waits until they are. It returns NS_OK if
all requested handles are returned or NS_ERROR on an error condition.
You must request all the database handles you will need for a specific
pool with one call to Ns_DbPoolGetHandle (if you need only one handle)
or Ns_DbPoolGetMultipleHandles (if you need more than one handle). You
must release all your database handles explicitly (with
Ns_DbPoolPutHandle) before acquiring more.
<h3>Examples</h3>
<pre>
#define NUM_HANDLES 5
Ns_DbHandle **handles;
handles = Ns_Malloc(NUM_HANDLES * sizeof (Ns_DbHandle *));
if (Ns_DbPoolGetMultipleHandles(handles, "aPoolName",
NUM_HANDLES) != NS_OK) {
Ns_Set *row;
row = Ns_DbSelect(handles[0], "select * from aTable");
...
} else {
/* handle error condition */
}
</pre>
<p>
<hr>
<br>
<h2><a name= href=./>Ns_DbPoolList</a></h2>
Get a list of available pools for a server
<h3>Syntax</h3>
<pre>
char *Ns_DbPoolList(
char *hServer
);
</pre>
<h3>Description</h3>
The Ns_DbPoolList function returns a list of pools available on the
specified server. Upon completion, the returned pointer points to a
list of pools in the following format:
"pool1\0pool2\0pool3\0\0"
<h3>Examples</h3>
<pre>
char *pools;
pools = Ns_DbPoolList("serverName");
while (*pools != '\0') {
printf("%s\n", pools);
pools += strlen(pools) + 1;
}
</pre>
<p>
<hr>
<br>
<h2><a name= href=./>Ns_DbPoolPutHandle</a></h2>
Release a database handle for a pool
<h3>Syntax</h3>
<pre>
void Ns_DbPoolPutHandle(
Ns_DbHandle *handle
);
</pre>
<h3>Description</h3>
The Ns_DbPoolPutHandle function releases the database handle handle
into the pool it was derived from. If the handle was not originally
obtained from a pool, an error message is written to the log.
<h3>Examples</h3>
<pre>
Ns_DbHandle *handle;
if ((handle = Ns_DbPoolGetHandle("aPoolName")) != NULL) {
Ns_Set *row;
row = Ns_DbSelect(handle, "select * from aTable");
...
Ns_DbPoolPutHandle(handle); /* done with handle */
}
</pre>
<p>
<hr>
<br>
<h2><a name= href=./>Ns_DbPoolTimedGetHandle</a></h2>
Get database handle from pool with timeout
<h3>Syntax</h3>
<pre>
Ns_DbHandle *Ns_DbPoolTimedGetHandle(
char *poolname,
int timeout
);
</pre>
<h3>Description</h3>
The Ns_DbPoolTimedGetHandle function gets a database handle from the
pool specified by poolname. If a timeout is not specified or timeout
is zero, it will wait indefinitely (perhaps forever) for the handle to
become available. If timeout is greater than zero, it will either
return with the handle within that time period, or return "" if the
time period was exceeded. If timeout is less than zero, it will not
block.
<p>
It returns NULL on error or if the attempt times out. Details relating
to error conditions are written to the server log. You must request
all the database handles you will need for a specific pool with one
call to Ns_DbPoolTimedGetHandle (if you need only one handle) or
Ns_DbPoolGetTimedMultipleHandles (if you need more than one handle).
You must release all your database handles explicitly (with
Ns_DbPoolPutHandle) before acquiring more.
<p>
<hr>
<br>
<h2><a name= href=./>Ns_DbPoolTimedGetMultipleHandles</a></h2>
Get multiple database handles from pool with timeout
<h3>Syntax</h3>
<pre>
int Ns_DbPoolTimedGetMultipleHandles(
Ns_DbHandle **handles,
char *poolname,
int nhandles,
int timeout
);
</pre>
<h3>Description</h3>
The Ns_DbPoolTimedGetMultipleHandles function gets multiple database
handles from the pool specified by poolname and returns an array of
handles (handles). If all of the specified number of handles
(nhandles) are not available, the function waits until they are,
depending on timeout. If a timeout is not specified or timeout is
zero, it will wait indefinitely (perhaps forever) for the handles to
become available. If timeout is greater than zero, it will either
return with the handles within that time period, or return "" if the
time period was exceeded. If timeout is less than zero, it will not
block.
<p>
It returns NS_OK if all requested handles are returned, NS_TIMEOUT if
the attempt timed out, or NS_ERROR on an error condition. You must
request all the database handles you will need for a specific pool
with one call to Ns_DbPoolTimedGetHandle (if you need only one handle)
or Ns_DbPoolTimedGetMultipleHandles (if you need more than one
handle). You must release all your database handles explicitly (with
Ns_DbPoolPutHandle) before acquiring more.
<p>
<hr>
<br>
<h2><a name= href=./>Ns_DbQuoteValue</a></h2>
Adds extra single quote to single quotes in string
<h3>Syntax</h3>
<pre>
void Ns_DbQuoteValue(
Ns_DString *pds,
char *string
);
</pre>
<h3>Description</h3>
The Ns_DbQuoteValue function places an additional single quote (') in
front of all single quotes in the string. The result is then copied to
pds. This function is typically used to pre-process a string used in
an SQL statement.
</pre>
<p>
<hr>
<br>
<h2><a name= href=./>Ns_DbRegisterDriver</a></h2>
Register database driver with the server
<h3>Syntax</h3>
<pre>
int Ns_DbRegisterDriver(
char *hDriver,
Ns_DbProc *procs
);
</pre>
<h3>Description</h3>
The Ns_DbRegisterDriver function registers a database driver with the
server. The procs argument specifies the functions that implement the
driver. For a complete example of a database driver for the Postgres95
DBMS, see the directory example/C/nspg under the AOLserver
installation directory. Ns_DbRegisterDriver returns a status of NS_OK
or NS_ERROR.
</pre>
<p>
<hr>
<br>
<h2><a name= href=./>Ns_DbSelect</a></h2>
Send a row-generating query to the database
<h3>Syntax</h3>
<pre>
Ns_Set *Ns_DbSelect(
Ns_DbHandle *handle,
char *sql
);
</pre>
<h3>Description</h3>
The Ns_DbSelect function executes the given SQL statement. It returns
an Ns_Set where the field key names are the column names that were
returned by the select statement on success. The field values are NULL
until the first call to Ns_DbGetRow where they are replaced with the
values of the first row fetched from the database. The set is
statically allocated; do not free it with Ns_SetFree when your query
is complete.
<p>
On error, Ns_DbSelect returns NULL. Detailed error message may have
accumulated in an internal buffer in the Ns_DbHandle.
<h3>Examples</h3>
<pre>
Ns_DbHandle *handle;
if ((handle = Ns_DbPoolGetHandle("aPoolName")) != NULL) {
Ns_Set *row;
row = Ns_DbSelect(handle, "select * from aTable");
if (row == NULL) {
/*... handle select error ...*/
}
while ((status = Ns_DbGetRow(handle, row)) == NS_OK) {
/*... process the row fetched from the database ...*/
}
if (status != NS_END_DATA) {
/*... handle get row error ...*/
}
Ns_DbPoolPutHandle(handle); /* done with handle */
}
</pre>
<p>
<hr>
<br>
<h2><a name= href=./>Ns_DbSetException</a></h2>
Set last error message for database
<h3>Syntax</h3>
<pre>
void Ns_DbSetException(
Ns_DbHandle *handle,
char *code,
char *msg
);
</pre>
<h3>Description</h3>
The Ns_DbSetException function sets the last error message for the
database referenced by handle. The code argument cannot be larger than
5 characters.
</pre>
<p>
<hr>
<br>
<h2><a name= href=./>Ns_DbSpExec</a></h2>
Run a stored procedure
<h3>Syntax</h3>
<pre>
int Ns_DbSpExec(
Ns_DbHandle *handle
);
</pre>
<h3>Description</h3>
Run a stored procedure begun with Ns_DbSpStart. Returns NS_OK on
success, NS_ERROR on failure.
</pre>
<p>
<hr>
<br>
<h2><a name= href=./>Ns_DbSpGetParams</a></h2>
Get output parameters from a stored procedure
<h3>Syntax</h3>
<pre>
Ns_Set * Ns_DbSpGetParams(
Ns_DbHandle *handle
);
</pre>
<h3>Description</h3>
Get output parameters after running a stored procedure with
Ns_DbSpExec. The returned set is allocated by this function and should
be freed by the caller.
</pre>
<p>
<hr>
<br>
<h2><a name= href=./>Ns_DbSpReturnCode</a></h2>
Get return code from a stored procedure
<h3>Syntax</h3>
<pre>
int Ns_DbSpReturnCode(
Ns_DbHandle *handle,
char *returnCode,
int bufsize
);
</pre>
<h3>Description</h3>
Get the return code from a stored procedure after running Ns_DbSpExec.
Returns NS_OK on success, NS_ERROR on failure.
</pre>
<p>
<hr>
<br>
<h2><a name= href=./>Ns_DbSpSetParam</a></h2>
Set input parameter for stored procedure
<h3>Syntax</h3>
<pre>
int Ns_DbSpSetParam(
Ns_DbHandle *handle,
char *paramname,
char *paramtype,
char *inout,
char *value
);
</pre>
<h3>Description</h3>
In preparing to run stored procedure, this function sets a parameter
to pass to that stored procedure. You must have executed Ns_DbSpStart
first. The paramname is the name of the parameter, such as "@foo";
paramtype is the data type, such as "int" or "varchar". The inout
argument is either "in" or "out", depending on what kind of parameter
it is. The value argument is the value to pass to the stored proc,
such as "123" (it's always a string). Returns NS_OK on success,
NS_ERROR on failure.
</pre>
<p>
<hr>
<br>
<h2><a name= href=./>Ns_DbSpStart</a></h2>
Start execution of a stored procedure
<h3>Syntax</h3>
<pre>
int Ns_DbSpStart(
Ns_DbHandle *handle,
char *procname
);
</pre>
<h3>Description</h3>
Start execution of a stored procedure. This must be run before any
other Ns_DbSp* call. Returns NS_OK on success, NS_ERROR on failure.
</pre>
<p>
<hr>
<br>
</body>
</html>
|