Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6f2c0d4

Browse files
committed
This is a proposed patch to doc/src/sgml/libpgtcl.sgml which documents
the libpgtcl "pg_execute" command. This was mentioned onpgsql-interfaces on Mar 3. I am posting it here in the hope that someonewill check to see if it makes sense and is correct SGML-wise. I did runit through jade, but this is my first try at this sort of thing.ljb
1 parent673788c commit6f2c0d4

File tree

1 file changed

+199
-0
lines changed

1 file changed

+199
-0
lines changed

‎doc/src/sgml/libpgtcl.sgml

Lines changed: 199 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@
6464
<ENTRY><function>pg_select</function></ENTRY>
6565
<ENTRY>loop over the result of a SELECT statement</ENTRY>
6666
</ROW>
67+
<ROW>
68+
<ENTRY><function>pg_execute</function></ENTRY>
69+
<ENTRY>send a query and optionally loop over the results</ENTRY>
6770
<ROW>
6871
<ENTRY><function>pg_listen</function></ENTRY>
6972
<ENTRY>establish a callback for NOTIFY messages</ENTRY>
@@ -994,6 +997,202 @@ This would work if table <classname>table</> has fields <structfield>control</>
994997

995998
<!-- ********************************************************** -->
996999

1000+
<REFENTRY ID="PGTCL-PGEXECUTE">
1001+
<REFMETA>
1002+
<REFENTRYTITLE>pg_execute</REFENTRYTITLE>
1003+
<REFMISCINFO>PGTCL - Query Processing</REFMISCINFO>
1004+
</REFMETA>
1005+
<REFNAMEDIV>
1006+
<REFNAME>pg_execute
1007+
</REFNAME>
1008+
<REFPURPOSE>
1009+
send a query and optionally loop over the results
1010+
</REFPURPOSE>
1011+
<INDEXTERM ID="IX-PGTCL-PGEXECUTE-1"><PRIMARY>pgtcl</PRIMARY><SECONDARY>query</SECONDARY></INDEXTERM>
1012+
<INDEXTERM ID="IX-PGTCL-PGEXECUTE-2"><PRIMARY>pg_execute</PRIMARY></INDEXTERM>
1013+
</REFNAMEDIV>
1014+
<REFSYNOPSISDIV>
1015+
<REFSYNOPSISDIVINFO>
1016+
<DATE>2002-03-06</DATE>
1017+
</REFSYNOPSISDIVINFO>
1018+
<SYNOPSIS>
1019+
pg_execute <OPTIONAL>-array <REPLACEABLE CLASS="PARAMETER">arrayVar</REPLACEABLE></OPTIONAL> <OPTIONAL>-oid <REPLACEABLE CLASS="PARAMETER">oidVar</REPLACEABLE></OPTIONAL> <REPLACEABLE CLASS="PARAMETER">dbHandle</REPLACEABLE> <REPLACEABLE CLASS="PARAMETER">queryString</REPLACEABLE> <OPTIONAL><REPLACEABLE CLASS="PARAMETER">queryProcedure</REPLACEABLE></OPTIONAL>
1020+
</SYNOPSIS>
1021+
1022+
<REFSECT2 ID="R2-PGTCL-PGEXECUTE-1">
1023+
<REFSECT2INFO>
1024+
<DATE>2002-03-06</DATE>
1025+
</REFSECT2INFO>
1026+
<TITLE>Inputs
1027+
</TITLE>
1028+
<VARIABLELIST>
1029+
<VARLISTENTRY>
1030+
<TERM>
1031+
<OPTIONAL>-array <REPLACEABLE CLASS="PARAMETER">arrayVar</REPLACEABLE></OPTIONAL>
1032+
</TERM>
1033+
<LISTITEM>
1034+
<PARA>Specifies the name of an array variable where result tuples are stored,
1035+
indexed by the field names.
1036+
This is ignored if queryString is not a SELECT statement. For SELECT
1037+
statements, if this option is not used, result tuples values are stored
1038+
in individual variables named according to the field names in the result.
1039+
</PARA>
1040+
</LISTITEM>
1041+
</VARLISTENTRY>
1042+
<VARLISTENTRY>
1043+
<TERM>
1044+
<OPTIONAL>-oid <REPLACEABLE CLASS="PARAMETER">oidVar</REPLACEABLE></OPTIONAL>
1045+
</TERM>
1046+
<LISTITEM>
1047+
<PARA>Specifies the name of a variable into which the OID from an INSERT
1048+
statement will be stored.
1049+
</PARA>
1050+
</LISTITEM>
1051+
</VARLISTENTRY>
1052+
<VARLISTENTRY>
1053+
<TERM>
1054+
<REPLACEABLE CLASS="PARAMETER">dbHandle</REPLACEABLE>
1055+
</TERM>
1056+
<LISTITEM>
1057+
<PARA>Specifies a valid database handle.
1058+
</PARA>
1059+
</LISTITEM>
1060+
</VARLISTENTRY>
1061+
<VARLISTENTRY>
1062+
<TERM>
1063+
<REPLACEABLE CLASS="PARAMETER">queryString</REPLACEABLE>
1064+
</TERM>
1065+
<LISTITEM>
1066+
<PARA>Specifies a valid SQL query.
1067+
</PARA>
1068+
</LISTITEM>
1069+
</VARLISTENTRY>
1070+
<VARLISTENTRY>
1071+
<TERM>
1072+
<OPTIONAL><REPLACEABLE CLASS="PARAMETER">queryProcedure</REPLACEABLE></OPTIONAL>
1073+
</TERM>
1074+
<LISTITEM>
1075+
<PARA>Optional command to execute for each result tuple of a SELECT statement.
1076+
</PARA>
1077+
</LISTITEM>
1078+
</VARLISTENTRY>
1079+
</VARIABLELIST>
1080+
1081+
</REFSECT2>
1082+
1083+
<REFSECT2 ID="R2-PGTCL-PGEXECUTE-2">
1084+
<REFSECT2INFO>
1085+
<DATE>2002-03-06</DATE>
1086+
</REFSECT2INFO>
1087+
<TITLE>Outputs
1088+
</TITLE>
1089+
<VARIABLELIST>
1090+
<VARLISTENTRY>
1091+
<TERM>
1092+
<REPLACEABLE CLASS="PARAMETER">ntuples</REPLACEABLE>
1093+
</TERM>
1094+
<LISTITEM>
1095+
<PARA>
1096+
The number of tuples affected or returned by the query.
1097+
</PARA>
1098+
</LISTITEM>
1099+
</VARLISTENTRY>
1100+
</VARIABLELIST>
1101+
</REFSECT2></REFSYNOPSISDIV>
1102+
1103+
<REFSECT1 ID="R1-PGTCL-PGEXECUTE-1">
1104+
<REFSECT1INFO>
1105+
<DATE>2002-03-06</DATE>
1106+
</REFSECT1INFO>
1107+
<TITLE>Description
1108+
</TITLE>
1109+
<PARA>
1110+
<FUNCTION>pg_execute</FUNCTION> submits a query to the PostgreSQL backend.
1111+
</PARA>
1112+
<PARA>
1113+
If the query is not a SELECT statement, the query is executed and the
1114+
number of tuples affected by the query is returned. If the query is an
1115+
INSERT and a single tuple is inserted, the OID of the inserted tuple is
1116+
stored in the oidVar variable if the optional <PARAMETER>-oid</PARAMETER>
1117+
argument is supplied.
1118+
</PARA>
1119+
<PARA>
1120+
If the query is a SELECT statement, the query is executed. For each tuple
1121+
in the result, the tuple field values are stored in the
1122+
<PARAMETER>arrayVar</PARAMETER> variable,
1123+
if supplied, using the field names as the array indexes, else in variables
1124+
named by the field names, and then the optional
1125+
<PARAMETER>queryProcedure</PARAMETER> is executed if supplied.
1126+
(Omitting the <PARAMETER>queryProcedure</PARAMETER> probably makes sense
1127+
only if the query will return a single tuple.)
1128+
The number of tuples selected is returned.
1129+
</PARA>
1130+
<PARA>
1131+
The <PARAMETER>queryProcedure</PARAMETER> can use the Tcl
1132+
<LITERAL>break</LITERAL>, <LITERAL>continue</LITERAL>, and
1133+
<LITERAL>return</LITERAL> commands, with the expected behavior.
1134+
Note that if the <PARAMETER>queryProcedure</PARAMETER> executes
1135+
<LITERAL>return</LITERAL>, <FUNCTION>pg_execute</FUNCTION> does
1136+
not return <PARAMETER>ntuples</PARAMETER>.
1137+
</PARA>
1138+
<PARA>
1139+
<FUNCTION>pg_execute</FUNCTION> is a newer function which provides a
1140+
superset of the features of <FUNCTION>pg_select</FUNCTION>, and can
1141+
replace <FUNCTION>pg_exec</FUNCTION> in many cases where access to
1142+
the result handle is not needed.
1143+
</PARA>
1144+
<PARA>
1145+
For backend-handled errors, <FUNCTION>pg_execute</FUNCTION> will
1146+
throw a Tcl error and return two element list. The first element
1147+
is an error code such as <LITERAL>PGRES_FATAL_ERROR</LITERAL>, and
1148+
the second element is the backend error text. For more serious
1149+
errors, such as failure to communicate with the backend,
1150+
<FUNCTION>pg_execute</FUNCTION> will throw a Tcl error and return
1151+
just the error message text.
1152+
</PARA>
1153+
1154+
</REFSECT1>
1155+
1156+
<REFSECT1 ID="R1-PGTCL-PGEXECUTE-2">
1157+
<TITLE>Usage
1158+
</TITLE>
1159+
<PARA>
1160+
In the following examples, error checking with <LITERAL>catch</LITERAL>
1161+
has been omitted for clarity.
1162+
</PARA>
1163+
<PARA>
1164+
Insert a row and save the OID in result_oid:
1165+
<ProgramListing>
1166+
pg_execute -oid result_oid $pgconn "insert into mytable values (1)"
1167+
</ProgramListing>
1168+
</PARA>
1169+
<PARA>
1170+
Print the item and value fields from each row:
1171+
<ProgramListing>
1172+
pg_execute -array d $pgconn "select item, value from mytable" {
1173+
puts "Item=$d(item) Value=$d(value)"
1174+
}
1175+
</ProgramListing>
1176+
</PARA>
1177+
<PARA>
1178+
Find the maximum and minimum values and store them in $s(max) and $s(min):
1179+
<ProgramListing>
1180+
pg_execute -array s $pgconn "select max(value) as max,\
1181+
min(value) as min from mytable"
1182+
</ProgramListing>
1183+
</PARA>
1184+
<PARA>
1185+
Find the maximum and minimum values and store them in $max and $min:
1186+
<ProgramListing>
1187+
pg_execute $pgconn "select max(value) as max, min(value) as min from mytable"
1188+
</ProgramListing>
1189+
</PARA>
1190+
</REFSECT1>
1191+
1192+
</REFENTRY>
1193+
1194+
<!-- ********************************************************** -->
1195+
9971196
<REFENTRY ID="PGTCL-PGLISTEN">
9981197
<REFMETA>
9991198
<REFENTRYTITLE>pg_listen</REFENTRYTITLE>

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp