.. highlightlang:: us .. _pq_exec: pq_exec ======= .. index:: pq_exec .. us.tag pq_exec NOTREADYGERMAN New550 postgres :ref:`pq_exec` führt SQL-Anweisungen aus. .. function:: res = pq_exec(db, ssCommand) .. us.return **Returnwert** *res* ist ein Pointer, über den auf das Abfrage-Ergebnis zugegriffen werden kann (siehe auch :ref:`pq_nfields`, :ref:`pq_ntuples`, :ref:`pq_fname`, :ref:`pq_getvalue`). .. us.params **Parameter** .. uparam:: db *db* ist der von der Funktion :ref:`pq_connectdb` erzeugte Connection-Pointer. .. uparam:: ssCommand *ssCommand* ist eine Zeichenkette mit einem oder mehreren SQL-Anweisungen. .. us.example **Beispiel** :: def test_create() { conn = pq_connectdb("host=localhost port=5432 user=postgres password=postgres") print pq_error_message(conn) print pq_status(conn) r = pq_exec(conn, "drop TABLE test1"); ssMsg = pq_result_error_message(r) pq_exec(conn, "CREATE TABLE test1 (i int4, f float, t text, b bytea)") pq_exec(conn, "BEGIN") for (i in 1:100) { s = sprintf("INSERT INTO test1 values(%d, %f, %s, '\001\002')", .. i, sin(i), sprintf("%f", sin(i))); pq_exec(conn, s) } pq_exec(conn, "END") pq_finish(conn) } def test_select() { conn = pq_connectdb("host=localhost port=5432 user=postgres password=postgres") print pq_error_message(conn) print pq_status(conn) res = pq_exec(conn, "SELECT i, f, t, b from test1 limit 10") print n = pq_nfields(res); print nrows = pq_ntuples(res); for (i in 1:n) { printf("%-15s", pq_fname(res, i-1)); } printf("\n"); for (i in 1:nrows) { for (j in 1:n) { printf("%-15s", pq_getvalue(res, i-1, j-1)); } printf("\n"); } pq_finish(conn) } .. us.history **History** .. list-table:: :header-rows: 1 * - Version - Beschreibung * - 5.5.0 - Neu. .. seealso:: :ref:`uberblick-postgresql`, :ref:`pq_nfields`, :ref:`pq_ntuples`, :ref:`pq_fname`, :ref:`pq_getvalue` :sub:`id-1281527`