pgsqldb.c revision 5aee7a4da49ab97751023a6e096ee8d473f47056
7d32c065c7bb56f281651ae3dd2888f32ce4f1d9Bob Halley * Copyright (C) 2000 Internet Software Consortium.
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * Permission to use, copy, modify, and distribute this software for any
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * purpose with or without fee is hereby granted, provided that the above
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * copyright notice and this permission notice appear in all copies.
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
6324997211a5e2d82528dcde98e8981190a35faeMichael Graff/* $Id: pgsqldb.c,v 1.4 2000/11/17 23:57:32 bwelling Exp $ */
1db2e6b81a0f14d702b5204a73a00372fdfa01e3Bob Halley * A simple database driver that interfaces to a PostgreSQL database. This
f7b99290c31abeb20c55fc55391510450ce60423Mark Andrews * is not complete, and not designed for general use. It opens one
1db2e6b81a0f14d702b5204a73a00372fdfa01e3Bob Halley * connection to the database per zone, which is inefficient. It also may
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * not support multiple threads and probably doesn't handle quoting correctly.
2192b4497348ccab94ca6f3f779cec399c72a8efMark Andrews * The table must contain the fields "name", "rdtype", and "rdata", and
deaaf94332abbfdb3aff53675546acfed16e5eb6Mark Andrews * is expected to contain a properly constructed zone. The program "zonetodb"
deaaf94332abbfdb3aff53675546acfed16e5eb6Mark Andrews * creates such a table.
1db2e6b81a0f14d702b5204a73a00372fdfa01e3Bob Halley * * Canonicalize a string before writing it to the database.
f7b99290c31abeb20c55fc55391510450ce60423Mark Andrews * * "dest" must be an array of at least size 2*strlen(source) + 1.
deaaf94332abbfdb3aff53675546acfed16e5eb6Mark Andrews while (*source != 0) {
0e8cf9a887c70f96ac448b06c069d90b830215ccMark Andrews * This database operates on absolute names.
1db2e6b81a0f14d702b5204a73a00372fdfa01e3Bob Halley * Queries are converted into SQL queries and issued synchronously. Errors
1db2e6b81a0f14d702b5204a73a00372fdfa01e3Bob Halley * are handled really badly.
1db2e6b81a0f14d702b5204a73a00372fdfa01e3Bob Halleypgsqldb_lookup(const char *zone, const char *name, void *dbdata,
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews canonname = isc_mem_get(ns_g_mctx, strlen(name) * 2 + 1);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews "SELECT TTL,RDTYPE,RDATA FROM \"%s\" WHERE "
1c3191528684f3dd93ebb122298c2f8ebfc6d397Mark Andrews "lower(NAME) = lower('%s')", dbi->table, canonname);
1c3191528684f3dd93ebb122298c2f8ebfc6d397Mark Andrews isc_mem_put(ns_g_mctx, canonname, strlen(name) * 2 + 1);
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews if (!res || PQresultStatus(res) != PGRES_TUPLES_OK ) {
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews result = dns_sdb_putrr(lookup, type, ttl, data);
94a3bcd132e515b4baa0884ba9dd0f361d2e17bcMark Andrews * Issue an SQL query to return all nodes in the database and fill the
4529cdaedaf1a0a5f8ff89aeca510b7a4475446cBob Halley * allnodes structure.
94a3bcd132e515b4baa0884ba9dd0f361d2e17bcMark Andrewspgsqldb_allnodes(const char *zone, void *dbdata, dns_sdballnodes_t *allnodes) {
1db2e6b81a0f14d702b5204a73a00372fdfa01e3Bob Halley "SELECT TTL,NAME,RDTYPE,RDATA FROM \"%s\" ORDER BY NAME",
d981ca645597116d227a48bf37cc5edc061c854dBob Halley if (!res || PQresultStatus(res) != PGRES_TUPLES_OK ) {
char *endp;
return (DNS_R_BADTTL);
return (ISC_R_FAILURE);
return (ISC_R_SUCCESS);
static isc_result_t
return (ISC_R_FAILURE);
return (ISC_R_NOMEMORY);
return (ISC_R_NOMEMORY);
return (ISC_R_FAILURE);
return (ISC_R_SUCCESS);
pgsqldb_init(void) {
unsigned int flags;
flags = 0;
pgsqldb_clear(void) {