File: README-postgres-helpers.md

package info (click to toggle)
pgtcl 1:2.6.1-1
  • links: PTS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 2,132 kB
  • sloc: ansic: 6,913; tcl: 643; sh: 470; makefile: 38; sql: 11
file content (73 lines) | stat: -rw-r--r-- 3,138 bytes parent folder | download
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

Welcome to the Postgres helpers functions.

These are actually quite soild.  They've been in use for years.

They are installed as part of *make install* from the top-level directory of the Pgtcl repo.

To make them available to your Tcl program, execute

```tcl
package require sc_postgres
```

* **sc_pg::foreach_tuple** *pgResult* *arrayName* *body*

    Given a postgres result, an array name, and a code body, fill the array in turn with each result tuple and execute the code body against it.

	This is largely superseded by the new Pgtcl pg_result -foreach option.


* **sc_pg::quote** *string*

    Quote a string for Postgres.  Puts single quotes around it and quotes single quotes if they're contained within it. It's just a synonym for pg_quote.

* **sc_pg::gen_insert_from_array** *tableName* *array*

    Return a postgres SQL insert statement based on the specified table and the contents of the specified array.


* **sc_pg::gen_update_from_array** *tableName* *array* *keyFieldList*

    Return a postgres SQL update statement based on the contents of an array.  Key field list specifies the keys and their values must be in the array.  The where clause is generated as a big "and", so all the keys in the key field list must match for a row to be updated.

* **sc_pg::perform_insert** *session* *insertStatement*

    Execute a statement on the given database session.  Grab the status out of the result.  Clear the result.  Return the status.

* **sc_pg::perform_update_from_array** *session* *tableName* *array* *keyFieldList*

    Generate an update statement and execute it on the given session.  Grab the status out of the result.  Clear the result.  Return the status.

* **sc_pg::gen_insert_from_lists** *tableName* *nameList* *valueList*

    Generate a sql insert command based on the contents of an element list and a one-for-one corresponding value list, and return it.

* **sc_pg::perform_insert_from_array** *session* *tableName* *arrayName*

    Generate a sql insert command based on the contents of an array and execute it against the specified database session.

* **sc_pg::clock_to_sql_time** *clockValue*

    Convert a clock value (integer seconds since 1970) to a SQL standard abstime value, accurate to a day.

* **sc_pg::clock_to_precise_sql_time** *clockValue*

    Generate a SQL time from an integer clock time (seconds since 1970), accurate to the second, with timezone.

* **sc_pg::clock_to_precise_sql_time_without_timezone** *clockValue*

    Generate a SQL time from an integer clock time (seconds since 1970), accurate to the second, without timezone.

* **sc_pg::sql_time_to_clock** *sqlDate*

    Given a SQL standard abstime value, convert it to an integer clock value (seconds since 1970) and return it.

* **sc_pg::res_must_succeed** *$resultHandle*

    The given postgres result must be PGRES_COMMAND_OK and, if it isn't, throw an error.  If it is OK, clear the postgres result.

* **sc_pg::res_dont_care** *$resultHandle*

    Whether or not the give postgres result is PGRES_COMMAND_OK, the result is cleared.  By default we write something to stdout, but that's probably dumb.